import { expect } from "chai" import { Loc } from "../../lib/ir/loc" import { prettyPrintSSA } from "../../lib/ir/pretty" import type { SSA, SSAWithBinary } from "../../lib/ir/ssa" describe("ir", () => { describe("prettyPrintSSA", () => { it("load with immediate", () => { const ssa: SSA = { dest: Loc.vari("x"), source: 42, } expect(prettyPrintSSA(ssa)).to.equal("x = 42") }) it("load with register", () => { const ssa: SSA = { dest: Loc.vari("x"), source: Loc.reg("A"), } expect(prettyPrintSSA(ssa)).to.equal("x = %A") }) it("load with temporary", () => { const ssa: SSA = { dest: Loc.vari("x"), source: Loc.temp("t0"), } expect(prettyPrintSSA(ssa)).to.equal("x = #t0") }) it("load with variable", () => { const ssa: SSA = { dest: Loc.vari("x"), source: Loc.vari("y"), } expect(prettyPrintSSA(ssa)).to.equal("x = y") }) it("unary op", () => { const ssa: SSA = { dest: Loc.vari("x"), source: Loc.vari("y"), op: "arith_negate", } expect(prettyPrintSSA(ssa)).to.equal("x = arith_negate(y)") }) it("binary op", () => { const ssa: SSAWithBinary = { dest: Loc.vari("x"), source: Loc.vari("y"), source1: 42, op: "add", } expect(prettyPrintSSA(ssa)).to.equal("x = add(y, 42)") }) }) })