aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-05-05 01:16:48 +0900
committernsfisis <nsfisis@gmail.com>2025-05-05 01:16:48 +0900
commitecffc7cf7aaa3fd447848568619161a95408aa0e (patch)
tree3cd21011da3c661a28b826c436a592fc5dd8b9b8 /main.c
parent992fc93278710bb41117d93531d9ed18db49e119 (diff)
downloadP4Dcc-ecffc7cf7aaa3fd447848568619161a95408aa0e.tar.gz
P4Dcc-ecffc7cf7aaa3fd447848568619161a95408aa0e.tar.zst
P4Dcc-ecffc7cf7aaa3fd447848568619161a95408aa0e.zip
align rsp
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/main.c b/main.c
index acc4c38..1ac07e3 100644
--- a/main.c
+++ b/main.c
@@ -1632,9 +1632,28 @@ void gen_func_call(struct CodeGen* g, struct AstNode* ast) {
fatal_error("gen_func_call: too many args");
}
}
+
+ int label = gen_new_label(g);
+
+ printf(" mov rax, rsp\n");
+ printf(" and rax, 15\n");
+ printf(" cmp rax, 0\n");
+ printf(" je .Laligned%d\n", label);
+
printf(" mov rax, 0\n");
+ printf(" sub rsp, 8\n");
printf(" call %s\n", func_name);
+ printf(" add rsp, 8\n");
printf(" push rax\n");
+
+ printf(" jmp .Lend%d\n", label);
+ printf(".Laligned%d:\n", label);
+
+ printf(" mov rax, 0\n");
+ printf(" call %s\n", func_name);
+ printf(" push rax\n");
+
+ printf(".Lend%d:\n", label);
}
void gen_lvar(struct CodeGen* g, struct AstNode* ast, int gen_mode) {