1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
llvm-mirror/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp
Lang Hames 7336034e4d [ORC] Add a utility to support dumping JIT'd objects to disk for debugging.
Adds a DumpObjects utility that can be used to dump JIT'd objects to disk.
Instances of DebugObjects may be used by ObjectTransformLayer as no-op
transforms.

This patch also adds an ObjectTransformLayer to LLJIT and an example of how
to use this utility to dump JIT'd objects in LLJIT.
2019-11-14 21:27:19 -08:00

40 lines
1.3 KiB
C++

//===---------- ObjectTransformLayer.cpp - Object Transform Layer ---------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
#include "llvm/Support/MemoryBuffer.h"
namespace llvm {
namespace orc {
ObjectTransformLayer::ObjectTransformLayer(ExecutionSession &ES,
ObjectLayer &BaseLayer,
TransformFunction Transform)
: ObjectLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
void ObjectTransformLayer::emit(MaterializationResponsibility R,
std::unique_ptr<MemoryBuffer> O) {
assert(O && "Module must not be null");
// If there is a transform set then apply it.
if (Transform) {
if (auto TransformedObj = Transform(std::move(O)))
O = std::move(*TransformedObj);
else {
R.failMaterialization();
getExecutionSession().reportError(TransformedObj.takeError());
return;
}
}
BaseLayer.emit(std::move(R), std::move(O));
}
} // End namespace orc.
} // End namespace llvm.