From 38fd557a61e7366140b6fbdacfebc3ad28f55369 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 25 Apr 2022 11:21:28 -0300 Subject: Remove and update old code in ir.h --- src/ir.c | 115 +-------------------------------------------------------------- 1 file changed, 1 insertion(+), 114 deletions(-) (limited to 'src/ir.c') diff --git a/src/ir.c b/src/ir.c index 075ebe3..f1b7eb9 100644 --- a/src/ir.c +++ b/src/ir.c @@ -1,121 +1,8 @@ -typedef enum Operator { - // Arithmetic ops. - OP_ADD, - OP_SUB, - OP_MUL, - OP_DIV, - OP_MOD, - - // Load/store/copy operations. - OP_LD8, - OP_LD16, - OP_LD32, - OP_LD64, - OP_ST8, - OP_ST16, - OP_ST32, - OP_ST64, - OP_CP8, - OP_CP16, - OP_CP32, - OP_CP64, - - // Bit fiddling operations. - OP_NOT, - OP_AND, - OP_OR, - OP_XOR, - OP_LSHIFT, - OP_RSHIFT, - OP_LROT, - OP_RROT, - - // (Un)conditional jump operations. - OP_LABEL, - OP_JMP, - OP_JMP_EQ, - OP_JMP_NEQ, - OP_JMP_GT, - OP_JMP_LT, - OP_JMP_GE, - OP_JMP_LE, -} Operator; - -typedef enum OperandType { - OP_TYPE_REG, - OP_TYPE_CONST, - OP_TYPE_LABEL, -} OperandType; +#include "ir.h" static size_t reg_gen_id = 0; static size_t lab_gen_id = 0; -#define NEW_REG() (Operand){ .type = OP_TYPE_REG, .id = reg_gen_id++ } -#define NEW_LAB() (Operand){ .type = OP_TYPE_LABEL, .id = lab_gen_id++ } -#define NEW_S64(C) (Operand){ .type = OP_TYPE_CONST, .constant.sval = (C) } -#define EMIT_0(PROGRAM, LINE, OP, DST) do { \ - Instruction inst = (Instruction){ \ - .op = (OP), \ - .dst = (DST), \ - }; \ - array_push((PROGRAM)->inst, inst); \ - array_push((PROGRAM)->lines, (LINE)); \ - } while(false); -#define EMIT_1(PROGRAM, LINE, OP, DST, A) do { \ - Instruction inst = (Instruction){ \ - .op = (OP), \ - .dst = (DST), \ - .src_a = (A), \ - }; \ - array_push((PROGRAM)->inst, inst); \ - array_push((PROGRAM)->lines, (LINE)); \ - } while(false); -#define EMIT_2(PROGRAM, LINE, OP, DST, A, B) do { \ - Instruction inst = (Instruction){ \ - .op = (OP), \ - .dst = (DST), \ - .src_a = (A), \ - .src_b = (B), \ - }; \ - array_push((PROGRAM)->inst, inst); \ - array_push((PROGRAM)->lines, (LINE)); \ - } while(false); - -typedef struct Operand { - OperandType type; - union { - // REG/LABEL - size_t id; - - // s64 constant; - struct { - union { - u64 uval; - s64 sval; - }; - } constant; - }; -} Operand; - -typedef struct Instruction { - Operator op; - Operand dst; - Operand src_a; - Operand src_b; -} Instruction; - -typedef struct LineInfo { - size_t line; - size_t col; -} LineInfo; - -typedef struct ProgramBASM { - Instruction *inst; - LineInfo *lines; -} ProgramBASM; - -Operand emit_basm(ProgramBASM *program, Node *node); - Operand emit_arith(ProgramBASM *program, Node *node, Operator op) { LineInfo line = (LineInfo){ -- cgit v1.2.1