import type { AbsInsn2 } from "./insn" import type { Loc } from "./loc" export class BasicBlock { insns: Array labels: { [label: string]: number } constructor(insns: Array) { this.insns = insns this.labels = this.insns .reduce((labels, insn, i) => { if (insn.type !== "label") { return labels } return { ...labels, [insn.dest]: i, } }, {}) } locs(): Set { return new Set( this.insns.flatMap(insn => { const insnLocs = [] if (insn.type === "copy" || insn.type === "unary") { insnLocs.push(insn.dest) if (typeof insn.source !== "number") { insnLocs.push(insn.source) } } return insnLocs }) ) } }