1 | //===---------- ObjectTransformLayer.cpp - Object Transform Layer ---------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h" |
10 | #include "llvm/Support/MemoryBuffer.h" |
11 | |
12 | namespace llvm { |
13 | namespace orc { |
14 | |
15 | char ObjectTransformLayer::ID; |
16 | |
17 | using BaseT = RTTIExtends<ObjectTransformLayer, ObjectLayer>; |
18 | |
19 | ObjectTransformLayer::ObjectTransformLayer(ExecutionSession &ES, |
20 | ObjectLayer &BaseLayer, |
21 | TransformFunction Transform) |
22 | : BaseT(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {} |
23 | |
24 | void ObjectTransformLayer::emit( |
25 | std::unique_ptr<MaterializationResponsibility> R, |
26 | std::unique_ptr<MemoryBuffer> O) { |
27 | assert(O && "Module must not be null"); |
28 | |
29 | // If there is a transform set then apply it. |
30 | if (Transform) { |
31 | if (auto TransformedObj = Transform(std::move(O))) |
32 | O = std::move(*TransformedObj); |
33 | else { |
34 | R->failMaterialization(); |
35 | getExecutionSession().reportError(Err: TransformedObj.takeError()); |
36 | return; |
37 | } |
38 | } |
39 | |
40 | BaseLayer.emit(R: std::move(R), O: std::move(O)); |
41 | } |
42 | |
43 | } // End namespace orc. |
44 | } // End namespace llvm. |
45 |