Skip to content

Commit

Permalink
[ASM] Fix define symbol bug
Browse files Browse the repository at this point in the history
Assembler's symbol table is set by Assembler::encode. If sytmbol
definition happens before any encode, symbol table of Assembler is
nullptr and unexpected undefined symbol error arise.
  • Loading branch information
tgtakaoka committed Feb 19, 2025
1 parent 582622d commit 53737ba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion driver/asm_directive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ Error AsmDirective::defineSymbol(
return setError(symbol, DUPLICATE_LABEL);
}

auto parserCtx = _assembler.parserContext(&context.symbols);
ErrorAt error;
context.value = _assembler.parseExpr(scan, error);
context.value = _assembler.parser().eval(scan, error, parserCtx);
if (error.hasError()) {
context.value.clear();
return setError(scan, error);
Expand Down
6 changes: 5 additions & 1 deletion src/asm_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ Value Assembler::parseInteger(StrScanner &expr, ErrorAt &error, char delim) cons
return value;
}

ParserContext Assembler::parserContext(const SymbolTable *symtab, char delim) const {
return ParserContext{_currentLocation, symtab, delim, _inputRadix};
}

Value Assembler::parseExpr(StrScanner &expr, ErrorAt &error, char delim) const {
ParserContext context{_currentLocation, _symtab, delim, _inputRadix};
auto context = parserContext(_symtab, delim);
return _parser.eval(expr, error, context);
}

Expand Down
1 change: 1 addition & 0 deletions src/asm_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct Assembler {
virtual void reset();

const ValueParser &parser() const { return _parser; }
ParserContext parserContext(const SymbolTable *symtab, char delim = 0) const;
bool endOfLine(StrScanner &scan) const { return _parser.endOfLine(scan); }
/** Parse |expr| text as an integer expression and get value. */
Value parseInteger(StrScanner &expr, ErrorAt &error, char delim = 0) const;
Expand Down

0 comments on commit 53737ba

Please sign in to comment.