mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
* fix(asm): consider asm blocks as volatile When asm blocks are not marked as volatile, they may be (wrongly) discarded by LLVM optimization passes. * fix(asm): mark syscall as clobbering return register The `syscall` instruction returns the system call result in the `rax` register. * feat(asm): add push instructions. * feat(asm): add pop instructions
51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
// #target: macos-x64
|
|
|
|
module test;
|
|
import std::io;
|
|
fn void main()
|
|
{
|
|
int x = 222;
|
|
int y = 223;
|
|
long z = 0;
|
|
z = (long)x + y;
|
|
z *= x;
|
|
int g = 0;
|
|
int* gp = &g;
|
|
int[4] a = { 3, 4, 5, 6 };
|
|
int* xa = &a;
|
|
usz asf = 1;
|
|
int aa = 3;
|
|
asm
|
|
{
|
|
|
|
movl x, 4;
|
|
movl [gp], x;
|
|
movl x, 1;
|
|
movl [xa + asf * 4 + 4], x;
|
|
movl $eax, (23 + x);
|
|
movl x, $eax;
|
|
movq [&z], 33;
|
|
addl aa, 22;
|
|
}
|
|
io::printfn("aa: %d", aa);
|
|
io::printfn("Z: %d", z);
|
|
io::printfn("x: %d", x);
|
|
io::printfn("G was: %d", g);
|
|
foreach(int abc : a) io::printfn("%d", abc);
|
|
|
|
}
|
|
|
|
/* #expect: test.ll
|
|
|
|
%4 = load ptr, ptr %gp, align 8
|
|
%5 = load ptr, ptr %xa, align 8
|
|
%6 = load i64, ptr %asf, align 8
|
|
%7 = load i32, ptr %x, align 4
|
|
%add3 = add i32 23, %7
|
|
%8 = load i32, ptr %aa, align 4
|
|
%9 = call { i32, i32 } asm sideeffect alignstack "movl $$4, $0\0Amovl $0, ($3)\0Amovl $$1, $0\0Amovl $0, 4($4,$5,4)\0Amovl $6, %eax\0Amovl %eax, $0\0Amovq $$33, $1\0Aaddl $$22, $2\0A", "=&r,=*&m,=r,r,r,r,r,2,~{cc},~{rax},~{flags},~{dirflag},~{fspr}"(ptr elementtype(i64) %z, ptr %4, ptr %5, i64 %6, i32 %add3, i32 %8)
|
|
%10 = extractvalue { i32, i32 } %9, 0
|
|
store i32 %10, ptr %x, align 4
|
|
%11 = extractvalue { i32, i32 } %9, 1
|
|
store i32 %11, ptr %aa, align 4
|