Allow parsing of asm instructions being a keyword

This commit is contained in:
gingerBill
2026-08-20 09:37:34 +01:00
parent 73bb97ceb4
commit 4e0fe5cf4f

View File

@@ -2570,6 +2570,7 @@ gb_internal Slice<Ast *> parse_asm_operands(AstFile *f) {
operands.allocator = heap_allocator();
while (f->curr_token.kind != Token_Semicolon &&
f->curr_token.kind != Token_CloseBrace &&
f->curr_token.kind != Token_EOF) {
Ast *operand = parse_asm_operand(f, true);
if (operand != nullptr) {
@@ -2587,19 +2588,40 @@ gb_internal Slice<Ast *> parse_asm_operands(AstFile *f) {
return slice_from_array(operands);
}
gb_internal Ast *parse_asm_ident(AstFile *f, bool allow_poly_names=false) {
Token token = f->curr_token;
if (token.kind == Token_Ident) {
advance_token(f);
} else if (token_is_keyword(token.kind)) {
advance_token(f);
} else {
token.string = str_lit("_");
expect_token(f, Token_Ident);
}
return ast_ident(f, token);
}
gb_internal Ast *parse_asm_instruction(AstFile *f) {
if (allow_token(f, Token_Semicolon)) {
return nullptr;
}
if (token_is_keyword(f->curr_token.kind)) {
Ast *name = parse_asm_ident(f);
auto operands = parse_asm_operands(f);
Ast *instruction = alloc_ast_node(f, Ast_AsmInstruction);
instruction->AsmInstruction.name = name;
instruction->AsmInstruction.operands = operands;
instruction->AsmInstruction.valid_form_index = -1;
return instruction;
}
switch (f->curr_token.kind) {
default:
if (!token_is_keyword(f->curr_token.kind)) {
break;
}
/*fallthrough*/
case Token_Ident:
{
Ast *name = parse_ident(f);
Ast *name = parse_asm_ident(f);
auto operands = parse_asm_operands(f);
Ast *instruction = alloc_ast_node(f, Ast_AsmInstruction);
instruction->AsmInstruction.name = name;