mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
57 lines
1.8 KiB
C
57 lines
1.8 KiB
C
// #target: macos-x64
|
|
|
|
extern fn char*! readLine();
|
|
extern fn int! atoi(char*);
|
|
|
|
extern fn int printf(char* fmt, ...);
|
|
|
|
fn 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 @try_with_chained_unwrap.main() #0 {
|
|
entry:
|
|
%val = alloca i32, align 4
|
|
%retparam = alloca i32, align 4
|
|
%retparam1 = alloca i8*, align 8
|
|
store i32 0, i32* %val, align 4
|
|
%0 = call i64 @readLine(i8** %retparam1)
|
|
%not_err = icmp eq i64 %0, 0
|
|
br i1 %not_err, label %after.errcheck, label %catch_landing
|
|
|
|
after.errcheck: ; preds = %entry
|
|
%1 = load i8*, i8** %retparam1, align 8
|
|
%2 = call i64 @atoi(i32* %retparam, i8* %1)
|
|
%not_err2 = icmp eq i64 %2, 0
|
|
br i1 %not_err2, label %after.errcheck3, label %catch_landing
|
|
|
|
after.errcheck3: ; preds = %after.errcheck
|
|
%3 = load i32, i32* %retparam, align 4
|
|
store i32 %3, i32* %val, align 4
|
|
br label %phi_try_catch
|
|
|
|
catch_landing: ; preds = %after.errcheck, %entry
|
|
br label %phi_try_catch
|
|
|
|
phi_try_catch: ; preds = %catch_landing, %after.errcheck3
|
|
%val4 = phi i1 [ true, %after.errcheck3 ], [ false, %catch_landing ]
|
|
br i1 %val4, label %if.then, label %if.exit
|
|
|
|
if.then: ; preds = %phi_try_catch
|
|
%4 = load i32, i32* %val, align 4
|
|
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0), i32 %4)
|
|
ret void
|
|
|
|
if.exit: ; preds = %phi_try_catch
|
|
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i32 0, i32 0))
|
|
ret void
|
|
} |