add instruction arities function

This commit is contained in:
Michael McLoughlin
2018-11-25 18:25:51 -08:00
parent 09848512cc
commit 4dcfed6e16
2 changed files with 35 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
package inst
import "sort"
type Instruction struct {
Opcode string
AliasOf string
@@ -7,6 +9,19 @@ type Instruction struct {
Forms []Form
}
func (i Instruction) Arities() []int {
s := map[int]bool{}
for _, f := range i.Forms {
s[len(f.Operands)] = true
}
a := make([]int, 0, len(s))
for n := range s {
a = append(a, n)
}
sort.Ints(a)
return a
}
type Form struct {
ISA []string
Operands []Operand