add instruction arities function
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user