Simplified file structure

This commit is contained in:
2024-08-07 19:39:10 +02:00
parent 1b13539b22
commit 66569446b1
219 changed files with 453 additions and 457 deletions

40
src/core/UsesRegister.go Normal file
View 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
}