Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / runtime / go-print.c
blob095909de2bf4e082cef19ac5c7adc79eefff72a9
1 /* go-print.c -- support for the go print statement.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include <stdint.h>
8 #include <stdio.h>
10 #include "array.h"
11 #include "go-panic.h"
12 #include "go-string.h"
13 #include "interface.h"
15 /* This implements the various little functions which are called by
16 the predeclared functions print/println/panic/panicln. */
18 void
19 __go_print_space ()
21 putchar (' ');
24 void
25 __go_print_nl ()
27 putchar ('\n');
30 void
31 __go_print_string (struct __go_string val)
33 printf ("%.*s", (int) val.__length, (const char *) val.__data);
36 void
37 __go_print_uint64 (uint64_t val)
39 printf ("%llu", (unsigned long long) val);
42 void
43 __go_print_int64 (int64_t val)
45 printf ("%lld", (long long) val);
48 void
49 __go_print_double (double val)
51 printf ("%.24g", val);
54 void
55 __go_print_complex (__complex double val)
57 printf ("(%.24g%s%.24gi)",
58 __builtin_creal (val),
59 (__builtin_cimag (val) >= 0 || __builtin_isnan (__builtin_cimag(val))
60 ? "+"
61 : ""),
62 __builtin_cimag (val));
65 void
66 __go_print_bool (_Bool val)
68 fputs (val ? "true" : "false", stdout);
71 void
72 __go_print_pointer (void *val)
74 printf ("%p", val);
77 void
78 __go_print_empty_interface (struct __go_empty_interface e)
80 printf ("(%p,%p)", e.__type_descriptor, e.__object);
83 void
84 __go_print_interface (struct __go_interface i)
86 printf ("(%p,%p)", i.__methods, i.__object);
89 void
90 __go_print_slice (struct __go_open_array val)
92 printf ("[%d/%d]%p", val.__count, val.__capacity, val.__values);