55 lines
838 B
C
55 lines
838 B
C
#ifndef IR_H
|
|
#define IR_H
|
|
|
|
#include "arena.h"
|
|
#include "parse.h"
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
typedef uint32_t VReg;
|
|
|
|
#define IR_MAX_ARITY 8 // adjust as needed
|
|
|
|
typedef enum {
|
|
OP_INT,
|
|
OP_ADD,
|
|
OP_SUB,
|
|
OP_MUL
|
|
} OpCode;
|
|
|
|
typedef struct IrInst IrInst;
|
|
|
|
struct IrInst {
|
|
OpCode op;
|
|
VReg vreg;
|
|
|
|
union {
|
|
uint64_t value; // OP_INT
|
|
|
|
struct {
|
|
size_t operand_count;
|
|
IrInst* operands[IR_MAX_ARITY]; // inline storage
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
typedef struct {
|
|
Arena arena;
|
|
VReg next_vreg;
|
|
|
|
IrInst** insts;
|
|
size_t count;
|
|
size_t capacity;
|
|
} IrBlock;
|
|
|
|
void ir_block_init(IrBlock* block);
|
|
void ir_block_free(IrBlock* block);
|
|
void ir_block_print(IrBlock* block);
|
|
|
|
IrInst* ir_lower_expr(IrBlock* block, const Expr* expr);
|
|
|
|
void test_ast_lower(void);
|
|
|
|
#endif
|