transform: add -print-allocs-cover and restore -print-allocs reason output

PR #5220 changed -print-allocs output to the go coverage tool format, which
replaced the original human-readable explanation of why each object had to be
heap allocated. That explanation is useful on its own, so this restores it as
the default behavior of -print-allocs and moves the coverage format behind a
-print-allocs-cover flag.

Signed-off-by: Piotr Bocheński <piotr@bochen.ski>
This commit is contained in:
Piotr Bocheński
2026-06-11 21:33:05 +02:00
committed by Ron Evans
parent c33113ab5f
commit 4465360f3d
9 changed files with 130 additions and 91 deletions
+17 -7
View File
@@ -86,13 +86,23 @@ func Optimize(mod llvm.Module, config *compileopts.Config) []error {
}
// Run TinyGo-specific interprocedural optimizations.
OptimizeAllocs(mod, config.Options.PrintAllocs, maxStackSize, func(pos token.Position, msg string) {
if pos.Filename != "" {
fmt.Fprintf(os.Stderr, "%s:%d:%d: %s\n", pos.Filename, pos.Line, pos.Column, msg)
} else {
fmt.Fprintln(os.Stderr, msg) // No prefix!
}
})
if config.Options.PrintAllocs != nil && config.Options.PrintAllocsCover {
// The go coverage tool expects this header before any blocks.
fmt.Fprintln(os.Stderr, "mode: set")
}
OptimizeAllocs(mod, config.Options.PrintAllocs, maxStackSize,
func(pos token.Position, reason string) {
var line string
if config.Options.PrintAllocsCover {
line = FormatAllocCover(pos)
} else {
line = FormatAllocReason(pos, reason)
}
if line != "" {
fmt.Fprintln(os.Stderr, line)
}
},
)
OptimizeStringToBytes(mod)
OptimizeStringEqual(mod)