"strings"
)
-// Names records state information collected in the first fixup
+// names records state information collected in the first fixup
// phase so that it can be passed to the second fixup phase.
-type Names struct {
+type names struct {
MetaVar *ir.Name
PkgIdVar *ir.Name
InitFn *ir.Func
CounterGran coverage.CounterGranularity
}
-// FixupVars is the first of two entry points for coverage compiler
-// fixup. It collects and returns the package ID and meta-data
-// variables being used for this "-cover" build, along with the
-// coverage counter mode and granularity. It also reclassifies selected
-// variables (for example, tagging coverage counter variables with
-// flags so that they can be handled properly downstream).
-func FixupVars() Names {
+// Fixup adds calls to the pkg init function as appropriate to
+// register coverage-related variables with the runtime.
+//
+// It also reclassifies selected variables (for example, tagging
+// coverage counter variables with flags so that they can be handled
+// properly downstream).
+func Fixup() {
+ if base.Flag.Cfg.CoverageInfo == nil {
+ return // not using coverage
+ }
+
metaVarName := base.Flag.Cfg.CoverageInfo.MetaVar
pkgIdVarName := base.Flag.Cfg.CoverageInfo.PkgIdVar
counterMode := base.Flag.Cfg.CoverageInfo.CounterMode
counterGran)
}
- return Names{
+ cnames := names{
MetaVar: metavar,
PkgIdVar: pkgidvar,
CounterMode: cm,
CounterGran: cg,
}
-}
-// FixupInit is the second main entry point for coverage compiler
-// fixup. It adds calls to the pkg init function as appropriate to
-// register coverage-related variables with the runtime.
-func FixupInit(cnames Names) {
for _, fn := range typecheck.Target.Funcs {
if ir.FuncName(fn) == "init" {
cnames.InitFn = fn
return hv, base.Flag.Cfg.CoverageInfo.MetaLen
}
-func registerMeta(cnames Names, hashv [16]byte, mdlen int) {
+func registerMeta(cnames names, hashv [16]byte, mdlen int) {
// Materialize expression for hash (an array literal)
pos := cnames.InitFn.Pos()
elist := make([]ir.Node, 0, 16)
// because it generates itabs for initializing global variables.
ssagen.InitConfig()
- // First part of coverage fixup (if applicable).
- var cnames coverage.Names
- if base.Flag.Cfg.CoverageInfo != nil {
- cnames = coverage.FixupVars()
- }
-
// Create "init" function for package-scope variable initialization
// statements, if any.
pkginit.MakeInit()
- // Second part of code coverage fixup (init func modification),
- // if applicable.
- if base.Flag.Cfg.CoverageInfo != nil {
- coverage.FixupInit(cnames)
- }
+ // Apply coverage fixups, if applicable.
+ coverage.Fixup()
// Compute Addrtaken for names.
// We need to wait until typechecking is done so that when we see &x[i]