Fixed incorrect number of history entries
This commit is contained in:
@ -2,8 +2,12 @@ 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 {
|
||||
// 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
|
||||
}
|
16
src/asm/CanSkipReturn.go
Normal file
16
src/asm/CanSkipReturn.go
Normal file
@ -0,0 +1,16 @@
|
||||
package asm
|
||||
|
||||
// CanSkipReturn returns true if the return operation can be skipped.
|
||||
func (a *Assembler) CanSkipReturn() bool {
|
||||
if len(a.Instructions) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
lastMnemonic := a.Instructions[len(a.Instructions)-1].Mnemonic
|
||||
|
||||
if lastMnemonic == RETURN || lastMnemonic == JUMP {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
@ -32,14 +32,6 @@ func (a *Assembler) DLLCall(name string) {
|
||||
|
||||
// Return returns back to the caller.
|
||||
func (a *Assembler) Return() {
|
||||
if len(a.Instructions) > 0 {
|
||||
lastMnemonic := a.Instructions[len(a.Instructions)-1].Mnemonic
|
||||
|
||||
if lastMnemonic == RETURN || lastMnemonic == JUMP {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
a.Instructions = append(a.Instructions, Instruction{Mnemonic: RETURN})
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,6 @@ func (data *RegisterRegister) String() string {
|
||||
|
||||
// RegisterRegister adds an instruction using two registers.
|
||||
func (a *Assembler) RegisterRegister(mnemonic Mnemonic, left cpu.Register, right cpu.Register) {
|
||||
if a.unnecessary(mnemonic, left, right) {
|
||||
return
|
||||
}
|
||||
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
Mnemonic: mnemonic,
|
||||
Data: &RegisterRegister{
|
||||
|
Reference in New Issue
Block a user