Implemented a basic API for SSA
All checks were successful
/ test (push) Successful in 16s

This commit is contained in:
Eduard Urbach 2025-06-20 23:42:58 +02:00
parent 89f375f4fc
commit 14bccadd0f
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
7 changed files with 54 additions and 16 deletions

View file

@ -4,11 +4,19 @@ import (
"testing"
"git.urbach.dev/cli/q/src/ssa"
"git.urbach.dev/go/assert"
)
func TestBlock(t *testing.T) {
block := &ssa.Block{}
block.Append(ssa.Instruction{Type: ssa.Int, Int: 1})
block.Append(ssa.Instruction{Type: ssa.Int, Int: 2})
block.Append(ssa.Instruction{Type: ssa.Add, Parameters: []ssa.Index{0, 1}})
f := ssa.Function{}
block := f.AddBlock()
a := block.Append(ssa.Instruction{Type: ssa.Int, Int: 1})
b := block.Append(ssa.Instruction{Type: ssa.Int, Int: 2})
c := block.Append(ssa.Instruction{Type: ssa.Add, Args: []*ssa.Instruction{a, b}})
assert.Equal(t, c.String(), "1 + 2")
}
func TestInvalidInstruction(t *testing.T) {
instr := ssa.Instruction{}
assert.Equal(t, instr.String(), "")
}