A "high-level" language for the Gameboy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

40 lines
1002 B

import type { AbsInsn2 } from "./insn"
import type { Loc } from "./loc"
export class BasicBlock {
insns: Array<AbsInsn2>
labels: { [label: string]: number }
constructor(insns: Array<AbsInsn2>) {
this.insns = insns
this.labels = this.insns
.reduce((labels, insn, i) => {
if (insn.type !== "label") {
return labels
}
return {
...labels,
[insn.dest]: i,
}
}, {})
}
locs(): Set<Loc> {
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
})
)
}
}