ingester for opcodes xml

This commit is contained in:
Michael McLoughlin
2018-11-20 13:51:17 -06:00
parent 7c2990754f
commit 19c5bbb3c6
2 changed files with 78 additions and 0 deletions

View 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"`
}