diff options
| author | gingerBill <bill@gingerbill.org> | 2020-10-24 16:32:37 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-10-24 16:32:37 +0100 |
| commit | 4629754f7ced5df477eb017872ef65539db64a27 (patch) | |
| tree | fc2fc4b7a493c58adeb10bf54254fbbad66f2f67 /src/parser.hpp | |
| parent | 0061e63db010cdb2043af63527b4c25f45652a51 (diff) | |
Inline asm expression (-llvm-api)
See https://llvm.org/docs/LangRef.html#inline-assembler-expressions
Example:
```
x := asm(i32) -> i32 {
"bswap $0",
"=r,r",
}(123);
```
Allowed directives `#side_effect`, `#align_stack`, `#att`, `#intel` e.g. `asm() #side_effect #intel {...}`
Diffstat (limited to 'src/parser.hpp')
| -rw-r--r-- | src/parser.hpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/parser.hpp b/src/parser.hpp index ff47d1887..8e210876f 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -209,6 +209,8 @@ enum ProcCallingConvention { ProcCC_None = 7, ProcCC_PureNone = 8, + ProcCC_InlineAsm = 9, + ProcCC_MAX, @@ -250,6 +252,20 @@ enum StmtAllowFlag { StmtAllowFlag_Label = 1<<1, }; +enum InlineAsmDialectKind : u8 { + InlineAsmDialect_Default, // ATT is default + InlineAsmDialect_ATT, + InlineAsmDialect_Intel, + + InlineAsmDialect_COUNT, +}; + +char const *inline_asm_dialect_strings[InlineAsmDialect_COUNT] = { + "", + "att", + "intel", +}; + #define AST_KINDS \ AST_KIND(Ident, "identifier", struct { \ Token token; \ @@ -323,6 +339,17 @@ AST_KIND(_ExprBegin, "", bool) \ AST_KIND(TypeAssertion, "type assertion", struct { Ast *expr; Token dot; Ast *type; Type *type_hint; }) \ AST_KIND(TypeCast, "type cast", struct { Token token; Ast *type, *expr; }) \ AST_KIND(AutoCast, "auto_cast", struct { Token token; Ast *expr; }) \ + AST_KIND(InlineAsmExpr, "inline asm expression", struct { \ + Token token; \ + Token open, close; \ + Array<Ast *> param_types; \ + Ast *return_type; \ + Ast *asm_string; \ + Ast *constraints_string; \ + bool has_side_effects; \ + bool is_align_stack; \ + InlineAsmDialectKind dialect; \ + }) \ AST_KIND(_ExprEnd, "", bool) \ AST_KIND(_StmtBegin, "", bool) \ AST_KIND(BadStmt, "bad statement", struct { Token begin, end; }) \ @@ -337,10 +364,6 @@ AST_KIND(_StmtBegin, "", bool) \ Token op; \ Array<Ast *> lhs, rhs; \ }) \ - AST_KIND(IncDecStmt, "increment decrement statement", struct { \ - Token op; \ - Ast *expr; \ - }) \ AST_KIND(_ComplexStmtBegin, "", bool) \ AST_KIND(BlockStmt, "block statement", struct { \ Array<Ast *> stmts; \ |