Improved code generation

This commit is contained in:
2024-07-03 16:37:59 +02:00
parent 795935ddfb
commit 4d88260333
15 changed files with 215 additions and 275 deletions

View File

@ -59,27 +59,6 @@ func (f *Function) AddVariable(variable *Variable) {
f.cpu.Use(variable.Register)
}
func (f *Function) addTemporary(root *expression.Expression) *Variable {
f.count.tmps++
name := fmt.Sprintf("t%d", f.count.tmps)
register := f.cpu.MustUseFree(f.cpu.General)
tmp := &Variable{
Name: name,
Value: root,
Alive: 1,
Register: register,
}
f.variables[name] = tmp
if config.Comments {
f.assembler.Comment(fmt.Sprintf("%s = %s (%s)", name, root, register))
}
return tmp
}
func (f *Function) useVariable(variable *Variable) {
variable.Alive--
@ -121,7 +100,7 @@ func (f *Function) storeVariableInRegister(name string, value *expression.Expres
panic("no free registers")
}
err := f.EvaluateTo(value, reg)
err := f.ExpressionToRegister(value, reg)
f.AddVariable(&Variable{
Name: name,