backend+mu: Add helper to return immediate values

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-02-16 13:48:00 -05:00
parent 38fab3f7e5
commit 222b96f20e
2 changed files with 46 additions and 0 deletions

View File

@@ -1,6 +1,19 @@
#include <stdio.h>
#include "rifle/mu.h"
#define retreg(msize) \
(msize >= MSIZE_MAX) \
? "bad" \
: rettab[(msize)]
/* Size to return register table */
static const char *rettab[] = {
[MSIZE_BYTE] = "al",
[MSIZE_WORD] = "ax",
[MSIZE_DWORD] = "eax",
[MSIZE_QWORD] = "rax"
};
int
mu_gen_label(struct rifle_state *state, const char *name, bool global)
{
@@ -25,6 +38,27 @@ mu_gen_label(struct rifle_state *state, const char *name, bool global)
return 0;
}
int
mu_gen_retimm(struct rifle_state *state, ssize_t v, msize_t size)
{
if (state == NULL) {
return -1;
}
if (size >= MSIZE_MAX) {
return -1;
}
fprintf(
state->out_fp,
INST("mov %s, %zd"),
retreg(size),
v
);
return 0;
}
int
mu_gen_ret(struct rifle_state *state)
{