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.
 
 

66 lines
1.7 KiB

import { expect } from "chai"
import { Loc } from "../../lib/ir/loc"
import { prettyPrintSSA } from "../../lib/ir/pretty"
import type { SSA } 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: SSA = {
dest: Loc.vari("x"),
source: Loc.vari("y"),
source1: 42,
op: "add",
}
expect(prettyPrintSSA(ssa)).to.equal("x = add(y, 42)")
})
})
})