package build import ( "git.akyoto.dev/cli/q/src/build/asm" "git.akyoto.dev/cli/q/src/build/config" "git.akyoto.dev/cli/q/src/build/cpu" ) // SaveRegister attempts to move a variable occupying this register to another register. func (f *Function) SaveRegister(register cpu.Register) { if f.cpu.IsFree(register) { return } var variable *Variable for _, v := range f.variables { if v.Register == register { variable = v break } } if variable == nil || variable.Alive == 0 { return } newRegister, exists := f.cpu.FindFree(f.cpu.General) if !exists { panic("no free registers") } if config.Verbose { f.Logf("moving %s from %s to %s (alive: %d)", variable.Name, variable.Register, newRegister, variable.Alive) } f.assembler.RegisterRegister(asm.MOVE, newRegister, register) f.cpu.Free(register) f.cpu.Use(newRegister) variable.Register = newRegister }