[orc-rt] Add SPS serialization for ExecutorAddr. (#157242)
diff --git a/orc-rt/include/orc-rt/SimplePackedSerialization.h b/orc-rt/include/orc-rt/SimplePackedSerialization.h
index 292e6a0..4c1343c 100644
--- a/orc-rt/include/orc-rt/SimplePackedSerialization.h
+++ b/orc-rt/include/orc-rt/SimplePackedSerialization.h
@@ -35,6 +35,7 @@
#define ORC_RT_SIMPLEPACKEDSERIALIZATION_H
#include "orc-rt/Error.h"
+#include "orc-rt/ExecutorAddress.h"
#include "orc-rt/bit.h"
#include "orc-rt/span.h"
@@ -174,9 +175,6 @@
/// Any empty placeholder suitable as a substitute for void when deserializing
class SPSEmpty {};
-/// Represents an address in the executor.
-class SPSExecutorAddr {};
-
/// SPS tag type for tuples.
///
/// A blob tuple should be serialized by serializing each of the elements in
@@ -511,9 +509,31 @@
}
};
+/// Represents an address in the executor.
+class SPSExecutorAddr {};
+
/// SPS tag type for errors.
class SPSError;
+template <> class SPSSerializationTraits<SPSExecutorAddr, ExecutorAddr> {
+public:
+ static size_t size(const ExecutorAddr &A) {
+ return SPSArgList<uint64_t>::size(A.getValue());
+ }
+
+ static bool serialize(SPSOutputBuffer &OB, const ExecutorAddr &A) {
+ return SPSArgList<uint64_t>::serialize(OB, A.getValue());
+ }
+
+ static bool deserialize(SPSInputBuffer &IB, ExecutorAddr &A) {
+ uint64_t Value;
+ if (!SPSArgList<uint64_t>::deserialize(IB, Value))
+ return false;
+ A = ExecutorAddr(Value);
+ return true;
+ }
+};
+
/// Helper type for serializing Errors.
///
/// llvm::Errors are move-only, and not inspectable except by consuming them.
diff --git a/orc-rt/unittests/SimplePackedSerializationTest.cpp b/orc-rt/unittests/SimplePackedSerializationTest.cpp
index 9ccedef..09cc168 100644
--- a/orc-rt/unittests/SimplePackedSerializationTest.cpp
+++ b/orc-rt/unittests/SimplePackedSerializationTest.cpp
@@ -108,6 +108,12 @@
blobSerializationRoundTrip<SPSSequence<int32_t>, std::vector<int32_t>>(V);
}
+TEST(SimplePackedSerializationTest, ExecutorAddr) {
+ int X = 42;
+ auto A = ExecutorAddr::fromPtr(&X);
+ blobSerializationRoundTrip<SPSExecutorAddr>(A);
+}
+
TEST(SimplePackedSerializationTest, StringViewCharSequenceSerialization) {
const char *HW = "Hello, world!";
blobSerializationRoundTrip<SPSString, std::string_view>(std::string_view(HW));