Files
avo/internal/opcodescsv/analysis.go

49 lines
862 B
Go
Raw Normal View History

2018-11-21 13:02:18 -06:00
package opcodescsv
import (
"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 {
s, err := datasize(i.DataSize)
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
}
func datasize(s string) (int, error) {
if s == "" {
return 0, nil
}
return strconv.Atoi(s)
}