Simplified the assembler
This commit is contained in:
parent
6c432154e6
commit
a0388ae15a
5 changed files with 146 additions and 122 deletions
30
src/asm/unnecessary.go
Normal file
30
src/asm/unnecessary.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package asm
|
||||
|
||||
import "git.akyoto.dev/cli/q/src/cpu"
|
||||
|
||||
// unnecessary returns true if the register/register operation can be skipped.
|
||||
func (a *Assembler) unnecessary(mnemonic Mnemonic, left cpu.Register, right cpu.Register) bool {
|
||||
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