ingester for opcodes xml
This commit is contained in:
64
internal/opcodesxml/opcodesxml.go
Normal file
64
internal/opcodesxml/opcodesxml.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package opcodesxml
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Read(r io.Reader) (*InstructionSet, error) {
|
||||
d := xml.NewDecoder(r)
|
||||
is := &InstructionSet{}
|
||||
if err := d.Decode(is); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return is, nil
|
||||
}
|
||||
|
||||
func ReadFile(filename string) (*InstructionSet, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return Read(f)
|
||||
}
|
||||
|
||||
type InstructionSet struct {
|
||||
Name string `xml:"name,attr"`
|
||||
Instructions []Instruction `xml:"Instruction"`
|
||||
}
|
||||
|
||||
type Instruction struct {
|
||||
Name string `xml:"name,attr"`
|
||||
Summary string `xml:"summary,attr"`
|
||||
Forms []Form `xml:"InstructionForm"`
|
||||
}
|
||||
|
||||
type Form struct {
|
||||
GASName string `xml:"gas-name,attr"`
|
||||
GoName string `xml:"go-name,attr"`
|
||||
MMXMode string `xml:"mmx-mode,attr"`
|
||||
XMMMode string `xml:"xmm-mode,attr"`
|
||||
CancellingInputs bool `xml:"cancelling-inputs,attr"`
|
||||
Operands []Operand `xml:"Operand"`
|
||||
ImplicitOperands []ImplicitOperand `xml:"ImplicitOperand"`
|
||||
ISA []ISA `xml:"ISA"`
|
||||
}
|
||||
|
||||
type Operand struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Input bool `xml:"input,attr"`
|
||||
Output bool `xml:"output,attr"`
|
||||
}
|
||||
|
||||
type ImplicitOperand struct {
|
||||
ID string `xml:"id,attr"`
|
||||
Input bool `xml:"input,attr"`
|
||||
Output bool `xml:"output,attr"`
|
||||
}
|
||||
|
||||
type ISA struct {
|
||||
ID string `xml:"id,attr"`
|
||||
}
|
||||
14
internal/opcodesxml/opcodesxml_test.go
Normal file
14
internal/opcodesxml/opcodesxml_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package opcodesxml
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadFile(t *testing.T) {
|
||||
is, err := ReadFile("testdata/x86_64.xml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%#v\n", is)
|
||||
}
|
||||
Reference in New Issue
Block a user