[script] Move InstrStat to script/stats.go

This commit is contained in:
Zorchenhimer 2025-09-13 14:03:45 -04:00
parent 045f204a6b
commit d8cc126c04
Signed by: Zorchenhimer
GPG Key ID: 70A1AB767AAB9C20
2 changed files with 26 additions and 11 deletions

View File

@ -1,7 +1,6 @@
package script
import (
"fmt"
)
type Script struct {
@ -14,15 +13,6 @@ type Script struct {
Labels map[int]*Label
}
type InstrStat struct {
Instr *Instruction
Count int
}
func (is InstrStat) String() string {
return fmt.Sprintf("0x%02X %3d %s", is.Instr.Opcode, is.Count, is.Instr.String())
}
func (s *Script) Stats() Stats {
st := make(Stats)

View File

@ -9,6 +9,15 @@ import (
type Stats map[byte]*InstrStat
type InstrStat struct {
Instr *Instruction
Count int
}
func (is InstrStat) String() string {
return fmt.Sprintf("0x%02X %6d %s", is.Instr.Opcode, is.Count, is.Instr.String())
}
func (this Stats) Add(that Stats) {
for _, st := range that {
op := st.Instr.Opcode
@ -40,7 +49,23 @@ func (s Stats) WriteTo(w io.Writer) (int64, error) {
}
}
n, err := fmt.Fprintln(w, "\nUnknown uses:", unknownUses)
n, err := fmt.Fprintln(w, "\nUnused OpCodes:")
count += int64(n)
if err != nil {
return count, err
}
for i := byte(0x80); i <= 0xFF && i >= 0x80; i++ {
if _, ok := s[i]; !ok {
n, err = fmt.Fprintf(w, "0x%02X %s\n", i, InstrMap[i].Name)
count += int64(n)
if err != nil {
return count, err
}
}
}
n, err = fmt.Fprintln(w, "\nUnknown uses:", unknownUses)
count += int64(n)
if err != nil {
return count, err