aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2014-07-30 09:01:52 -0700
committerKeith Randall <khr@golang.org>2014-07-30 09:01:52 -0700
commit4aa50434e13d12eb9755a992d6d4ad93e201d624 (patch)
tree16bdb1935477b9d70d443d2b1f5c0bcb4c636682 /src/cmd
parentfe4fc94b044df5e6d08ad9e480f0bce70cc4e5d5 (diff)
downloadgo-4aa50434e13d12eb9755a992d6d4ad93e201d624.tar.xz
runtime: rewrite malloc in Go.
This change introduces gomallocgc, a Go clone of mallocgc. Only a few uses have been moved over, so there are still lots of uses from C. Many of these C uses will be moved over to Go (e.g. in slice.goc), but probably not all. What should remain of C's mallocgc is an open question. LGTM=rsc, dvyukov R=rsc, khr, dave, bradfitz, dvyukov CC=golang-codereviews https://golang.org/cl/108840046
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/api/goapi.go2
-rw-r--r--src/cmd/cc/godefs.c28
-rw-r--r--src/cmd/gc/builtin.c2
-rw-r--r--src/cmd/gc/runtime.go2
-rw-r--r--src/cmd/gc/walk.c2
5 files changed, 28 insertions, 8 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go
index 007601328c..7216f4e0ed 100644
--- a/src/cmd/api/goapi.go
+++ b/src/cmd/api/goapi.go
@@ -378,7 +378,7 @@ func (w *Walker) parseFile(dir, file string) (*ast.File, error) {
}
if w.context != nil && file == fmt.Sprintf("zruntime_defs_%s_%s.go", w.context.GOOS, w.context.GOARCH) {
// Just enough to keep the api checker happy.
- src := "package runtime; type maptype struct{}; type _type struct{}; type alg struct{}"
+ src := "package runtime; type maptype struct{}; type _type struct{}; type alg struct{}; type mspan struct{}; type m struct{}; type lock struct{}"
f, err = parser.ParseFile(fset, filename, src, 0)
if err != nil {
log.Fatalf("incorrect generated file: %s", err)
diff --git a/src/cmd/cc/godefs.c b/src/cmd/cc/godefs.c
index 7457bd0007..3755a8fc09 100644
--- a/src/cmd/cc/godefs.c
+++ b/src/cmd/cc/godefs.c
@@ -206,16 +206,36 @@ printtypename(Type *t)
Bprint(&outbuf, "uint16");
break;
case TLONG:
- Bprint(&outbuf, "int32");
+ // The 32/64-bit ambiguous types (int,uint,uintptr)
+ // are assigned a TLONG/TULONG to distinguish them
+ // from always 32-bit types which get a TINT/TUINT.
+ // (See int_x/uint_x in pkg/runtime/runtime.h.)
+ // For LONG and VLONG types, we generate the
+ // unqualified Go type when appropriate.
+ // This makes it easier to write Go code that
+ // modifies objects with autogenerated-from-C types.
+ if(ewidth[TIND] == 4)
+ Bprint(&outbuf, "int");
+ else
+ Bprint(&outbuf, "int32");
break;
case TULONG:
- Bprint(&outbuf, "uint32");
+ if(ewidth[TIND] == 4)
+ Bprint(&outbuf, "uint");
+ else
+ Bprint(&outbuf, "uint32");
break;
case TVLONG:
- Bprint(&outbuf, "int64");
+ if(ewidth[TIND] == 8)
+ Bprint(&outbuf, "int");
+ else
+ Bprint(&outbuf, "int64");
break;
case TUVLONG:
- Bprint(&outbuf, "uint64");
+ if(ewidth[TIND] == 8)
+ Bprint(&outbuf, "uint");
+ else
+ Bprint(&outbuf, "uint64");
break;
case TFLOAT:
Bprint(&outbuf, "float32");
diff --git a/src/cmd/gc/builtin.c b/src/cmd/gc/builtin.c
index 986a1de9ac..9de934b067 100644
--- a/src/cmd/gc/builtin.c
+++ b/src/cmd/gc/builtin.c
@@ -2,7 +2,7 @@
char *runtimeimport =
"package runtime\n"
"import runtime \"runtime\"\n"
- "func @\"\".new (@\"\".typ·2 *byte) (? *any)\n"
+ "func @\"\".newobject (@\"\".typ·2 *byte) (? *any)\n"
"func @\"\".panicindex ()\n"
"func @\"\".panicslice ()\n"
"func @\"\".panicdivide ()\n"
diff --git a/src/cmd/gc/runtime.go b/src/cmd/gc/runtime.go
index 6a9e68bcb4..2f282d6a03 100644
--- a/src/cmd/gc/runtime.go
+++ b/src/cmd/gc/runtime.go
@@ -12,7 +12,7 @@ package PACKAGE
// emitted by compiler, not referred to by go programs
-func new(typ *byte) *any
+func newobject(typ *byte) *any
func panicindex()
func panicslice()
func panicdivide()
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index eb9ce11316..e8d9e1ebcc 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -1915,7 +1915,7 @@ callnew(Type *t)
Node *fn;
dowidth(t);
- fn = syslook("new", 1);
+ fn = syslook("newobject", 1);
argtype(fn, t);
return mkcall1(fn, ptrto(t), nil, typename(t));
}