q/src/asm/CanSkipReturn.go

25 lines
465 B
Go

package asm
// CanSkipReturn returns true if the return operation can be skipped.
func (a *Assembler) CanSkipReturn() bool {
if len(a.Instructions) == 0 {
return false
}
last := a.Instructions[len(a.Instructions)-1]
if last.Mnemonic == RETURN || last.Mnemonic == JUMP {
return true
}
if last.Mnemonic == CALL && last.Type == TypeLabel {
label := a.Param.Label[last.Index]
if label.String() == "core.exit" {
return true
}
}
return false
}