summaryrefslogtreecommitdiff
path: root/libgo/runtime/go-append.c
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2010-12-03 04:34:57 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2010-12-03 04:34:57 +0000
commite440a3286bc89368b8d3a8fd6accd47191790bf2 (patch)
tree38fe54a4f38ede5d949c915d66191f24a6fe5153 /libgo/runtime/go-append.c
parenta641ee368e2614349084a9a7bda2ec2b0b2bc1cf (diff)
downloadgcc-e440a3286bc89368b8d3a8fd6accd47191790bf2.tar.gz
Add Go frontend, libgo library, and Go testsuite.
gcc/: * gcc.c (default_compilers): Add entry for ".go". * common.opt: Add -static-libgo as a driver option. * doc/install.texi (Configuration): Mention libgo as an option for --enable-shared. Mention go as an option for --enable-languages. * doc/invoke.texi (Overall Options): Mention .go as a file name suffix. Mention go as a -x option. * doc/frontends.texi (G++ and GCC): Mention Go as a supported language. * doc/sourcebuild.texi (Top Level): Mention libgo. * doc/standards.texi (Standards): Add section on Go language. Move references for other languages into their own section. * doc/contrib.texi (Contributors): Mention that I contributed the Go frontend. gcc/testsuite/: * lib/go.exp: New file. * lib/go-dg.exp: New file. * lib/go-torture.exp: New file. * lib/target-supports.exp (check_compile): Match // Go. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167407 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/runtime/go-append.c')
-rw-r--r--libgo/runtime/go-append.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/libgo/runtime/go-append.c b/libgo/runtime/go-append.c
new file mode 100644
index 00000000000..aa8f4a16d0c
--- /dev/null
+++ b/libgo/runtime/go-append.c
@@ -0,0 +1,62 @@
+/* go-append.c -- the go builtin append function.
+
+ Copyright 2010 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 "go-assert.h"
+#include "go-type.h"
+#include "array.h"
+#include "runtime.h"
+#include "malloc.h"
+
+struct __go_open_array
+__go_append (const struct __go_slice_type *type,
+ struct __go_open_array a, struct __go_open_array b)
+{
+ size_t element_size;
+ unsigned int ucount;
+ int count;
+
+ if (b.__values == NULL || b.__count == 0)
+ return a;
+
+ __go_assert (type->__common.__code == GO_SLICE);
+ element_size = type->__element_type->__size;
+
+ ucount = (unsigned int) a.__count + (unsigned int) b.__count;
+ count = (int) ucount;
+ __go_assert (ucount == (unsigned int) count && count >= a.__count);
+ if (count > a.__capacity)
+ {
+ int m;
+ struct __go_open_array n;
+
+ m = a.__capacity;
+ if (m == 0)
+ m = b.__count;
+ else
+ {
+ do
+ {
+ if (a.__count < 1024)
+ m += m;
+ else
+ m += m / 4;
+ }
+ while (m < count);
+ }
+
+ n.__values = __go_alloc (m * element_size);
+ n.__count = a.__count;
+ n.__capacity = m;
+ __builtin_memcpy (n.__values, a.__values, n.__count * element_size);
+
+ a = n;
+ }
+
+ __builtin_memmove ((char *) a.__values + a.__count * element_size,
+ b.__values, b.__count * element_size);
+ a.__count = count;
+ return a;
+}