From 4e0fe5cf4f86dd0f20f6e151a865cb75700a0afd Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 20 Aug 2026 09:37:34 +0100 Subject: [PATCH] Allow parsing of asm instructions being a keyword --- src/parser.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index 69f9c2690..f9605cd47 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2570,6 +2570,7 @@ gb_internal Slice 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 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;