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 "cmd/internal/src"
13 )
14
15 func LookupRuntime(name string) *ir.Name {
16 s := ir.Pkgs.Runtime.Lookup(name)
17 if s == nil || s.Def == nil {
18 base.Fatalf("LookupRuntime: can't find runtime.%s", name)
19 }
20 return ir.AsNode(s.Def).(*ir.Name)
21 }
22
23
24
25
26
27
28 func SubstArgTypes(old *ir.Name, types_ ...*types.Type) *ir.Name {
29 for _, t := range types_ {
30 types.CalcSize(t)
31 }
32 n := ir.NewNameAt(old.Pos(), old.Sym())
33 n.Class = old.Class
34 n.SetType(types.SubstAny(old.Type(), &types_))
35 n.Func = old.Func
36 if len(types_) > 0 {
37 base.Fatalf("SubstArgTypes: too many argument types")
38 }
39 return n
40 }
41
42
43
44
45
46
47
48 func AutoLabel(prefix string) *types.Sym {
49 if prefix[0] != '.' {
50 base.Fatalf("autolabel prefix must start with '.', have %q", prefix)
51 }
52 fn := ir.CurFunc
53 if ir.CurFunc == nil {
54 base.Fatalf("autolabel outside function")
55 }
56 n := fn.Label
57 fn.Label++
58 return LookupNum(prefix, int(n))
59 }
60
61 func Lookup(name string) *types.Sym {
62 return types.LocalPkg.Lookup(name)
63 }
64
65
66
67
68 func InitRuntime() {
69 base.Timer.Start("fe", "loadsys")
70 types.Block = 1
71
72 typs := runtimeTypes()
73 for _, d := range &runtimeDecls {
74 sym := ir.Pkgs.Runtime.Lookup(d.name)
75 typ := typs[d.typ]
76 switch d.tag {
77 case funcTag:
78 importfunc(src.NoXPos, sym, typ)
79 case varTag:
80 importvar(src.NoXPos, sym, typ)
81 default:
82 base.Fatalf("unhandled declaration tag %v", d.tag)
83 }
84 }
85 }
86
87
88
89 func LookupRuntimeFunc(name string) *obj.LSym {
90 return LookupRuntimeABI(name, obj.ABIInternal)
91 }
92
93
94
95
96 func LookupRuntimeVar(name string) *obj.LSym {
97 return LookupRuntimeABI(name, obj.ABI0)
98 }
99
100
101 func LookupRuntimeABI(name string, abi obj.ABI) *obj.LSym {
102 return base.PkgLinksym("runtime", name, abi)
103 }
104
View as plain text