LLVM: include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEPACKEDSERIALIZATION_H
33#define LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEPACKEDSERIALIZATION_H
34
41
42#include
43#include
44#include
45#include
46#include <type_traits>
47#include
48#include
49
50namespace llvm {
51namespace orc {
53
54
56public:
58 : Buffer(Buffer), Remaining(Remaining) {}
60 assert(Data && "Data must not be null");
61 if (Size > Remaining)
62 return false;
64 Buffer += Size;
65 Remaining -= Size;
66 return true;
67 }
68
69private:
70 char *Buffer = nullptr;
71 size_t Remaining = 0;
72};
73
74
76public:
79 : Buffer(Buffer), Remaining(Remaining) {}
81 if (Size > Remaining)
82 return false;
84 Buffer += Size;
85 Remaining -= Size;
86 return true;
87 }
88
89 const char *data() const { return Buffer; }
91 if (Size > Remaining)
92 return false;
93 Buffer += Size;
94 Remaining -= Size;
95 return true;
96 }
97
98private:
99 const char *Buffer = nullptr;
100 size_t Remaining = 0;
101};
102
103
104
105template <typename SPSTagT, typename ConcreteT, typename _ = void>
107
108
110
111
113public:
114 static size_t size() { return 0; }
115
118
120
124};
125
126
127template <typename SPSTagT, typename... SPSTagTs>
129public:
130
131
133
134 template <typename ArgT, typename... ArgTs>
135 static size_t size(const ArgT &Arg, const ArgTs &...Args) {
138 }
139
140 template <typename ArgT, typename... ArgTs>
142 const ArgTs &...Args) {
145 }
146
147 template <typename ArgT, typename... ArgTs>
152};
153
154
155template
157 SPSTagT, SPSTagT,
158 std::enable_if_t<std::is_same<SPSTagT, bool>::value ||
159 std::is_same<SPSTagT, char>::value ||
160 std::is_same<SPSTagT, int8_t>::value ||
161 std::is_same<SPSTagT, int16_t>::value ||
162 std::is_same<SPSTagT, int32_t>::value ||
163 std::is_same<SPSTagT, int64_t>::value ||
164 std::is_same<SPSTagT, uint8_t>::value ||
165 std::is_same<SPSTagT, uint16_t>::value ||
166 std::is_same<SPSTagT, uint32_t>::value ||
167 std::is_same<SPSTagT, uint64_t>::value>> {
168public:
169 static size_t size(const SPSTagT &Value) { return sizeof(SPSTagT); }
170
172 SPSTagT Tmp = Value;
175 return OB.write(reinterpret_cast<const char *>(&Tmp), sizeof(Tmp));
176 }
177
179 SPSTagT Tmp;
180 if (!IB.read(reinterpret_cast<char *>(&Tmp), sizeof(Tmp)))
181 return false;
185 return true;
186 }
187};
188
189
191
192
193
194
195
196template <typename... SPSTagTs> class SPSTuple {
197public:
198
200};
201
202
203
204
205
206
207
209
210
211
212
213
215
216
218
219
220
221
222template <typename SPSTagT1, typename SPSTagT2>
224
225
234
235
236
237
238
239
240
241
242
243
244template <typename SPSElementTagT, typename ConcreteSequenceT>
249
250
251
252
253
254
255
256
257
258
259
260template <typename SPSElementTagT, typename ConcreteSequenceT>
265
266
271
272
274public:
276
278
280 static bool append(std::string &S, char C) {
281 S.push_back(C);
282 return true;
283 }
284};
285
286
287template <typename SPSElementTagT, typename T>
292
293
294template <typename SPSElementTagT, typename T>
296public:
298
299 using element_type = typename std::vector::value_type;
300
302 static bool append(std::vector &V, T E) {
303 V.push_back(std::move(E));
304 return true;
305 }
306};
307
308
309template <typename SPSElementTagT, typename T>
314
315
316template <typename SPSElementTagT, typename T>
318public:
320
322
325 V.push_back(std::move(E));
326 return true;
327 }
328};
329
330
331template <typename SPSElementTagT, typename T, unsigned N>
334 SmallVectorImpl> {};
335
336
337template <typename SPSElementTagT, typename T, unsigned N>
340 SmallVectorImpl> {};
341
342
343template <typename SPSElementTagT, typename T>
348
349
350
351
353public:
358
361 return false;
362 if (A.empty())
363 return true;
364 return OB.write(A.data(), A.size());
365 }
366
370 return false;
371 if (Size > std::numeric_limits<size_t>::max())
372 return false;
373 A = {Size ? IB.data() : nullptr, static_cast<size_t>(Size)};
374 return IB.skip(Size);
375 }
376};
377
378
379
380
381template <typename SPSElementTagT, typename SequenceT>
383 std::enable_if_t<TrivialSPSSequenceSerialization<
384 SPSElementTagT, SequenceT>::available>> {
385public:
386 static size_t size(const SequenceT &S) {
388 for (const auto &E : S)
391 }
392
395 return false;
396 for (const auto &E : S)
398 return false;
399 return true;
400 }
401
406 return false;
407 TBSD::reserve(S, Size);
408 for (size_t I = 0; I != Size; ++I) {
409 typename TBSD::element_type E;
411 return false;
412 if (!TBSD::append(S, std::move(E)))
413 return false;
414 }
415 return true;
416 }
417};
418
419
420template <typename... SPSTagTs, typename... Ts>
422private:
423 using TupleArgList = typename SPSTuple<SPSTagTs...>::AsArgList;
424 using ArgIndices = std::make_index_sequence<sizeof...(Ts)>;
425
426 template <std::size_t... I>
427 static size_t size(const std::tuple<Ts...> &T, std::index_sequence<I...>) {
428 return TupleArgList::size(std::get(T)...);
429 }
430
431 template <std::size_t... I>
432 static bool serialize(SPSOutputBuffer &OB, const std::tuple<Ts...> &T,
433 std::index_sequence<I...>) {
434 return TupleArgList::serialize(OB, std::get(T)...);
435 }
436
437 template <std::size_t... I>
438 static bool deserialize(SPSInputBuffer &IB, std::tuple<Ts...> &T,
439 std::index_sequence<I...>) {
440 return TupleArgList::deserialize(IB, std::get(T)...);
441 }
442
443public:
444 static size_t size(const std::tuple<Ts...> &T) {
445 return size(T, ArgIndices{});
446 }
447
449 return serialize(OB, T, ArgIndices{});
450 }
451
453 return deserialize(IB, T, ArgIndices{});
454 }
455};
456
457
458template <typename SPSTagT1, typename SPSTagT2, typename T1, typename T2>
460public:
461 static size_t size(const std::pair<T1, T2> &P) {
464 }
465
470
475};
476
477
478template <typename SPSTagT, typename T>
480public:
481 static size_t size(const std::optional &Value) {
486 }
487
490 return false;
493 return true;
494 }
495
499 return false;
503 } else
504 Value = std::optional();
505 return true;
506 }
507};
508
509
510
511
512
514public:
519
522 return false;
523 if (S.empty())
524 return true;
525 return OB.write(S.data(), S.size());
526 }
527
529 const char *Data = nullptr;
532 return false;
533 Data = IB.data();
534 if (!IB.skip(Size))
535 return false;
537 return true;
538 }
539};
540
541
542template <typename SPSValueT, typename ValueT>
545public:
548 for (auto &E : M)
550 return Sz;
551 }
552
555 return false;
556
557 for (auto &E : M)
559 return false;
560
561 return true;
562 }
563
566 assert(M.empty() && "M already contains elements");
567
569 return false;
570
571 while (Size--) {
573 ValueT V;
575 return false;
576 if (!M.insert(std::make_pair(S, V)).second)
577 return false;
578 }
579
580 return true;
581 }
582};
583
584
585class SPSError;
586
587
588
590
592
593
594
595
596
597
598
599
600
601
606
607
608
609
610
611
617
619 if (Err)
620 return {true, toString(std::move(Err))};
621 return {false, {}};
622}
623
629
630template
632 if (E)
633 return {true, std::move(*E), {}};
634 else
635 return {false, T(), toString(E.takeError())};
636}
637
638template
641 return std::move(BSE.Value);
642 else
644}
645
646}
647
648
649template <>
651public:
658
662 return false;
665 return false;
666 return true;
667 }
668
672 return false;
673
675 return true;
676
678 }
679};
680
681
682
683template <typename SPSTagT, typename T>
685 detail::SPSSerializableExpected> {
686public:
695
699 return false;
700
703
705 }
706
710 return false;
711
714
716 }
717};
718
719
720template
722 detail::SPSSerializableError> {
723public:
725 assert(BSE.HasError && "Cannot serialize expected from a success value");
728 }
729
732 assert(BSE.HasError && "Cannot serialize expected from a success value");
734 return false;
736 }
737};
738
739
740template <typename SPSTagT, typename T>
753
754}
755}
756}
757
758#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
LLVM Value Representation.
@ C
The default llvm calling convention, compatible with C.
constexpr bool IsBigEndianHost
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
detail::ValueMatchesPoly< M > HasValue(M Matcher)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
Implement std::hash so that hash_code can be used in STL containers.