aboutsummaryrefslogtreecommitdiffhomepage
path: root/amd64
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-17 14:31:54 +0200
committerlemon <lsof@mailbox.org>2023-06-17 14:31:54 +0200
commitec28e9057e84b92acabb7ebf9122af59738917ad (patch)
treefe532fac21015cde652ee0472efc86569e30a9aa /amd64
parent78b7a3a6874abad6d2326093287554f3e565a382 (diff)
misc
Diffstat (limited to 'amd64')
-rw-r--r--amd64/emit.c24
-rw-r--r--amd64/isel.c6
-rw-r--r--amd64/sysv.c2
3 files changed, 19 insertions, 13 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);
}
diff --git a/amd64/isel.c b/amd64/isel.c
index 8d19cad..7725013 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -190,7 +190,7 @@ sel(struct function *fn, struct instr *ins, struct block *blk, int *curi)
case Osub:
if (ins->r.bits == mkref(RICON, 1).bits) {
/* sub x,1 -> dec x */
- ins->op = Oxdec;
+ ins->op = op = Oxdec;
ins->r = NOREF;
} else if (iscon(ins->l)) {
/* sub imm, x -> sub x, imm; neg x */
@@ -204,13 +204,13 @@ sel(struct function *fn, struct instr *ins, struct block *blk, int *curi)
case Oadd:
if (ins->l.bits == mkref(RICON, 1).bits) {
/* add 1,x -> inc x */
- ins->op = Oxinc;
+ ins->op = op = Oxinc;
ins->l = ins->r;
ins->r = NOREF;
goto ALU;
} else if (ins->r.bits == mkref(RICON, 1).bits) {
/* add x,1 -> inc x */
- ins->op = Oxinc;
+ ins->op = op = Oxinc;
ins->r = NOREF;
goto ALU;
} else if (kisint(ins->cls) && (addarg4addrp(ins->l) || addarg4addrp(ins->r))) {
diff --git a/amd64/sysv.c b/amd64/sysv.c
index 1c84909..dc43b81 100644
--- a/amd64/sysv.c
+++ b/amd64/sysv.c
@@ -144,6 +144,8 @@ const struct mctarg t_amd64_sysv = {
.rcallee = {{1<<RBX | 1<<R12 | 1<<R13 | 1<<R14 | 1<<R15}},
.rglob = {{1<<RSP | 1<<RBP}},
.rnames = amd64_rnames,
+ .objkind = OBJELF,
+ .isa = ISamd64,
.abiret = abiret,
.abiarg = abiarg,
.isel = amd64_isel,