From f41c27255f364076c5848526429a4e9f9e1c69ca Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 20 Jul 2025 02:26:25 -0400 Subject: usr: oasm: Lex registers and operands Signed-off-by: Ian Moffett --- usr.bin/oasm/lex.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'usr.bin') diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c index 56c6eb5..afbe21d 100644 --- a/usr.bin/oasm/lex.c +++ b/usr.bin/oasm/lex.c @@ -205,6 +205,17 @@ token_xreg(char *p) return TT_UNKNOWN; } +static tt_t +token_operand(char *p) +{ + /* Is this a numeric constant? */ + if (p[0] == '#') { + return TT_IMM; + } + + return TT_UNKNOWN; +} + static tt_t token_reg(char *p) { @@ -263,6 +274,14 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp) /* Register? */ if ((tok = token_reg(p)) != TT_UNKNOWN) { + ttp->is_reg = 1; + ttp->type = tok; + ttp->raw = p; + return 0; + } + + /* Immediate operand? */ + if ((tok = token_operand(p)) != TT_UNKNOWN) { ttp->type = tok; ttp->raw = p; return 0; -- cgit v1.2.3