Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions orc-rt/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(ORC_RT_HEADERS
orc-rt/SPSAllocAction.h
orc-rt/SPSMemoryFlags.h
orc-rt/SPSWrapperFunction.h
orc-rt/SPSWrapperFunctionBuffer.h
orc-rt/bind.h
orc-rt/bit.h
orc-rt/move_only_function.h
Expand Down
7 changes: 7 additions & 0 deletions orc-rt/include/orc-rt-c/WrapperFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ orc_rt_WrapperFunctionBufferData(orc_rt_WrapperFunctionBuffer *B) {
return B->Size > sizeof(B->Data.Value) ? B->Data.ValuePtr : B->Data.Value;
}

static inline const char *
orc_rt_WrapperFunctionBufferConstData(const orc_rt_WrapperFunctionBuffer *B) {
assert((B->Size != 0 || B->Data.ValuePtr == NULL) &&
"Cannot get data for out-of-band error value");
return B->Size > sizeof(B->Data.Value) ? B->Data.ValuePtr : B->Data.Value;
}

/**
* Safely get the size of the given orc_rt_WrapperFunctionBuffer.
*
Expand Down
48 changes: 48 additions & 0 deletions orc-rt/include/orc-rt/SPSWrapperFunctionBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===-- SPSWrapperFunctionBuffer.h - SPS serialization for WFB --*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// SPS serialization for WrapperFunctionBuffer.
//
//===----------------------------------------------------------------------===//

#ifndef ORC_RT_SPSWRAPPERFUNCTIONBUFFER_H
#define ORC_RT_SPSWRAPPERFUNCTIONBUFFER_H

#include "orc-rt/SimplePackedSerialization.h"
#include "orc-rt/WrapperFunction.h"

namespace orc_rt {

struct SPSWrapperFunctionBuffer;

template <>
class SPSSerializationTraits<SPSWrapperFunctionBuffer, WrapperFunctionBuffer> {
public:
static size_t size(const WrapperFunctionBuffer &WFB) {
return SPSArgList<uint64_t>::size(static_cast<uint64_t>(WFB.size())) +
WFB.size();
}

static bool serialize(SPSOutputBuffer &OB, const WrapperFunctionBuffer &WFB) {
if (!SPSArgList<uint64_t>::serialize(OB, static_cast<uint64_t>(WFB.size())))
return false;
return OB.write(WFB.data(), WFB.size());
}

static bool deserialize(SPSInputBuffer &IB, WrapperFunctionBuffer &WFB) {
uint64_t Size;
if (!SPSArgList<uint64_t>::deserialize(IB, Size))
return false;
WFB = WrapperFunctionBuffer::allocate(Size);
return IB.read(WFB.data(), WFB.size());
}
};

} // namespace orc_rt

#endif // ORC_RT_SPSWRAPPERFUNCTIONBUFFER_H
3 changes: 3 additions & 0 deletions orc-rt/include/orc-rt/WrapperFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class WrapperFunctionBuffer {
/// Get a pointer to the data contained in this instance.
char *data() { return orc_rt_WrapperFunctionBufferData(&B); }

/// Get a pointer to the data contained is this instance.
const char *data() const { return orc_rt_WrapperFunctionBufferConstData(&B); }

/// Returns the size of the data contained in this instance.
size_t size() const { return orc_rt_WrapperFunctionBufferSize(&B); }

Expand Down
1 change: 1 addition & 0 deletions orc-rt/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_orc_rt_unittest(CoreTests
SimplePackedSerializationTest.cpp
SPSMemoryFlagsTest.cpp
SPSWrapperFunctionTest.cpp
SPSWrapperFunctionBufferTest.cpp
WrapperFunctionBufferTest.cpp
bind-test.cpp
bit-test.cpp
Expand Down
42 changes: 42 additions & 0 deletions orc-rt/unittests/SPSWrapperFunctionBufferTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===-- SPSWrapperFunctionBufferTest.cpp ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Test SPS serialization for WrapperFunctionBuffers.
//
//===----------------------------------------------------------------------===//

#include "orc-rt/SPSWrapperFunctionBuffer.h"

#include "SimplePackedSerializationTestUtils.h"
#include "gtest/gtest.h"

using namespace orc_rt;

static bool WFBEQ(const WrapperFunctionBuffer &LHS,
const WrapperFunctionBuffer &RHS) {
if (LHS.size() != RHS.size())
return false;
return memcmp(LHS.data(), RHS.data(), LHS.size()) == 0;
}

TEST(SPSWrapperFunctionBufferTest, EmptyBuffer) {
WrapperFunctionBuffer EB;
blobSerializationRoundTrip<SPSWrapperFunctionBuffer>(EB, WFBEQ);
}

TEST(SPSWrapperFunctionBufferTest, SmallBuffer) {
const char *Source = "foo";
auto EB = WrapperFunctionBuffer::copyFrom(Source);
blobSerializationRoundTrip<SPSWrapperFunctionBuffer>(EB, WFBEQ);
}

TEST(SPSWrapperFunctionBufferTest, BigBuffer) {
const char *Source = "The quick brown fox jumps over the lazy dog";
auto EB = WrapperFunctionBuffer::copyFrom(Source);
blobSerializationRoundTrip<SPSWrapperFunctionBuffer>(EB, WFBEQ);
}
7 changes: 4 additions & 3 deletions orc-rt/unittests/SimplePackedSerializationTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ static bool spsDeserialize(orc_rt::WrapperFunctionBuffer &B, ArgTs &...Args) {
return SPSTraitsT::deserialize(IB, Args...);
}

template <typename SPSTagT, typename T>
static inline void blobSerializationRoundTrip(const T &Value) {
template <typename SPSTagT, typename T, typename Comparator = std::equal_to<T>>
static inline void blobSerializationRoundTrip(const T &Value,
Comparator &&C = Comparator()) {
using BST = orc_rt::SPSSerializationTraits<SPSTagT, T>;

size_t Size = BST::size(Value);
Expand All @@ -46,7 +47,7 @@ static inline void blobSerializationRoundTrip(const T &Value) {
T DSValue;
EXPECT_TRUE(BST::deserialize(IB, DSValue));

EXPECT_EQ(Value, DSValue)
EXPECT_TRUE(C(Value, DSValue))
<< "Incorrect value after serialization/deserialization round-trip";
}

Expand Down
Loading