mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
230 lines
7.4 KiB
C
230 lines
7.4 KiB
C
// #target: macos-x64
|
|
|
|
module foo;
|
|
|
|
extern fn void printf(char*, ...);
|
|
|
|
fn void main()
|
|
{
|
|
for (int i = 0; i < 12; i++)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 1 .. 3:
|
|
printf("1-3\n");
|
|
case 7 .. 277:
|
|
printf("7-277 %d\n", i);
|
|
case 4 .. 5:
|
|
printf("4-5 %d\n", i);
|
|
case 6:
|
|
printf("6 %d\n", i);
|
|
default:
|
|
printf("Something else: %d\n", i);
|
|
nextcase 5;
|
|
}
|
|
}
|
|
for (int i = 0; i < 12; i++)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 1 .. 3:
|
|
printf("1-3\n");
|
|
case 4 .. 6:
|
|
printf("4-6 %d\n", i);
|
|
default:
|
|
printf("Something else: %d\n", i);
|
|
nextcase 5;
|
|
}
|
|
}
|
|
bool x = false;
|
|
switch (x)
|
|
{
|
|
case true:
|
|
printf("Was true!\n");
|
|
case false:
|
|
printf("Was false!\n");
|
|
}
|
|
}
|
|
|
|
/* #expect: foo.ll
|
|
|
|
source_filename = "foo"
|
|
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-apple-darwin"
|
|
|
|
@.str = private unnamed_addr constant [5 x i8] c"1-3\0A\00", align 1
|
|
@.str.1 = private unnamed_addr constant [10 x i8] c"7-277 %d\0A\00", align 1
|
|
@.str.2 = private unnamed_addr constant [8 x i8] c"4-5 %d\0A\00", align 1
|
|
@.str.3 = private unnamed_addr constant [6 x i8] c"6 %d\0A\00", align 1
|
|
@.str.4 = private unnamed_addr constant [20 x i8] c"Something else: %d\0A\00", align 1
|
|
@.str.5 = private unnamed_addr constant [5 x i8] c"1-3\0A\00", align 1
|
|
@.str.6 = private unnamed_addr constant [8 x i8] c"4-6 %d\0A\00", align 1
|
|
@.str.7 = private unnamed_addr constant [20 x i8] c"Something else: %d\0A\00", align 1
|
|
@.str.8 = private unnamed_addr constant [11 x i8] c"Was true!\0A\00", align 1
|
|
@.str.9 = private unnamed_addr constant [12 x i8] c"Was false!\0A\00", align 1
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @printf(ptr, ...) #0
|
|
|
|
; Function Attrs: nounwind
|
|
define void @foo.main() #0 {
|
|
entry:
|
|
%i = alloca i32, align 4
|
|
%switch = alloca i32, align 4
|
|
%i11 = alloca i32, align 4
|
|
%switch15 = alloca i32, align 4
|
|
%x = alloca i8, align 1
|
|
%switch23 = alloca i8, align 1
|
|
store i32 0, ptr %i, align 4
|
|
br label %loop.cond
|
|
|
|
loop.cond: ; preds = %switch.exit, %entry
|
|
%0 = load i32, ptr %i, align 4
|
|
%lt = icmp slt i32 %0, 12
|
|
br i1 %lt, label %loop.body, label %loop.exit
|
|
|
|
loop.body: ; preds = %loop.cond
|
|
%1 = load i32, ptr %i, align 4
|
|
store i32 %1, ptr %switch, align 4
|
|
br label %switch.entry
|
|
|
|
switch.entry: ; preds = %loop.body
|
|
%2 = load i32, ptr %switch, align 4
|
|
%le = icmp sle i32 1, %2
|
|
%ge = icmp sge i32 3, %2
|
|
%3 = and i1 %le, %ge
|
|
br i1 %3, label %switch.case, label %next_if
|
|
|
|
switch.case: ; preds = %switch.entry
|
|
call void (ptr, ...) @printf(ptr @.str)
|
|
br label %switch.exit
|
|
|
|
next_if: ; preds = %switch.entry
|
|
%le1 = icmp sle i32 7, %2
|
|
%ge2 = icmp sge i32 277, %2
|
|
%4 = and i1 %le1, %ge2
|
|
br i1 %4, label %switch.case3, label %next_if4
|
|
|
|
switch.case3: ; preds = %next_if
|
|
%5 = load i32, ptr %i, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.1, i32 %5)
|
|
br label %switch.exit
|
|
|
|
next_if4: ; preds = %next_if
|
|
%le5 = icmp sle i32 4, %2
|
|
%ge6 = icmp sge i32 5, %2
|
|
%6 = and i1 %le5, %ge6
|
|
br i1 %6, label %switch.case7, label %next_if8
|
|
|
|
switch.case7: ; preds = %switch.default, %next_if4
|
|
%7 = load i32, ptr %i, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.2, i32 %7)
|
|
br label %switch.exit
|
|
|
|
next_if8: ; preds = %next_if4
|
|
%eq = icmp eq i32 6, %2
|
|
br i1 %eq, label %switch.case9, label %next_if10
|
|
|
|
switch.case9: ; preds = %next_if8
|
|
%8 = load i32, ptr %i, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.3, i32 %8)
|
|
br label %switch.exit
|
|
|
|
next_if10: ; preds = %next_if8
|
|
br label %switch.default
|
|
|
|
switch.default: ; preds = %next_if10
|
|
%9 = load i32, ptr %i, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.4, i32 %9)
|
|
br label %switch.case7
|
|
|
|
switch.exit: ; preds = %switch.case9, %switch.case7, %switch.case3, %switch.case
|
|
%10 = load i32, ptr %i, align 4
|
|
%add = add i32 %10, 1
|
|
store i32 %add, ptr %i, align 4
|
|
br label %loop.cond
|
|
|
|
loop.exit: ; preds = %loop.cond
|
|
store i32 0, ptr %i11, align 4
|
|
br label %loop.cond12
|
|
|
|
loop.cond12: ; preds = %switch.exit20, %loop.exit
|
|
%11 = load i32, ptr %i11, align 4
|
|
%lt13 = icmp slt i32 %11, 12
|
|
br i1 %lt13, label %loop.body14, label %loop.exit22
|
|
|
|
loop.body14: ; preds = %loop.cond12
|
|
%12 = load i32, ptr %i11, align 4
|
|
store i32 %12, ptr %switch15, align 4
|
|
br label %switch.entry16
|
|
|
|
switch.entry16: ; preds = %loop.body14
|
|
%13 = load i32, ptr %switch15, align 4
|
|
switch i32 %13, label %switch.default19 [
|
|
i32 1, label %switch.case17
|
|
i32 2, label %switch.case17
|
|
i32 3, label %switch.case17
|
|
i32 4, label %switch.case18
|
|
i32 5, label %switch.case18
|
|
i32 6, label %switch.case18
|
|
]
|
|
|
|
switch.case17: ; preds = %switch.entry16, %switch.entry16, %switch.entry16
|
|
call void (ptr, ...) @printf(ptr @.str.5)
|
|
br label %switch.exit20
|
|
|
|
switch.case18: ; preds = %switch.default19, %switch.entry16, %switch.entry16, %switch.entry16
|
|
%14 = load i32, ptr %i11, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.6, i32 %14)
|
|
br label %switch.exit20
|
|
|
|
switch.default19: ; preds = %switch.entry16
|
|
%15 = load i32, ptr %i11, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.7, i32 %15)
|
|
br label %switch.case18
|
|
|
|
switch.exit20: ; preds = %switch.case18, %switch.case17
|
|
%16 = load i32, ptr %i11, align 4
|
|
%add21 = add i32 %16, 1
|
|
store i32 %add21, ptr %i11, align 4
|
|
br label %loop.cond12
|
|
|
|
loop.exit22: ; preds = %loop.cond12
|
|
store i8 0, ptr %x, align 1
|
|
%17 = load i8, ptr %x, align 1
|
|
store i8 %17, ptr %switch23, align 1
|
|
br label %switch.entry24
|
|
|
|
switch.entry24: ; preds = %loop.exit22
|
|
%18 = load i8, ptr %switch23, align 1
|
|
%19 = trunc i8 %18 to i1
|
|
%eq25 = icmp eq i1 true, %19
|
|
br i1 %eq25, label %switch.case26, label %next_if27
|
|
|
|
switch.case26: ; preds = %switch.entry24
|
|
call void (ptr, ...) @printf(ptr @.str.8)
|
|
br label %switch.exit31
|
|
|
|
next_if27: ; preds = %switch.entry24
|
|
%eq28 = icmp eq i1 false, %19
|
|
br i1 %eq28, label %switch.case29, label %next_if30
|
|
|
|
switch.case29: ; preds = %next_if27
|
|
call void (ptr, ...) @printf(ptr @.str.9)
|
|
br label %switch.exit31
|
|
|
|
next_if30: ; preds = %next_if27
|
|
br label %switch.exit31
|
|
|
|
switch.exit31: ; preds = %next_if30, %switch.case29, %switch.case26
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define i32 @main(i32 %0, ptr %1) #0 {
|
|
entry:
|
|
call void @foo.main()
|
|
ret i32 0
|
|
}
|
|
|