From bf3bd19f79936fa519a5285701763da58935592a Mon Sep 17 00:00:00 2001 From: hachem Date: Wed, 9 Sep 2026 05:43:06 +0200 Subject: refactor: split code gen into arch seam --- src/ast.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/ast.h') diff --git a/src/ast.h b/src/ast.h index d764c13..75d8b12 100644 --- a/src/ast.h +++ b/src/ast.h @@ -118,6 +118,7 @@ enum StatementKind STATEMENT_WHILE, STATEMENT_CALL, STATEMENT_STACK, + STATEMENT_INSTRUCTION, }; struct AssignStatement @@ -175,6 +176,17 @@ struct StackStatement struct Expr* size; }; +// a bare instruction: a mnemonic and its operands emitted verbatim, the escape +// hatch for anything outside the assignment / control-flow model (int, hlt, +// lgdt, in/out, ...) +struct InstructionStatement +{ + struct Token mnemonic; + struct Expr** operands; + size_t operand_count; + size_t operand_capacity; +}; + struct Statement { enum StatementKind kind; @@ -187,6 +199,7 @@ struct Statement struct WhileStatement loop; struct CallStatement call; struct StackStatement stack; + struct InstructionStatement instruction; }; }; @@ -202,12 +215,22 @@ struct ProcDecl size_t body_capacity; }; +enum OutputFormat +{ + OUTPUT_ELF, + OUTPUT_BIN, +}; + struct Config { uint32_t bits; bool has_entry; struct Token entry; bool logical_registers; + enum OutputFormat format; + bool has_org; + struct Token org; + bool boot; }; struct Program -- cgit v1.3