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