diff options
| author | 2023-06-17 14:31:54 +0200 | |
|---|---|---|
| committer | 2023-06-17 14:31:54 +0200 | |
| commit | ec28e9057e84b92acabb7ebf9122af59738917ad (patch) | |
| tree | fe532fac21015cde652ee0472efc86569e30a9aa /amd64/emit.c | |
| parent | 78b7a3a6874abad6d2326093287554f3e565a382 (diff) | |
misc
Diffstat (limited to 'amd64/emit.c')
| -rw-r--r-- | amd64/emit.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/amd64/emit.c b/amd64/emit.c index d2c5aa8..b7cea24 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -641,16 +641,19 @@ emitbin(struct function *fn) aligncode(pcode, 16); /** prologue **/ - /* push rbp; mov rbp, rsp */ - DS("\x55\x48\x89\xE5"); + if (fn->stksiz != 0) + /* push rbp; mov rbp, rsp */ + DS("\x55\x48\x89\xE5"); calleesave(pcode, fn); - /* sub rsp, <stack size> */ - if (fn->stksiz < 128) - DS("\x48\x83\xEC"), B(fn->stksiz); - else if (fn->stksiz == 128) - DS("\x48\x83\xC4\x80"); /* add rsp, -128 */ - else - DS("\x48\x81\xEC"), I32(fn->stksiz); + if (fn->stksiz != 0) { + /* sub rsp, <stack size> */ + if (fn->stksiz < 128) + DS("\x48\x83\xEC"), B(fn->stksiz); + else if (fn->stksiz == 128) + DS("\x48\x83\xC4\x80"); /* add rsp, -128 */ + else + DS("\x48\x81\xEC"), I32(fn->stksiz); + } blk = fn->entry; do { @@ -660,7 +663,8 @@ emitbin(struct function *fn) if (blk->jmp.t == Jret) { /* epilogue */ calleerestore(pcode, fn); - DS("\xC9\xC3"); /* leave; ret */ + if (fn->stksiz) B(0xC9); /* leave */ + B(0xC3); /* ret */ } } while ((blk = blk->lnext) != fn->entry); } |