Improved code generation
This commit is contained in:
parent
6e22febc01
commit
3c189a025f
23 changed files with 201 additions and 95 deletions
|
@ -14,6 +14,12 @@ func (f *Function) SaveRegister(register cpu.Register) {
|
|||
return
|
||||
}
|
||||
|
||||
for _, general := range f.cpu.General {
|
||||
if register == general {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var variable *Variable
|
||||
|
||||
for _, v := range f.variables {
|
||||
|
@ -29,13 +35,12 @@ func (f *Function) SaveRegister(register cpu.Register) {
|
|||
|
||||
newRegister := f.cpu.MustFindFree(f.cpu.General)
|
||||
f.cpu.Reserve(newRegister)
|
||||
f.cpu.Use(newRegister)
|
||||
|
||||
if config.Comments {
|
||||
f.assembler.Comment(fmt.Sprintf("save %s to %s", register, newRegister))
|
||||
f.Comment(fmt.Sprintf("save %s to %s", register, newRegister))
|
||||
}
|
||||
|
||||
f.assembler.RegisterRegister(asm.MOVE, newRegister, register)
|
||||
f.RegisterRegister(asm.MOVE, newRegister, register)
|
||||
f.cpu.Free(register)
|
||||
variable.Register = newRegister
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue