@@ -210,9 +210,11 @@ static void emit(Program &P, std::vector<std::byte> &Code, const T &Val,
210
210
}
211
211
}
212
212
213
- template <>
214
- void emit (Program &P, std::vector<std::byte> &Code, const Floating &Val,
215
- bool &Success) {
213
+ // / Emits a serializable value. These usually (potentially) contain
214
+ // / heap-allocated memory and aren't trivially copyable.
215
+ template <typename T>
216
+ static void emitSerialized (std::vector<std::byte> &Code, const T &Val,
217
+ bool &Success) {
216
218
size_t Size = Val.bytesToSerialize ();
217
219
218
220
if (Code.size () + Size > std::numeric_limits<unsigned >::max ()) {
@@ -229,40 +231,22 @@ void emit(Program &P, std::vector<std::byte> &Code, const Floating &Val,
229
231
Val.serialize (Code.data () + ValPos);
230
232
}
231
233
234
+ template <>
235
+ void emit (Program &P, std::vector<std::byte> &Code, const Floating &Val,
236
+ bool &Success) {
237
+ emitSerialized (Code, Val, Success);
238
+ }
239
+
232
240
template <>
233
241
void emit (Program &P, std::vector<std::byte> &Code,
234
242
const IntegralAP<false > &Val, bool &Success) {
235
- size_t Size = Val.bytesToSerialize ();
236
-
237
- if (Code.size () + Size > std::numeric_limits<unsigned >::max ()) {
238
- Success = false ;
239
- return ;
240
- }
241
-
242
- // Access must be aligned!
243
- size_t ValPos = align (Code.size ());
244
- Size = align (Size);
245
- assert (aligned (ValPos + Size));
246
- Code.resize (ValPos + Size);
247
- Val.serialize (Code.data () + ValPos);
243
+ emitSerialized (Code, Val, Success);
248
244
}
249
245
250
246
template <>
251
247
void emit (Program &P, std::vector<std::byte> &Code, const IntegralAP<true > &Val,
252
248
bool &Success) {
253
- size_t Size = Val.bytesToSerialize ();
254
-
255
- if (Code.size () + Size > std::numeric_limits<unsigned >::max ()) {
256
- Success = false ;
257
- return ;
258
- }
259
-
260
- // Access must be aligned!
261
- size_t ValPos = align (Code.size ());
262
- Size = align (Size);
263
- assert (aligned (ValPos + Size));
264
- Code.resize (ValPos + Size);
265
- Val.serialize (Code.data () + ValPos);
249
+ emitSerialized (Code, Val, Success);
266
250
}
267
251
268
252
template <typename ... Tys>
0 commit comments