Reduced number of register moves
This commit is contained in:
@ -4,12 +4,23 @@ import (
|
||||
"git.akyoto.dev/cli/q/src/ast"
|
||||
"git.akyoto.dev/cli/q/src/cpu"
|
||||
"git.akyoto.dev/cli/q/src/expression"
|
||||
"git.akyoto.dev/cli/q/src/token"
|
||||
)
|
||||
|
||||
// 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 expr.Token.Kind != token.Identifier {
|
||||
return false
|
||||
}
|
||||
|
||||
variable := f.VariableByName(expr.Token.Text(f.File.Bytes))
|
||||
|
||||
if variable == nil || variable.Register != register {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if ast.IsFunctionCall(expr) {
|
||||
|
Reference in New Issue
Block a user