summaryrefslogtreecommitdiff
path: root/usr.bin/oasm/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/oasm/parse.c')
-rw-r--r--usr.bin/oasm/parse.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/usr.bin/oasm/parse.c b/usr.bin/oasm/parse.c
index 673fbcd..c81b498 100644
--- a/usr.bin/oasm/parse.c
+++ b/usr.bin/oasm/parse.c
@@ -34,10 +34,12 @@
#include <oasm/lex.h>
#include <oasm/parse.h>
#include <oasm/log.h>
+#include <oasm/label.h>
static struct emit_state emit_state;
static const char *tokstr[] = {
[ TT_UNKNOWN] = "bad",
+ [ TT_NOP ] = "nop",
[ TT_ADD ] = "add",
[ TT_SUB ] = "sub",
[ TT_MUL ] = "mul",
@@ -49,6 +51,14 @@ static const char *tokstr[] = {
[ TT_DEC ] = "dec",
[ TT_MOV ] = "mov",
[ TT_IMM ] = "<imm>",
+ [ TT_LABEL] = "<label>",
+
+ /* Bitwise */
+ [ TT_MROB ] = "mrob",
+ [ TT_MROW ] = "mrow",
+ [ TT_MROD ] = "mrod",
+ [ TT_MROQ ] = "mroq",
+
/* X<n> registers */
[ TT_X0 ] = "x0",
@@ -117,8 +127,12 @@ parse_reg(struct oasm_state *state, struct oasm_token *tok)
state->last = tok->type;
break;
default:
+ if (tok_is_mro(state->last)) {
+ break;
+ }
+
p = tokstr[state->last];
- oasm_err("bad instruction '%s' for regop\n", p);
+ oasm_err("bad token '%s' for regop\n", p);
return -1;
}
@@ -134,22 +148,24 @@ parse_reg(struct oasm_state *state, struct oasm_token *tok)
}
static int
-parse_imm(struct oasm_token *tok, tt_t last)
-{
- return 0;
-}
-
-static int
parse_tok(struct oasm_state *state, struct oasm_token *tok)
{
const char *p;
int error;
switch (tok->type) {
+ case TT_NOP:
+ state->last = tok->type;
+ emit_osmx64(&emit_state, tok);
+ break;
case TT_BR:
state->last = tok->type;
emit_osmx64(&emit_state, tok);
break;
+ case TT_LABEL:
+ state->last = tok->type;
+ label_enter(tok->raw, state->pip);
+ break;
case TT_HLT:
state->last = tok->type;
emit_osmx64(&emit_state, tok);
@@ -188,6 +204,12 @@ parse_tok(struct oasm_state *state, struct oasm_token *tok)
emit_osmx64(&emit_state, tok);
break;
default:
+ if (tok_is_mro(tok->type)) {
+ state->last = tok->type;
+ emit_osmx64(&emit_state, tok);
+ return 0;
+ }
+
if (!tok->is_reg) {
oasm_err("syntax error\n");
return -1;
@@ -230,4 +252,5 @@ parse_enter(struct oasm_state *state)
/* Process then destroy the emit state */
emit_process(state, &emit_state);
emit_destroy(&emit_state);
+ labels_destroy();
}