mirror of
https://github.com/odin-lang/Odin.git
synced 2026-09-02 10:13:35 +00:00
Support asm template groups
This commit is contained in:
@@ -237,6 +237,9 @@ gb_internal Ast *clone_ast(Ast *node, AstFile *f) {
|
||||
case Ast_ProcGroup:
|
||||
n->ProcGroup.args = clone_ast_array(n->ProcGroup.args, f);
|
||||
break;
|
||||
case Ast_AsmGroup:
|
||||
n->AsmGroup.args = clone_ast_array(n->AsmGroup.args, f);
|
||||
break;
|
||||
case Ast_ProcLit:
|
||||
n->ProcLit.type = clone_ast(n->ProcLit.type, f);
|
||||
n->ProcLit.body = clone_ast(n->ProcLit.body, f);
|
||||
@@ -975,6 +978,15 @@ gb_internal Ast *ast_proc_group(AstFile *f, Token token, Token open, Token close
|
||||
return result;
|
||||
}
|
||||
|
||||
gb_internal Ast *ast_asm_group(AstFile *f, Token token, Token open, Token close, Array<Ast *> const &args) {
|
||||
Ast *result = alloc_ast_node(f, Ast_AsmGroup);
|
||||
result->AsmGroup.token = token;
|
||||
result->AsmGroup.open = open;
|
||||
result->AsmGroup.close = close;
|
||||
result->AsmGroup.args = slice_from_array(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
gb_internal Ast *ast_proc_lit(AstFile *f, Ast *type, Ast *body, u64 tags, Token where_token, Array<Ast *> const &where_clauses) {
|
||||
Ast *result = alloc_ast_node(f, Ast_ProcLit);
|
||||
result->ProcLit.type = type;
|
||||
@@ -2466,6 +2478,8 @@ gb_internal Ast *parse_asm_operand(AstFile *f, bool allow_memory_operand) {
|
||||
case Token_Float:
|
||||
case Token_Rune:
|
||||
return ast_basic_lit(f, advance_token(f));
|
||||
case Token_OpenParen:
|
||||
return parse_expr(f, false);
|
||||
case Token_OpenBracket:
|
||||
if (allow_memory_operand) {
|
||||
Token open = expect_token(f, Token_OpenBracket);
|
||||
@@ -3484,6 +3498,36 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
|
||||
}
|
||||
|
||||
case Token_asm:
|
||||
if (peek_token(f).kind == Token_OpenBrace) { // asm group
|
||||
Token token = expect_token(f, Token_asm);
|
||||
Token open = expect_token(f, Token_OpenBrace);
|
||||
|
||||
auto args = array_make<Ast *>(ast_allocator(f));
|
||||
|
||||
while (f->curr_token.kind != Token_CloseBrace &&
|
||||
f->curr_token.kind != Token_EOF) {
|
||||
Ast *elem = parse_expr(f, false);
|
||||
|
||||
if (f->curr_token.kind == Token_where) {
|
||||
Token where = expect_token(f, Token_where);
|
||||
Ast *cond = parse_expr(f, false);
|
||||
elem = ast_binary_expr(f, where, elem, cond);
|
||||
}
|
||||
|
||||
array_add(&args, elem);
|
||||
if (!allow_field_separator(f)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Token close = expect_token(f, Token_CloseBrace);
|
||||
|
||||
if (args.count == 0) {
|
||||
syntax_error(token, "Expected a least 1 argument in a procedure group");
|
||||
}
|
||||
|
||||
return ast_asm_group(f, token, open, close, args);
|
||||
}
|
||||
return parse_asm_template(f);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user