1 package asm
2
3 import (
4 "testing"
5 )
6
7 func TestDSL(t *testing.T) {
8 testcases := []struct {
9 name string
10 have Instruction
11 want Instruction
12 }{
13 {"Call", FnMapLookupElem.Call(), Instruction{OpCode: 0x85, Constant: 1}},
14 {"Exit", Return(), Instruction{OpCode: 0x95}},
15 {"LoadAbs", LoadAbs(2, Byte), Instruction{OpCode: 0x30, Constant: 2}},
16 {"Store", StoreMem(RFP, -4, R0, Word), Instruction{
17 OpCode: 0x63,
18 Dst: RFP,
19 Src: R0,
20 Offset: -4,
21 }},
22 {"Add.Imm", Add.Imm(R1, 22), Instruction{OpCode: 0x07, Dst: R1, Constant: 22}},
23 {"Add.Reg", Add.Reg(R1, R2), Instruction{OpCode: 0x0f, Dst: R1, Src: R2}},
24 {"Add.Imm32", Add.Imm32(R1, 22), Instruction{
25 OpCode: 0x04, Dst: R1, Constant: 22,
26 }},
27 {"JSGT.Imm", JSGT.Imm(R1, 4, "foo"), Instruction{
28 OpCode: 0x65, Dst: R1, Constant: 4, Offset: -1,
29 }.WithReference("foo")},
30 {"JSGT.Imm32", JSGT.Imm32(R1, -2, "foo"), Instruction{
31 OpCode: 0x66, Dst: R1, Constant: -2, Offset: -1,
32 }.WithReference("foo")},
33 {"JSLT.Reg", JSLT.Reg(R1, R2, "foo"), Instruction{
34 OpCode: 0xcd, Dst: R1, Src: R2, Offset: -1,
35 }.WithReference("foo")},
36 {"JSLT.Reg32", JSLT.Reg32(R1, R3, "foo"), Instruction{
37 OpCode: 0xce, Dst: R1, Src: R3, Offset: -1,
38 }.WithReference("foo")},
39 }
40
41 for _, tc := range testcases {
42 if !tc.have.equal(tc.want) {
43 t.Errorf("%s: have %v, want %v", tc.name, tc.have, tc.want)
44 }
45 }
46 }
47
View as plain text