mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
152 lines
5.0 KiB
C
152 lines
5.0 KiB
C
// #target: x64-darwin
|
|
|
|
extern fn int! err();
|
|
optenum FooErr { QBERT }
|
|
extern fn int printf(char* fmt, ...);
|
|
|
|
fn void main()
|
|
{
|
|
int x = 123;
|
|
int! z = 234;
|
|
int! w;
|
|
int gh = 1;
|
|
if (try x = z && try gh = w)
|
|
{
|
|
printf("Success %d && %d!\n", x, gh);
|
|
}
|
|
if (try x = z + w)
|
|
{
|
|
printf("Test\n");
|
|
}
|
|
anyerr e;
|
|
if (catch e = z)
|
|
{
|
|
printf("Oh noes!\n");
|
|
}
|
|
}
|
|
|
|
// #expect: try_assign.ll
|
|
|
|
define void @try_assign.main() #0 {
|
|
entry:
|
|
%x = alloca i32, align 4
|
|
%z = alloca i32, align 4
|
|
%z.f = alloca i64, align 8
|
|
%w = alloca i32, align 4
|
|
%w.f = alloca i64, align 8
|
|
%gh = alloca i32, align 4
|
|
%e = alloca i64, align 8
|
|
store i32 123, i32* %x, align 4
|
|
store i32 234, i32* %z, align 4
|
|
store i64 0, i64* %z.f, align 8
|
|
store i64 0, i64* %w.f, align 8
|
|
store i32 0, i32* %w, align 4
|
|
store i32 1, i32* %gh, align 4
|
|
%0 = load i64, i64* %z.f, align 8
|
|
%not_err = icmp eq i64 %0, 0
|
|
br i1 %not_err, label %after_check, label %catch_landing
|
|
|
|
after_check: ; preds = %entry
|
|
%1 = load i32, i32* %z, align 4
|
|
store i32 %1, i32* %x, align 4
|
|
br label %phi_try_catch
|
|
|
|
catch_landing: ; preds = %entry
|
|
br label %phi_try_catch
|
|
|
|
phi_try_catch: ; preds = %catch_landing, %after_check
|
|
%val = phi i1 [ true, %after_check ], [ false, %catch_landing ]
|
|
br i1 %val, label %chain_next, label %fail_chain
|
|
|
|
chain_next: ; preds = %phi_try_catch
|
|
%2 = load i64, i64* %w.f, align 8
|
|
%not_err1 = icmp eq i64 %2, 0
|
|
br i1 %not_err1, label %after_check2, label %catch_landing3
|
|
|
|
after_check2: ; preds = %chain_next
|
|
%3 = load i32, i32* %w, align 4
|
|
store i32 %3, i32* %gh, align 4
|
|
br label %phi_try_catch4
|
|
|
|
catch_landing3: ; preds = %chain_next
|
|
br label %phi_try_catch4
|
|
|
|
phi_try_catch4: ; preds = %catch_landing3, %after_check2
|
|
%val5 = phi i1 [ true, %after_check2 ], [ false, %catch_landing3 ]
|
|
br i1 %val5, label %chain_next6, label %fail_chain
|
|
|
|
chain_next6: ; preds = %phi_try_catch4
|
|
br label %end_chain
|
|
|
|
fail_chain: ; preds = %phi_try_catch4, %phi_try_catch
|
|
br label %end_chain
|
|
|
|
end_chain: ; preds = %fail_chain, %chain_next6
|
|
%chain.phi = phi i1 [ true, %chain_next6 ], [ false, %fail_chain ]
|
|
br i1 %chain.phi, label %if.then, label %if.exit
|
|
|
|
if.then: ; preds = %end_chain
|
|
%4 = load i32, i32* %x, align 4
|
|
%5 = load i32, i32* %gh, align 4
|
|
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i32 0, i32 0), i32 %4, i32 %5)
|
|
br label %if.exit
|
|
|
|
if.exit: ; preds = %if.then, %end_chain
|
|
%7 = load i64, i64* %z.f, align 8
|
|
%not_err7 = icmp eq i64 %7, 0
|
|
br i1 %not_err7, label %after_check8, label %catch_landing11
|
|
|
|
after_check8: ; preds = %if.exit
|
|
%8 = load i32, i32* %z, align 4
|
|
%9 = load i64, i64* %w.f, align 8
|
|
%not_err9 = icmp eq i64 %9, 0
|
|
br i1 %not_err9, label %after_check10, label %catch_landing11
|
|
|
|
after_check10: ; preds = %after_check8
|
|
%10 = load i32, i32* %w, align 4
|
|
%add = add i32 %8, %10
|
|
store i32 %add, i32* %x, align 4
|
|
br label %phi_try_catch12
|
|
|
|
catch_landing11: ; preds = %after_check8, %if.exit
|
|
br label %phi_try_catch12
|
|
|
|
phi_try_catch12: ; preds = %catch_landing11, %after_check10
|
|
%val13 = phi i1 [ true, %after_check10 ], [ false, %catch_landing11 ]
|
|
br i1 %val13, label %if.then14, label %if.exit15
|
|
|
|
if.then14: ; preds = %phi_try_catch12
|
|
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0))
|
|
br label %if.exit15
|
|
|
|
if.exit15: ; preds = %if.then14, %phi_try_catch12
|
|
store i64 0, i64* %e, align 8
|
|
br label %testblock
|
|
|
|
testblock: ; preds = %if.exit15
|
|
%12 = load i64, i64* %z.f, align 8
|
|
%not_err16 = icmp eq i64 %12, 0
|
|
br i1 %not_err16, label %after_check17, label %error
|
|
|
|
error: ; preds = %testblock
|
|
store i64 %12, i64* %e, align 8
|
|
br label %end_block
|
|
|
|
after_check17: ; preds = %testblock
|
|
store i64 0, i64* %e, align 8
|
|
br label %end_block
|
|
|
|
end_block: ; preds = %after_check17, %error
|
|
%13 = load i64, i64* %e, align 8
|
|
%neq = icmp ne i64 %13, 0
|
|
br i1 %neq, label %if.then18, label %if.exit19
|
|
|
|
if.then18: ; preds = %end_block
|
|
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0))
|
|
br label %if.exit19
|
|
|
|
if.exit19: ; preds = %if.then18, %end_block
|
|
ret void
|
|
}
|
|
|