summaryrefslogtreecommitdiff
path: root/usr.bin/oasm/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/oasm/lex.c')
-rw-r--r--usr.bin/oasm/lex.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c
index 7b78d54..a33a570 100644
--- a/usr.bin/oasm/lex.c
+++ b/usr.bin/oasm/lex.c
@@ -34,6 +34,7 @@
#include <oasm/lex.h>
#include <oasm/log.h>
+#define COMMENT '!'
#define is_num(c) ((c) >= '0' && (c) <= '9')
static char putback = '\0';
@@ -47,6 +48,7 @@ static char putback = '\0';
#define S_IMN_INC "inc"
#define S_IMN_DEC "dec"
#define S_IMN_HLT "hlt"
+#define S_IMN_BR "br"
/*
* Returns 0 if a char is counted as a
@@ -190,6 +192,19 @@ token_arith(char *p)
return TT_UNKNOWN;
}
+/*
+ * Control flow instructions
+ */
+static tt_t
+token_cfi(char *p)
+{
+ if (strcmp(p, S_IMN_BR) == 0) {
+ return TT_BR;
+ }
+
+ return TT_UNKNOWN;
+}
+
static tt_t
token_xreg(char *p)
{
@@ -254,6 +269,7 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp)
{
char *p = NULL;
char c = ' ';
+ short in_comment = 0;
int tmp;
tt_t tok;
@@ -262,13 +278,19 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp)
}
/*
- * Grab characters. If they are skippable,
- * don't use them.
+ * Grab characters. If they are skippable or
+ * comments, don't use them.
*/
- while (lex_skippable(state, c) == 0) {
+ while (lex_skippable(state, c) == 0 || in_comment) {
if ((c = lex_cin(state)) == 0) {
return -1;
}
+
+ if (c == COMMENT) {
+ in_comment = 1;
+ } else if (c == '\n') {
+ in_comment = 0;
+ }
}
switch (c) {
@@ -293,6 +315,13 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp)
return 0;
}
+ /* Control flow instruction? */
+ if ((tok = token_cfi(p)) != TT_UNKNOWN) {
+ ttp->type = tok;
+ ttp->raw = p;
+ return 0;
+ }
+
/* Register? */
if ((tok = token_reg(p)) != TT_UNKNOWN) {
ttp->is_reg = 1;