#include #include #include "regalloc.h" struct allocation* regalloc(const struct ir *ir) { int maxreg = 0; for (int i = 0; i < ir->len; i++) { const struct irins *ins = ir->inss[i]; bool haveref[3]; irins_which_refs(ins, haveref); for (int ri = 0; ri < 3; ri++) { if (haveref[ri] && ins->three_refs[ri].reg > maxreg) { maxreg = ins->three_refs[ri].reg; } } } struct allocation *alloc = malloc(sizeof(struct allocation)); alloc->numregs = maxreg + 1; alloc->allocs = malloc(alloc->numregs * sizeof(struct allocation_record)); for (int i = 0; i < alloc->numregs; i++) { alloc->allocs[i].spill = true; // lel } return alloc; } void allocation_delete(struct allocation *alloc) { free(alloc->allocs); free(alloc); }