add more immediates to loader test

This commit is contained in:
Michael McLoughlin
2018-11-22 11:17:46 -06:00
parent c1601f0fe0
commit c67dcb7fa9
2 changed files with 29 additions and 14 deletions

View File

@@ -70,9 +70,10 @@ func arg(t string) string {
m := map[string]string{
// <xs:enumeration value="1" />
// <xs:enumeration value="3" />
"imm2u": "$3",
// <xs:enumeration value="imm4" />
// <xs:enumeration value="imm8" />
// <xs:enumeration value="imm16" />
"imm8": fmt.Sprintf("$%d", math.MaxInt8), // <xs:enumeration value="imm8" />
"imm16": fmt.Sprintf("$%d", math.MaxInt16), // <xs:enumeration value="imm16" />
"imm32": fmt.Sprintf("$%d", math.MaxInt32), // <xs:enumeration value="imm32" />
"imm64": fmt.Sprintf("$%d", math.MaxInt64), // <xs:enumeration value="imm64" />
// <xs:enumeration value="al" />

View File

@@ -49,16 +49,15 @@ func (l *Loader) Load() ([]*inst.Instruction, error) {
continue
}
opcode := l.goname(f)
if im[opcode] == nil {
im[opcode] = &inst.Instruction{
Opcode: opcode,
Summary: i.Summary,
for _, opcode := range l.gonames(f) {
if im[opcode] == nil {
im[opcode] = &inst.Instruction{
Opcode: opcode,
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]
}
func (l Loader) goname(f opcodesxml.Form) string {
func (l Loader) gonames(f opcodesxml.Form) []string {
// Return alias if available.
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.
if f.GoName != "" {
return f.GoName
return []string{f.GoName}
}
// Fallback to GAS name.
@@ -151,16 +156,25 @@ func (l Loader) goname(f opcodesxml.Form) string {
n += suffix[s]
}
return n
return []string{n}
}
func (l Loader) form(opcode string, f opcodesxml.Form) inst.Form {
// Map operands to avo format and ensure correct order.
ops := operands(f.Operands)
if !l.usesIntelOrder[opcode] {
for l, r := 0, len(ops)-1; l < r; l, r = l+1, r-1 {
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{
Operands: ops,
}