|
|
- import { expect } from "chai"
-
- import { Loc } from "../lib/ir/loc"
- import type { SSA } from "../lib/ir/ssa"
- import { liveness } from "../lib/live"
-
- describe("liveness", () => {
- it("computes liveness", () => {
- const x = [0, 1, 2].map(i => Loc.vari("x" + i))
- const y = [0, 1].map(i => Loc.vari("y" + i))
-
- const block: Array<SSA> = [
- { dest: x[0], source: 1 },
- { dest: x[1], source: x[0], op: "add", source1: x[0] },
- { dest: x[2], source: x[1], op: "add", source1: x[0] },
- { dest: y[0], source: x[0], op: "add", source1: x[1] },
- { dest: y[1], source: y[0], op: "add", source1: x[2] },
- ]
-
- const info = liveness(block)
-
- expect(info[0]).to.deep.equal(new Set())
- expect(info[1]).to.deep.equal(new Set([x[0]]))
- expect(info[2]).to.deep.equal(new Set([x[0], x[1]]))
- expect(info[3]).to.deep.equal(new Set([x[0], x[1], x[2]]))
- expect(info[4]).to.deep.equal(new Set([y[0], x[2]]))
- })
- })
|