Improved SSA and added unused value checks
All checks were successful
/ test (push) Successful in 17s

This commit is contained in:
Eduard Urbach 2025-06-23 23:11:05 +02:00
parent cc2e98ca49
commit 2b703e9af2
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
25 changed files with 519 additions and 213 deletions

View file

@ -4,23 +4,19 @@ import (
"testing"
"git.urbach.dev/cli/q/src/ssa"
"git.urbach.dev/cli/q/src/token"
"git.urbach.dev/go/assert"
)
func TestFunction(t *testing.T) {
fn := ssa.Function{}
fn := ssa.IR{}
a := fn.AppendInt(1)
b := fn.AppendInt(2)
c := fn.Append(ssa.Value{Type: ssa.Add, Args: []*ssa.Value{a, b}})
c := fn.Append(&ssa.BinaryOperation{Op: token.Add, Left: a, Right: b})
fn.AddBlock()
d := fn.AppendInt(3)
e := fn.AppendInt(4)
f := fn.Append(ssa.Value{Type: ssa.Add, Args: []*ssa.Value{d, e}})
f := fn.Append(&ssa.BinaryOperation{Op: token.Add, Left: d, Right: e})
assert.Equal(t, c.String(), "1 + 2")
assert.Equal(t, f.String(), "3 + 4")
}
func TestInvalidInstruction(t *testing.T) {
instr := ssa.Value{}
assert.Equal(t, instr.String(), "")
}