xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp (revision 5def4c47d4bd90b209b9b4a4ba9faec15846d8fd)
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 ObjectTransformLayer::ObjectTransformLayer(ExecutionSession &ES,
16                                             ObjectLayer &BaseLayer,
17                                             TransformFunction Transform)
18     : ObjectLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
19 
20 void ObjectTransformLayer::emit(
21     std::unique_ptr<MaterializationResponsibility> R,
22     std::unique_ptr<MemoryBuffer> O) {
23   assert(O && "Module must not be null");
24 
25   // If there is a transform set then apply it.
26   if (Transform) {
27     if (auto TransformedObj = Transform(std::move(O)))
28       O = std::move(*TransformedObj);
29     else {
30       R->failMaterialization();
31       getExecutionSession().reportError(TransformedObj.takeError());
32       return;
33     }
34   }
35 
36   BaseLayer.emit(std::move(R), std::move(O));
37 }
38 
39 } // End namespace orc.
40 } // End namespace llvm.
41