Add numeric label support to assembler

This commit is contained in:
vyuuui
2025-03-24 07:16:14 -07:00
parent 5d4b884e64
commit e34907025d
7 changed files with 224 additions and 9 deletions

View File

@ -84,6 +84,26 @@ void ParseId(ParseState* state)
}
}
void ParseNumLocation(ParseState* state)
{
AssemblerToken tok = state->lexer.Lookahead();
switch (tok.token_type)
{
case TokenType::NumLabFwd:
state->plugin.OnTerminal(Terminal::NumLabFwd, tok);
break;
case TokenType::NumLabBwd:
state->plugin.OnTerminal(Terminal::NumLabBwd, tok);
break;
default:
state->EmitErrorHere(fmt::format("Invalid {} with value '{}'", tok.TypeStr(), tok.ValStr()));
return;
}
state->lexer.Eat();
}
void ParseIdLocation(ParseState* state)
{
std::array<AssemblerToken, 3> toks;
@ -184,6 +204,11 @@ void ParseBaseexpr(ParseState* state)
ParsePpcBuiltin(state);
break;
case TokenType::NumLabFwd:
case TokenType::NumLabBwd:
ParseNumLocation(state);
break;
case TokenType::Dot:
state->plugin.OnTerminal(Terminal::Dot, state->lexer.Lookahead());
if (state->error)
@ -589,6 +614,21 @@ void ParseLabel(ParseState* state)
}
state->lexer.EatN<2>();
}
if (tokens[0].token_type == TokenType::DecimalLit && tokens[1].token_type == TokenType::Colon)
{
std::optional<u32> labnum = tokens[0].EvalToken<u32>();
if (!labnum)
{
return;
}
state->plugin.OnNumericLabelDecl(tokens[0].token_val, *labnum);
if (state->error)
{
return;
}
state->lexer.EatN<2>();
}
}
void ParseResolvedExpr(ParseState* state)