mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: refactor constant rewriting
Extract all rewrite-to-OLITERAL expressions to use a single setconst helper function. Does not pass toolstash-check for two reasons: 1) We now consistently clear Left/Right/etc when rewriting Nodes into OLITERALs, which results in their inlining complexity being correctly computed. So more functions can now be inlined. 2) We preserve Pos, so PC line tables change somewhat. Change-Id: I2b5c293bee7c69c2ccd704677f5aba4ec40e3155 Reviewed-on: https://go-review.googlesource.com/103860 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
parent
3c588b3fe7
commit
0250ef910f
5 changed files with 72 additions and 142 deletions
|
|
@ -364,15 +364,6 @@ func nodSym(op Op, left *Node, sym *types.Sym) *Node {
|
|||
return n
|
||||
}
|
||||
|
||||
func saveorignode(n *Node) {
|
||||
if n.Orig != nil {
|
||||
return
|
||||
}
|
||||
norig := nod(n.Op, nil, nil)
|
||||
*norig = *n
|
||||
n.Orig = norig
|
||||
}
|
||||
|
||||
// methcmp sorts methods by name with exported methods first,
|
||||
// and then non-exported methods by their package path.
|
||||
type methcmp []*types.Field
|
||||
|
|
@ -424,19 +415,6 @@ func nodfltconst(v *Mpflt) *Node {
|
|||
return nodlit(Val{u})
|
||||
}
|
||||
|
||||
func nodconst(n *Node, t *types.Type, v int64) {
|
||||
*n = Node{}
|
||||
n.Op = OLITERAL
|
||||
n.SetAddable(true)
|
||||
n.SetVal(Val{new(Mpint)})
|
||||
n.Val().U.(*Mpint).SetInt64(v)
|
||||
n.Type = t
|
||||
|
||||
if t.IsFloat() {
|
||||
Fatalf("nodconst: bad type %v", t)
|
||||
}
|
||||
}
|
||||
|
||||
func nodnil() *Node {
|
||||
return nodlit(Val{new(NilVal)})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue