Fixed incorrect number of history entries
This commit is contained in:
parent
77d354936c
commit
5f8b859f4a
9 changed files with 39 additions and 20 deletions
34
src/asm/CanSkip.go
Normal file
34
src/asm/CanSkip.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package asm
|
||||
|
||||
import "git.akyoto.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 {
|
||||
lastData, isRegReg := last.Data.(*RegisterRegister)
|
||||
|
||||
if !isRegReg {
|
||||
return false
|
||||
}
|
||||
|
||||
if lastData.Destination == left && lastData.Source == right {
|
||||
return true
|
||||
}
|
||||
|
||||
if lastData.Destination == right && lastData.Source == left {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue