notes *EscNote
}
-func init() {
- ir.EscFmt = escFmt
-}
-
// escFmt is called from node printing to print information about escape analysis results.
func escFmt(n ir.Node) string {
text := ""
// so we can use index to reference the symbol.
var typeSymIdx = make(map[*types.Type][2]int64)
+func BaseTypeIndex(t *types.Type) int64 {
+ tbase := t
+ if t.IsPtr() && t.Sym() == nil && t.Elem().Sym() != nil {
+ tbase = t.Elem()
+ }
+ i, ok := typeSymIdx[tbase]
+ if !ok {
+ return -1
+ }
+ if t != tbase {
+ return i[1]
+ }
+ return i[0]
+}
+
func (r *importReader) doInline(fn *ir.Func) {
if len(fn.Inl.Body) != 0 {
base.Fatalf("%v already has inline body", fn)
// Target is the package being compiled.
var Target *ir.Package
-// timing data for compiler phases
-var timings Timings
-
// Main parses flags and Go source files specified in the command-line
// arguments, type-checks the parsed Go package, compiles functions to machine
// code, and finally writes the compiled package definition to disk.
logopt.LogJsonOption(base.Flag.JSON)
}
+ ir.EscFmt = escFmt
IsIntrinsicCall = isIntrinsicCall
SSADumpInline = ssaDumpInline
initSSAEnv()
// any language version is supported.
var langWant lang
-// langSupported reports whether language version major.minor is
-// supported in a particular package.
-func langSupported(major, minor int, pkg *types.Pkg) bool {
+// AllowsGoVersion reports whether a particular package
+// is allowed to use Go version major.minor.
+// We assume the imported packages have all been checked,
+// so we only have to check the local package against the -lang flag.
+func AllowsGoVersion(pkg *types.Pkg, major, minor int) bool {
if pkg == nil {
// TODO(mdempsky): Set Pkg for local types earlier.
pkg = types.LocalPkg
// Assume imported packages passed type-checking.
return true
}
-
if langWant.major == 0 && langWant.minor == 0 {
return true
}
return langWant.major > major || (langWant.major == major && langWant.minor >= minor)
}
+func langSupported(major, minor int, pkg *types.Pkg) bool {
+ return AllowsGoVersion(pkg, major, minor)
+}
+
// checkLang verifies that the -lang flag holds a valid value, and
// exits if not. It initializes data used by langSupported.
func checkLang() {
addsignats(Target.Externs)
dumpsignats()
dumptabs()
- ptabsLen := len(ptabs)
- itabsLen := len(itabs)
+ numPTabs, numITabs := CountTabs()
dumpimportstrings()
dumpbasictypes()
dumpembeds()
if numExports != len(Target.Exports) {
base.Fatalf("Target.Exports changed after compile functions loop")
}
- if ptabsLen != len(ptabs) {
+ newNumPTabs, newNumITabs := CountTabs()
+ if newNumPTabs != numPTabs {
base.Fatalf("ptabs changed after compile functions loop")
}
- if itabsLen != len(itabs) {
+ if newNumITabs != numITabs {
base.Fatalf("itabs changed after compile functions loop")
}
}
t *types.Type
}
+func CountTabs() (numPTabs, numITabs int) {
+ return len(ptabs), len(itabs)
+}
+
// runtime interface and reflection data structures
var (
signatmu sync.Mutex // protects signatset and signatslice
if base.Ctxt.Pkgpath != "runtime" || (tbase != types.Types[tbase.Kind()] && tbase != types.ByteType && tbase != types.RuneType && tbase != types.ErrorType) { // int, float, etc
// named types from other files are defined only by those files
if tbase.Sym() != nil && tbase.Sym().Pkg != types.LocalPkg {
- if i, ok := typeSymIdx[tbase]; ok {
+ if i := BaseTypeIndex(t); i >= 0 {
lsym.Pkg = tbase.Sym().Pkg.Prefix
- if t != tbase {
- lsym.SymIdx = int32(i[1])
- } else {
- lsym.SymIdx = int32(i[0])
- }
+ lsym.SymIdx = int32(i)
lsym.Set(obj.AttrIndexed, true)
}
return lsym
"time"
)
+var timings Timings
+
// Timings collects the execution times of labeled phases
// which are added trough a sequence of Start/Stop calls.
// Events may be associated with each phase via AddEvent.
package ir
import (
+ "cmd/compile/internal/base"
"cmd/compile/internal/types"
"cmd/internal/src"
)
func NewBlockStmt(pos src.XPos, list []Node) *BlockStmt {
n := &BlockStmt{}
n.pos = pos
+ if !pos.IsKnown() {
+ n.pos = base.Pos
+ if len(list) > 0 {
+ n.pos = list[0].Pos()
+ }
+ }
n.op = OBLOCK
n.List_.Set(list)
return n