1
2
3
4
5 package walk
6
7 import (
8 "cmd/compile/internal/base"
9 "cmd/compile/internal/ir"
10 "cmd/compile/internal/typecheck"
11 "cmd/compile/internal/types"
12 )
13
14
15
16 func initStackTemp(init *ir.Nodes, tmp *ir.Name, val ir.Node) *ir.AddrExpr {
17 if val != nil && !types.Identical(tmp.Type(), val.Type()) {
18 base.Fatalf("bad initial value for %L: %L", tmp, val)
19 }
20 appendWalkStmt(init, ir.NewAssignStmt(base.Pos, tmp, val))
21 return typecheck.Expr(typecheck.NodAddr(tmp)).(*ir.AddrExpr)
22 }
23
24
25
26
27 func stackTempAddr(init *ir.Nodes, typ *types.Type) *ir.AddrExpr {
28 return initStackTemp(init, typecheck.Temp(typ), nil)
29 }
30
31
32
33
34 func stackBufAddr(len int64, elem *types.Type) *ir.AddrExpr {
35 if elem.HasPointers() {
36 base.FatalfAt(base.Pos, "%v has pointers", elem)
37 }
38 tmp := typecheck.Temp(types.NewArray(elem, len))
39 return typecheck.Expr(typecheck.NodAddr(tmp)).(*ir.AddrExpr)
40 }
41
View as plain text