Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344package optimizer_test
import ( "testing"
"git.urbach.dev/cli/q/src/optimizer" "git.urbach.dev/cli/q/src/ssa" "git.urbach.dev/cli/q/src/token" "git.urbach.dev/go/assert")
func TestFoldConstants(t *testing.T) { operations := []token.Kind{ token.Add, token.And, token.Div, token.Mul, token.Mod, token.Or, token.Shl, token.Shr, token.Sub, token.Xor, }
for _, op := range operations { ir := ssa.IR{} block := ssa.NewBlock("test") ir.AddBlock(block) one := ir.Append(&ssa.Int{Int: 1}) two := ir.Append(&ssa.Int{Int: 2}) binOp := ir.Append(&ssa.BinaryOp{Op: op, Left: one, Right: two})
folded := optimizer.Fold(ir) assert.NotNil(t, folded) assert.Equal(t, block.Index(binOp), -1)
_, oneFolded := folded[one] assert.True(t, oneFolded)
_, twoFolded := folded[two] assert.True(t, twoFolded) }}