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

  1. import { expect } from "chai"
  2. import { Loc } from "../../lib/ir/loc"
  3. import { prettyPrintSSA } from "../../lib/ir/pretty"
  4. import type { SSA, SSAWithBinary } from "../../lib/ir/ssa"
  5. describe("ir", () => {
  6. describe("prettyPrintSSA", () => {
  7. it("load with immediate", () => {
  8. const ssa: SSA = {
  9. dest: Loc.vari("x"),
  10. source: 42,
  11. }
  12. expect(prettyPrintSSA(ssa)).to.equal("x = 42")
  13. })
  14. it("load with register", () => {
  15. const ssa: SSA = {
  16. dest: Loc.vari("x"),
  17. source: Loc.reg("A"),
  18. }
  19. expect(prettyPrintSSA(ssa)).to.equal("x = %A")
  20. })
  21. it("load with temporary", () => {
  22. const ssa: SSA = {
  23. dest: Loc.vari("x"),
  24. source: Loc.temp("t0"),
  25. }
  26. expect(prettyPrintSSA(ssa)).to.equal("x = #t0")
  27. })
  28. it("load with variable", () => {
  29. const ssa: SSA = {
  30. dest: Loc.vari("x"),
  31. source: Loc.vari("y"),
  32. }
  33. expect(prettyPrintSSA(ssa)).to.equal("x = y")
  34. })
  35. it("unary op", () => {
  36. const ssa: SSA = {
  37. dest: Loc.vari("x"),
  38. source: Loc.vari("y"),
  39. op: "arith_negate",
  40. }
  41. expect(prettyPrintSSA(ssa)).to.equal("x = arith_negate(y)")
  42. })
  43. it("binary op", () => {
  44. const ssa: SSAWithBinary = {
  45. dest: Loc.vari("x"),
  46. source: Loc.vari("y"),
  47. source1: 42,
  48. op: "add",
  49. }
  50. expect(prettyPrintSSA(ssa)).to.equal("x = add(y, 42)")
  51. })
  52. })
  53. })