diff --git a/arm64/instgen/xmlspec/generator.go b/arm64/instgen/xmlspec/generator.go
index f81584f..e37a93f 100644
--- a/arm64/instgen/xmlspec/generator.go
+++ b/arm64/instgen/xmlspec/generator.go
@@ -125,11 +125,11 @@
const (
{{- range $i, $e := .NewGoOps}}
- {{if eq $i 0}}
+ {{- if eq $i 0}}
{{$e}} obj.As = obj.ABaseARM64 + obj.A_ARCHSPECIFIC + 1000 + iota
- {{else}}
+ {{- else}}
{{$e}}
- {{end}}
+ {{- end}}
{{- end}}
)
`
@@ -182,6 +182,16 @@
newGoOps := make(map[string]bool)
existingGoOps := readExistingGoOps(filepath.Join(outputDir, "a.out.go"))
+ allowedOperandTypes := map[string]bool{
+ "AC_ARNG": true,
+ "AC_PREG": true,
+ "AC_PREGZ": true,
+ "AC_PREGM": true,
+ "AC_ZREG": true,
+ }
+
+ usedFuncIndices := make(map[int]bool)
+
for _, inst := range insts {
for _, iclass := range inst.Classes.Iclass {
if !iclass.Regdiagram.parsed {
@@ -192,6 +202,26 @@
if !encoding.parsed {
continue
}
+
+ // Filtering logic:
+ // 1. If 0 operands (len <= 1), keep with warning.
+ // 2. If > 0 operands, ALL must be in allowedOperandTypes.
+ keep := true
+ if len(encoding.operands) <= 1 {
+ log.Printf("Warning: instruction with 0 operands kept: %s", encoding.asm)
+ } else {
+ for _, op := range encoding.operands[1:] {
+ if !allowedOperandTypes[op.typ] {
+ keep = false
+ break
+ }
+ }
+ }
+
+ if !keep {
+ continue
+ }
+
if _, ok := goOps[encoding.goOp]; !ok {
goOps[encoding.goOp] = struct{}{}
}
@@ -224,6 +254,7 @@
Index: j,
FuncIndex: idx,
})
+ usedFuncIndices[idx] = true
}
}
instData.Args = append(instData.Args, arg)
@@ -241,6 +272,8 @@
// Collect constants
encodedInMap := make(map[string]string) // raw string -> constant name
var uniqueEncodedIn []string
+
+ // Collect ALL constants from global map to ensure invariant names (ENC_X)
for _, v := range encodingDescsToEncodedIn {
if v == "" || v == "nil" {
continue
@@ -252,17 +285,33 @@
}
sort.Strings(uniqueEncodedIn)
+ // Identify used constants
+ neededEncodedIn := make(map[string]bool)
+ for k, idx := range encodingFuncs {
+ if usedFuncIndices[idx] {
+ if v := encodingDescsToEncodedIn[k]; v != "" && v != "nil" {
+ neededEncodedIn[v] = true
+ }
+ }
+ }
+
var constants []constantData
for i, v := range uniqueEncodedIn {
name := fmt.Sprintf("ENC_%d", i)
encodedInMap[v] = name
- constants = append(constants, constantData{
- ConstName: name,
- BinName: v,
- })
+ // Only add to output if used
+ if neededEncodedIn[v] {
+ constants = append(constants, constantData{
+ ConstName: name,
+ BinName: v,
+ })
+ }
}
for i, k := range sortedEncodings {
+ if !usedFuncIndices[i+1] {
+ continue
+ }
sym := encodingDescsToEncodedIn[k]
if name, ok := encodedInMap[sym]; ok {
sym = name