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.

33 lines
754 B

  1. import type { Loc } from "./ir/loc"
  2. import type { SSA } from "./ir/ssa"
  3. export type LivenessInfo = Array<Set<Loc>>
  4. export const liveness = (block: Array<SSA>): LivenessInfo => {
  5. const info: LivenessInfo = []
  6. for (let i = block.length - 1; i >= 0; --i) {
  7. const insn = block[i]
  8. const last = info[i + 1] || new Set()
  9. info[i] = new Set()
  10. if (typeof insn.source !== "number") {
  11. info[i].add(insn.source)
  12. }
  13. if ("source1" in insn && typeof insn.source1 !== "number") {
  14. info[i].add(insn.source1)
  15. }
  16. last.forEach(loc => {
  17. if (loc === insn.dest) {
  18. return
  19. }
  20. info[i].add(loc)
  21. })
  22. }
  23. return info
  24. }