mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
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:
committed by
Ron Evans
parent
c33113ab5f
commit
4465360f3d
+17
-7
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user