runtime.def 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. // runtime.def -- runtime functions called by generated code. -*- C++ -*-
  2. // Copyright 2011 The Go Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. // Definitions for the Go runtime functions.
  6. // Parameter type helper macros.
  7. #define ABFT6(T1, T2, T3, T4, T5, T6) \
  8. { RFT_ ## T1, RFT_ ## T2, RFT_ ## T3, RFT_ ## T4, RFT_ ## T5, RFT_ ## T6 }
  9. #define P0() ABFT6(VOID, VOID, VOID, VOID, VOID, VOID)
  10. #define P1(T) ABFT6(T, VOID, VOID, VOID, VOID, VOID)
  11. #define P2(T1, T2) ABFT6(T1, T2, VOID, VOID, VOID, VOID)
  12. #define P3(T1, T2, T3) ABFT6(T1, T2, T3, VOID, VOID, VOID)
  13. #define P4(T1, T2, T3, T4) ABFT6(T1, T2, T3, T4, VOID, VOID)
  14. #define P5(T1, T2, T3, T4, T5) ABFT6(T1, T2, T3, T4, T5, VOID)
  15. #define P6(T1,T2,T3,T4,T5,T6) ABFT6(T1, T2, T3, T4, T5, T6)
  16. // Result type helper macros.
  17. #define ABFT2(T1, T2) { RFT_ ## T1, RFT_ ## T2 }
  18. #define R0() ABFT2(VOID, VOID)
  19. #define R1(T) ABFT2(T, VOID)
  20. #define R2(T1, T2) ABFT2(T1, T2)
  21. // Define all the Go runtime functions. The first parameter is the
  22. // enum code used to refer to the function. The second parameter is
  23. // the name. The third is the parameter types and the fourth is the
  24. // result types.
  25. // The standard C memcmp function, used for struct comparisons.
  26. DEF_GO_RUNTIME(MEMCMP, "__go_memcmp", P3(POINTER, POINTER, UINTPTR), R1(INT))
  27. // Range over a string, returning the next index.
  28. DEF_GO_RUNTIME(STRINGITER, "runtime.stringiter", P2(STRING, INT), R1(INT))
  29. // Range over a string, returning the next index and character.
  30. DEF_GO_RUNTIME(STRINGITER2, "runtime.stringiter2", P2(STRING, INT),
  31. R2(INT, RUNE))
  32. // Concatenate two strings.
  33. DEF_GO_RUNTIME(STRING_PLUS, "__go_string_plus", P2(STRING, STRING), R1(STRING))
  34. // Compare two strings.
  35. DEF_GO_RUNTIME(STRCMP, "__go_strcmp", P2(STRING, STRING), R1(INT))
  36. // Take a slice of a string.
  37. DEF_GO_RUNTIME(STRING_SLICE, "__go_string_slice", P3(STRING, INT, INT),
  38. R1(STRING))
  39. // Convert an integer to a string.
  40. DEF_GO_RUNTIME(INT_TO_STRING, "__go_int_to_string", P1(INT), R1(STRING))
  41. // Convert a byte array to a string.
  42. DEF_GO_RUNTIME(BYTE_ARRAY_TO_STRING, "__go_byte_array_to_string",
  43. P2(POINTER, INT), R1(STRING))
  44. // Convert an int array to a string.
  45. DEF_GO_RUNTIME(INT_ARRAY_TO_STRING, "__go_int_array_to_string",
  46. P2(POINTER, INT), R1(STRING))
  47. // Convert a string to a byte slice.
  48. DEF_GO_RUNTIME(STRING_TO_BYTE_ARRAY, "__go_string_to_byte_array",
  49. P1(STRING), R1(SLICE))
  50. // Convert a string to an int slice.
  51. DEF_GO_RUNTIME(STRING_TO_INT_ARRAY, "__go_string_to_int_array",
  52. P1(STRING), R1(SLICE))
  53. // Complex division.
  54. DEF_GO_RUNTIME(COMPLEX64_DIV, "__go_complex64_div",
  55. P2(COMPLEX64, COMPLEX64), R1(COMPLEX64))
  56. DEF_GO_RUNTIME(COMPLEX128_DIV, "__go_complex128_div",
  57. P2(COMPLEX128, COMPLEX128), R1(COMPLEX128))
  58. // Make a slice.
  59. DEF_GO_RUNTIME(MAKESLICE1, "__go_make_slice1", P2(TYPE, UINTPTR), R1(SLICE))
  60. DEF_GO_RUNTIME(MAKESLICE2, "__go_make_slice2", P3(TYPE, UINTPTR, UINTPTR),
  61. R1(SLICE))
  62. DEF_GO_RUNTIME(MAKESLICE1BIG, "__go_make_slice1_big", P2(TYPE, UINT64),
  63. R1(SLICE))
  64. DEF_GO_RUNTIME(MAKESLICE2BIG, "__go_make_slice2_big", P3(TYPE, UINT64, UINT64),
  65. R1(SLICE))
  66. // Make a map.
  67. DEF_GO_RUNTIME(MAKEMAP, "__go_new_map", P2(MAPDESCRIPTOR, UINTPTR), R1(MAP))
  68. DEF_GO_RUNTIME(MAKEMAPBIG, "__go_new_map_big", P2(MAPDESCRIPTOR, UINT64),
  69. R1(MAP))
  70. // Build a map from a composite literal.
  71. DEF_GO_RUNTIME(CONSTRUCT_MAP, "__go_construct_map",
  72. P6(POINTER, UINTPTR, UINTPTR, UINTPTR, UINTPTR, POINTER),
  73. R1(MAP))
  74. // Get the length of a map (the number of entries).
  75. DEF_GO_RUNTIME(MAP_LEN, "__go_map_len", P1(MAP), R1(INT))
  76. // Look up a key in a map.
  77. DEF_GO_RUNTIME(MAP_INDEX, "__go_map_index", P3(MAP, POINTER, BOOL),
  78. R1(POINTER))
  79. // Look up a key in a map returning whether it is present.
  80. DEF_GO_RUNTIME(MAPACCESS2, "runtime.mapaccess2",
  81. P4(TYPE, MAP, POINTER, POINTER), R1(BOOL))
  82. // Tuple assignment to a map element.
  83. DEF_GO_RUNTIME(MAPASSIGN2, "runtime.mapassign2",
  84. P4(MAP, POINTER, POINTER, BOOL), R0())
  85. // Delete a key from a map.
  86. DEF_GO_RUNTIME(MAPDELETE, "runtime.mapdelete", P2(MAP, POINTER), R0())
  87. // Begin a range over a map.
  88. DEF_GO_RUNTIME(MAPITERINIT, "runtime.mapiterinit", P2(MAP, MAPITER), R0())
  89. // Range over a map, returning the next key.
  90. DEF_GO_RUNTIME(MAPITER1, "runtime.mapiter1", P2(MAPITER, POINTER), R0())
  91. // Range over a map, returning the next key and value.
  92. DEF_GO_RUNTIME(MAPITER2, "runtime.mapiter2", P3(MAPITER, POINTER, POINTER),
  93. R0())
  94. // Range over a map, moving to the next map entry.
  95. DEF_GO_RUNTIME(MAPITERNEXT, "runtime.mapiternext", P1(MAPITER), R0())
  96. // Make a channel.
  97. DEF_GO_RUNTIME(MAKECHAN, "__go_new_channel", P2(TYPE, UINTPTR), R1(CHAN))
  98. DEF_GO_RUNTIME(MAKECHANBIG, "__go_new_channel_big", P2(TYPE, UINT64), R1(CHAN))
  99. // Get the length of a channel (the number of unread values).
  100. DEF_GO_RUNTIME(CHAN_LEN, "__go_chan_len", P1(CHAN), R1(INT))
  101. // Get the capacity of a channel (the size of the buffer).
  102. DEF_GO_RUNTIME(CHAN_CAP, "__go_chan_cap", P1(CHAN), R1(INT))
  103. // Send a small value on a channel.
  104. DEF_GO_RUNTIME(SEND_SMALL, "__go_send_small", P3(TYPE, CHAN, UINT64), R0())
  105. // Send a big value on a channel.
  106. DEF_GO_RUNTIME(SEND_BIG, "__go_send_big", P3(TYPE, CHAN, POINTER), R0())
  107. // Receive a value from a channel.
  108. DEF_GO_RUNTIME(RECEIVE, "__go_receive", P3(TYPE, CHAN, POINTER), R0())
  109. // Receive a value from a channel returning whether it is closed.
  110. DEF_GO_RUNTIME(CHANRECV2, "runtime.chanrecv2", P3(TYPE, CHAN, POINTER),
  111. R1(BOOL))
  112. // Start building a select statement.
  113. DEF_GO_RUNTIME(NEWSELECT, "runtime.newselect", P1(INT32), R1(POINTER))
  114. // Add a default clause to a select statement.
  115. DEF_GO_RUNTIME(SELECTDEFAULT, "runtime.selectdefault",
  116. P2(POINTER, INT32), R0())
  117. // Add a send clause to a select statement.
  118. DEF_GO_RUNTIME(SELECTSEND, "runtime.selectsend",
  119. P4(POINTER, CHAN, POINTER, INT32), R0())
  120. // Add a receive clause to a select statement, for a clause which does
  121. // not check whether the channel is closed.
  122. DEF_GO_RUNTIME(SELECTRECV, "runtime.selectrecv",
  123. P4(POINTER, CHAN, POINTER, INT32), R0())
  124. // Add a receive clause to a select statement, for a clause which does
  125. // check whether the channel is closed.
  126. DEF_GO_RUNTIME(SELECTRECV2, "runtime.selectrecv2",
  127. P5(POINTER, CHAN, POINTER, BOOLPTR, INT32), R0())
  128. // Run a select, returning the index of the selected clause.
  129. DEF_GO_RUNTIME(SELECTGO, "runtime.selectgo", P1(POINTER), R1(INT32))
  130. // Panic.
  131. DEF_GO_RUNTIME(PANIC, "__go_panic", P1(EFACE), R0())
  132. // Recover.
  133. DEF_GO_RUNTIME(RECOVER, "__go_recover", P0(), R1(EFACE))
  134. // Recover when called directly from defer.
  135. DEF_GO_RUNTIME(DEFERRED_RECOVER, "__go_deferred_recover", P0(), R1(EFACE))
  136. // Decide whether this function can call recover.
  137. DEF_GO_RUNTIME(CAN_RECOVER, "__go_can_recover", P1(POINTER), R1(BOOL))
  138. // Get the return address of the function.
  139. DEF_GO_RUNTIME(RETURN_ADDRESS, "__go_return_address", P1(INT), R1(POINTER))
  140. // Set the return address for defer in a defer thunk.
  141. DEF_GO_RUNTIME(SET_DEFER_RETADDR, "__go_set_defer_retaddr", P1(POINTER),
  142. R1(BOOL))
  143. // Check for a deferred function in an exception handler.
  144. DEF_GO_RUNTIME(CHECK_DEFER, "__go_check_defer", P1(BOOLPTR), R0())
  145. // Run deferred functions.
  146. DEF_GO_RUNTIME(UNDEFER, "__go_undefer", P1(BOOLPTR), R0())
  147. // Panic with a runtime error.
  148. DEF_GO_RUNTIME(RUNTIME_ERROR, "__go_runtime_error", P1(INT32), R0())
  149. // Close.
  150. DEF_GO_RUNTIME(CLOSE, "__go_builtin_close", P1(CHAN), R0())
  151. // Copy.
  152. DEF_GO_RUNTIME(COPY, "__go_copy", P3(POINTER, POINTER, UINTPTR), R0())
  153. // Append.
  154. DEF_GO_RUNTIME(APPEND, "__go_append", P4(SLICE, POINTER, UINTPTR, UINTPTR),
  155. R1(SLICE))
  156. // Register roots (global variables) for the garbage collector.
  157. DEF_GO_RUNTIME(REGISTER_GC_ROOTS, "__go_register_gc_roots", P1(POINTER), R0())
  158. // Allocate memory.
  159. DEF_GO_RUNTIME(NEW, "__go_new", P2(TYPE, UINTPTR), R1(POINTER))
  160. // Allocate memory which can not contain pointers.
  161. DEF_GO_RUNTIME(NEW_NOPOINTERS, "__go_new_nopointers", P2(TYPE, UINTPTR), R1(POINTER))
  162. // Start a new goroutine.
  163. DEF_GO_RUNTIME(GO, "__go_go", P2(FUNC_PTR, POINTER), R0())
  164. // Defer a function.
  165. DEF_GO_RUNTIME(DEFER, "__go_defer", P3(BOOLPTR, FUNC_PTR, POINTER), R0())
  166. // Convert an empty interface to an empty interface, returning ok.
  167. DEF_GO_RUNTIME(IFACEE2E2, "runtime.ifaceE2E2", P1(EFACE), R2(EFACE, BOOL))
  168. // Convert a non-empty interface to an empty interface, returning ok.
  169. DEF_GO_RUNTIME(IFACEI2E2, "runtime.ifaceI2E2", P1(IFACE), R2(EFACE, BOOL))
  170. // Convert an empty interface to a non-empty interface, returning ok.
  171. DEF_GO_RUNTIME(IFACEE2I2, "runtime.ifaceE2I2", P2(TYPE, EFACE),
  172. R2(IFACE, BOOL))
  173. // Convert a non-empty interface to a non-empty interface, returning ok.
  174. DEF_GO_RUNTIME(IFACEI2I2, "runtime.ifaceI2I2", P2(TYPE, IFACE),
  175. R2(IFACE, BOOL))
  176. // Convert an empty interface to a pointer type, returning ok.
  177. DEF_GO_RUNTIME(IFACEE2T2P, "runtime.ifaceE2T2P", P2(TYPE, EFACE),
  178. R2(POINTER, BOOL))
  179. // Convert a non-empty interface to a pointer type, return ok.
  180. DEF_GO_RUNTIME(IFACEI2T2P, "runtime.ifaceI2T2P", P2(TYPE, IFACE),
  181. R2(POINTER, BOOL))
  182. // Convert an empty interface to a non-pointer type, returning ok.
  183. DEF_GO_RUNTIME(IFACEE2T2, "runtime.ifaceE2T2", P3(TYPE, EFACE, POINTER),
  184. R1(BOOL))
  185. // Convert a non-empty interface to a non-pointer type, returning ok.
  186. DEF_GO_RUNTIME(IFACEI2T2, "runtime.ifaceI2T2", P3(TYPE, IFACE, POINTER),
  187. R1(BOOL))
  188. // A type assertion from one interface type to another. This is
  189. // used for a type assertion.
  190. DEF_GO_RUNTIME(ASSERT_INTERFACE, "__go_assert_interface", P2(TYPE, TYPE), R1(POINTER))
  191. // Convert one interface type to another. This is used for an
  192. // assignment.
  193. DEF_GO_RUNTIME(CONVERT_INTERFACE, "__go_convert_interface", P2(TYPE, TYPE),
  194. R1(POINTER))
  195. // Check whether an interface type may be converted to a
  196. // non-interface type.
  197. DEF_GO_RUNTIME(CHECK_INTERFACE_TYPE, "__go_check_interface_type",
  198. P3(TYPE, TYPE, TYPE), R0())
  199. // Return whether we can convert an interface type to a type.
  200. DEF_GO_RUNTIME(IFACEI2TP, "runtime.ifaceI2Tp", P2(TYPE, TYPE), R1(BOOL))
  201. // Get the type descriptor of an empty interface.
  202. DEF_GO_RUNTIME(EFACETYPE, "runtime.efacetype", P1(EFACE), R1(TYPE))
  203. // Get the type descriptor of a non-empty interface.
  204. DEF_GO_RUNTIME(IFACETYPE, "runtime.ifacetype", P1(IFACE), R1(TYPE))
  205. // Compare two type descriptors for equality.
  206. DEF_GO_RUNTIME(IFACETYPEEQ, "runtime.ifacetypeeq", P2(TYPE, TYPE), R1(BOOL))
  207. // Compare two empty interface values.
  208. DEF_GO_RUNTIME(EMPTY_INTERFACE_COMPARE, "__go_empty_interface_compare",
  209. P2(EFACE, EFACE), R1(INT))
  210. // Compare an empty interface value to a non-interface value.
  211. DEF_GO_RUNTIME(EMPTY_INTERFACE_VALUE_COMPARE,
  212. "__go_empty_interface_value_compare",
  213. P3(EFACE, TYPE, POINTER), R1(INT))
  214. // Compare two non-empty interface values.
  215. DEF_GO_RUNTIME(INTERFACE_COMPARE, "__go_interface_compare",
  216. P2(IFACE, IFACE), R1(INT))
  217. // Compare a non-empty interface value to a non-interface value.
  218. DEF_GO_RUNTIME(INTERFACE_VALUE_COMPARE, "__go_interface_value_compare",
  219. P3(IFACE, TYPE, POINTER), R1(INT))
  220. // Compare a non-empty interface value to an interface value.
  221. DEF_GO_RUNTIME(INTERFACE_EMPTY_COMPARE, "__go_interface_empty_compare",
  222. P2(IFACE, EFACE), R1(INT))
  223. // Print a string (for print/println).
  224. DEF_GO_RUNTIME(PRINT_STRING, "__go_print_string", P1(STRING), R0())
  225. // Print a uint64 (for print/println).
  226. DEF_GO_RUNTIME(PRINT_UINT64, "__go_print_uint64", P1(UINT64), R0())
  227. // Print a int64 (for print/println).
  228. DEF_GO_RUNTIME(PRINT_INT64, "__go_print_int64", P1(INT64), R0())
  229. // Print a float64 (for print/println).
  230. DEF_GO_RUNTIME(PRINT_DOUBLE, "__go_print_double", P1(FLOAT64), R0())
  231. // Print a complex128 (for print/println).
  232. DEF_GO_RUNTIME(PRINT_COMPLEX, "__go_print_complex", P1(COMPLEX128), R0())
  233. // Print a bool (for print/println).
  234. DEF_GO_RUNTIME(PRINT_BOOL, "__go_print_bool", P1(BOOL), R0())
  235. // Print a pointer/map/channel/function (for print/println).
  236. DEF_GO_RUNTIME(PRINT_POINTER, "__go_print_pointer", P1(POINTER), R0())
  237. // Print an empty interface (for print/println).
  238. DEF_GO_RUNTIME(PRINT_EMPTY_INTERFACE, "__go_print_empty_interface",
  239. P1(EFACE), R0())
  240. // Print a non-empty interface (for print/println).
  241. DEF_GO_RUNTIME(PRINT_INTERFACE, "__go_print_interface", P1(IFACE), R0())
  242. // Print a slice (for print/println).
  243. DEF_GO_RUNTIME(PRINT_SLICE, "__go_print_slice", P1(SLICE), R0())
  244. // Print a space (for println).
  245. DEF_GO_RUNTIME(PRINT_SPACE, "__go_print_space", P0(), R0())
  246. // Print a newline (for println).
  247. DEF_GO_RUNTIME(PRINT_NL, "__go_print_nl", P0(), R0())
  248. // Used for field tracking for data analysis.
  249. DEF_GO_RUNTIME(FIELDTRACK, "__go_fieldtrack", P1(POINTER), R0())
  250. // Remove helper macros.
  251. #undef ABFT6
  252. #undef ABFT2
  253. #undef P0
  254. #undef P1
  255. #undef P2
  256. #undef P3
  257. #undef P4
  258. #undef P5
  259. #undef P6
  260. #undef R0
  261. #undef R1
  262. #undef R2