cmd/compile: move a lot of declarations outside of go.go
go.go is currently a grab bag of various unrelated type and variable
declarations. Move a bunch of them into other more relevant source
files.
There are still more that can be moved, but these were the low hanging
fruit with obvious homes.
No code/comment changes. Just shuffling stuff around.
Change-Id: I43dbe1a5b8b707709c1a3a034c693d38b8465063
Reviewed-on: https://go-review.googlesource.com/21561
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go
index 5c9a67c..c7fb4d9 100644
--- a/src/cmd/compile/internal/gc/const.go
+++ b/src/cmd/compile/internal/gc/const.go
@@ -10,6 +10,59 @@
"strings"
)
+// Ctype describes the constant kind of an "ideal" (untyped) constant.
+type Ctype int8
+
+const (
+ CTxxx Ctype = iota
+
+ CTINT
+ CTRUNE
+ CTFLT
+ CTCPLX
+ CTSTR
+ CTBOOL
+ CTNIL
+)
+
+type Val struct {
+ // U contains one of:
+ // bool bool when n.ValCtype() == CTBOOL
+ // *Mpint int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
+ // *Mpflt float when n.ValCtype() == CTFLT
+ // *Mpcplx pair of floats when n.ValCtype() == CTCPLX
+ // string string when n.ValCtype() == CTSTR
+ // *Nilval when n.ValCtype() == CTNIL
+ U interface{}
+}
+
+func (v Val) Ctype() Ctype {
+ switch x := v.U.(type) {
+ default:
+ Fatalf("unexpected Ctype for %T", v.U)
+ panic("not reached")
+ case nil:
+ return 0
+ case *NilVal:
+ return CTNIL
+ case bool:
+ return CTBOOL
+ case *Mpint:
+ if x.Rune {
+ return CTRUNE
+ }
+ return CTINT
+ case *Mpflt:
+ return CTFLT
+ case *Mpcplx:
+ return CTCPLX
+ case string:
+ return CTSTR
+ }
+}
+
+type NilVal struct{}
+
// IntLiteral returns the Node's literal value as an integer.
func (n *Node) IntLiteral() (x int64, ok bool) {
switch {
diff --git a/src/cmd/compile/internal/gc/dcl.go b/src/cmd/compile/internal/gc/dcl.go
index 8553e2f..fb81545 100644
--- a/src/cmd/compile/internal/gc/dcl.go
+++ b/src/cmd/compile/internal/gc/dcl.go
@@ -26,6 +26,12 @@
return true
}
+var externdcl []*Node
+
+var blockgen int32 // max block number
+
+var block int32 // current block number
+
// dclstack maintains a stack of shadowed symbol declarations so that
// popdcl can restore their declarations when a block scope ends.
// The stack is maintained as a linked list, using Sym's Link field.
diff --git a/src/cmd/compile/internal/gc/go.go b/src/cmd/compile/internal/gc/go.go
index f4b3dc9..4cb985b 100644
--- a/src/cmd/compile/internal/gc/go.go
+++ b/src/cmd/compile/internal/gc/go.go
@@ -5,7 +5,6 @@
package gc
import (
- "bytes"
"cmd/compile/internal/ssa"
"cmd/internal/obj"
)
@@ -16,44 +15,6 @@
MaxStackVarSize = 10 * 1024 * 1024
)
-type Val struct {
- // U contains one of:
- // bool bool when n.ValCtype() == CTBOOL
- // *Mpint int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
- // *Mpflt float when n.ValCtype() == CTFLT
- // *Mpcplx pair of floats when n.ValCtype() == CTCPLX
- // string string when n.ValCtype() == CTSTR
- // *Nilval when n.ValCtype() == CTNIL
- U interface{}
-}
-
-type NilVal struct{}
-
-func (v Val) Ctype() Ctype {
- switch x := v.U.(type) {
- default:
- Fatalf("unexpected Ctype for %T", v.U)
- panic("not reached")
- case nil:
- return 0
- case *NilVal:
- return CTNIL
- case bool:
- return CTBOOL
- case *Mpint:
- if x.Rune {
- return CTRUNE
- }
- return CTINT
- case *Mpflt:
- return CTFLT
- case *Mpcplx:
- return CTCPLX
- case string:
- return CTSTR
- }
-}
-
type Pkg struct {
Name string // package name, e.g. "sys"
Path string // string literal used in import statement, e.g. "runtime/internal/sys"
@@ -119,35 +80,6 @@
SymAlgGen
)
-// Ctype describes the constant kind of an "ideal" (untyped) constant.
-type Ctype int8
-
-const (
- CTxxx Ctype = iota
-
- CTINT
- CTRUNE
- CTFLT
- CTCPLX
- CTSTR
- CTBOOL
- CTNIL
-)
-
-// ChanDir is whether a channel can send, receive, or both.
-type ChanDir uint8
-
-func (c ChanDir) CanRecv() bool { return c&Crecv != 0 }
-func (c ChanDir) CanSend() bool { return c&Csend != 0 }
-
-const (
- // types of channel
- // must match ../../../../reflect/type.go:/ChanDir
- Crecv ChanDir = 1 << 0
- Csend ChanDir = 1 << 1
- Cboth ChanDir = Crecv | Csend
-)
-
// The Class of a variable/function describes the "storage class"
// of a variable or function. During parsing, storage classes are
// called declaration contexts.
@@ -167,30 +99,6 @@
PHEAP = 1 << 7 // an extra bit to identify an escaped variable
)
-const (
- Etop = 1 << 1 // evaluated at statement level
- Erv = 1 << 2 // evaluated in value context
- Etype = 1 << 3
- Ecall = 1 << 4 // call-only expressions are ok
- Efnstruct = 1 << 5 // multivalue function returns are ok
- Eiota = 1 << 6 // iota is ok
- Easgn = 1 << 7 // assigning to expression
- Eindir = 1 << 8 // indirecting through expression
- Eaddr = 1 << 9 // taking address of expression
- Eproc = 1 << 10 // inside a go statement
- Ecomplit = 1 << 11 // type in composite literal
-)
-
-type Sig struct {
- name string
- pkg *Pkg
- isym *Sym
- tsym *Sym
- type_ *Type
- mtype *Type
- offset int32
-}
-
// note this is the runtime representation
// of the compilers arrays.
//
@@ -218,13 +126,6 @@
// } String;
var sizeof_String int // runtime sizeof(String)
-// lexlineno is the line number _after_ the most recently read rune.
-// In particular, it's advanced (or rewound) as newlines are read (or unread).
-var lexlineno int32
-
-// lineno is the line number at the start of the most recently lexed token.
-var lineno int32
-
var pragcgobuf string
var infile string
@@ -245,10 +146,6 @@
var nolocalimports int
-var lexbuf bytes.Buffer
-var strbuf bytes.Buffer
-var litbuf string // LLITERAL value for use in syntax error messages
-
var Debug [256]int
var debugstr string
@@ -324,8 +221,6 @@
var xtop []*Node
-var externdcl []*Node
-
var exportlist []*Node
var importlist []*Node // imported functions and methods with inlinable bodies
@@ -350,10 +245,6 @@
var stkptrsize int64 // prefix of stack containing pointers
-var blockgen int32 // max block number
-
-var block int32 // current block number
-
var hasdefer bool // flag that curfn has defer statement
var Curfn *Node
@@ -410,34 +301,6 @@
var Disable_checknil int
-type Flow struct {
- Prog *obj.Prog // actual instruction
- P1 *Flow // predecessors of this instruction: p1,
- P2 *Flow // and then p2 linked though p2link.
- P2link *Flow
- S1 *Flow // successors of this instruction (at most two: s1 and s2).
- S2 *Flow
- Link *Flow // next instruction in function code
-
- Active int32 // usable by client
-
- Id int32 // sequence number in flow graph
- Rpo int32 // reverse post ordering
- Loop uint16 // x5 for every loop
- Refset bool // diagnostic generated
-
- Data interface{} // for use by client
-}
-
-type Graph struct {
- Start *Flow
- Num int
-
- // After calling flowrpo, rpo lists the flow nodes in reverse postorder,
- // and each non-dead Flow node f has g->rpo[f->rpo] == f.
- Rpo []*Flow
-}
-
// interface to back end
const (
diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go
index 6f1331c..2dbbd92 100644
--- a/src/cmd/compile/internal/gc/lex.go
+++ b/src/cmd/compile/internal/gc/lex.go
@@ -6,6 +6,7 @@
import (
"bufio"
+ "bytes"
"cmd/internal/obj"
"fmt"
"io"
@@ -20,6 +21,17 @@
BOM = 0xFEFF
)
+// lexlineno is the line number _after_ the most recently read rune.
+// In particular, it's advanced (or rewound) as newlines are read (or unread).
+var lexlineno int32
+
+// lineno is the line number at the start of the most recently lexed token.
+var lineno int32
+
+var lexbuf bytes.Buffer
+var strbuf bytes.Buffer
+var litbuf string // LLITERAL value for use in syntax error messages
+
func isSpace(c rune) bool {
return c == ' ' || c == '\t' || c == '\n' || c == '\r'
}
diff --git a/src/cmd/compile/internal/gc/popt.go b/src/cmd/compile/internal/gc/popt.go
index 41f8ba9..001a715 100644
--- a/src/cmd/compile/internal/gc/popt.go
+++ b/src/cmd/compile/internal/gc/popt.go
@@ -235,6 +235,34 @@
// for every f.Data field, for use by the client.
// If newData is nil, f.Data will be nil.
+type Graph struct {
+ Start *Flow
+ Num int
+
+ // After calling flowrpo, rpo lists the flow nodes in reverse postorder,
+ // and each non-dead Flow node f has g->rpo[f->rpo] == f.
+ Rpo []*Flow
+}
+
+type Flow struct {
+ Prog *obj.Prog // actual instruction
+ P1 *Flow // predecessors of this instruction: p1,
+ P2 *Flow // and then p2 linked though p2link.
+ P2link *Flow
+ S1 *Flow // successors of this instruction (at most two: s1 and s2).
+ S2 *Flow
+ Link *Flow // next instruction in function code
+
+ Active int32 // usable by client
+
+ Id int32 // sequence number in flow graph
+ Rpo int32 // reverse post ordering
+ Loop uint16 // x5 for every loop
+ Refset bool // diagnostic generated
+
+ Data interface{} // for use by client
+}
+
var flowmark int
// MaxFlowProg is the maximum size program (counted in instructions)
diff --git a/src/cmd/compile/internal/gc/reflect.go b/src/cmd/compile/internal/gc/reflect.go
index 11bcd4c..c069b35 100644
--- a/src/cmd/compile/internal/gc/reflect.go
+++ b/src/cmd/compile/internal/gc/reflect.go
@@ -22,6 +22,16 @@
var signatlist []*Node
var itabs []itabEntry
+type Sig struct {
+ name string
+ pkg *Pkg
+ isym *Sym
+ tsym *Sym
+ type_ *Type
+ mtype *Type
+ offset int32
+}
+
// byMethodNameAndPackagePath sorts method signatures by name, then package path.
type byMethodNameAndPackagePath []*Sig
diff --git a/src/cmd/compile/internal/gc/type.go b/src/cmd/compile/internal/gc/type.go
index b89c5db..05e30df 100644
--- a/src/cmd/compile/internal/gc/type.go
+++ b/src/cmd/compile/internal/gc/type.go
@@ -75,6 +75,20 @@
dddBound = -100 // arrays declared as [...]T start life with Bound=dddBound
)
+// ChanDir is whether a channel can send, receive, or both.
+type ChanDir uint8
+
+func (c ChanDir) CanRecv() bool { return c&Crecv != 0 }
+func (c ChanDir) CanSend() bool { return c&Csend != 0 }
+
+const (
+ // types of channel
+ // must match ../../../../reflect/type.go:/ChanDir
+ Crecv ChanDir = 1 << 0
+ Csend ChanDir = 1 << 1
+ Cboth ChanDir = Crecv | Csend
+)
+
// Types stores pointers to predeclared named types.
//
// It also stores pointers to several special types:
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go
index 688936e..d21552d 100644
--- a/src/cmd/compile/internal/gc/typecheck.go
+++ b/src/cmd/compile/internal/gc/typecheck.go
@@ -11,6 +11,20 @@
"strings"
)
+const (
+ Etop = 1 << 1 // evaluated at statement level
+ Erv = 1 << 2 // evaluated in value context
+ Etype = 1 << 3
+ Ecall = 1 << 4 // call-only expressions are ok
+ Efnstruct = 1 << 5 // multivalue function returns are ok
+ Eiota = 1 << 6 // iota is ok
+ Easgn = 1 << 7 // assigning to expression
+ Eindir = 1 << 8 // indirecting through expression
+ Eaddr = 1 << 9 // taking address of expression
+ Eproc = 1 << 10 // inside a go statement
+ Ecomplit = 1 << 11 // type in composite literal
+)
+
// type check the whole tree of an expression.
// calculates expression types.
// evaluates compile time constants.