mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
67 lines
2.0 KiB
Plaintext
67 lines
2.0 KiB
Plaintext
// #target: x64_darwin
|
|
|
|
extern func char*! readLine();
|
|
extern func int! atoi(char*);
|
|
|
|
extern func int printf(char* fmt, ...);
|
|
|
|
func void main()
|
|
{
|
|
int val;
|
|
if (try val = atoi(readLine()))
|
|
{
|
|
printf("You typed the number %d\n", val);
|
|
return;
|
|
}
|
|
printf("You didn't type an integer :(\n");
|
|
}
|
|
|
|
// #expect: try_with_chained_unwrap.ll
|
|
|
|
define void @main() #0 {
|
|
entry:
|
|
%val = alloca i32, align 4
|
|
%retparam = alloca i32, align 4
|
|
%retparam1 = alloca i8*, align 8
|
|
%result = alloca %error_union, align 8
|
|
%result2 = alloca %error_union, align 8
|
|
store i32 0, i32* %val, align 4
|
|
%0 = call { i64, i64 } @readLine(i8** %retparam1)
|
|
%1 = bitcast %error_union* %result to { i64, i64 }*
|
|
store { i64, i64 } %0, { i64, i64 }* %1, align 8
|
|
%err_domain = getelementptr inbounds %error_union, %error_union* %result, i32 0, i32 0
|
|
%2 = load i64, i64* %err_domain, align 8
|
|
%not_err = icmp eq i64 %2, 0
|
|
br i1 %not_err, label %after_check, label %catch_landing
|
|
|
|
after_check:
|
|
%3 = load i8*, i8** %retparam1, align 8
|
|
%4 = call { i64, i64 } @atoi(i32* %retparam, i8* %3)
|
|
%5 = bitcast %error_union* %result2 to { i64, i64 }*
|
|
store { i64, i64 } %4, { i64, i64 }* %5, align 8
|
|
%err_domain3 = getelementptr inbounds %error_union, %error_union* %result2, i32 0, i32 0
|
|
%6 = load i64, i64* %err_domain3, align 8
|
|
%not_err4 = icmp eq i64 %6, 0
|
|
br i1 %not_err4, label %after_check5, label %catch_landing
|
|
|
|
after_check5:
|
|
%7 = load i32, i32* %retparam, align 4
|
|
store i32 %7, i32* %val, align 4
|
|
br label %phi_try_catch
|
|
|
|
catch_landing:
|
|
br label %phi_try_catch
|
|
|
|
phi_try_catch:
|
|
%val6 = phi i1 [ true, %after_check5 ], [ false, %catch_landing ]
|
|
br i1 %val6, label %if.then, label %if.exit
|
|
|
|
if.then:
|
|
%8 = load i32, i32* %val, align 4
|
|
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0), i32 %8)
|
|
ret void
|
|
|
|
if.exit:
|
|
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i32 0, i32 0))
|
|
ret void
|
|
} |