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// The standard C memcmp function, used for struct comparisons. 32DEF_GO_RUNTIME(MEMCMP, "__go_memcmp", P3(POINTER, POINTER, UINTPTR), R1(INT)) 33 34// Range over a string, returning the next index. 35DEF_GO_RUNTIME(STRINGITER, "runtime.stringiter", P2(STRING, INT), R1(INT)) 36 37// Range over a string, returning the next index and character. 38DEF_GO_RUNTIME(STRINGITER2, "runtime.stringiter2", P2(STRING, INT), 39 R2(INT, RUNE)) 40 41// Concatenate two strings. 42DEF_GO_RUNTIME(STRING_PLUS, "__go_string_plus", P2(STRING, STRING), R1(STRING)) 43 44// Compare two strings. 45DEF_GO_RUNTIME(STRCMP, "__go_strcmp", P2(STRING, STRING), R1(INT)) 46 47// Take a slice of a string. 48DEF_GO_RUNTIME(STRING_SLICE, "__go_string_slice", P3(STRING, INT, INT), 49 R1(STRING)) 50 51// Convert an integer to a string. 52DEF_GO_RUNTIME(INT_TO_STRING, "__go_int_to_string", P1(INT), R1(STRING)) 53 54// Convert a byte array to a string. 55DEF_GO_RUNTIME(BYTE_ARRAY_TO_STRING, "__go_byte_array_to_string", 56 P2(POINTER, INT), R1(STRING)) 57 58// Convert an int array to a string. 59DEF_GO_RUNTIME(INT_ARRAY_TO_STRING, "__go_int_array_to_string", 60 P2(POINTER, INT), R1(STRING)) 61 62// Convert a string to a byte slice. 63DEF_GO_RUNTIME(STRING_TO_BYTE_ARRAY, "__go_string_to_byte_array", 64 P1(STRING), R1(SLICE)) 65 66// Convert a string to an int slice. 67DEF_GO_RUNTIME(STRING_TO_INT_ARRAY, "__go_string_to_int_array", 68 P1(STRING), R1(SLICE)) 69 70 71// Complex division. 72DEF_GO_RUNTIME(COMPLEX64_DIV, "__go_complex64_div", 73 P2(COMPLEX64, COMPLEX64), R1(COMPLEX64)) 74DEF_GO_RUNTIME(COMPLEX128_DIV, "__go_complex128_div", 75 P2(COMPLEX128, COMPLEX128), R1(COMPLEX128)) 76 77// Make a slice. 78DEF_GO_RUNTIME(MAKESLICE1, "__go_make_slice1", P2(TYPE, UINTPTR), R1(SLICE)) 79DEF_GO_RUNTIME(MAKESLICE2, "__go_make_slice2", P3(TYPE, UINTPTR, UINTPTR), 80 R1(SLICE)) 81DEF_GO_RUNTIME(MAKESLICE1BIG, "__go_make_slice1_big", P2(TYPE, UINT64), 82 R1(SLICE)) 83DEF_GO_RUNTIME(MAKESLICE2BIG, "__go_make_slice2_big", P3(TYPE, UINT64, UINT64), 84 R1(SLICE)) 85 86 87// Make a map. 88DEF_GO_RUNTIME(MAKEMAP, "__go_new_map", P2(MAPDESCRIPTOR, UINTPTR), R1(MAP)) 89DEF_GO_RUNTIME(MAKEMAPBIG, "__go_new_map_big", P2(MAPDESCRIPTOR, UINT64), 90 R1(MAP)) 91 92// Build a map from a composite literal. 93DEF_GO_RUNTIME(CONSTRUCT_MAP, "__go_construct_map", 94 P6(POINTER, UINTPTR, UINTPTR, UINTPTR, UINTPTR, POINTER), 95 R1(MAP)) 96 97// Get the length of a map (the number of entries). 98DEF_GO_RUNTIME(MAP_LEN, "__go_map_len", P1(MAP), R1(INT)) 99 100// Look up a key in a map. 101DEF_GO_RUNTIME(MAP_INDEX, "__go_map_index", P3(MAP, POINTER, BOOL), 102 R1(POINTER)) 103 104// Look up a key in a map returning whether it is present. 105DEF_GO_RUNTIME(MAPACCESS2, "runtime.mapaccess2", 106 P4(TYPE, MAP, POINTER, POINTER), R1(BOOL)) 107 108// Tuple assignment to a map element. 109DEF_GO_RUNTIME(MAPASSIGN2, "runtime.mapassign2", 110 P4(MAP, POINTER, POINTER, BOOL), R0()) 111 112// Delete a key from a map. 113DEF_GO_RUNTIME(MAPDELETE, "runtime.mapdelete", P2(MAP, POINTER), R0()) 114 115// Begin a range over a map. 116DEF_GO_RUNTIME(MAPITERINIT, "runtime.mapiterinit", P2(MAP, MAPITER), R0()) 117 118// Range over a map, returning the next key. 119DEF_GO_RUNTIME(MAPITER1, "runtime.mapiter1", P2(MAPITER, POINTER), R0()) 120 121// Range over a map, returning the next key and value. 122DEF_GO_RUNTIME(MAPITER2, "runtime.mapiter2", P3(MAPITER, POINTER, POINTER), 123 R0()) 124 125// Range over a map, moving to the next map entry. 126DEF_GO_RUNTIME(MAPITERNEXT, "runtime.mapiternext", P1(MAPITER), R0()) 127 128 129// Make a channel. 130DEF_GO_RUNTIME(MAKECHAN, "__go_new_channel", P2(TYPE, UINTPTR), R1(CHAN)) 131DEF_GO_RUNTIME(MAKECHANBIG, "__go_new_channel_big", P2(TYPE, UINT64), R1(CHAN)) 132 133// Get the length of a channel (the number of unread values). 134DEF_GO_RUNTIME(CHAN_LEN, "__go_chan_len", P1(CHAN), R1(INT)) 135 136// Get the capacity of a channel (the size of the buffer). 137DEF_GO_RUNTIME(CHAN_CAP, "__go_chan_cap", P1(CHAN), R1(INT)) 138 139// Send a small value on a channel. 140DEF_GO_RUNTIME(SEND_SMALL, "__go_send_small", P3(TYPE, CHAN, UINT64), R0()) 141 142// Send a big value on a channel. 143DEF_GO_RUNTIME(SEND_BIG, "__go_send_big", P3(TYPE, CHAN, POINTER), R0()) 144 145// Receive a value from a channel. 146DEF_GO_RUNTIME(RECEIVE, "__go_receive", P3(TYPE, CHAN, POINTER), R0()) 147 148// Receive a value from a channel returning whether it is closed. 149DEF_GO_RUNTIME(CHANRECV2, "runtime.chanrecv2", P3(TYPE, CHAN, POINTER), 150 R1(BOOL)) 151 152 153// Start building a select statement. 154DEF_GO_RUNTIME(NEWSELECT, "runtime.newselect", P1(INT32), R1(POINTER)) 155 156// Add a default clause to a select statement. 157DEF_GO_RUNTIME(SELECTDEFAULT, "runtime.selectdefault", 158 P2(POINTER, INT32), R0()) 159 160// Add a send clause to a select statement. 161DEF_GO_RUNTIME(SELECTSEND, "runtime.selectsend", 162 P4(POINTER, CHAN, POINTER, INT32), R0()) 163 164// Add a receive clause to a select statement, for a clause which does 165// not check whether the channel is closed. 166DEF_GO_RUNTIME(SELECTRECV, "runtime.selectrecv", 167 P4(POINTER, CHAN, POINTER, INT32), R0()) 168 169// Add a receive clause to a select statement, for a clause which does 170// check whether the channel is closed. 171DEF_GO_RUNTIME(SELECTRECV2, "runtime.selectrecv2", 172 P5(POINTER, CHAN, POINTER, BOOLPTR, INT32), R0()) 173 174// Run a select, returning the index of the selected clause. 175DEF_GO_RUNTIME(SELECTGO, "runtime.selectgo", P1(POINTER), R1(INT32)) 176 177 178// Panic. 179DEF_GO_RUNTIME(PANIC, "__go_panic", P1(EFACE), R0()) 180 181// Recover. 182DEF_GO_RUNTIME(RECOVER, "__go_recover", P0(), R1(EFACE)) 183 184// Recover when called directly from defer. 185DEF_GO_RUNTIME(DEFERRED_RECOVER, "__go_deferred_recover", P0(), R1(EFACE)) 186 187// Decide whether this function can call recover. 188DEF_GO_RUNTIME(CAN_RECOVER, "__go_can_recover", P1(POINTER), R1(BOOL)) 189 190// Get the return address of the function. 191DEF_GO_RUNTIME(RETURN_ADDRESS, "__go_return_address", P1(INT), R1(POINTER)) 192 193// Set the return address for defer in a defer thunk. 194DEF_GO_RUNTIME(SET_DEFER_RETADDR, "__go_set_defer_retaddr", P1(POINTER), 195 R1(BOOL)) 196 197// Check for a deferred function in an exception handler. 198DEF_GO_RUNTIME(CHECK_DEFER, "__go_check_defer", P1(BOOLPTR), R0()) 199 200// Run deferred functions. 201DEF_GO_RUNTIME(UNDEFER, "__go_undefer", P1(BOOLPTR), R0()) 202 203// Panic with a runtime error. 204DEF_GO_RUNTIME(RUNTIME_ERROR, "__go_runtime_error", P1(INT32), R0()) 205 206 207// Close. 208DEF_GO_RUNTIME(CLOSE, "__go_builtin_close", P1(CHAN), R0()) 209 210 211// Copy. 212DEF_GO_RUNTIME(COPY, "__go_copy", P3(POINTER, POINTER, UINTPTR), R0()) 213 214// Append. 215DEF_GO_RUNTIME(APPEND, "__go_append", P4(SLICE, POINTER, UINTPTR, UINTPTR), 216 R1(SLICE)) 217 218 219// Register roots (global variables) for the garbage collector. 220DEF_GO_RUNTIME(REGISTER_GC_ROOTS, "__go_register_gc_roots", P1(POINTER), R0()) 221 222 223// Allocate memory. 224DEF_GO_RUNTIME(NEW, "__go_new", P2(TYPE, UINTPTR), R1(POINTER)) 225 226// Start a new goroutine. 227DEF_GO_RUNTIME(GO, "__go_go", P2(FUNC_PTR, POINTER), R0()) 228 229// Defer a function. 230DEF_GO_RUNTIME(DEFER, "__go_defer", P3(BOOLPTR, FUNC_PTR, POINTER), R0()) 231 232 233// Convert an empty interface to an empty interface, returning ok. 234DEF_GO_RUNTIME(IFACEE2E2, "runtime.ifaceE2E2", P1(EFACE), R2(EFACE, BOOL)) 235 236// Convert a non-empty interface to an empty interface, returning ok. 237DEF_GO_RUNTIME(IFACEI2E2, "runtime.ifaceI2E2", P1(IFACE), R2(EFACE, BOOL)) 238 239// Convert an empty interface to a non-empty interface, returning ok. 240DEF_GO_RUNTIME(IFACEE2I2, "runtime.ifaceE2I2", P2(TYPE, EFACE), 241 R2(IFACE, BOOL)) 242 243// Convert a non-empty interface to a non-empty interface, returning ok. 244DEF_GO_RUNTIME(IFACEI2I2, "runtime.ifaceI2I2", P2(TYPE, IFACE), 245 R2(IFACE, BOOL)) 246 247// Convert an empty interface to a pointer type, returning ok. 248DEF_GO_RUNTIME(IFACEE2T2P, "runtime.ifaceE2T2P", P2(TYPE, EFACE), 249 R2(POINTER, BOOL)) 250 251// Convert a non-empty interface to a pointer type, return ok. 252DEF_GO_RUNTIME(IFACEI2T2P, "runtime.ifaceI2T2P", P2(TYPE, IFACE), 253 R2(POINTER, BOOL)) 254 255// Convert an empty interface to a non-pointer type, returning ok. 256DEF_GO_RUNTIME(IFACEE2T2, "runtime.ifaceE2T2", P3(TYPE, EFACE, POINTER), 257 R1(BOOL)) 258 259// Convert a non-empty interface to a non-pointer type, returning ok. 260DEF_GO_RUNTIME(IFACEI2T2, "runtime.ifaceI2T2", P3(TYPE, IFACE, POINTER), 261 R1(BOOL)) 262 263// A type assertion from one interface type to another. This is 264// used for a type assertion. 265DEF_GO_RUNTIME(ASSERT_INTERFACE, "__go_assert_interface", P2(TYPE, TYPE), R1(POINTER)) 266 267// Convert one interface type to another. This is used for an 268// assignment. 269DEF_GO_RUNTIME(CONVERT_INTERFACE, "__go_convert_interface", P2(TYPE, TYPE), 270 R1(POINTER)) 271 272// Check whether an interface type may be converted to a 273// non-interface type. 274DEF_GO_RUNTIME(CHECK_INTERFACE_TYPE, "__go_check_interface_type", 275 P3(TYPE, TYPE, TYPE), R0()) 276 277// Return whether we can convert an interface type to a type. 278DEF_GO_RUNTIME(IFACEI2TP, "runtime.ifaceI2Tp", P2(TYPE, TYPE), R1(BOOL)) 279 280// Get the type descriptor of an empty interface. 281DEF_GO_RUNTIME(EFACETYPE, "runtime.efacetype", P1(EFACE), R1(TYPE)) 282 283// Get the type descriptor of a non-empty interface. 284DEF_GO_RUNTIME(IFACETYPE, "runtime.ifacetype", P1(IFACE), R1(TYPE)) 285 286 287// Compare two type descriptors for equality. 288DEF_GO_RUNTIME(IFACETYPEEQ, "runtime.ifacetypeeq", P2(TYPE, TYPE), R1(BOOL)) 289 290// Compare two empty interface values. 291DEF_GO_RUNTIME(EMPTY_INTERFACE_COMPARE, "__go_empty_interface_compare", 292 P2(EFACE, EFACE), R1(INT)) 293 294// Compare an empty interface value to a non-interface value. 295DEF_GO_RUNTIME(EMPTY_INTERFACE_VALUE_COMPARE, 296 "__go_empty_interface_value_compare", 297 P3(EFACE, TYPE, POINTER), R1(INT)) 298 299// Compare two non-empty interface values. 300DEF_GO_RUNTIME(INTERFACE_COMPARE, "__go_interface_compare", 301 P2(IFACE, IFACE), R1(INT)) 302 303// Compare a non-empty interface value to a non-interface value. 304DEF_GO_RUNTIME(INTERFACE_VALUE_COMPARE, "__go_interface_value_compare", 305 P3(IFACE, TYPE, POINTER), R1(INT)) 306 307// Compare a non-empty interface value to an interface value. 308DEF_GO_RUNTIME(INTERFACE_EMPTY_COMPARE, "__go_interface_empty_compare", 309 P2(IFACE, EFACE), R1(INT)) 310 311 312// Print a string (for print/println). 313DEF_GO_RUNTIME(PRINT_STRING, "__go_print_string", P1(STRING), R0()) 314 315// Print a uint64 (for print/println). 316DEF_GO_RUNTIME(PRINT_UINT64, "__go_print_uint64", P1(UINT64), R0()) 317 318// Print a int64 (for print/println). 319DEF_GO_RUNTIME(PRINT_INT64, "__go_print_int64", P1(INT64), R0()) 320 321// Print a float64 (for print/println). 322DEF_GO_RUNTIME(PRINT_DOUBLE, "__go_print_double", P1(FLOAT64), R0()) 323 324// Print a complex128 (for print/println). 325DEF_GO_RUNTIME(PRINT_COMPLEX, "__go_print_complex", P1(COMPLEX128), R0()) 326 327// Print a bool (for print/println). 328DEF_GO_RUNTIME(PRINT_BOOL, "__go_print_bool", P1(BOOL), R0()) 329 330// Print a pointer/map/channel/function (for print/println). 331DEF_GO_RUNTIME(PRINT_POINTER, "__go_print_pointer", P1(POINTER), R0()) 332 333// Print an empty interface (for print/println). 334DEF_GO_RUNTIME(PRINT_EMPTY_INTERFACE, "__go_print_empty_interface", 335 P1(EFACE), R0()) 336 337// Print a non-empty interface (for print/println). 338DEF_GO_RUNTIME(PRINT_INTERFACE, "__go_print_interface", P1(IFACE), R0()) 339 340// Print a slice (for print/println). 341DEF_GO_RUNTIME(PRINT_SLICE, "__go_print_slice", P1(SLICE), R0()) 342 343// Print a space (for println). 344DEF_GO_RUNTIME(PRINT_SPACE, "__go_print_space", P0(), R0()) 345 346// Print a newline (for println). 347DEF_GO_RUNTIME(PRINT_NL, "__go_print_nl", P0(), R0()) 348 349 350// Used for field tracking for data analysis. 351DEF_GO_RUNTIME(FIELDTRACK, "__go_fieldtrack", P1(POINTER), R0()) 352 353 354// Remove helper macros. 355#undef ABFT6 356#undef ABFT2 357#undef P0 358#undef P1 359#undef P2 360#undef P3 361#undef P4 362#undef P5 363#undef P6 364#undef R0 365#undef R1 366#undef R2 367