add more immediates to loader test
This commit is contained in:
@@ -70,9 +70,10 @@ func arg(t string) string {
|
|||||||
m := map[string]string{
|
m := map[string]string{
|
||||||
// <xs:enumeration value="1" />
|
// <xs:enumeration value="1" />
|
||||||
// <xs:enumeration value="3" />
|
// <xs:enumeration value="3" />
|
||||||
|
"imm2u": "$3",
|
||||||
// <xs:enumeration value="imm4" />
|
// <xs:enumeration value="imm4" />
|
||||||
// <xs:enumeration value="imm8" />
|
"imm8": fmt.Sprintf("$%d", math.MaxInt8), // <xs:enumeration value="imm8" />
|
||||||
// <xs:enumeration value="imm16" />
|
"imm16": fmt.Sprintf("$%d", math.MaxInt16), // <xs:enumeration value="imm16" />
|
||||||
"imm32": fmt.Sprintf("$%d", math.MaxInt32), // <xs:enumeration value="imm32" />
|
"imm32": fmt.Sprintf("$%d", math.MaxInt32), // <xs:enumeration value="imm32" />
|
||||||
"imm64": fmt.Sprintf("$%d", math.MaxInt64), // <xs:enumeration value="imm64" />
|
"imm64": fmt.Sprintf("$%d", math.MaxInt64), // <xs:enumeration value="imm64" />
|
||||||
// <xs:enumeration value="al" />
|
// <xs:enumeration value="al" />
|
||||||
|
|||||||
@@ -49,16 +49,15 @@ func (l *Loader) Load() ([]*inst.Instruction, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
opcode := l.goname(f)
|
for _, opcode := range l.gonames(f) {
|
||||||
|
if im[opcode] == nil {
|
||||||
if im[opcode] == nil {
|
im[opcode] = &inst.Instruction{
|
||||||
im[opcode] = &inst.Instruction{
|
Opcode: opcode,
|
||||||
Opcode: opcode,
|
Summary: i.Summary,
|
||||||
Summary: i.Summary,
|
}
|
||||||
}
|
}
|
||||||
|
im[opcode].Forms = append(im[opcode].Forms, l.form(opcode, f))
|
||||||
}
|
}
|
||||||
|
|
||||||
im[opcode].Forms = append(im[opcode].Forms, l.form(opcode, f))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,15 +127,21 @@ func (l Loader) lookupAlias(f opcodesxml.Form) string {
|
|||||||
return l.alias[a]
|
return l.alias[a]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Loader) goname(f opcodesxml.Form) string {
|
func (l Loader) gonames(f opcodesxml.Form) []string {
|
||||||
// Return alias if available.
|
// Return alias if available.
|
||||||
if a := l.lookupAlias(f); a != "" {
|
if a := l.lookupAlias(f); a != "" {
|
||||||
return a
|
return []string{a}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some odd special cases.
|
||||||
|
// TODO(mbm): can this be handled by processing csv entries with slashes /
|
||||||
|
if f.GoName == "RET" && len(f.Operands) == 1 {
|
||||||
|
return []string{"RETFW", "RETFL", "RETFQ"}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use go opcode from Opcodes XML where available.
|
// Use go opcode from Opcodes XML where available.
|
||||||
if f.GoName != "" {
|
if f.GoName != "" {
|
||||||
return f.GoName
|
return []string{f.GoName}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to GAS name.
|
// Fallback to GAS name.
|
||||||
@@ -151,16 +156,25 @@ func (l Loader) goname(f opcodesxml.Form) string {
|
|||||||
n += suffix[s]
|
n += suffix[s]
|
||||||
}
|
}
|
||||||
|
|
||||||
return n
|
return []string{n}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Loader) form(opcode string, f opcodesxml.Form) inst.Form {
|
func (l Loader) form(opcode string, f opcodesxml.Form) inst.Form {
|
||||||
|
// Map operands to avo format and ensure correct order.
|
||||||
ops := operands(f.Operands)
|
ops := operands(f.Operands)
|
||||||
if !l.usesIntelOrder[opcode] {
|
if !l.usesIntelOrder[opcode] {
|
||||||
for l, r := 0, len(ops)-1; l < r; l, r = l+1, r-1 {
|
for l, r := 0, len(ops)-1; l < r; l, r = l+1, r-1 {
|
||||||
ops[l], ops[r] = ops[r], ops[l]
|
ops[l], ops[r] = ops[r], ops[l]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle some exceptions.
|
||||||
|
// TODO(mbm): consider if there's some nicer way to handle the list of special cases.
|
||||||
|
switch opcode {
|
||||||
|
case "SHA1RNDS4":
|
||||||
|
ops[0].Type = "imm2u"
|
||||||
|
}
|
||||||
|
|
||||||
return inst.Form{
|
return inst.Form{
|
||||||
Operands: ops,
|
Operands: ops,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user