asm.h (2034B)
1 #ifndef KIT_ARCH_RV64_ASM_H 2 #define KIT_ARCH_RV64_ASM_H 3 4 /* RV64 standalone .s instruction parser + inline-asm template walker. 5 * 6 * The standalone path is exposed through the ArchAsm vtable returned by 7 * rv64_arch_asm_new. Inline asm uses the lower-level Rv64Asm handle plus 8 * the bind / run_template pair, mirroring the aa64 surface. */ 9 10 #include "arch/arch.h" 11 #include "asm/asm_lex.h" 12 #include "core/core.h" 13 14 typedef struct AsmDriver AsmDriver; 15 typedef struct Rv64Asm Rv64Asm; 16 17 /* Private pseudo operand used by the rv64 inline-asm binder. Semantic CG 18 * operands never expose physical registers, so native.c lowers register 19 * constraints into this arch-private shape before template substitution: 20 * Operand.kind = RV64_INLINE_OPK_REG, Operand.v.local carries the 5-bit 21 * physical register number, Operand.pad[0] carries RV64_INLINE_OPCLS_*. 22 * Memory operands reuse OPK_INDIRECT with v.ind.base holding the physical 23 * base register and v.ind.index == CG_LOCAL_NONE. */ 24 enum { 25 RV64_INLINE_OPK_REG = 0xf0u, 26 RV64_INLINE_OPCLS_INT = 0u, 27 RV64_INLINE_OPCLS_FP = 1u, 28 }; 29 30 ArchAsm* rv64_arch_asm_new(Compiler*); 31 32 /* ---- inline-asm entry points (parallel to aa64) ---- */ 33 34 Rv64Asm* rv64_asm_open(Compiler* c); 35 void rv64_asm_close(Rv64Asm*); 36 37 /* Bind the operand arrays + clobbers from the cg-side asm_block call onto 38 * the Rv64Asm handle. Operand indexing per the GCC convention: outputs are 39 * indexed 0..nout-1, then nout..nout+nin-1. */ 40 void rv64_inline_bind(Rv64Asm*, const AsmConstraint* outs, u32 nout, 41 Operand* out_ops, const AsmConstraint* ins, u32 nin, 42 const Operand* in_ops, const Sym* clobbers, u32 nclob); 43 44 /* Walk the inline-asm template, substituting placeholders into per-line 45 * source text and re-lexing each line through the standalone rv64 46 * instruction parser. Must be called after rv64_inline_bind. Emits into 47 * `mc` (must equal the MCEmitter the caller's CGTarget is using). */ 48 void rv64_asm_run_template(Rv64Asm*, MCEmitter* mc, const char* tmpl); 49 50 #endif