From 19c5bbb3c67170e5acfe91e133a52fc936ab0b2a Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Tue, 20 Nov 2018 13:51:17 -0600 Subject: [PATCH] ingester for opcodes xml --- internal/opcodesxml/opcodesxml.go | 64 ++++++++++++++++++++++++++ internal/opcodesxml/opcodesxml_test.go | 14 ++++++ 2 files changed, 78 insertions(+) create mode 100644 internal/opcodesxml/opcodesxml.go create mode 100644 internal/opcodesxml/opcodesxml_test.go diff --git a/internal/opcodesxml/opcodesxml.go b/internal/opcodesxml/opcodesxml.go new file mode 100644 index 0000000..e2a4dd0 --- /dev/null +++ b/internal/opcodesxml/opcodesxml.go @@ -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"` +} diff --git a/internal/opcodesxml/opcodesxml_test.go b/internal/opcodesxml/opcodesxml_test.go new file mode 100644 index 0000000..24a16c0 --- /dev/null +++ b/internal/opcodesxml/opcodesxml_test.go @@ -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) +}