mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
40 lines
1.1 KiB
Plaintext
40 lines
1.1 KiB
Plaintext
// #target: macos-x64
|
|
module test;
|
|
struct Word {int x;}
|
|
typedef Byte = inline ushort;
|
|
|
|
macro Word Word.add0(self, int other) @operator(+) => { self.x + (int)other };
|
|
macro Word Word.add1(self, Byte other) @operator(+) => { self.x + (int)other };
|
|
|
|
fn int main()
|
|
{
|
|
Word a = {1};
|
|
Byte b = 2;
|
|
Word c = a + b;
|
|
return 0;
|
|
}
|
|
|
|
/* #expect: test.ll
|
|
|
|
define i32 @main() #0 {
|
|
entry:
|
|
%a = alloca %Word, align 4
|
|
%b = alloca i16, align 2
|
|
%c = alloca %Word, align 4
|
|
%self = alloca %Word, align 4
|
|
%other = alloca i16, align 2
|
|
%literal = alloca %Word, align 4
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %a, ptr align 4 @.__const, i32 4, i1 false)
|
|
store i16 2, ptr %b, align 2
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %self, ptr align 4 %a, i32 4, i1 false)
|
|
%0 = load i16, ptr %b, align 2
|
|
store i16 %0, ptr %other, align 2
|
|
%1 = load i32, ptr %self, align 4
|
|
%2 = load i16, ptr %other, align 2
|
|
%zext = zext i16 %2 to i32
|
|
%add = add i32 %1, %zext
|
|
store i32 %add, ptr %literal, align 4
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %c, ptr align 4 %literal, i32 4, i1 false)
|
|
ret i32 0
|
|
}
|