1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 extern void runtime_printlock(void)
12 __asm__(GOSYM_PREFIX
"runtime.printlock");
13 extern void runtime_printunlock(void)
14 __asm__(GOSYM_PREFIX
"runtime.printunlock");
15 extern void gwrite(Slice
)
16 __asm__(GOSYM_PREFIX
"runtime.gwrite");
17 extern void runtime_printint(int64
)
18 __asm__(GOSYM_PREFIX
"runtime.printint");
19 extern void runtime_printuint(uint64
)
20 __asm__(GOSYM_PREFIX
"runtime.printuint");
21 extern void runtime_printhex(uint64
)
22 __asm__(GOSYM_PREFIX
"runtime.printhex");
23 extern void runtime_printfloat(float64
)
24 __asm__(GOSYM_PREFIX
"runtime.printfloat");
25 extern void runtime_printcomplex(complex double)
26 __asm__(GOSYM_PREFIX
"runtime.printcomplex");
27 extern void runtime_printbool(_Bool
)
28 __asm__(GOSYM_PREFIX
"runtime.printbool");
29 extern void runtime_printstring(String
)
30 __asm__(GOSYM_PREFIX
"runtime.printstring");
31 extern void runtime_printpointer(void *)
32 __asm__(GOSYM_PREFIX
"runtime.printpointer");
33 extern void runtime_printslice(Slice
)
34 __asm__(GOSYM_PREFIX
"runtime.printslice");
35 extern void runtime_printeface(Eface
)
36 __asm__(GOSYM_PREFIX
"runtime.printeface");
37 extern void runtime_printiface(Iface
)
38 __asm__(GOSYM_PREFIX
"runtime.printiface");
40 // Clang requires this function to not be inlined (see below).
41 static void go_vprintf(const char*, va_list)
42 __attribute__((noinline
));
45 runtime_prints(const char *s
)
49 // Use memcpy to avoid const-cast warning.
50 memcpy(&sl
.__values
, &s
, sizeof(char*));
51 sl
.__count
= runtime_findnull((const byte
*)s
);
52 sl
.__capacity
= sl
.__count
;
57 runtime_printbyte(int8 c
)
67 #if defined (__clang__) && (defined (__i386__) || defined (__x86_64__))
68 // LLVM's code generator does not currently support split stacks for vararg
69 // functions, so we disable the feature for this function under Clang. This
70 // appears to be OK as long as:
71 // - this function only calls non-inlined, internal-linkage (hence no dynamic
72 // loader) functions compiled with split stacks (i.e. go_vprintf), which can
73 // allocate more stack space as required;
74 // - this function itself does not occupy more than BACKOFF bytes of stack space
75 // (see libgcc/config/i386/morestack.S).
76 // These conditions are currently known to be satisfied by Clang on x86-32 and
77 // x86-64. Note that signal handlers receive slightly less stack space than they
78 // would normally do if they happen to be called while this function is being
79 // run. If this turns out to be a problem we could consider increasing BACKOFF.
82 runtime_printf(const char *s
, ...)
83 __attribute__((no_split_stack
));
86 runtime_snprintf(byte
*buf
, int32 n
, const char *s
, ...)
87 __attribute__((no_split_stack
));
92 runtime_printf(const char *s
, ...)
102 runtime_snprintf(byte
*buf
, int32 n
, const char *s
, ...)
108 g
->writebuf
.__values
= buf
;
109 g
->writebuf
.__count
= 0;
110 g
->writebuf
.__capacity
= n
-1;
114 m
= g
->writebuf
.__count
;
115 ((byte
*)g
->writebuf
.__values
)[m
] = '\0';
116 g
->writebuf
.__values
= nil
;
117 g
->writebuf
.__count
= 0;
118 g
->writebuf
.__capacity
= 0;
122 // Very simple printf. Only for debugging prints.
123 // Do not add to this without checking with Rob.
125 go_vprintf(const char *s
, va_list va
)
137 // Use memcpy to avoid const-cast warning.
138 memcpy(&sl
.__values
, &lp
, sizeof(char*));
140 sl
.__capacity
= p
- lp
;
146 runtime_printslice(va_arg(va
, Slice
));
149 runtime_printbyte(va_arg(va
, int32
));
152 runtime_printint(va_arg(va
, int32
));
155 runtime_printint(va_arg(va
, int64
));
158 runtime_printeface(va_arg(va
, Eface
));
161 runtime_printfloat(va_arg(va
, float64
));
164 runtime_printcomplex(va_arg(va
, complex double));
167 runtime_printiface(va_arg(va
, Iface
));
170 runtime_printpointer(va_arg(va
, void*));
173 runtime_prints(va_arg(va
, char*));
176 runtime_printstring(va_arg(va
, String
));
179 runtime_printbool(va_arg(va
, int));
182 runtime_printuint(va_arg(va
, uint64
));
185 runtime_printhex(va_arg(va
, uint32
));
188 runtime_printhex(va_arg(va
, uint64
));
194 // Use memcpy to avoid const-cast warning.
195 memcpy(&sl
.__values
, &lp
, sizeof(char*));
197 sl
.__capacity
= p
- lp
;
201 runtime_printunlock();