OSDN Git Service

a72942d385dc924fbf3c4ab05402dbfcbd80658c
[pf3gnuchains/gcc-fork.git] / gcc / go / gofrontend / runtime.def
1 // runtime.def -- runtime functions called by generated code.  -*- C++ -*-
2
3 // Copyright 2011 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.
6
7 // Definitions for the Go runtime functions.
8
9 // Parameter type helper macros.
10 #define ABFT6(T1, T2, T3, T4, T5, T6) \
11   { RFT_ ## T1, RFT_ ## T2, RFT_ ## T3, RFT_ ## T4, RFT_ ## T5, RFT_ ## T6 }
12 #define P0()                    ABFT6(VOID, VOID, VOID, VOID, VOID, VOID)
13 #define P1(T)                   ABFT6(T, VOID, VOID, VOID, VOID, VOID)
14 #define P2(T1, T2)              ABFT6(T1, T2, VOID, VOID, VOID, VOID)
15 #define P3(T1, T2, T3)          ABFT6(T1, T2, T3, VOID, VOID, VOID)
16 #define P4(T1, T2, T3, T4)      ABFT6(T1, T2, T3, T4, VOID, VOID)
17 #define P5(T1, T2, T3, T4, T5)  ABFT6(T1, T2, T3, T4, T5, VOID)
18 #define P6(T1,T2,T3,T4,T5,T6)   ABFT6(T1, T2, T3, T4, T5, T6)
19
20 // Result type helper macros.
21 #define ABFT2(T1, T2) { RFT_ ## T1, RFT_ ## T2 }
22 #define R0()                    ABFT2(VOID, VOID)
23 #define R1(T)                   ABFT2(T, VOID)
24 #define R2(T1, T2)              ABFT2(T1, T2)
25
26 // Define all the Go runtime functions.  The first parameter is the
27 // enum code used to refer to the function.  The second parameter is
28 // the name.  The third is the parameter types and the fourth is the
29 // result types.
30
31 // Range over a string, returning the next index.
32 DEF_GO_RUNTIME(STRINGITER, "runtime.stringiter", P2(STRING, INT), R1(INT))
33
34 // Range over a string, returning the next index and character.
35 DEF_GO_RUNTIME(STRINGITER2, "runtime.stringiter2", P2(STRING, INT),
36                R2(INT, INT))
37
38 // Concatenate two strings.
39 DEF_GO_RUNTIME(STRING_PLUS, "__go_string_plus", P2(STRING, STRING), R1(STRING))
40
41 // Compare two strings.
42 DEF_GO_RUNTIME(STRCMP, "__go_strcmp", P2(STRING, STRING), R1(INT))
43
44 // Take a slice of a string.
45 DEF_GO_RUNTIME(STRING_SLICE, "__go_string_slice", P3(STRING, INT, INT),
46                R1(STRING))
47
48 // Convert an integer to a string.
49 DEF_GO_RUNTIME(INT_TO_STRING, "__go_int_to_string", P1(INT), R1(STRING))
50
51 // Convert a byte array to a string.
52 DEF_GO_RUNTIME(BYTE_ARRAY_TO_STRING, "__go_byte_array_to_string",
53                P2(POINTER, INT), R1(STRING))
54
55 // Convert an int array to a string.
56 DEF_GO_RUNTIME(INT_ARRAY_TO_STRING, "__go_int_array_to_string",
57                P2(POINTER, INT), R1(STRING))
58
59 // Convert a string to a byte slice.
60 DEF_GO_RUNTIME(STRING_TO_BYTE_ARRAY, "__go_string_to_byte_array",
61                P1(STRING), R1(SLICE))
62
63 // Convert a string to an int slice.
64 DEF_GO_RUNTIME(STRING_TO_INT_ARRAY, "__go_string_to_int_array",
65                P1(STRING), R1(SLICE))
66
67
68 // Make a slice.
69 DEF_GO_RUNTIME(MAKESLICE1, "__go_make_slice1", P2(TYPE, UINTPTR), R1(SLICE))
70 DEF_GO_RUNTIME(MAKESLICE2, "__go_make_slice2", P3(TYPE, UINTPTR, UINTPTR),
71                R1(SLICE))
72
73
74 // Make a map.
75 DEF_GO_RUNTIME(MAKEMAP, "__go_new_map", P2(MAPDESCRIPTOR, UINTPTR), R1(MAP))
76
77 // Build a map from a composite literal.
78 DEF_GO_RUNTIME(CONSTRUCT_MAP, "__go_construct_map",
79                P6(POINTER, UINTPTR, UINTPTR, UINTPTR, UINTPTR, POINTER),
80                R1(MAP))
81
82 // Get the length of a map (the number of entries).
83 DEF_GO_RUNTIME(MAP_LEN, "__go_map_len", P1(MAP), R1(INT))
84
85 // Look up a key in a map.
86 DEF_GO_RUNTIME(MAP_INDEX, "__go_map_index", P3(MAP, POINTER, BOOL),
87                R1(POINTER))
88
89 // Look up a key in a map returning whether it is present.
90 DEF_GO_RUNTIME(MAPACCESS2, "runtime.mapaccess2",
91                P4(TYPE, MAP, POINTER, POINTER), R1(BOOL))
92
93 // Tuple assignment to a map element.
94 DEF_GO_RUNTIME(MAPASSIGN2, "runtime.mapassign2",
95                P4(MAP, POINTER, POINTER, BOOL), R0())
96
97 // Begin a range over a map.
98 DEF_GO_RUNTIME(MAPITERINIT, "runtime.mapiterinit", P2(MAP, MAPITER), R0())
99
100 // Range over a map, returning the next key.
101 DEF_GO_RUNTIME(MAPITER1, "runtime.mapiter1", P2(MAPITER, POINTER), R0())
102
103 // Range over a map, returning the next key and value.
104 DEF_GO_RUNTIME(MAPITER2, "runtime.mapiter2", P3(MAPITER, POINTER, POINTER),
105                R0())
106
107 // Range over a map, moving to the next map entry.
108 DEF_GO_RUNTIME(MAPITERNEXT, "runtime.mapiternext", P1(MAPITER), R0())
109
110
111 // Make a channel.
112 DEF_GO_RUNTIME(MAKECHAN, "__go_new_channel", P2(TYPE, UINTPTR), R1(CHAN))
113
114 // Get the length of a channel (the number of unread values).
115 DEF_GO_RUNTIME(CHAN_LEN, "__go_chan_len", P1(CHAN), R1(INT))
116
117 // Get the capacity of a channel (the size of the buffer).
118 DEF_GO_RUNTIME(CHAN_CAP, "__go_chan_cap", P1(CHAN), R1(INT))
119
120 // Send a small value on a channel.
121 DEF_GO_RUNTIME(SEND_SMALL, "__go_send_small", P3(CHAN, UINT64, BOOL), R0())
122
123 // Send a small value on a channel without blocking.
124 DEF_GO_RUNTIME(SEND_NONBLOCKING_SMALL, "__go_send_nonblocking_small",
125                P2(CHAN, UINT64), R1(BOOL))
126
127 // Send a big value on a channel.
128 DEF_GO_RUNTIME(SEND_BIG, "__go_send_big", P3(CHAN, POINTER, BOOL), R0())
129
130 // Send a big value on a channel without blocking.
131 DEF_GO_RUNTIME(SEND_NONBLOCKING_BIG, "__go_send_nonblocking_big",
132                P2(CHAN, POINTER), R1(BOOL))
133
134 // Receive a small value from a channel.
135 DEF_GO_RUNTIME(RECEIVE_SMALL, "__go_receive_small", P2(CHAN, BOOL), R1(UINT64))
136
137 // Receive a big value from a channel.
138 DEF_GO_RUNTIME(RECEIVE_BIG, "__go_receive_big", P3(CHAN, POINTER, BOOL),
139                R1(BOOL))
140
141 // Receive a value from a channel returning whether it is closed.
142 DEF_GO_RUNTIME(CHANRECV2, "runtime.chanrecv2", P2(CHAN, POINTER), R1(BOOL))
143
144 // Receive a value from a channel returning whether it is closed, for select.
145 DEF_GO_RUNTIME(CHANRECV3, "runtime.chanrecv3", P2(CHAN, POINTER), R1(BOOL))
146
147
148 // Panic.
149 DEF_GO_RUNTIME(PANIC, "__go_panic", P1(EFACE), R0())
150
151 // Recover.
152 DEF_GO_RUNTIME(RECOVER, "__go_recover", P0(), R1(EFACE))
153
154 // Recover when called directly from defer.
155 DEF_GO_RUNTIME(DEFERRED_RECOVER, "__go_deferred_recover", P0(), R1(EFACE))
156
157 // Decide whether this function can call recover.
158 DEF_GO_RUNTIME(CAN_RECOVER, "__go_can_recover", P1(POINTER), R1(BOOL))
159
160 // Get the return address of the function.
161 DEF_GO_RUNTIME(RETURN_ADDRESS, "__go_return_address", P1(INT), R1(POINTER))
162
163 // Set the return address for defer in a defer thunk.
164 DEF_GO_RUNTIME(SET_DEFER_RETADDR, "__go_set_defer_retaddr", P1(POINTER),
165                R1(BOOL))
166
167 // Check for a deferred function in an exception handler.
168 DEF_GO_RUNTIME(CHECK_DEFER, "__go_check_defer", P1(BOOLPTR), R0())
169
170 // Run deferred functions.
171 DEF_GO_RUNTIME(UNDEFER, "__go_undefer", P1(BOOLPTR), R0())
172
173 // Panic with a runtime error.
174 DEF_GO_RUNTIME(RUNTIME_ERROR, "__go_runtime_error", P1(INT), R0())
175
176
177 // Close.
178 DEF_GO_RUNTIME(CLOSE, "__go_close", P1(CHAN), R0())
179
180
181 // Copy.
182 DEF_GO_RUNTIME(COPY, "__go_copy", P3(POINTER, POINTER, UINTPTR), R0())
183
184 // Append.
185 DEF_GO_RUNTIME(APPEND, "__go_append", P4(SLICE, POINTER, UINTPTR, UINTPTR),
186                R1(SLICE))
187
188
189 // Register roots (global variables) for the garbage collector.
190 DEF_GO_RUNTIME(REGISTER_GC_ROOTS, "__go_register_gc_roots", P1(POINTER), R0())
191
192
193 // Allocate memory.
194 DEF_GO_RUNTIME(NEW, "__go_new", P1(UINTPTR), R1(POINTER))
195
196 // Allocate memory which can not contain pointers.
197 DEF_GO_RUNTIME(NEW_NOPOINTERS, "__go_new_nopointers", P1(UINTPTR), R1(POINTER))
198
199
200 // Allocate a trampoline for a function literal.
201 DEF_GO_RUNTIME(ALLOCATE_GO_TRAMPOLINE, "__go_allocate_trampoline",
202                P2(UINTPTR, POINTER), R1(POINTER))
203
204
205 // Start a new goroutine.
206 DEF_GO_RUNTIME(GO, "__go_go", P2(FUNC_PTR, POINTER), R0())
207
208
209 // Defer a function.
210 DEF_GO_RUNTIME(DEFER, "__go_defer", P3(BOOLPTR, FUNC_PTR, POINTER), R0())
211
212
213 // Run a select statement.
214 DEF_GO_RUNTIME(SELECT, "__go_select", P4(UINTPTR, BOOL, CHANPTR, BOOLPTR),
215                R1(UINTPTR))
216
217
218 // Convert an empty interface to an empty interface, returning ok.
219 DEF_GO_RUNTIME(IFACEE2E2, "runtime.ifaceE2E2", P1(EFACE), R2(EFACE, BOOL))
220
221 // Convert a non-empty interface to an empty interface, returning ok.
222 DEF_GO_RUNTIME(IFACEI2E2, "runtime.ifaceI2E2", P1(IFACE), R2(EFACE, BOOL))
223
224 // Convert an empty interface to a non-empty interface, returning ok.
225 DEF_GO_RUNTIME(IFACEE2I2, "runtime.ifaceE2I2", P2(TYPE, EFACE),
226                R2(IFACE, BOOL))
227
228 // Convert a non-empty interface to a non-empty interface, returning ok.
229 DEF_GO_RUNTIME(IFACEI2I2, "runtime.ifaceI2I2", P2(TYPE, IFACE),
230                R2(IFACE, BOOL))
231
232 // Convert an empty interface to a pointer type, returning ok.
233 DEF_GO_RUNTIME(IFACEE2T2P, "runtime.ifaceE2T2P", P2(TYPE, EFACE),
234                R2(POINTER, BOOL))
235
236 // Convert a non-empty interface to a pointer type, return ok.
237 DEF_GO_RUNTIME(IFACEI2T2P, "runtime.ifaceI2T2P", P2(TYPE, IFACE),
238                R2(POINTER, BOOL))
239
240 // Convert an empty interface to a non-pointer type, returning ok.
241 DEF_GO_RUNTIME(IFACEE2T2, "runtime.ifaceE2T2", P3(TYPE, EFACE, POINTER),
242                R1(BOOL))
243
244 // Convert a non-empty interface to a non-pointer type, returning ok.
245 DEF_GO_RUNTIME(IFACEI2T2, "runtime.ifaceI2T2", P3(TYPE, IFACE, POINTER),
246                R1(BOOL))
247
248 // A type assertion from one interface type to another.  This is
249 // used for a type assertion.
250 DEF_GO_RUNTIME(ASSERT_INTERFACE, "__go_assert_interface", P2(TYPE, TYPE), R0())
251
252 // Convert one interface type to another.  This is used for an
253 // assignment.
254 DEF_GO_RUNTIME(CONVERT_INTERFACE, "__go_convert_interface", P2(TYPE, TYPE),
255                R1(POINTER))
256
257 // Check whether an interface type may be converted to a
258 // non-interface type.
259 DEF_GO_RUNTIME(CHECK_INTERFACE_TYPE, "__go_check_interface_type",
260                P3(TYPE, TYPE, TYPE), R0())
261
262 // Return whether we can convert an interface type to a type.
263 DEF_GO_RUNTIME(IFACEI2TP, "runtime.ifaceI2Tp", P2(TYPE, TYPE), R1(BOOL))
264
265 // Get the type descriptor of an empty interface.
266 DEF_GO_RUNTIME(EFACETYPE, "runtime.efacetype", P1(EFACE), R1(TYPE))
267
268 // Get the type descriptor of a non-empty interface.
269 DEF_GO_RUNTIME(IFACETYPE, "runtime.ifacetype", P1(IFACE), R1(TYPE))
270
271
272 // Compare two type descriptors for equality.
273 DEF_GO_RUNTIME(IFACETYPEEQ, "runtime.ifacetypeeq", P2(TYPE, TYPE), R1(BOOL))
274
275 // Compare two empty interface values.
276 DEF_GO_RUNTIME(EMPTY_INTERFACE_COMPARE, "__go_empty_interface_compare",
277                P2(EFACE, EFACE), R1(INT))
278
279 // Compare an empty interface value to a non-interface value.
280 DEF_GO_RUNTIME(EMPTY_INTERFACE_VALUE_COMPARE,
281                "__go_empty_interface_value_compare",
282                P3(EFACE, TYPE, POINTER), R1(INT))
283
284 // Compare two non-empty interface values.
285 DEF_GO_RUNTIME(INTERFACE_COMPARE, "__go_interface_compare",
286                P2(IFACE, IFACE), R1(INT))
287
288 // Compare a non-empty interface value to a non-interface value.
289 DEF_GO_RUNTIME(INTERFACE_VALUE_COMPARE, "__go_interface_value_compare",
290                P3(IFACE, TYPE, POINTER), R1(INT))
291
292 // Compare a non-empty interface value to an interface value.
293 DEF_GO_RUNTIME(INTERFACE_EMPTY_COMPARE, "__go_interface_empty_compare",
294                P2(IFACE, EFACE), R1(INT))
295
296
297 // Print a string (for print/println).
298 DEF_GO_RUNTIME(PRINT_STRING, "__go_print_string", P1(STRING), R0())
299
300 // Print a uint64 (for print/println).
301 DEF_GO_RUNTIME(PRINT_UINT64, "__go_print_uint64", P1(UINT64), R0())
302
303 // Print a int64 (for print/println).
304 DEF_GO_RUNTIME(PRINT_INT64, "__go_print_int64", P1(INT64), R0())
305
306 // Print a float64 (for print/println).
307 DEF_GO_RUNTIME(PRINT_DOUBLE, "__go_print_double", P1(FLOAT64), R0())
308
309 // Print a complex128 (for print/println).
310 DEF_GO_RUNTIME(PRINT_COMPLEX, "__go_print_complex", P1(COMPLEX128), R0())
311
312 // Print a bool (for print/println).
313 DEF_GO_RUNTIME(PRINT_BOOL, "__go_print_bool", P1(BOOL), R0())
314
315 // Print a pointer/map/channel/function (for print/println).
316 DEF_GO_RUNTIME(PRINT_POINTER, "__go_print_pointer", P1(POINTER), R0())
317
318 // Print an empty interface (for print/println).
319 DEF_GO_RUNTIME(PRINT_EMPTY_INTERFACE, "__go_print_empty_interface",
320                P1(EFACE), R0())
321
322 // Print a non-empty interface (for print/println).
323 DEF_GO_RUNTIME(PRINT_INTERFACE, "__go_print_interface", P1(IFACE), R0())
324
325 // Print a slice (for print/println).
326 DEF_GO_RUNTIME(PRINT_SLICE, "__go_print_slice", P1(SLICE), R0())
327
328 // Print a space (for println).
329 DEF_GO_RUNTIME(PRINT_SPACE, "__go_print_space", P0(), R0())
330
331 // Print a newline (for println).
332 DEF_GO_RUNTIME(PRINT_NL, "__go_print_nl", P0(), R0())
333
334
335 // Remove helper macros.
336 #undef ABFT6
337 #undef ABFT2
338 #undef P0
339 #undef P1
340 #undef P2
341 #undef P3
342 #undef P4
343 #undef P5
344 #undef P6
345 #undef R0
346 #undef R1
347 #undef R2