q/src/asm/CanSkip.go

35 lines
725 B
Go
Raw Normal View History

2024-07-09 11:43:33 +02:00
package asm
2025-02-25 17:16:09 +01:00
import "git.urbach.dev/cli/q/src/cpu"
2024-07-09 11:43:33 +02:00
// 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
}
2024-07-09 11:43:33 +02:00
if len(a.Instructions) == 0 {
return false
}
last := a.Instructions[len(a.Instructions)-1]
if mnemonic == MOVE && last.Mnemonic == MOVE {
2025-03-11 06:31:21 +01:00
if last.Type != TypeRegisterRegister {
2024-07-09 11:43:33 +02:00
return false
}
2025-03-11 06:31:21 +01:00
lastData := a.Param.RegisterRegister[last.Index]
2025-03-02 17:53:18 +01:00
if lastData.Destination == right && lastData.Source == left {
2024-07-09 11:43:33 +02:00
return true
}
2025-03-02 17:53:18 +01:00
if lastData.Destination == left && lastData.Source == right {
2024-07-09 11:43:33 +02:00
return true
}
}
return false
}