#ifndef CODEGEN_X86_H #define CODEGEN_X86_H #include "arena.h" #include "ir.h" #include #include typedef enum { CG_MOV, CG_ADD8, CG_SUB8, CG_MUL8, CG_IMM64 } CgOpCode; typedef enum { RAX = 0, RDX, RCX, RBX, RSI, RDI, R8, R9, REG_COUNT } PhysReg; typedef struct { PhysReg reg; int assigned; } RegMap; typedef struct CgInst { CgOpCode op; VReg dst; union { struct { VReg lhs; VReg rhs; } binop; uint64_t imm; }; } CgInst; typedef struct { CgInst** insts; size_t count; size_t capacity; VReg next_vreg; RegMap* vreg_map; size_t vreg_map_size; Arena arena; VReg result_vreg; } CgBlock; void cg_block_init(CgBlock* b); void cg_block_free(CgBlock* b); void cg_block_print_vreg(const CgBlock* block); void cg_block_print_phys(const CgBlock* block); void ir_block_isel_x86(CgBlock* cg, const IrBlock* ir); void cg_block_regalloc_x86(CgBlock* block); void test_codegen_x86(void); #endif