q/src/asm/CanSkip.go

35 lines
725 B
Go

package asm
import "git.urbach.dev/cli/q/src/cpu"
// CanSkip returns true if the register/register operation can be skipped.
func (a *Assembler) CanSkip(mnemonic Mnemonic, left cpu.Register, right cpu.Register) bool {
if mnemonic == MOVE && left == right {
return true
}
if len(a.Instructions) == 0 {
return false
}
last := a.Instructions[len(a.Instructions)-1]
if mnemonic == MOVE && last.Mnemonic == MOVE {
if last.Type != TypeRegisterRegister {
return false
}
lastData := a.Param.RegisterRegister[last.Index]
if lastData.Destination == right && lastData.Source == left {
return true
}
if lastData.Destination == left && lastData.Source == right {
return true
}
}
return false
}