mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add support for : slices. Version bumped to 0.2.16
This commit is contained in:
committed by
Christoffer Lerno
parent
48a31cfa48
commit
4beb7eff8f
@@ -18,10 +18,6 @@ fn void main()
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
|
||||
|
||||
declare void @printf(i8*, ...) #0
|
||||
|
||||
define void @test.main() #0 {
|
||||
entry:
|
||||
%x = alloca [8 x i32], align 16
|
||||
@@ -45,12 +41,10 @@ entry:
|
||||
store i32 52, i32* %7, align 4
|
||||
store i64 0, i64* %anon, align 8
|
||||
br label %loop.cond
|
||||
|
||||
loop.cond: ; preds = %loop.body, %entry
|
||||
%8 = load i64, i64* %anon, align 8
|
||||
%gt = icmp ugt i64 8, %8
|
||||
br i1 %gt, label %loop.body, label %loop.exit
|
||||
|
||||
loop.body: ; preds = %loop.cond
|
||||
%9 = load i64, i64* %anon, align 8
|
||||
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %x, i64 0, i64 %9
|
||||
@@ -62,27 +56,18 @@ loop.body: ; preds = %loop.cond
|
||||
%add = add i64 %13, 1
|
||||
store i64 %add, i64* %anon, align 8
|
||||
br label %loop.cond
|
||||
|
||||
loop.exit: ; preds = %loop.cond
|
||||
br label %cond
|
||||
|
||||
cond: ; preds = %assign, %loop.exit
|
||||
%14 = phi i64 [ 0, %loop.exit ], [ %add1, %assign ]
|
||||
%le = icmp sle i64 %14, 7
|
||||
br i1 %le, label %assign, label %exit
|
||||
|
||||
%lt = icmp slt i64 %14, 8
|
||||
br i1 %lt, label %assign, label %exit
|
||||
assign: ; preds = %cond
|
||||
%15 = getelementptr inbounds [8 x i32], [8 x i32]* %x, i64 0, i64 %14
|
||||
store i32 123, i32* %15, align 4
|
||||
%add1 = add i64 %14, 1
|
||||
br label %cond
|
||||
|
||||
exit: ; preds = %cond
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, i8** %1) #0 {
|
||||
entry:
|
||||
call void @test.main()
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// #target: macos-x64
|
||||
module mymodule;
|
||||
|
||||
extern fn void printf(char *, ...);
|
||||
@@ -49,9 +50,195 @@ fn void test()
|
||||
default:
|
||||
printf("None of the above\n");
|
||||
}
|
||||
switch
|
||||
{
|
||||
case a < 0:
|
||||
printf("A negative\n");
|
||||
case a == 1:
|
||||
printf("A is 1\n");
|
||||
default:
|
||||
printf("Unexpected a\n");
|
||||
}
|
||||
}
|
||||
fn void main()
|
||||
{
|
||||
test();
|
||||
printf("Hello!\n");
|
||||
}
|
||||
|
||||
/* #expect: mymodule.ll
|
||||
|
||||
define void @mymodule.test() #0 {
|
||||
entry:
|
||||
%x = alloca i32, align 4
|
||||
%x.f = alloca i64, align 8
|
||||
%z = alloca i64, align 8
|
||||
%err = alloca i64, align 8
|
||||
%switch = alloca i64, align 8
|
||||
%switch4 = alloca i64, align 8
|
||||
%a = alloca i32, align 4
|
||||
%b = alloca i32, align 4
|
||||
%zy = alloca i32, align 4
|
||||
%switch17 = alloca i32, align 4
|
||||
%switch27 = alloca i8, align 1
|
||||
store i64 ptrtoint (i8* @mymodule.ByeErr.BAR to i64), i64* %x.f, align 8
|
||||
store i64 ptrtoint ({ i8, i16 }* @.typeid.int to i64), i64* %z, align 8
|
||||
br label %testblock
|
||||
|
||||
testblock: ; preds = %entry
|
||||
%0 = load i64, i64* %x.f, align 8
|
||||
%not_err = icmp eq i64 %0, 0
|
||||
br i1 %not_err, label %after_check, label %error
|
||||
|
||||
error: ; preds = %testblock
|
||||
store i64 %0, i64* %err, align 8
|
||||
br label %end_block
|
||||
|
||||
after_check: ; preds = %testblock
|
||||
store i64 0, i64* %err, align 8
|
||||
br label %end_block
|
||||
|
||||
end_block: ; preds = %after_check, %error
|
||||
%1 = load i64, i64* %err, align 8
|
||||
%neq = icmp ne i64 %1, 0
|
||||
br i1 %neq, label %if.then, label %if.exit
|
||||
|
||||
if.then: ; preds = %end_block
|
||||
store i64 %1, i64* %switch, align 8
|
||||
br label %switch.entry
|
||||
|
||||
switch.entry: ; preds = %if.then
|
||||
%2 = load i64, i64* %switch, align 8
|
||||
%eq = icmp eq i64 ptrtoint (i8* @mymodule.HelloErr.FOO to i64), %2
|
||||
br i1 %eq, label %switch.case, label %next_if
|
||||
|
||||
switch.case: ; preds = %switch.entry
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0))
|
||||
br label %switch.exit
|
||||
|
||||
next_if: ; preds = %switch.entry
|
||||
%eq1 = icmp eq i64 ptrtoint (i8* @mymodule.ByeErr.BAR to i64), %2
|
||||
br i1 %eq1, label %switch.case2, label %next_if3
|
||||
|
||||
switch.case2: ; preds = %next_if
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0))
|
||||
br label %switch.exit
|
||||
|
||||
next_if3: ; preds = %next_if
|
||||
br label %switch.default
|
||||
|
||||
switch.default: ; preds = %next_if3
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0))
|
||||
br label %switch.exit
|
||||
|
||||
switch.exit: ; preds = %switch.default, %switch.case2, %switch.case
|
||||
br label %if.exit
|
||||
|
||||
if.exit: ; preds = %switch.exit, %end_block
|
||||
%3 = load i64, i64* %z, align 8
|
||||
store i64 %3, i64* %switch4, align 8
|
||||
br label %switch.entry5
|
||||
|
||||
switch.entry5: ; preds = %if.exit
|
||||
%4 = load i64, i64* %switch4, align 8
|
||||
%eq6 = icmp eq i64 ptrtoint ({ i8, i16 }* @.typeid.int to i64), %4
|
||||
br i1 %eq6, label %switch.case7, label %next_if8
|
||||
|
||||
switch.case7: ; preds = %switch.entry5
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0))
|
||||
br label %switch.exit16
|
||||
|
||||
next_if8: ; preds = %switch.entry5
|
||||
%eq9 = icmp eq i64 ptrtoint ({ i8 }* @.typeid.bool to i64), %4
|
||||
br i1 %eq9, label %switch.case10, label %next_if11
|
||||
|
||||
switch.case10: ; preds = %next_if8
|
||||
br label %switch.case13
|
||||
|
||||
next_if11: ; preds = %next_if8
|
||||
%eq12 = icmp eq i64 ptrtoint ({ i8, i16 }* @.typeid.double to i64), %4
|
||||
br i1 %eq12, label %switch.case13, label %next_if14
|
||||
|
||||
switch.case13: ; preds = %next_if11, %switch.case10
|
||||
br label %switch.default15
|
||||
|
||||
next_if14: ; preds = %next_if11
|
||||
br label %switch.default15
|
||||
|
||||
switch.default15: ; preds = %next_if14, %switch.case13
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i32 0, i32 0))
|
||||
br label %switch.exit16
|
||||
|
||||
switch.exit16: ; preds = %switch.default15, %switch.case7
|
||||
store i32 1, i32* %a, align 4
|
||||
store i32 2, i32* %b, align 4
|
||||
%5 = load i32, i32* %b, align 4
|
||||
%6 = load i32, i32* %a, align 4
|
||||
%add = add i32 %5, %6
|
||||
store i32 %add, i32* %zy, align 4
|
||||
%7 = load i32, i32* %zy, align 4
|
||||
store i32 %7, i32* %switch17, align 4
|
||||
br label %switch.entry18
|
||||
|
||||
switch.entry18: ; preds = %switch.exit16
|
||||
%8 = load i32, i32* %switch17, align 4
|
||||
%9 = load i32, i32* %a, align 4
|
||||
%eq19 = icmp eq i32 %9, %8
|
||||
br i1 %eq19, label %switch.case20, label %next_if21
|
||||
|
||||
switch.case20: ; preds = %switch.entry18
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0))
|
||||
br label %switch.exit26
|
||||
|
||||
next_if21: ; preds = %switch.entry18
|
||||
%10 = load i32, i32* %b, align 4
|
||||
%eq22 = icmp eq i32 %10, %8
|
||||
br i1 %eq22, label %switch.case23, label %next_if24
|
||||
|
||||
switch.case23: ; preds = %next_if21
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0))
|
||||
br label %switch.exit26
|
||||
|
||||
next_if24: ; preds = %next_if21
|
||||
br label %switch.default25
|
||||
|
||||
switch.default25: ; preds = %next_if24
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i32 0, i32 0))
|
||||
br label %switch.exit26
|
||||
|
||||
switch.exit26: ; preds = %switch.default25, %switch.case23, %switch.case20
|
||||
store i8 1, i8* %switch27, align 1
|
||||
br label %switch.entry28
|
||||
|
||||
switch.entry28: ; preds = %switch.exit26
|
||||
%11 = load i8, i8* %switch27, align 1
|
||||
%12 = trunc i8 %11 to i1
|
||||
%13 = load i32, i32* %a, align 4
|
||||
%lt = icmp slt i32 %13, 0
|
||||
%eq29 = icmp eq i1 %lt, %12
|
||||
br i1 %eq29, label %switch.case30, label %next_if31
|
||||
|
||||
switch.case30: ; preds = %switch.entry28
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i32 0, i32 0))
|
||||
br label %switch.exit37
|
||||
|
||||
next_if31: ; preds = %switch.entry28
|
||||
%14 = load i32, i32* %a, align 4
|
||||
%eq32 = icmp eq i32 %14, 1
|
||||
%eq33 = icmp eq i1 %eq32, %12
|
||||
br i1 %eq33, label %switch.case34, label %next_if35
|
||||
|
||||
switch.case34: ; preds = %next_if31
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i32 0, i32 0))
|
||||
br label %switch.exit37
|
||||
|
||||
next_if35: ; preds = %next_if31
|
||||
br label %switch.default36
|
||||
|
||||
switch.default36: ; preds = %next_if35
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i32 0, i32 0))
|
||||
br label %switch.exit37
|
||||
|
||||
switch.exit37: ; preds = %switch.default36, %switch.case34, %switch.case30
|
||||
ret void
|
||||
}
|
||||
@@ -23,7 +23,6 @@ fn void main()
|
||||
; Function Attrs: nounwind
|
||||
declare void @printf(ptr, ...) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define void @test.main() #0 {
|
||||
entry:
|
||||
%x = alloca [8 x i32], align 16
|
||||
@@ -69,8 +68,8 @@ loop.exit: ; preds = %loop.cond
|
||||
|
||||
cond: ; preds = %assign, %loop.exit
|
||||
%13 = phi i64 [ 0, %loop.exit ], [ %add1, %assign ]
|
||||
%le = icmp sle i64 %13, 7
|
||||
br i1 %le, label %assign, label %exit
|
||||
%lt = icmp slt i64 %13, 8
|
||||
br i1 %lt, label %assign, label %exit
|
||||
|
||||
assign: ; preds = %cond
|
||||
%14 = getelementptr inbounds [8 x i32], ptr %x, i64 0, i64 %13
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// #target: macos-x64
|
||||
module mymodule;
|
||||
|
||||
extern fn void printf(char *, ...);
|
||||
@@ -49,9 +50,195 @@ fn void test()
|
||||
default:
|
||||
printf("None of the above\n");
|
||||
}
|
||||
switch
|
||||
{
|
||||
case a < 0:
|
||||
printf("A negative\n");
|
||||
case a == 1:
|
||||
printf("A is 1\n");
|
||||
default:
|
||||
printf("Unexpected a\n");
|
||||
}
|
||||
}
|
||||
fn void main()
|
||||
{
|
||||
test();
|
||||
printf("Hello!\n");
|
||||
}
|
||||
|
||||
/* #expect: mymodule.ll
|
||||
|
||||
define void @mymodule.test() #0 {
|
||||
entry:
|
||||
%x = alloca i32, align 4
|
||||
%x.f = alloca i64, align 8
|
||||
%z = alloca i64, align 8
|
||||
%err = alloca i64, align 8
|
||||
%switch = alloca i64, align 8
|
||||
%switch4 = alloca i64, align 8
|
||||
%a = alloca i32, align 4
|
||||
%b = alloca i32, align 4
|
||||
%zy = alloca i32, align 4
|
||||
%switch17 = alloca i32, align 4
|
||||
%switch27 = alloca i8, align 1
|
||||
store i64 ptrtoint (ptr @mymodule.ByeErr.BAR to i64), ptr %x.f, align 8
|
||||
store i64 ptrtoint (ptr @.typeid.int to i64), ptr %z, align 8
|
||||
br label %testblock
|
||||
|
||||
testblock: ; preds = %entry
|
||||
%0 = load i64, ptr %x.f, align 8
|
||||
%not_err = icmp eq i64 %0, 0
|
||||
br i1 %not_err, label %after_check, label %error
|
||||
|
||||
error: ; preds = %testblock
|
||||
store i64 %0, ptr %err, align 8
|
||||
br label %end_block
|
||||
|
||||
after_check: ; preds = %testblock
|
||||
store i64 0, ptr %err, align 8
|
||||
br label %end_block
|
||||
|
||||
end_block: ; preds = %after_check, %error
|
||||
%1 = load i64, ptr %err, align 8
|
||||
%neq = icmp ne i64 %1, 0
|
||||
br i1 %neq, label %if.then, label %if.exit
|
||||
|
||||
if.then: ; preds = %end_block
|
||||
store i64 %1, ptr %switch, align 8
|
||||
br label %switch.entry
|
||||
|
||||
switch.entry: ; preds = %if.then
|
||||
%2 = load i64, ptr %switch, align 8
|
||||
%eq = icmp eq i64 ptrtoint (ptr @mymodule.HelloErr.FOO to i64), %2
|
||||
br i1 %eq, 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
|
||||
%eq1 = icmp eq i64 ptrtoint (ptr @mymodule.ByeErr.BAR to i64), %2
|
||||
br i1 %eq1, label %switch.case2, label %next_if3
|
||||
|
||||
switch.case2: ; preds = %next_if
|
||||
call void (ptr, ...) @printf(ptr @.str.1)
|
||||
br label %switch.exit
|
||||
|
||||
next_if3: ; preds = %next_if
|
||||
br label %switch.default
|
||||
|
||||
switch.default: ; preds = %next_if3
|
||||
call void (ptr, ...) @printf(ptr @.str.2)
|
||||
br label %switch.exit
|
||||
|
||||
switch.exit: ; preds = %switch.default, %switch.case2, %switch.case
|
||||
br label %if.exit
|
||||
|
||||
if.exit: ; preds = %switch.exit, %end_block
|
||||
%3 = load i64, ptr %z, align 8
|
||||
store i64 %3, ptr %switch4, align 8
|
||||
br label %switch.entry5
|
||||
|
||||
switch.entry5: ; preds = %if.exit
|
||||
%4 = load i64, ptr %switch4, align 8
|
||||
%eq6 = icmp eq i64 ptrtoint (ptr @.typeid.int to i64), %4
|
||||
br i1 %eq6, label %switch.case7, label %next_if8
|
||||
|
||||
switch.case7: ; preds = %switch.entry5
|
||||
call void (ptr, ...) @printf(ptr @.str.3)
|
||||
br label %switch.exit16
|
||||
|
||||
next_if8: ; preds = %switch.entry5
|
||||
%eq9 = icmp eq i64 ptrtoint (ptr @.typeid.bool to i64), %4
|
||||
br i1 %eq9, label %switch.case10, label %next_if11
|
||||
|
||||
switch.case10: ; preds = %next_if8
|
||||
br label %switch.case13
|
||||
|
||||
next_if11: ; preds = %next_if8
|
||||
%eq12 = icmp eq i64 ptrtoint (ptr @.typeid.double to i64), %4
|
||||
br i1 %eq12, label %switch.case13, label %next_if14
|
||||
|
||||
switch.case13: ; preds = %next_if11, %switch.case10
|
||||
br label %switch.default15
|
||||
|
||||
next_if14: ; preds = %next_if11
|
||||
br label %switch.default15
|
||||
|
||||
switch.default15: ; preds = %next_if14, %switch.case13
|
||||
call void (ptr, ...) @printf(ptr @.str.4)
|
||||
br label %switch.exit16
|
||||
|
||||
switch.exit16: ; preds = %switch.default15, %switch.case7
|
||||
store i32 1, ptr %a, align 4
|
||||
store i32 2, ptr %b, align 4
|
||||
%5 = load i32, ptr %b, align 4
|
||||
%6 = load i32, ptr %a, align 4
|
||||
%add = add i32 %5, %6
|
||||
store i32 %add, ptr %zy, align 4
|
||||
%7 = load i32, ptr %zy, align 4
|
||||
store i32 %7, ptr %switch17, align 4
|
||||
br label %switch.entry18
|
||||
|
||||
switch.entry18: ; preds = %switch.exit16
|
||||
%8 = load i32, ptr %switch17, align 4
|
||||
%9 = load i32, ptr %a, align 4
|
||||
%eq19 = icmp eq i32 %9, %8
|
||||
br i1 %eq19, label %switch.case20, label %next_if21
|
||||
|
||||
switch.case20: ; preds = %switch.entry18
|
||||
call void (ptr, ...) @printf(ptr @.str.5)
|
||||
br label %switch.exit26
|
||||
|
||||
next_if21: ; preds = %switch.entry18
|
||||
%10 = load i32, ptr %b, align 4
|
||||
%eq22 = icmp eq i32 %10, %8
|
||||
br i1 %eq22, label %switch.case23, label %next_if24
|
||||
|
||||
switch.case23: ; preds = %next_if21
|
||||
call void (ptr, ...) @printf(ptr @.str.6)
|
||||
br label %switch.exit26
|
||||
|
||||
next_if24: ; preds = %next_if21
|
||||
br label %switch.default25
|
||||
|
||||
switch.default25: ; preds = %next_if24
|
||||
call void (ptr, ...) @printf(ptr @.str.7)
|
||||
br label %switch.exit26
|
||||
|
||||
switch.exit26: ; preds = %switch.default25, %switch.case23, %switch.case20
|
||||
store i8 1, ptr %switch27, align 1
|
||||
br label %switch.entry28
|
||||
|
||||
switch.entry28: ; preds = %switch.exit26
|
||||
%11 = load i8, ptr %switch27, align 1
|
||||
%12 = trunc i8 %11 to i1
|
||||
%13 = load i32, ptr %a, align 4
|
||||
%lt = icmp slt i32 %13, 0
|
||||
%eq29 = icmp eq i1 %lt, %12
|
||||
br i1 %eq29, label %switch.case30, label %next_if31
|
||||
|
||||
switch.case30: ; preds = %switch.entry28
|
||||
call void (ptr, ...) @printf(ptr @.str.8)
|
||||
br label %switch.exit37
|
||||
|
||||
next_if31: ; preds = %switch.entry28
|
||||
%14 = load i32, ptr %a, align 4
|
||||
%eq32 = icmp eq i32 %14, 1
|
||||
%eq33 = icmp eq i1 %eq32, %12
|
||||
br i1 %eq33, label %switch.case34, label %next_if35
|
||||
|
||||
switch.case34: ; preds = %next_if31
|
||||
call void (ptr, ...) @printf(ptr @.str.9)
|
||||
br label %switch.exit37
|
||||
|
||||
next_if35: ; preds = %next_if31
|
||||
br label %switch.default36
|
||||
|
||||
switch.default36: ; preds = %next_if35
|
||||
call void (ptr, ...) @printf(ptr @.str.10)
|
||||
br label %switch.exit37
|
||||
|
||||
switch.exit37: ; preds = %switch.default36, %switch.case34, %switch.case30
|
||||
ret void
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user