add codegen
All checks were successful
Check / Explore-Gitea-Actions (push) Successful in 8s

This commit is contained in:
sfja 2026-04-16 16:36:34 +02:00
parent 728148ae42
commit ca6e9d1656
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,4 @@
import * as mir from "../../mir.ts";
export function selectFnInstructions(fn: mir.Fn) {
}

View File

@ -0,0 +1,66 @@
export class Module {
private fns: Fn[] = [];
}
export class Fn {
private blocks: Block[] = [];
}
export class Block {
private insts: Inst[] = [];
push(inst: Inst) {
this.insts.push(inst);
}
}
export class Inst {
}
export type InstKind =
| { tag: "PushR"; src: Reg }
| { tag: "PopR"; dst: Reg }
| { tag: "MovRR"; dst: Reg; src: Reg }
| { tag: "SubRI"; dst: Reg; imm: number }
| { tag: "MovRI"; dst: Reg; imm: number }
| { tag: "MovMRR"; dst: Reg; offset: number; src: Reg }
| { tag: "MovRMR"; dst: Reg; src: Reg; offset: number }
| { tag: "AddR"; dst_op1: Reg; op2: Reg }
| { tag: "Jmp"; bb: number }
| { tag: "Ret" };
export class Reg {
static tempId = 1000;
private constructor(
private id: number,
) {}
static reg(reg: Regs): Reg {
return new Reg(reg);
}
static temp(): Reg {
return new Reg(this.tempId++);
}
}
export const Regs = {
a: 1,
b: 2,
c: 3,
si: 4,
di: 5,
sp: 6,
bp: 7,
r8: 8,
r9: 9,
r10: 10,
r11: 11,
r12: 12,
r13: 13,
r14: 14,
r15: 15,
} as const;
export type Regs = typeof Regs[keyof typeof Regs];