aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-06-14 13:51:16 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-06-14 13:51:16 +0000
commitde38eefaa72cbf065d501f7548471c42621c4e73 (patch)
treeb1dabaf44c302fc461ce9c53e78e3903d642301a
parent6868b351c74950c9ff5c2bbc041c88ee705d2fc8 (diff)
downloadgcc-de38eefaa72cbf065d501f7548471c42621c4e73.zip
gcc-de38eefaa72cbf065d501f7548471c42621c4e73.tar.gz
gcc-de38eefaa72cbf065d501f7548471c42621c4e73.tar.bz2
Change builtin make to runtime call at lowering time.
Use kindNoPointers as 6g does. * Make-lang.in (go/expressions.o): Depend on $(GO_RUNTIME_H). From-SVN: r175020
-rw-r--r--libgo/runtime/go-make-slice.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/libgo/runtime/go-make-slice.c b/libgo/runtime/go-make-slice.c
new file mode 100644
index 0000000..cd2d55b
--- /dev/null
+++ b/libgo/runtime/go-make-slice.c
@@ -0,0 +1,57 @@
+/* go-make-slice.c -- make a slice.
+
+ Copyright 2011 The Go Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style
+ license that can be found in the LICENSE file. */
+
+#include <stdint.h>
+
+#include "go-alloc.h"
+#include "go-assert.h"
+#include "go-panic.h"
+#include "go-type.h"
+#include "array.h"
+#include "runtime.h"
+#include "malloc.h"
+
+struct __go_open_array
+__go_make_slice2 (const struct __go_type_descriptor *td, uintptr_t len,
+ uintptr_t cap)
+{
+ const struct __go_slice_type* std;
+ int ilen;
+ int icap;
+ uintptr_t size;
+ struct __go_open_array ret;
+ unsigned int flag;
+
+ __go_assert (td->__code == GO_SLICE);
+ std = (const struct __go_slice_type *) td;
+
+ ilen = (int) len;
+ if (ilen < 0 || (uintptr_t) ilen != len)
+ __go_panic_msg ("makeslice: len out of range");
+
+ icap = (int) cap;
+ if (cap < len
+ || (uintptr_t) icap != cap
+ || cap > (uintptr_t) -1U / std->__element_type->__size)
+ __go_panic_msg ("makeslice: cap out of range");
+
+ ret.__count = ilen;
+ ret.__capacity = icap;
+
+ size = cap * std->__element_type->__size;
+ flag = ((std->__element_type->__code & GO_NO_POINTERS) != 0
+ ? FlagNoPointers
+ : 0);
+ ret.__values = runtime_mallocgc (size, flag, 1, 1);
+
+ return ret;
+}
+
+struct __go_open_array
+__go_make_slice1 (const struct __go_type_descriptor *td, uintptr_t len)
+{
+ return __go_make_slice2 (td, len, len);
+}