mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
99 lines
3.2 KiB
Plaintext
99 lines
3.2 KiB
Plaintext
// #target: macos-x64
|
|
module test;
|
|
extern fn int strcmp(char *s1, char *s2);
|
|
|
|
fn int test(char *x) {
|
|
/* LLVM-GCC used to emit:
|
|
%.LC0 = internal global [3 x sbyte] c"\1F\FFFFFF8B\00"
|
|
*/
|
|
return strcmp(x, "\x1f\x8B");
|
|
}
|
|
|
|
int[10] a = { [0] = 0, [1] = 2 };
|
|
|
|
char[10] str = "x";
|
|
|
|
void*[5] arr = { [0] = null, [1] = null };
|
|
|
|
float[12] f = { [0] = 1.23f, [1] = 34.7f };
|
|
|
|
struct Test { int x; double y; }
|
|
|
|
Test[10] array = { [0] = { 2, 12.0 }, [1] = { 3, 24.0 } };
|
|
|
|
int[4][4] b = { [0] = { 1, 2, 3, 4}, [1] = { [0] = 5, [1] = 6, [2] = 7 }, [2] = { [0] = 8, [1] = 9 } };
|
|
|
|
struct Connection {
|
|
long to;
|
|
char[10] type;
|
|
long length;
|
|
}
|
|
|
|
Connection[3] link
|
|
= { {1, "link1", 10},
|
|
{2, "link2", 20},
|
|
{3, "link3", 30} };
|
|
|
|
|
|
fn int trys(char *s, int x)
|
|
{
|
|
int asa;
|
|
double val;
|
|
int lLS;
|
|
if (x) {
|
|
asa = lLS + asa;
|
|
} else {
|
|
}
|
|
return asa+(int)(val);
|
|
}
|
|
|
|
fn char* foo() {
|
|
return "*** Word \"%s\" on line %d is not";
|
|
}
|
|
|
|
/* #expect: test.ll
|
|
|
|
@test.a = local_unnamed_addr global { i32, i32, [8 x i32] } { i32 0, i32 2, [8 x i32] zeroinitializer }, align 16
|
|
@test.str = local_unnamed_addr global [10 x i8] c"x\00\00\00\00\00\00\00\00\00", align 1
|
|
@test.arr = local_unnamed_addr global { ptr, ptr, [3 x ptr] } zeroinitializer, align 16
|
|
@test.f = local_unnamed_addr global { float, float, [10 x float] } { float 0x3FF3AE1480000000, float 0x40415999A0000000, [10 x float] zeroinitializer }, align 16
|
|
@test.array = local_unnamed_addr global { %Test, %Test, [8 x %Test] } { %Test { i32 2, double 1.200000e+01 }, %Test { i32 3, double 2.400000e+01 }, [8 x %Test] zeroinitializer }, align 16
|
|
@test.b = local_unnamed_addr global { [4 x i32], [4 x i32], { i32, i32, [2 x i32] }, [4 x i32] } { [4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32] [i32 5, i32 6, i32 7, i32 0], { i32, i32, [2 x i32] } { i32 8, i32 9, [2 x i32] zeroinitializer }, [4 x i32] zeroinitializer }, align 16
|
|
@test.link = local_unnamed_addr global [3 x %Connection] [%Connection { i64 1, [10 x i8] c"link1\00\00\00\00\00", i64 10 }, %Connection { i64 2, [10 x i8] c"link2\00\00\00\00\00", i64 20 }, %Connection { i64 3, [10 x i8] c"link3\00\00\00\00\00", i64 30 }], align 16
|
|
@.str = private unnamed_addr constant [3 x i8] c"\1F\8B\00", align 1
|
|
@.str.7 = private unnamed_addr constant [32 x i8] c"*** Word \22%s\22 on line %d is not\00", align 1
|
|
|
|
declare i32 @strcmp(ptr, ptr) #0
|
|
|
|
define i32 @test.test(ptr %0) #0 {
|
|
entry:
|
|
%1 = call i32 @strcmp(ptr %0, ptr @.str)
|
|
ret i32 %1
|
|
}
|
|
|
|
define i32 @test.trys(ptr %0, i32 %1) #0 {
|
|
entry:
|
|
%asa = alloca i32, align 4
|
|
%val = alloca double, align 8
|
|
%lLS = alloca i32, align 4
|
|
store i32 0, ptr %asa, align 4
|
|
store double 0.000000e+00, ptr %val, align 8
|
|
store i32 0, ptr %lLS, align 4
|
|
%i2b = icmp ne i32 %1, 0
|
|
br i1 %i2b, label %if.then, label %if.exit
|
|
|
|
if.then: ; preds = %entry
|
|
%2 = load i32, ptr %lLS, align 4
|
|
%3 = load i32, ptr %asa, align 4
|
|
%add = add i32 %2, %3
|
|
store i32 %add, ptr %asa, align 4
|
|
br label %if.exit
|
|
|
|
if.exit: ; preds = %if.then, %entry
|
|
%4 = load i32, ptr %asa, align 4
|
|
%5 = load double, ptr %val, align 8
|
|
%fpsi = fptosi double %5 to i32
|
|
%add1 = add i32 %4, %fpsi
|
|
ret i32 %add1
|
|
}
|