d: Merge upstream dmd 3982604c5, druntime bc58b1e9, phobos 12329adb6.
[official-gcc.git] / gcc / d / runtime.def
blob3961a1d9bed37354593fc6083163c63d3b2f2196
1 /* runtime.def -- Definitions for D runtime functions.
2 Copyright (C) 2014-2021 Free Software Foundation, Inc.
4 GCC is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
9 GCC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
18 /* D runtime library functions. */
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.
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. */
28 /* Helper macros for parameter building. */
29 #define P0() 0
30 #define P1(T1) 1, LCT_ ## T1
31 #define P2(T1, T2) \
32 2, LCT_ ## T1, LCT_ ## T2
33 #define P3(T1, T2, T3) \
34 3, LCT_ ## T1, LCT_ ## T2, LCT_ ## T3
35 #define P4(T1, T2, T3, T4) \
36 4, LCT_ ## T1, LCT_ ## T2, LCT_ ## T3, LCT_ ## T4
37 #define P5(T1, T2, T3, T4, T5) \
38 5, LCT_ ## T1, LCT_ ## T2, LCT_ ## T3, LCT_ ## T4, LCT_ ## T5
39 #define RT(T1) LCT_ ## T1
41 /* Used when an assert() contract fails. */
42 DEF_D_RUNTIME (ASSERTP, "_d_assertp", RT(VOID), P2(IMMUTABLE_CHARPTR, UINT),
43 ECF_NORETURN)
44 DEF_D_RUNTIME (ASSERT_MSG, "_d_assert_msg", RT(VOID), P3(STRING, STRING, UINT),
45 ECF_NORETURN)
47 /* Used when an assert() contract fails in a unittest function. */
48 DEF_D_RUNTIME (UNITTESTP, "_d_unittestp", RT(VOID), P2(IMMUTABLE_CHARPTR, UINT),
49 ECF_NORETURN)
50 DEF_D_RUNTIME (UNITTEST_MSG, "_d_unittest_msg", RT(VOID),
51 P3(STRING, STRING, UINT), ECF_NORETURN)
53 /* Used when an array index outside the bounds of its range. */
54 DEF_D_RUNTIME (ARRAYBOUNDSP, "_d_arrayboundsp", RT(VOID),
55 P2(IMMUTABLE_CHARPTR, UINT), ECF_NORETURN)
56 DEF_D_RUNTIME (ARRAYBOUNDS_SLICEP, "_d_arraybounds_slicep", RT(VOID),
57 P5(IMMUTABLE_CHARPTR, UINT, SIZE_T, SIZE_T, SIZE_T),
58 ECF_NORETURN)
59 DEF_D_RUNTIME (ARRAYBOUNDS_INDEXP, "_d_arraybounds_indexp", RT(VOID),
60 P4(IMMUTABLE_CHARPTR, UINT, SIZE_T, SIZE_T), ECF_NORETURN)
62 /* Used when calling new on a class. */
63 DEF_D_RUNTIME (NEWCLASS, "_d_newclass", RT(OBJECT), P1(CONST_CLASSINFO), 0)
64 DEF_D_RUNTIME (NEWTHROW, "_d_newThrowable", RT(OBJECT), P1(CONST_CLASSINFO), 0)
66 /* Used when calling delete on a class or interface. */
67 DEF_D_RUNTIME (DELCLASS, "_d_delclass", RT(VOID), P1(VOIDPTR), 0)
68 DEF_D_RUNTIME (DELINTERFACE, "_d_delinterface", RT(VOID), P1(VOIDPTR), 0)
70 /* Same as deleting a class, but used for stack-allocated classes. */
71 DEF_D_RUNTIME (CALLFINALIZER, "_d_callfinalizer", RT(VOID), P1(VOIDPTR), 0)
72 DEF_D_RUNTIME (CALLINTERFACEFINALIZER, "_d_callinterfacefinalizer", RT(VOID),
73 P1(VOIDPTR), 0)
75 /* Used for casting to a class or interface. */
76 DEF_D_RUNTIME (DYNAMIC_CAST, "_d_dynamic_cast", RT(OBJECT),
77 P2(OBJECT, CLASSINFO), 0)
78 DEF_D_RUNTIME (INTERFACE_CAST, "_d_interface_cast", RT(OBJECT),
79 P2(OBJECT, CLASSINFO), 0)
81 /* Used when calling new on a pointer. The `i' variant is for when the
82 initializer is nonzero. */
83 DEF_D_RUNTIME (NEWITEMT, "_d_newitemT", RT(VOIDPTR), P1(CONST_TYPEINFO), 0)
84 DEF_D_RUNTIME (NEWITEMIT, "_d_newitemiT", RT(VOIDPTR), P1(CONST_TYPEINFO), 0)
86 /* Used when calling delete on a pointer. */
87 DEF_D_RUNTIME (DELMEMORY, "_d_delmemory", RT(VOID), P1(POINTER_VOIDPTR), 0)
88 DEF_D_RUNTIME (DELSTRUCT, "_d_delstruct", RT(VOID),
89 P2(POINTER_VOIDPTR, TYPEINFO), 0)
91 /* Used when calling new on an array. The `i' variant is for when the
92 initializer is nonzero, and the `m' variant is when initializing a
93 multi-dimensional array. */
94 DEF_D_RUNTIME (NEWARRAYT, "_d_newarrayT", RT(ARRAY_VOID),
95 P2(CONST_TYPEINFO, SIZE_T), 0)
96 DEF_D_RUNTIME (NEWARRAYIT, "_d_newarrayiT", RT(ARRAY_VOID),
97 P2(CONST_TYPEINFO, SIZE_T), 0)
98 DEF_D_RUNTIME (NEWARRAYMTX, "_d_newarraymTX", RT(ARRAY_VOID),
99 P2(CONST_TYPEINFO, ARRAY_SIZE_T), 0)
100 DEF_D_RUNTIME (NEWARRAYMITX, "_d_newarraymiTX", RT(ARRAY_VOID),
101 P2(CONST_TYPEINFO, ARRAY_SIZE_T), 0)
103 /* Used for allocating an array literal on the GC heap. */
104 DEF_D_RUNTIME (ARRAYLITERALTX, "_d_arrayliteralTX", RT(VOIDPTR),
105 P2(CONST_TYPEINFO, SIZE_T), 0)
107 /* Used when calling delete on an array. */
108 DEF_D_RUNTIME (DELARRAYT, "_d_delarray_t", RT(VOID),
109 P2(ARRAYPTR_VOID, CONST_TYPEINFO), 0)
111 /* Used for value equality (x == y) and comparisons (x < y) of non-trivial
112 arrays. Such as an array of structs or classes. */
113 DEF_D_RUNTIME (ADEQ2, "_adEq2", RT(INT),
114 P3(ARRAY_VOID, ARRAY_VOID, CONST_TYPEINFO), 0)
116 /* Used for (array.length = n) expressions. The `i' variant is for when the
117 initializer is nonzero. */
118 DEF_D_RUNTIME (ARRAYSETLENGTHT, "_d_arraysetlengthT", RT(ARRAY_VOID),
119 P3(CONST_TYPEINFO, SIZE_T, ARRAYPTR_VOID), 0)
120 DEF_D_RUNTIME (ARRAYSETLENGTHIT, "_d_arraysetlengthiT", RT(ARRAY_VOID),
121 P3(CONST_TYPEINFO, SIZE_T, ARRAYPTR_VOID), 0)
123 /* Used for allocating closures on the GC heap. */
124 DEF_D_RUNTIME (ALLOCMEMORY, "_d_allocmemory", RT(VOIDPTR), P1(SIZE_T),
125 ECF_MALLOC)
127 /* Used for copying an array into a slice, adds an enforcment that the source
128 and destination are equal in size and do not overlap. */
129 DEF_D_RUNTIME (ARRAYCOPY, "_d_arraycopy", RT(ARRAY_VOID),
130 P3(SIZE_T, ARRAY_VOID, ARRAY_VOID), 0)
132 /* Used for array assignments from an existing array. The `set' variant is for
133 when the assignment value is a single element. */
134 DEF_D_RUNTIME (ARRAYASSIGN, "_d_arrayassign", RT(ARRAY_VOID),
135 P3(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID), 0)
136 DEF_D_RUNTIME (ARRAYASSIGN_L, "_d_arrayassign_l", RT(ARRAY_VOID),
137 P4(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID, VOIDPTR), 0)
138 DEF_D_RUNTIME (ARRAYASSIGN_R, "_d_arrayassign_r", RT(ARRAY_VOID),
139 P4(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID, VOIDPTR), 0)
140 DEF_D_RUNTIME (ARRAYSETASSIGN, "_d_arraysetassign", RT(VOIDPTR),
141 P4(VOIDPTR, VOIDPTR, SIZE_T, CONST_TYPEINFO), 0)
143 /* Used for concatenating two or more arrays together. Then `n' variant is
144 for when there is more than two arrays to handle. */
145 DEF_D_RUNTIME (ARRAYCATT, "_d_arraycatT", RT(ARRAY_BYTE),
146 P3(CONST_TYPEINFO, ARRAY_BYTE, ARRAY_BYTE), 0)
147 DEF_D_RUNTIME (ARRAYCATNTX, "_d_arraycatnTX", RT(ARRAY_VOID),
148 P2(CONST_TYPEINFO, ARRAYARRAY_BYTE), 0)
150 /* Used for appending a single element to an array. */
151 DEF_D_RUNTIME (ARRAYAPPENDCTX, "_d_arrayappendcTX", RT(ARRAY_BYTE),
152 P3(CONST_TYPEINFO, ARRAYPTR_BYTE, SIZE_T), 0)
154 /* Same as appending a single element to an array, but specific for when the
155 source is a UTF-32 character, and the destination is a UTF-8 or 16 array. */
156 DEF_D_RUNTIME (ARRAYAPPENDCD, "_d_arrayappendcd", RT(ARRAY_VOID),
157 P2(ARRAYPTR_BYTE, DCHAR), 0)
158 DEF_D_RUNTIME (ARRAYAPPENDWD, "_d_arrayappendwd", RT(ARRAY_VOID),
159 P2(ARRAYPTR_BYTE, DCHAR), 0)
161 /* Used for appending an existing array to another. */
162 DEF_D_RUNTIME (ARRAYAPPENDT, "_d_arrayappendT", RT(ARRAY_VOID),
163 P3(TYPEINFO, ARRAYPTR_BYTE, ARRAY_BYTE), 0)
165 /* Used for allocating a new associative array. */
166 DEF_D_RUNTIME (ASSOCARRAYLITERALTX, "_d_assocarrayliteralTX", RT(VOIDPTR),
167 P3(CONST_TYPEINFO, ARRAY_VOID, ARRAY_VOID), 0)
169 /* Used for value equality of two associative arrays. */
170 DEF_D_RUNTIME (AAEQUAL, "_aaEqual", RT(INT),
171 P3(CONST_TYPEINFO, ASSOCARRAY, ASSOCARRAY), 0)
173 /* Used to determine is a key exists in an associative array. */
174 DEF_D_RUNTIME (AAINX, "_aaInX", RT(VOIDPTR),
175 P3(ASSOCARRAY, CONST_TYPEINFO, VOIDPTR), 0)
177 /* Used to retrieve a value from an associative array index by a key. The
178 `Rvalue' variant returns null if the key is not found, where as aaGetY
179 will create new key entry for assignment. */
180 DEF_D_RUNTIME (AAGETY, "_aaGetY", RT(VOIDPTR),
181 P4(POINTER_ASSOCARRAY, CONST_TYPEINFO, SIZE_T, VOIDPTR), 0)
182 DEF_D_RUNTIME (AAGETRVALUEX, "_aaGetRvalueX", RT(VOIDPTR),
183 P4(ASSOCARRAY, CONST_TYPEINFO, SIZE_T, VOIDPTR), 0)
185 /* Used when calling delete on a key entry in an associative array. */
186 DEF_D_RUNTIME (AADELX, "_aaDelX", RT(BOOL),
187 P3(ASSOCARRAY, CONST_TYPEINFO, VOIDPTR), 0)
189 /* Used for throw() expressions. */
190 DEF_D_RUNTIME (THROW, "_d_throw", RT(VOID), P1(OBJECT), ECF_NORETURN)
191 DEF_D_RUNTIME (BEGIN_CATCH, "__gdc_begin_catch", RT(VOIDPTR), P1(VOIDPTR), 0)
193 /* C++ exception handlers. */
194 DEF_D_RUNTIME (CXA_BEGIN_CATCH, "__cxa_begin_catch", RT(VOIDPTR), P1(VOIDPTR),
195 ECF_NOTHROW)
196 DEF_D_RUNTIME (CXA_END_CATCH, "__cxa_end_catch", RT(VOID), P0(), 0)
198 /* When invariant() contracts are turned on, used after testing whether a
199 class != null for validating the state of a class. */
200 DEF_D_RUNTIME (INVARIANT, "_D9invariant12_d_invariantFC6ObjectZv", RT(VOID),
201 P1(OBJECT), 0)
203 #undef P0
204 #undef P1
205 #undef P2
206 #undef P3
207 #undef P4
208 #undef P5
209 #undef RT