Simplified ssa package
All checks were successful
/ test (push) Successful in 15s

This commit is contained in:
Eduard Urbach 2025-07-03 22:54:30 +02:00
parent b77d876ebb
commit ca9595d1fb
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
28 changed files with 179 additions and 649 deletions

65
src/ssa/common.go Normal file
View file

@ -0,0 +1,65 @@
package ssa
import (
"strings"
"git.urbach.dev/cli/q/src/token"
)
// Arguments defines a list of values that this value depends on.
type Arguments []Value
func (v Arguments) Inputs() []Value { return v }
// String returns a comma-separated list of all arguments.
func (v Arguments) String() string {
tmp := strings.Builder{}
for i, arg := range v {
tmp.WriteString(arg.String())
if i != len(v)-1 {
tmp.WriteString(", ")
}
}
return tmp.String()
}
func (a Arguments) Equals(b Arguments) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if !a[i].Equals(b[i]) {
return false
}
}
return true
}
// Liveness tracks where the value is used.
type Liveness struct {
users []Value
}
func (v *Liveness) AddUser(user Value) { v.users = append(v.users, user) }
func (v *Liveness) Users() []Value { return v.users }
type HasLiveness interface {
AddUser(Value)
Users() []Value
}
// Source tracks the source tokens.
type Source token.List
func (v Source) Start() token.Position { return v[0].Position }
func (v Source) End() token.Position { return v[len(v)-1].End() }
type HasSource interface {
Start() token.Position
End() token.Position
}