1/* runtime.def -- Definitions for D runtime functions. 2 Copyright (C) 2014-2020 Free Software Foundation, Inc. 3 4GCC is free software; you can redistribute it and/or modify 5it under the terms of the GNU General Public License as published by 6the Free Software Foundation; either version 3, or (at your option) 7any later version. 8 9GCC is distributed in the hope that it will be useful, 10but WITHOUT ANY WARRANTY; without even the implied warranty of 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12GNU General Public License for more details. 13 14You should have received a copy of the GNU General Public License 15along with GCC; see the file COPYING3. If not see 16<http://www.gnu.org/licenses/>. */ 17 18/* D runtime library functions. */ 19 20/* DEF_D_RUNTIME (CODE, NAME, FLAGS) 21 CODE The enum code used to refer to this function. 22 NAME The name of this function as a string. 23 FLAGS ECF flags to describe attributes of the function. 24 25 Used for declaring functions that are called by generated code. Most are 26 extern(C) - for those that are not, ensure to use correct mangling. */ 27 28/* Helper macros for parameter building. */ 29#define P0() 0 30#define P1(T1) 1, LCT_ ## T1 31#define P2(T1, T2) 2, LCT_ ## T1, LCT_ ## T2 32#define P3(T1, T2, T3) 3, LCT_ ## T1, LCT_ ## T2, LCT_ ## T3 33#define P4(T1, T2, T3, T4) 4, LCT_ ## T1, LCT_ ## T2, LCT_ ## T3, LCT_ ## T4 34#define RT(T1) LCT_ ## T1 35 36/* Used when an assert() contract fails. */ 37DEF_D_RUNTIME (ASSERT, "_d_assert", RT(VOID), P2(STRING, UINT), ECF_NORETURN) 38DEF_D_RUNTIME (ASSERT_MSG, "_d_assert_msg", RT(VOID), P3(STRING, STRING, UINT), 39 ECF_NORETURN) 40 41/* Used when an assert() contract fails in a unittest function. */ 42DEF_D_RUNTIME (UNITTEST, "_d_unittest", RT(VOID), P2(STRING, UINT), 43 ECF_NORETURN) 44DEF_D_RUNTIME (UNITTEST_MSG, "_d_unittest_msg", RT(VOID), 45 P3(STRING, STRING, UINT), ECF_NORETURN) 46 47/* Used when an array index outside the bounds of its range. */ 48DEF_D_RUNTIME (ARRAY_BOUNDS, "_d_arraybounds", RT(VOID), P2(STRING, UINT), 49 ECF_NORETURN) 50 51/* Used when calling new on a class. */ 52DEF_D_RUNTIME (NEWCLASS, "_d_newclass", RT(OBJECT), P1(CONST_CLASSINFO), 0) 53 54/* Used when calling delete on a class or interface. */ 55DEF_D_RUNTIME (DELCLASS, "_d_delclass", RT(VOID), P1(VOIDPTR), 0) 56DEF_D_RUNTIME (DELINTERFACE, "_d_delinterface", RT(VOID), P1(VOIDPTR), 0) 57 58/* Same as deleting a class, but used for stack-allocated classes. */ 59DEF_D_RUNTIME (CALLFINALIZER, "_d_callfinalizer", RT(VOID), P1(VOIDPTR), 0) 60DEF_D_RUNTIME (CALLINTERFACEFINALIZER, "_d_callinterfacefinalizer", RT(VOID), 61 P1(VOIDPTR), 0) 62 63/* Used for casting to a class or interface. */ 64DEF_D_RUNTIME (DYNAMIC_CAST, "_d_dynamic_cast", RT(OBJECT), 65 P2(OBJECT, CLASSINFO), 0) 66DEF_D_RUNTIME (INTERFACE_CAST, "_d_interface_cast", RT(OBJECT), 67 P2(OBJECT, CLASSINFO), 0) 68 69/* Used when calling new on a pointer. The `i' variant is for when the 70 initializer is nonzero. */ 71DEF_D_RUNTIME (NEWITEMT, "_d_newitemT", RT(VOIDPTR), P1(CONST_TYPEINFO), 0) 72DEF_D_RUNTIME (NEWITEMIT, "_d_newitemiT", RT(VOIDPTR), P1(CONST_TYPEINFO), 0) 73 74/* Used when calling delete on a pointer. */ 75DEF_D_RUNTIME (DELMEMORY, "_d_delmemory", RT(VOID), P1(POINTER_VOIDPTR), 0) 76DEF_D_RUNTIME (DELSTRUCT, "_d_delstruct", RT(VOID), 77 P2(POINTER_VOIDPTR, TYPEINFO), 0) 78 79/* Used when calling new on an array. The `i' variant is for when the 80 initializer is nonzero, and the `m' variant is when initializing a 81 multi-dimensional array. */ 82DEF_D_RUNTIME (NEWARRAYT, "_d_newarrayT", RT(ARRAY_VOID), 83 P2(CONST_TYPEINFO, SIZE_T), 0) 84DEF_D_RUNTIME (NEWARRAYIT, "_d_newarrayiT", RT(ARRAY_VOID), 85 P2(CONST_TYPEINFO, SIZE_T), 0) 86DEF_D_RUNTIME (NEWARRAYMTX, "_d_newarraymTX", RT(ARRAY_VOID), 87 P2(CONST_TYPEINFO, ARRAY_SIZE_T), 0) 88DEF_D_RUNTIME (NEWARRAYMITX, "_d_newarraymiTX", RT(ARRAY_VOID), 89 P2(CONST_TYPEINFO, ARRAY_SIZE_T), 0) 90 91/* Used for allocating an array literal on the GC heap. */ 92DEF_D_RUNTIME (ARRAYLITERALTX, "_d_arrayliteralTX", RT(VOIDPTR), 93 P2(CONST_TYPEINFO, SIZE_T), 0) 94 95/* Used when calling delete on an array. */ 96DEF_D_RUNTIME (DELARRAYT, "_d_delarray_t", RT(VOID), 97 P2(ARRAYPTR_VOID, CONST_TYPEINFO), 0) 98 99/* Used for value equality (x == y) and comparisons (x < y) of non-trivial 100 arrays. Such as an array of structs or classes. */ 101DEF_D_RUNTIME (ADEQ2, "_adEq2", RT(INT), 102 P3(ARRAY_VOID, ARRAY_VOID, CONST_TYPEINFO), 0) 103DEF_D_RUNTIME (ADCMP2, "_adCmp2", RT(INT), 104 P3(ARRAY_VOID, ARRAY_VOID, CONST_TYPEINFO), 0) 105 106/* Used when casting from one array type to another where the index type 107 sizes differ. Such as from int[] to short[]. */ 108DEF_D_RUNTIME (ARRAYCAST, "_d_arraycast", RT(ARRAY_VOID), 109 P3(SIZE_T, SIZE_T, ARRAY_VOID), 0) 110 111/* Used for (array.length = n) expressions. The `i' variant is for when the 112 initializer is nonzero. */ 113DEF_D_RUNTIME (ARRAYSETLENGTHT, "_d_arraysetlengthT", RT(ARRAY_VOID), 114 P3(CONST_TYPEINFO, SIZE_T, ARRAYPTR_VOID), 0) 115DEF_D_RUNTIME (ARRAYSETLENGTHIT, "_d_arraysetlengthiT", RT(ARRAY_VOID), 116 P3(CONST_TYPEINFO, SIZE_T, ARRAYPTR_VOID), 0) 117 118/* Used for allocating closures on the GC heap. */ 119DEF_D_RUNTIME (ALLOCMEMORY, "_d_allocmemory", RT(VOIDPTR), P1(SIZE_T), 120 ECF_MALLOC) 121 122/* Used for copying an array into a slice, adds an enforcment that the source 123 and destination are equal in size and do not overlap. */ 124DEF_D_RUNTIME (ARRAYCOPY, "_d_arraycopy", RT(ARRAY_VOID), 125 P3(SIZE_T, ARRAY_VOID, ARRAY_VOID), 0) 126 127/* Used for array assignments from an existing array. The `set' variant is for 128 when the assignment value is a single element. */ 129DEF_D_RUNTIME (ARRAYASSIGN, "_d_arrayassign", RT(ARRAY_VOID), 130 P3(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID), 0) 131DEF_D_RUNTIME (ARRAYASSIGN_L, "_d_arrayassign_l", RT(ARRAY_VOID), 132 P4(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID, VOIDPTR), 0) 133DEF_D_RUNTIME (ARRAYASSIGN_R, "_d_arrayassign_r", RT(ARRAY_VOID), 134 P4(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID, VOIDPTR), 0) 135DEF_D_RUNTIME (ARRAYSETASSIGN, "_d_arraysetassign", RT(VOIDPTR), 136 P4(VOIDPTR, VOIDPTR, SIZE_T, CONST_TYPEINFO), 0) 137 138/* Used for constructing a new array from an existing array. The `set' variant 139 is for when the constructor value is a single element. */ 140DEF_D_RUNTIME (ARRAYCTOR, "_d_arrayctor", RT(ARRAY_VOID), 141 P3(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID), 0) 142DEF_D_RUNTIME (ARRAYSETCTOR, "_d_arraysetctor", RT(VOIDPTR), 143 P4(VOIDPTR, VOIDPTR, SIZE_T, CONST_TYPEINFO), 0) 144 145/* Used for concatenating two or more arrays together. Then `n' variant is 146 for when there is more than two arrays to handle. */ 147DEF_D_RUNTIME (ARRAYCATT, "_d_arraycatT", RT(ARRAY_BYTE), 148 P3(CONST_TYPEINFO, ARRAY_BYTE, ARRAY_BYTE), 0) 149DEF_D_RUNTIME (ARRAYCATNTX, "_d_arraycatnTX", RT(ARRAY_VOID), 150 P2(CONST_TYPEINFO, ARRAYARRAY_BYTE), 0) 151 152/* Used for appending a single element to an array. */ 153DEF_D_RUNTIME (ARRAYAPPENDCTX, "_d_arrayappendcTX", RT(ARRAY_BYTE), 154 P3(CONST_TYPEINFO, ARRAYPTR_BYTE, SIZE_T), 0) 155 156/* Same as appending a single element to an array, but specific for when the 157 source is a UTF-32 character, and the destination is a UTF-8 or 16 array. */ 158DEF_D_RUNTIME (ARRAYAPPENDCD, "_d_arrayappendcd", RT(ARRAY_VOID), 159 P2(ARRAYPTR_BYTE, DCHAR), 0) 160DEF_D_RUNTIME (ARRAYAPPENDWD, "_d_arrayappendwd", RT(ARRAY_VOID), 161 P2(ARRAYPTR_BYTE, DCHAR), 0) 162 163/* Used for appending an existing array to another. */ 164DEF_D_RUNTIME (ARRAYAPPENDT, "_d_arrayappendT", RT(ARRAY_VOID), 165 P3(TYPEINFO, ARRAYPTR_BYTE, ARRAY_BYTE), 0) 166 167/* Used for allocating a new associative array. */ 168DEF_D_RUNTIME (ASSOCARRAYLITERALTX, "_d_assocarrayliteralTX", RT(VOIDPTR), 169 P3(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID), 0) 170 171/* Used for value equality of two associative arrays. */ 172DEF_D_RUNTIME (AAEQUAL, "_aaEqual", RT(INT), 173 P3(CONST_TYPEINFO, ASSOCARRAY, ASSOCARRAY), 0) 174 175/* Used to determine is a key exists in an associative array. */ 176DEF_D_RUNTIME (AAINX, "_aaInX", RT(VOIDPTR), 177 P3(ASSOCARRAY, CONST_TYPEINFO, VOIDPTR), 0) 178 179/* Used to retrieve a value from an associative array index by a key. The 180 `Rvalue' variant returns null if the key is not found, where as aaGetY 181 will create new key entry for assignment. */ 182DEF_D_RUNTIME (AAGETY, "_aaGetY", RT(VOIDPTR), 183 P4(POINTER_ASSOCARRAY, CONST_TYPEINFO, SIZE_T, VOIDPTR), 0) 184DEF_D_RUNTIME (AAGETRVALUEX, "_aaGetRvalueX", RT(VOIDPTR), 185 P4(ASSOCARRAY, CONST_TYPEINFO, SIZE_T, VOIDPTR), 0) 186 187/* Used when calling delete on a key entry in an associative array. */ 188DEF_D_RUNTIME (AADELX, "_aaDelX", RT(BOOL), 189 P3(ASSOCARRAY, CONST_TYPEINFO, VOIDPTR), 0) 190 191/* Used for throw() expressions. */ 192DEF_D_RUNTIME (THROW, "_d_throw", RT(VOID), P1(OBJECT), ECF_NORETURN) 193DEF_D_RUNTIME (BEGIN_CATCH, "__gdc_begin_catch", RT(VOIDPTR), P1(VOIDPTR), 0) 194 195/* C++ exception handlers. */ 196DEF_D_RUNTIME (CXA_BEGIN_CATCH, "__cxa_begin_catch", RT(VOIDPTR), P1(VOIDPTR), 197 ECF_NOTHROW) 198DEF_D_RUNTIME (CXA_END_CATCH, "__cxa_end_catch", RT(VOID), P0(), 0) 199 200/* When invariant() contracts are turned on, used after testing whether a 201 class != null for validating the state of a class. */ 202DEF_D_RUNTIME (INVARIANT, "_D9invariant12_d_invariantFC6ObjectZv", RT(VOID), 203 P1(OBJECT), 0) 204 205/* Used when performing a switch/cases on a string. The `u' and `d' variants 206 are for UTF-16 and UTF-32 strings respectively. */ 207DEF_D_RUNTIME (SWITCH_STRING, "_d_switch_string", RT(INT), 208 P2(ARRAY_STRING, STRING), 0) 209DEF_D_RUNTIME (SWITCH_USTRING, "_d_switch_ustring", RT(INT), 210 P2(ARRAY_WSTRING, WSTRING), 0) 211DEF_D_RUNTIME (SWITCH_DSTRING, "_d_switch_dstring", RT(INT), 212 P2(ARRAY_DSTRING, DSTRING), 0) 213 214/* Used when throwing an error that a switch statement has no default case, 215 and yet none of the existing cases matched. */ 216DEF_D_RUNTIME (SWITCH_ERROR, "_d_switch_error", RT(VOID), P2(STRING, UINT), 217 ECF_NORETURN) 218 219#undef P0 220#undef P1 221#undef P2 222#undef P3 223#undef P4 224#undef RT 225