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.

28 lines
1022 B

  1. import { expect } from "chai"
  2. import { Loc } from "../lib/ir/loc"
  3. import type { SSA } from "../lib/ir/ssa"
  4. import { liveness } from "../lib/live"
  5. describe("liveness", () => {
  6. it("computes liveness", () => {
  7. const x = [0, 1, 2].map(i => Loc.vari("x" + i))
  8. const y = [0, 1].map(i => Loc.vari("y" + i))
  9. const block: Array<SSA> = [
  10. { dest: x[0], source: 1 },
  11. { dest: x[1], source: x[0], op: "add", source1: x[0] },
  12. { dest: x[2], source: x[1], op: "add", source1: x[0] },
  13. { dest: y[0], source: x[0], op: "add", source1: x[1] },
  14. { dest: y[1], source: y[0], op: "add", source1: x[2] },
  15. ]
  16. const info = liveness(block)
  17. expect(info[0]).to.deep.equal(new Set())
  18. expect(info[1]).to.deep.equal(new Set([x[0]]))
  19. expect(info[2]).to.deep.equal(new Set([x[0], x[1]]))
  20. expect(info[3]).to.deep.equal(new Set([x[0], x[1], x[2]]))
  21. expect(info[4]).to.deep.equal(new Set([y[0], x[2]]))
  22. })
  23. })