Simplified file structure
This commit is contained in:
40
src/core/UsesRegister.go
Normal file
40
src/core/UsesRegister.go
Normal file
@ -0,0 +1,40 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/ast"
|
||||
"git.akyoto.dev/cli/q/src/cpu"
|
||||
"git.akyoto.dev/cli/q/src/expression"
|
||||
)
|
||||
|
||||
// UsesRegister returns true if evaluating the expression would write or read the given register.
|
||||
func (f *Function) UsesRegister(expr *expression.Expression, register cpu.Register) bool {
|
||||
if expr.IsLeaf() {
|
||||
return false
|
||||
}
|
||||
|
||||
if ast.IsFunctionCall(expr) {
|
||||
if register == f.CPU.Output[0] {
|
||||
return true
|
||||
}
|
||||
|
||||
for i, parameter := range expr.Children[1:] {
|
||||
if register == f.CPU.Input[i] {
|
||||
return true
|
||||
}
|
||||
|
||||
if f.UsesRegister(parameter, register) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
for _, child := range expr.Children {
|
||||
if f.UsesRegister(child, register) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user