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