start at some basic passes

This commit is contained in:
Michael McLoughlin
2018-12-02 12:28:33 -08:00
parent 0ceb1c55a4
commit 43575d8b61
14 changed files with 7209 additions and 3904 deletions

View File

@@ -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 {