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.
12 extern void runtime_printlock(void)
13 __asm__(GOSYM_PREFIX
"runtime.printlock");
14 extern void runtime_printunlock(void)
15 __asm__(GOSYM_PREFIX
"runtime.printunlock");
16 extern void gwrite(Slice
)
17 __asm__(GOSYM_PREFIX
"runtime.gwrite");
18 extern void runtime_printint(int64
)
19 __asm__(GOSYM_PREFIX
"runtime.printint");
20 extern void runtime_printuint(uint64
)
21 __asm__(GOSYM_PREFIX
"runtime.printuint");
22 extern void runtime_printhex(uint64
)
23 __asm__(GOSYM_PREFIX
"runtime.printhex");
24 extern void runtime_printfloat(float64
)
25 __asm__(GOSYM_PREFIX
"runtime.printfloat");
26 extern void runtime_printcomplex(complex double)
27 __asm__(GOSYM_PREFIX
"runtime.printcomplex");
28 extern void runtime_printbool(_Bool
)
29 __asm__(GOSYM_PREFIX
"runtime.printbool");
30 extern void runtime_printstring(String
)
31 __asm__(GOSYM_PREFIX
"runtime.printstring");
32 extern void runtime_printpointer(void *)
33 __asm__(GOSYM_PREFIX
"runtime.printpointer");
34 extern void runtime_printslice(Slice
)
35 __asm__(GOSYM_PREFIX
"runtime.printslice");
36 extern void runtime_printeface(Eface
)
37 __asm__(GOSYM_PREFIX
"runtime.printeface");
38 extern void runtime_printiface(Iface
)
39 __asm__(GOSYM_PREFIX
"runtime.printiface");
41 // Clang requires this function to not be inlined (see below).
42 static void go_vprintf(const char*, va_list)
43 __attribute__((noinline
));
46 runtime_prints(const char *s
)
50 // Use memcpy to avoid const-cast warning.
51 memcpy(&sl
.__values
, &s
, sizeof(char*));
52 sl
.__count
= runtime_findnull((const byte
*)s
);
53 sl
.__capacity
= sl
.__count
;
58 runtime_printbyte(int8 c
)
68 #if defined (__clang__) && (defined (__i386__) || defined (__x86_64__))
69 // LLVM's code generator does not currently support split stacks for vararg
70 // functions, so we disable the feature for this function under Clang. This
71 // appears to be OK as long as:
72 // - this function only calls non-inlined, internal-linkage (hence no dynamic
73 // loader) functions compiled with split stacks (i.e. go_vprintf), which can
74 // allocate more stack space as required;
75 // - this function itself does not occupy more than BACKOFF bytes of stack space
76 // (see libgcc/config/i386/morestack.S).
77 // These conditions are currently known to be satisfied by Clang on x86-32 and
78 // x86-64. Note that signal handlers receive slightly less stack space than they
79 // would normally do if they happen to be called while this function is being
80 // run. If this turns out to be a problem we could consider increasing BACKOFF.
83 runtime_printf(const char *s
, ...)
84 __attribute__((no_split_stack
));
87 runtime_snprintf(byte
*buf
, int32 n
, const char *s
, ...)
88 __attribute__((no_split_stack
));
93 runtime_printf(const char *s
, ...)
103 runtime_snprintf(byte
*buf
, int32 n
, const char *s
, ...)
109 g
->writebuf
.__values
= buf
;
110 g
->writebuf
.__count
= 0;
111 g
->writebuf
.__capacity
= n
-1;
115 m
= g
->writebuf
.__count
;
116 ((byte
*)g
->writebuf
.__values
)[m
] = '\0';
117 g
->writebuf
.__values
= nil
;
118 g
->writebuf
.__count
= 0;
119 g
->writebuf
.__capacity
= 0;
123 // Very simple printf. Only for debugging prints.
124 // Do not add to this without checking with Rob.
126 go_vprintf(const char *s
, va_list va
)
138 // Use memcpy to avoid const-cast warning.
139 memcpy(&sl
.__values
, &lp
, sizeof(char*));
141 sl
.__capacity
= p
- lp
;
147 runtime_printslice(va_arg(va
, Slice
));
150 runtime_printbyte(va_arg(va
, int32
));
153 runtime_printint(va_arg(va
, int32
));
156 runtime_printint(va_arg(va
, int64
));
159 runtime_printeface(va_arg(va
, Eface
));
162 runtime_printfloat(va_arg(va
, float64
));
165 runtime_printcomplex(va_arg(va
, complex double));
168 runtime_printiface(va_arg(va
, Iface
));
171 runtime_printpointer(va_arg(va
, void*));
174 runtime_prints(va_arg(va
, char*));
177 runtime_printstring(va_arg(va
, String
));
180 runtime_printbool(va_arg(va
, int));
183 runtime_printuint(va_arg(va
, uint64
));
186 runtime_printhex(va_arg(va
, uint32
));
189 runtime_printhex(va_arg(va
, uint64
));
195 // Use memcpy to avoid const-cast warning.
196 memcpy(&sl
.__values
, &lp
, sizeof(char*));
198 sl
.__capacity
= p
- lp
;
202 runtime_printunlock();