From 2b80662967868d18c45b1fdb90c5b89c888326c6 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 10 Dec 2018 21:59:37 +0100 Subject: [PATCH] src/as/parser.c: store address for label declaration in the symbol table. --- src/as/parser.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/as/parser.c b/src/as/parser.c index eca613b..bb8653a 100644 --- a/src/as/parser.c +++ b/src/as/parser.c @@ -116,6 +116,16 @@ static int match_typeJ(struct lexer* lex, struct ast *ast) { return 1; } +// Match \n* +static int match_label_decl(struct lexer* lex, struct ast *ast) { + + uint16_t location = ast->instr.size / sizeof(struct ast_instr); + + ast_location(ast, lex->token.value.s, location); + + return 1; +} + #define opcode_guard(op) \ if (op_set == 0) { op_set = 1; ast_instr(ast, op); } @@ -154,8 +164,7 @@ static int parse_line(struct lexer* lex, struct ast *ast) { case TOKEN_OPCODE_JMP : opcode_guard(OP_JMP); return match_typeJ(lex, ast); case TOKEN_LABEL_DECL : - asm_warn(lex->lineno, "labels are not supported yet. ignoring."); - break; + return match_label_decl(lex, ast); default: return asm_error(lex->lineno, "Opcode or label expected"); }