Commit 45983827 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile/internal/gc: export & import function bodies, but don't hook up

Function bodies are not yet hooked up because the node structure is not
100% correct. This commit establishes that we can correctly write bodies
out and read them in again.

- export and import all exported inlined function bodies:
  (export GO_GCFLAGS="-newexport"; sh all.bash) working
- inlined functions are not yet hooked up (just dropped on the floor)
- improved tracing output and error messages
- make mkbuiltin.go work for both textual and binary export data
  so we can run tests with the new format

Change-Id: I70dc4de419df1b604389c3747041d6dba8730b0b
Reviewed-on: https://go-review.googlesource.com/16284Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent c0f7195d
This diff is collapsed.
This diff is collapsed.
......@@ -64,30 +64,49 @@ func mkbuiltin(w io.Writer, name string) {
log.Fatal(err)
}
// Look for $$ that introduces imports.
i := bytes.Index(b, []byte("\n$$\n"))
// Look for $$B that introduces binary export data.
textual := false // TODO(gri) remove once we switched to binary export format
i := bytes.Index(b, []byte("\n$$B\n"))
if i < 0 {
log.Fatal("did not find beginning of imports")
// Look for $$ that introduces textual export data.
i = bytes.Index(b, []byte("\n$$\n"))
if i < 0 {
log.Fatal("did not find beginning of export data")
}
textual = true
i-- // textual data doesn't have B
}
i += 4
b = b[i+5:]
// Look for $$ that closes imports.
j := bytes.Index(b[i:], []byte("\n$$\n"))
if j < 0 {
log.Fatal("did not find end of imports")
// Look for $$ that closes export data.
i = bytes.Index(b, []byte("\n$$\n"))
if i < 0 {
log.Fatal("did not find end of export data")
}
j += i + 4
b = b[:i+4]
// Process and reformat imports.
// Process and reformat export data.
fmt.Fprintf(w, "\nconst %simport = \"\"", name)
for _, p := range bytes.SplitAfter(b[i:j], []byte("\n")) {
// Chop leading white space.
p = bytes.TrimLeft(p, " \t")
if len(p) == 0 {
continue
}
if textual {
for _, p := range bytes.SplitAfter(b, []byte("\n")) {
// Chop leading white space.
p = bytes.TrimLeft(p, " \t")
if len(p) == 0 {
continue
}
fmt.Fprintf(w, " +\n\t%q", p)
fmt.Fprintf(w, " +\n\t%q", p)
}
} else {
const n = 40 // number of bytes per line
for len(b) > 0 {
i := len(b)
if i > n {
i = n
}
fmt.Fprintf(w, " +\n\t%q", b[:i])
b = b[i:]
}
}
fmt.Fprintf(w, "\n")
}
......@@ -1765,19 +1765,18 @@ func (p *parser) chan_elem() *Node {
return nil
}
func (p *parser) new_dotname(pkg *Node) *Node {
func (p *parser) new_dotname(obj *Node) *Node {
if trace && Debug['x'] != 0 {
defer p.trace("new_dotname")()
}
sel := p.sym()
if pkg.Op == OPACK {
s := restrictlookup(sel.Name, pkg.Name.Pkg)
pkg.Used = true
if obj.Op == OPACK {
s := restrictlookup(sel.Name, obj.Name.Pkg)
obj.Used = true
return oldname(s)
}
return Nod(OXDOT, pkg, newname(sel))
return Nod(OXDOT, obj, newname(sel))
}
func (p *parser) dotname() *Node {
......
......@@ -195,7 +195,7 @@ const (
OSUB // Left - Right
OOR // Left | Right
OXOR // Left ^ Right
OADDSTR // Left + Right (string addition)
OADDSTR // +{List} (string addition, list elements are strings)
OADDR // &Left
OANDAND // Left && Right
OAPPEND // append(List)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment