Simplified file structure
This commit is contained in:
29
src/register/SaveRegister.go
Normal file
29
src/register/SaveRegister.go
Normal file
@ -0,0 +1,29 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/asm"
|
||||
"git.akyoto.dev/cli/q/src/cpu"
|
||||
)
|
||||
|
||||
// SaveRegister attempts to move a variable occupying this register to another register.
|
||||
func (f *Machine) SaveRegister(register cpu.Register) {
|
||||
if !f.RegisterIsUsed(register) {
|
||||
return
|
||||
}
|
||||
|
||||
if slices.Contains(f.CPU.General, register) {
|
||||
return
|
||||
}
|
||||
|
||||
variable := f.VariableByRegister(register)
|
||||
|
||||
if variable == nil || variable.Alive == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
newRegister := f.NewRegister()
|
||||
f.RegisterRegister(asm.MOVE, newRegister, register)
|
||||
variable.Register = newRegister
|
||||
}
|
Reference in New Issue
Block a user