9 #ifndef LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H 10 #define LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H 33 template <
typename OStream>
34 OStream &operator<<(OStream &OS, const RPCTypeNameSequence<> &V) {
39 template <
typename OStream,
typename ArgT>
40 OStream &operator<<(OStream &OS, const RPCTypeNameSequence<ArgT> &V) {
46 template <
typename OStream,
typename ArgT1,
typename ArgT2,
typename... ArgTs>
57 static const char*
getName() {
return "void"; }
63 static const char*
getName() {
return "int8_t"; }
69 static const char*
getName() {
return "uint8_t"; }
75 static const char*
getName() {
return "int16_t"; }
81 static const char*
getName() {
return "uint16_t"; }
87 static const char*
getName() {
return "int32_t"; }
93 static const char*
getName() {
return "uint32_t"; }
99 static const char*
getName() {
return "int64_t"; }
105 static const char*
getName() {
return "uint64_t"; }
111 static const char*
getName() {
return "bool"; }
117 static const char*
getName() {
return "std::string"; }
123 static const char*
getName() {
return "Error"; }
126 template <
typename T>
130 static std::string
Name = [] {
141 template <
typename T1,
typename T2>
145 static std::string
Name = [] {
155 template <
typename... ArgTs>
159 static std::string
Name = [] {
169 template <
typename T>
173 static std::string
Name = [] {
186 static std::string
Name = [] {
199 static std::string
Name = [] {
241 template <
typename ChannelT,
typename WireType,
242 typename ConcreteType = WireType,
typename =
void>
245 template <
typename ChannelT>
261 template <
typename ChannelT,
typename... ArgTs>
264 template <
typename ChannelT>
271 template <
typename ChannelT,
typename ArgT>
275 template <
typename CArgT>
278 typename std::decay<CArgT>::type>::
279 serialize(C, std::forward<CArgT>(CArg));
282 template <
typename CArgT>
288 template <
typename ChannelT,
typename ArgT,
typename... ArgTs>
292 template <
typename CArgT,
typename... CArgTs>
294 CArgTs &&... CArgs) {
297 serialize(C, std::forward<CArgT>(CArg)))
302 serialize(C, std::forward<CArgTs>(CArgs)...);
305 template <
typename CArgT,
typename... CArgTs>
317 template <
typename ChannelT,
typename... ArgTs>
320 serialize(C, std::forward<ArgTs>(
Args)...);
323 template <
typename ChannelT,
typename... ArgTs>
328 template <
typename ChannelT>
333 std::function<Error(ChannelT &C, const ErrorInfoBase&)>;
336 std::function<Error(ChannelT &C, Error &Err)>;
338 template <
typename ErrorInfoT,
typename SerializeFtor,
339 typename DeserializeFtor>
341 DeserializeFtor Deserialize) {
343 "The empty string is reserved for the Success value");
345 const std::string *KeyName =
nullptr;
351 std::lock_guard<std::recursive_mutex>
Lock(DeserializersMutex);
353 Deserializers.insert(Deserializers.begin(),
354 std::make_pair(std::move(Name),
355 std::move(Deserialize)));
360 assert(KeyName !=
nullptr &&
"No keyname pointer");
361 std::lock_guard<std::recursive_mutex>
Lock(SerializersMutex);
362 Serializers[ErrorInfoT::classID()] =
363 [KeyName, Serialize = std::move(Serialize)](
365 assert(EIB.dynamicClassID() == ErrorInfoT::classID() &&
366 "Serializer called for wrong error type");
369 return Serialize(C, static_cast<const ErrorInfoT &>(EIB));
375 std::lock_guard<std::recursive_mutex>
Lock(SerializersMutex);
383 if (
SI == Serializers.end())
384 return serializeAsStringError(C, EIB);
385 return (
SI->second)(
C, EIB);
390 std::lock_guard<std::recursive_mutex>
Lock(DeserializersMutex);
402 auto DI = Deserializers.find(Key);
403 assert(DI != Deserializers.end() &&
"No deserializer for error type");
404 return (DI->second)(
C, Err);
413 EIB.
log(ErrMsgStream);
415 return serialize(C, make_error<StringError>(std::move(ErrMsg),
419 static std::recursive_mutex SerializersMutex;
420 static std::recursive_mutex DeserializersMutex;
421 static std::map<const void*, WrappedErrorSerializer> Serializers;
422 static std::map<std::string, WrappedErrorDeserializer> Deserializers;
425 template <
typename ChannelT>
428 template <
typename ChannelT>
431 template <
typename ChannelT>
432 std::map<
const void*,
436 template <
typename ChannelT>
437 std::map<std::string,
443 template <
typename ChannelT,
typename ErrorInfoT,
typename SerializeFtor,
444 typename DeserializeFtor>
446 DeserializeFtor &&Deserialize) {
449 std::forward<SerializeFtor>(Serialize),
450 std::forward<DeserializeFtor>(Deserialize));
454 template <
typename ChannelT>
456 static bool AlreadyRegistered =
false;
457 if (!AlreadyRegistered) {
458 registerErrorSerialization<ChannelT, StringError>(
469 make_error<StringError>(std::move(Msg),
474 AlreadyRegistered =
true;
479 template <
typename ChannelT,
typename T1,
typename T2>
504 ValOrErr = std::move(Err);
510 template <
typename ChannelT,
typename T1,
typename T2>
520 template <
typename ChannelT,
typename T>
530 template <
typename ChannelT,
typename T1,
typename T2,
typename T3,
typename T4>
548 template <
typename ChannelT,
typename... ArgTs>
554 return serializeTupleHelper(C, V, std::index_sequence_for<ArgTs...>());
559 return deserializeTupleHelper(C, V, std::index_sequence_for<ArgTs...>());
564 template <
size_t... Is>
565 static Error serializeTupleHelper(ChannelT &
C,
const std::tuple<ArgTs...> &V,
566 std::index_sequence<Is...>
_) {
571 template <
size_t... Is>
572 static Error deserializeTupleHelper(ChannelT &C, std::tuple<ArgTs...> &V,
573 std::index_sequence<Is...> _) {
579 template <
typename ChannelT,
typename T>
585 if (
auto Err =
serializeSeq(C, static_cast<uint64_t>(V.size())))
588 for (
const auto &
E : V)
598 "Expected default-constructed vector to deserialize into");
613 template <
typename ChannelT,
typename T,
typename T2>
618 if (
auto Err =
serializeSeq(C, static_cast<uint64_t>(S.size())))
621 for (
const auto &
E : S)
630 assert(S.empty() &&
"Expected default-constructed set to deserialize into");
636 while (Count-- != 0) {
641 auto Added = S.insert(Val).second;
643 return make_error<StringError>(
"Duplicate element in deserialized set",
651 template <
typename ChannelT,
typename K,
typename V,
typename K2,
typename V2>
656 if (
auto Err =
serializeSeq(C, static_cast<uint64_t>(M.size())))
659 for (
const auto &
E : M) {
673 assert(M.empty() &&
"Expected default-constructed map to deserialize into");
679 while (Count-- != 0) {
680 std::pair<K2, V2> Val;
689 auto Added = M.insert(Val).second;
691 return make_error<StringError>(
"Duplicate element in deserialized map",
703 #endif // LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
This class represents lattice values for constants.
static const char * getName()
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static Error deserialize(ChannelT &C, std::vector< T > &V)
Deserialize a std::vector<T> to a std::vector<T>.
static const char * getName()
Helper for Expected<T>s used as out-parameters.
detail::ValueMatchesPoly< M > HasValue(M Matcher)
static const char * getName()
static const char * getName()
static Error serialize(ChannelT &C, Error &&Err)
static Error serialize(ChannelT &C)
Base class for error info classes.
static const char * getName()
std::function< Error(ChannelT &C, Error &Err)> WrappedErrorDeserializer
std::error_code orcError(OrcErrorCode ErrCode)
static const char * getName()
virtual void log(raw_ostream &OS) const =0
Print an error message to an output stream.
static StringRef getName(Value *V)
Tagged union holding either a T or a Error.
static const char * getName()
Error serializeSeq(ChannelT &C, ArgTs &&... Args)
static Error serialize(ChannelT &C, CArgT &&CArg, CArgTs &&... CArgs)
static Error emitSeparator(ChannelT &C)
static Error deserialize(ChannelT &C, std::pair< T3, T4 > &V)
static const char * getName()
void registerStringError()
Registers serialization/deserialization for StringError.
static const char * getName()
virtual const void * dynamicClassID() const =0
static Error deserialize(ChannelT &C)
void registerErrorSerialization(std::string Name, SerializeFtor &&Serialize, DeserializeFtor &&Deserialize)
Registers a serializer and deserializer for the given error type on the given channel type...
static const char * getName()
static Error serialize(ChannelT &C, const std::map< K2, V2 > &M)
Serialize a std::map<K, V> from std::map<K2, V2>.
The SerializationTraits<ChannelT, T> class describes how to serialize and deserialize an instance of ...
static Error deserialize(ChannelT &C, std::tuple< ArgTs... > &V)
RPC channel deserialization for std::tuple.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static const char * getName()
static const char * getName()
static Error deserialize(ChannelT &C, std::set< T2 > &S)
Deserialize a std::set<T> to a std::set<T>.
static Error deserialize(ChannelT &C, std::map< K2, V2 > &M)
Deserialize a std::map<K, V> to a std::map<K, V>.
static Error serialize(ChannelT &C, const std::set< T2 > &S)
Serialize a std::set<T> from std::set<T2>.
OStream & operator<<(OStream &OS, const RPCTypeNameSequence<> &V)
Render an empty TypeNameSequence to an ostream.
static ErrorSuccess success()
Create a success value.
static Error serialize(ChannelT &C, const std::pair< T3, T4 > &V)
static void registerErrorType(std::string Name, SerializeFtor Serialize, DeserializeFtor Deserialize)
static const char * getName()
static const char * getName()
static const char * getName()
static const char * getName()
static Error deserialize(ChannelT &C, Expected< T2 > &ValOrErr)
Helper for Errors used as out-parameters.
static const char * getName()
static Error deserialize(ChannelT &C, Error &Err)
This class wraps a string in an Error.
Error deserializeSeq(ChannelT &C, ArgTs &... Args)
static Error serialize(ChannelT &C, const std::vector< T > &V)
Serialize a std::vector<T> from std::vector<T>.
TypeNameSequence is a utility for rendering sequences of types to a string by rendering each type...
std::function< Error(ChannelT &C, const ErrorInfoBase &)> WrappedErrorSerializer
static Error serialize(ChannelT &C, Error &&Err)
Utility class for serializing sequences of values of varying types.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Error deserialize(ChannelT &C, CArgT &CArg, CArgTs &... CArgs)
A raw_ostream that writes to an std::string.
static Error deserialize(ChannelT &C, CArgT &CArg)
Lightweight error class with error context and mandatory checking.
static Error serialize(ChannelT &C, CArgT &&CArg)
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
static Error serialize(ChannelT &C, T2 &&Val)
static Error serialize(ChannelT &C, const std::tuple< ArgTs... > &V)
RPC channel serialization for std::tuple.
static const char * getName()
static Error serialize(ChannelT &C, Expected< T2 > &&ValOrErr)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static Error consumeSeparator(ChannelT &C)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...