wip
This commit is contained in:
38
internal/opcodescsv/analysis.go
Normal file
38
internal/opcodescsv/analysis.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package opcodescsv
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/arch/x86/x86csv"
|
||||
)
|
||||
|
||||
type Alias struct {
|
||||
Opcode string
|
||||
DataSize int
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
for _, alt := range []string{i.IntelOpcode(), i.GNUOpcode()} {
|
||||
if strings.ToUpper(alt) != i.GoOpcode() {
|
||||
m[Alias{Opcode: strings.ToLower(alt), DataSize: s}] = i.GoOpcode()
|
||||
}
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func datasize(s string) (int, error) {
|
||||
if s == "" {
|
||||
return 0, nil
|
||||
}
|
||||
return strconv.Atoi(s)
|
||||
}
|
||||
19
internal/opcodescsv/io.go
Normal file
19
internal/opcodescsv/io.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package opcodescsv
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"golang.org/x/arch/x86/x86csv"
|
||||
)
|
||||
|
||||
// ReadFile reads the given x86 CSV file.
|
||||
func ReadFile(filename string) ([]*x86csv.Inst, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
r := x86csv.NewReader(f)
|
||||
return r.ReadAll()
|
||||
}
|
||||
Reference in New Issue
Block a user