start at some basic passes
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package inst
|
||||
|
||||
import "sort"
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Instruction struct {
|
||||
Opcode string
|
||||
@@ -9,6 +12,29 @@ type Instruction struct {
|
||||
Forms []Form
|
||||
}
|
||||
|
||||
func (i Instruction) IsTerminal() bool {
|
||||
// TODO(mbm): how about the RETF* instructions
|
||||
return i.Opcode == "RET"
|
||||
}
|
||||
|
||||
func (i Instruction) IsBranch() bool {
|
||||
if i.Opcode == "CALL" {
|
||||
return false
|
||||
}
|
||||
for _, f := range i.Forms {
|
||||
for _, op := range f.Operands {
|
||||
if strings.HasPrefix(op.Type, "rel") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (i Instruction) IsConditionalBranch() bool {
|
||||
return i.IsBranch() && i.Opcode != "JMP"
|
||||
}
|
||||
|
||||
func (i Instruction) Arities() []int {
|
||||
s := map[int]bool{}
|
||||
for _, f := range i.Forms {
|
||||
|
||||
Reference in New Issue
Block a user