Files
avo/internal/opcodescsv/analysis.go

54 lines
1.1 KiB
Go
Raw Normal View History

2018-11-21 13:02:18 -06:00
package opcodescsv
import (
2018-11-21 23:06:29 -06:00
"reflect"
2018-11-21 13:02:18 -06:00
"strconv"
"strings"
"golang.org/x/arch/x86/x86csv"
)
type Alias struct {
2018-11-21 22:28:55 -06:00
Opcode string
DataSize int
NumOperands int
2018-11-21 13:02:18 -06:00
}
// BuildAliasMap constructs a map from AT&T/GNU/Intel to Go syntax.
func BuildAliasMap(is []*x86csv.Inst) (map[Alias]string, error) {
m := map[Alias]string{}
for _, i := range is {
2018-11-21 23:06:29 -06:00
s, err := strconv.Atoi("0" + i.DataSize)
2018-11-21 13:02:18 -06:00
if err != nil {
return nil, err
}
2018-11-21 22:28:55 -06:00
if strings.Contains(i.GoOpcode(), "/") {
continue
}
2018-11-21 13:02:18 -06:00
for _, alt := range []string{i.IntelOpcode(), i.GNUOpcode()} {
if strings.ToUpper(alt) != i.GoOpcode() {
2018-11-21 22:28:55 -06:00
a := Alias{
Opcode: strings.ToLower(alt),
DataSize: s,
NumOperands: len(i.GoArgs()),
}
m[a] = i.GoOpcode()
2018-11-21 13:02:18 -06:00
}
}
}
return m, nil
}
2018-11-21 23:06:29 -06:00
// BuildIntelOrderSet builds the set of instructions that use intel order rather than the usual GNU/AT&T order.
func BuildIntelOrderSet(is []*x86csv.Inst) map[string]bool {
s := map[string]bool{}
for _, i := range is {
if !reflect.DeepEqual(i.GoArgs(), i.GNUArgs()) {
s[i.GoOpcode()] = true
}
2018-11-21 13:02:18 -06:00
}
2018-11-21 23:06:29 -06:00
return s
2018-11-21 13:02:18 -06:00
}