...
  
  
     1  
     2  
     3  
     4  
     5  package typecheck
     6  
     7  import (
     8  	"cmd/compile/internal/base"
     9  	"cmd/compile/internal/ir"
    10  	"cmd/compile/internal/types"
    11  	"cmd/internal/obj"
    12  )
    13  
    14  
    15  
    16  
    17  func LookupRuntime(name string, types_ ...*types.Type) *ir.Name {
    18  	s := ir.Pkgs.Runtime.Lookup(name)
    19  	if s == nil || s.Def == nil {
    20  		base.Fatalf("LookupRuntime: can't find runtime.%s", name)
    21  	}
    22  	n := s.Def.(*ir.Name)
    23  	if len(types_) != 0 {
    24  		n = substArgTypes(n, types_...)
    25  	}
    26  	return n
    27  }
    28  
    29  
    30  
    31  
    32  func substArgTypes(old *ir.Name, types_ ...*types.Type) *ir.Name {
    33  	for _, t := range types_ {
    34  		types.CalcSize(t)
    35  	}
    36  	n := ir.NewNameAt(old.Pos(), old.Sym(), types.SubstAny(old.Type(), &types_))
    37  	n.Class = old.Class
    38  	n.Func = old.Func
    39  	if len(types_) > 0 {
    40  		base.Fatalf("SubstArgTypes: too many argument types")
    41  	}
    42  	return n
    43  }
    44  
    45  
    46  
    47  
    48  
    49  
    50  
    51  func AutoLabel(prefix string) *types.Sym {
    52  	if prefix[0] != '.' {
    53  		base.Fatalf("autolabel prefix must start with '.', have %q", prefix)
    54  	}
    55  	fn := ir.CurFunc
    56  	if ir.CurFunc == nil {
    57  		base.Fatalf("autolabel outside function")
    58  	}
    59  	n := fn.Label
    60  	fn.Label++
    61  	return LookupNum(prefix, int(n))
    62  }
    63  
    64  func Lookup(name string) *types.Sym {
    65  	return types.LocalPkg.Lookup(name)
    66  }
    67  
    68  
    69  
    70  
    71  func InitRuntime() {
    72  	base.Timer.Start("fe", "loadsys")
    73  
    74  	typs := runtimeTypes()
    75  	for _, d := range &runtimeDecls {
    76  		sym := ir.Pkgs.Runtime.Lookup(d.name)
    77  		typ := typs[d.typ]
    78  		switch d.tag {
    79  		case funcTag:
    80  			importfunc(sym, typ)
    81  		case varTag:
    82  			importvar(sym, typ)
    83  		default:
    84  			base.Fatalf("unhandled declaration tag %v", d.tag)
    85  		}
    86  	}
    87  }
    88  
    89  
    90  
    91  func LookupRuntimeFunc(name string) *obj.LSym {
    92  	return LookupRuntimeABI(name, obj.ABIInternal)
    93  }
    94  
    95  
    96  
    97  
    98  func LookupRuntimeVar(name string) *obj.LSym {
    99  	return LookupRuntimeABI(name, obj.ABI0)
   100  }
   101  
   102  
   103  func LookupRuntimeABI(name string, abi obj.ABI) *obj.LSym {
   104  	return base.PkgLinksym("runtime", name, abi)
   105  }
   106  
   107  
   108  
   109  func InitCoverage() {
   110  	typs := coverageTypes()
   111  	for _, d := range &coverageDecls {
   112  		sym := ir.Pkgs.Coverage.Lookup(d.name)
   113  		typ := typs[d.typ]
   114  		switch d.tag {
   115  		case funcTag:
   116  			importfunc(sym, typ)
   117  		case varTag:
   118  			importvar(sym, typ)
   119  		default:
   120  			base.Fatalf("unhandled declaration tag %v", d.tag)
   121  		}
   122  	}
   123  }
   124  
   125  
   126  
   127  
   128  func LookupCoverage(name string) *ir.Name {
   129  	sym := ir.Pkgs.Coverage.Lookup(name)
   130  	if sym == nil {
   131  		base.Fatalf("LookupCoverage: can't find runtime/coverage.%s", name)
   132  	}
   133  	return sym.Def.(*ir.Name)
   134  }
   135  
View as plain text