mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
65 lines
2.4 KiB
C
65 lines
2.4 KiB
C
// #target: macos-x64
|
|
module foo;
|
|
|
|
extern fn void printf(char* fmt, ...);
|
|
struct Foo
|
|
{
|
|
int x;
|
|
}
|
|
|
|
macro void Foo.@hello(Foo &this) { this.x = 3; printf("-%d\n", this.x); }
|
|
macro void Foo.hello(Foo* this) { this.x = 4; printf("-%d\n", this.x); }
|
|
macro void Foo.hello2(Foo this) { this.x = 5; printf("-%d\n", this.x); }
|
|
|
|
fn void main()
|
|
{
|
|
Foo a;
|
|
a.@hello();
|
|
printf("%d\n", a.x);
|
|
a.hello();
|
|
printf("%d\n", a.x);
|
|
a.hello2();
|
|
printf("%d\n", a.x);
|
|
}
|
|
|
|
/* #expect: foo.ll
|
|
|
|
define void @foo_main() #0 {
|
|
entry:
|
|
%a = alloca %Foo, align 4
|
|
%this = alloca %Foo*, align 8
|
|
%this1 = alloca %Foo, align 4
|
|
%0 = bitcast %Foo* %a to i32*
|
|
store i32 0, i32* %0, align 4
|
|
%1 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
|
store i32 3, i32* %1, align 4
|
|
%2 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
|
%3 = load i32, i32* %2, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 %3)
|
|
%4 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
|
%5 = load i32, i32* %4, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i32 %5)
|
|
store %Foo* %a, %Foo** %this, align 8
|
|
%6 = load %Foo*, %Foo** %this, align 8
|
|
%7 = getelementptr inbounds %Foo, %Foo* %6, i32 0, i32 0
|
|
store i32 4, i32* %7, align 8
|
|
%8 = load %Foo*, %Foo** %this, align 8
|
|
%9 = getelementptr inbounds %Foo, %Foo* %8, i32 0, i32 0
|
|
%10 = load i32, i32* %9, align 8
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 %10)
|
|
%11 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
|
%12 = load i32, i32* %11, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 %12)
|
|
%13 = bitcast %Foo* %this1 to i8*
|
|
%14 = bitcast %Foo* %a to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %13, i8* align 4 %14, i32 4, i1 false)
|
|
%15 = getelementptr inbounds %Foo, %Foo* %this1, i32 0, i32 0
|
|
store i32 5, i32* %15, align 4
|
|
%16 = getelementptr inbounds %Foo, %Foo* %this1, i32 0, i32 0
|
|
%17 = load i32, i32* %16, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i32 %17)
|
|
%18 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
|
%19 = load i32, i32* %18, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i32 %19)
|
|
ret void
|
|
}
|