10 #ifndef LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H 11 #define LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H 34 template <
typename OStream>
35 OStream &operator<<(OStream &OS, const RPCTypeNameSequence<> &V) {
40 template <
typename OStream,
typename ArgT>
41 OStream &operator<<(OStream &OS, const RPCTypeNameSequence<ArgT> &V) {
47 template <
typename OStream,
typename ArgT1,
typename ArgT2,
typename... ArgTs>
58 static const char*
getName() {
return "void"; }
64 static const char*
getName() {
return "int8_t"; }
70 static const char*
getName() {
return "uint8_t"; }
76 static const char*
getName() {
return "int16_t"; }
82 static const char*
getName() {
return "uint16_t"; }
88 static const char*
getName() {
return "int32_t"; }
94 static const char*
getName() {
return "uint32_t"; }
100 static const char*
getName() {
return "int64_t"; }
106 static const char*
getName() {
return "uint64_t"; }
112 static const char*
getName() {
return "bool"; }
118 static const char*
getName() {
return "std::string"; }
124 static const char*
getName() {
return "Error"; }
127 template <
typename T>
131 std::lock_guard<std::mutex>
Lock(NameMutex);
140 static std::mutex NameMutex;
141 static std::string
Name;
144 template <
typename T>
147 template <
typename T>
150 template <
typename T1,
typename T2>
154 std::lock_guard<std::mutex>
Lock(NameMutex);
161 static std::mutex NameMutex;
162 static std::string
Name;
165 template <
typename T1,
typename T2>
167 template <
typename T1,
typename T2>
170 template <
typename... ArgTs>
174 std::lock_guard<std::mutex>
Lock(NameMutex);
181 static std::mutex NameMutex;
182 static std::string
Name;
185 template <
typename... ArgTs>
186 std::mutex
RPCTypeName<std::tuple<ArgTs...>>::NameMutex;
187 template <
typename... ArgTs>
190 template <
typename T>
194 std::lock_guard<std::mutex>
Lock(NameMutex);
202 static std::mutex NameMutex;
203 static std::string
Name;
206 template <
typename T>
208 template <
typename T>
214 std::lock_guard<std::mutex>
Lock(NameMutex);
222 static std::mutex NameMutex;
223 static std::string
Name;
232 std::lock_guard<std::mutex>
Lock(NameMutex);
240 static std::mutex NameMutex;
241 static std::string
Name;
244 template <
typename K,
typename V>
280 template <
typename ChannelT,
typename WireType,
281 typename ConcreteType = WireType,
typename =
void>
284 template <
typename ChannelT>
300 template <
typename ChannelT,
typename... ArgTs>
303 template <
typename ChannelT>
310 template <
typename ChannelT,
typename ArgT>
314 template <
typename CArgT>
317 typename std::decay<CArgT>::type>::
318 serialize(C, std::forward<CArgT>(CArg));
321 template <
typename CArgT>
327 template <
typename ChannelT,
typename ArgT,
typename... ArgTs>
331 template <
typename CArgT,
typename... CArgTs>
333 CArgTs &&... CArgs) {
336 serialize(C, std::forward<CArgT>(CArg)))
341 serialize(C, std::forward<CArgTs>(CArgs)...);
344 template <
typename CArgT,
typename... CArgTs>
356 template <
typename ChannelT,
typename... ArgTs>
359 serialize(C, std::forward<ArgTs>(
Args)...);
362 template <
typename ChannelT,
typename... ArgTs>
367 template <
typename ChannelT>
372 std::function<Error(ChannelT &C, const ErrorInfoBase&)>;
375 std::function<Error(ChannelT &C, Error &Err)>;
377 template <
typename ErrorInfoT,
typename SerializeFtor,
378 typename DeserializeFtor>
380 DeserializeFtor Deserialize) {
382 "The empty string is reserved for the Success value");
384 const std::string *KeyName =
nullptr;
390 std::lock_guard<std::recursive_mutex>
Lock(DeserializersMutex);
392 Deserializers.insert(Deserializers.begin(),
393 std::make_pair(std::move(Name),
394 std::move(Deserialize)));
399 assert(KeyName !=
nullptr &&
"No keyname pointer");
400 std::lock_guard<std::recursive_mutex>
Lock(SerializersMutex);
402 Serializers[ErrorInfoT::classID()] =
404 assert(EIB.dynamicClassID() == ErrorInfoT::classID() &&
405 "Serializer called for wrong error type");
408 return Serialize(C, static_cast<const ErrorInfoT &>(EIB));
414 std::lock_guard<std::recursive_mutex>
Lock(SerializersMutex);
422 if (
SI == Serializers.end())
423 return serializeAsStringError(C, EIB);
424 return (
SI->second)(
C, EIB);
429 std::lock_guard<std::recursive_mutex>
Lock(DeserializersMutex);
441 auto DI = Deserializers.find(Key);
442 assert(DI != Deserializers.end() &&
"No deserializer for error type");
443 return (DI->second)(
C, Err);
452 EIB.
log(ErrMsgStream);
454 return serialize(C, make_error<StringError>(std::move(ErrMsg),
458 static std::recursive_mutex SerializersMutex;
459 static std::recursive_mutex DeserializersMutex;
460 static std::map<const void*, WrappedErrorSerializer> Serializers;
461 static std::map<std::string, WrappedErrorDeserializer> Deserializers;
464 template <
typename ChannelT>
467 template <
typename ChannelT>
470 template <
typename ChannelT>
471 std::map<
const void*,
475 template <
typename ChannelT>
476 std::map<std::string,
482 template <
typename ChannelT,
typename ErrorInfoT,
typename SerializeFtor,
483 typename DeserializeFtor>
485 DeserializeFtor &&Deserialize) {
488 std::forward<SerializeFtor>(Serialize),
489 std::forward<DeserializeFtor>(Deserialize));
493 template <
typename ChannelT>
495 static bool AlreadyRegistered =
false;
496 if (!AlreadyRegistered) {
497 registerErrorSerialization<ChannelT, StringError>(
508 make_error<StringError>(std::move(Msg),
513 AlreadyRegistered =
true;
518 template <
typename ChannelT,
typename T1,
typename T2>
543 ValOrErr = std::move(Err);
549 template <
typename ChannelT,
typename T1,
typename T2>
559 template <
typename ChannelT,
typename T>
569 template <
typename ChannelT,
typename T1,
typename T2,
typename T3,
typename T4>
587 template <
typename ChannelT,
typename... ArgTs>
603 template <
size_t... Is>
604 static Error serializeTupleHelper(ChannelT &
C,
const std::tuple<ArgTs...> &V,
610 template <
size_t... Is>
611 static Error deserializeTupleHelper(ChannelT &C, std::tuple<ArgTs...> &V,
618 template <
typename ChannelT,
typename T>
624 if (
auto Err =
serializeSeq(C, static_cast<uint64_t>(V.size())))
627 for (
const auto &
E : V)
637 "Expected default-constructed vector to deserialize into");
652 template <
typename ChannelT,
typename T,
typename T2>
657 if (
auto Err =
serializeSeq(C, static_cast<uint64_t>(S.size())))
660 for (
const auto &
E : S)
669 assert(S.empty() &&
"Expected default-constructed set to deserialize into");
675 while (Count-- != 0) {
680 auto Added = S.insert(Val).second;
682 return make_error<StringError>(
"Duplicate element in deserialized set",
690 template <
typename ChannelT,
typename K,
typename V,
typename K2,
typename V2>
695 if (
auto Err =
serializeSeq(C, static_cast<uint64_t>(M.size())))
698 for (
const auto &
E : M) {
712 assert(M.empty() &&
"Expected default-constructed map to deserialize into");
718 while (Count-- != 0) {
719 std::pair<K2, V2> Val;
728 auto Added = M.insert(Val).second;
730 return make_error<StringError>(
"Duplicate element in deserialized map",
742 #endif // LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
This class represents lattice values for constants.
static const char * getName()
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
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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()
Alias for the common case of a sequence of size_ts.
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()
Creates a compile-time integer sequence for a parameter pack.
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...