1 //===- ObjectTransformLayer.h - Run all objects through functor -*- C++ -*-===//
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 // Run all objects passed in through a user supplied functor.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTTRANSFORMLAYER_H
14 #define LLVM_EXECUTIONENGINE_ORC_OBJECTTRANSFORMLAYER_H
15 
16 #include "llvm/ExecutionEngine/JITSymbol.h"
17 #include "llvm/ExecutionEngine/Orc/Layer.h"
18 #include <algorithm>
19 #include <memory>
20 #include <string>
21 
22 namespace llvm {
23 namespace orc {
24 
25 class ObjectTransformLayer : public ObjectLayer {
26 public:
27   using TransformFunction =
28       std::function<Expected<std::unique_ptr<MemoryBuffer>>(
29           std::unique_ptr<MemoryBuffer>)>;
30 
31   ObjectTransformLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
32                        TransformFunction Transform = TransformFunction());
33 
34   void emit(std::unique_ptr<MaterializationResponsibility> R,
35             std::unique_ptr<MemoryBuffer> O) override;
36 
37   void setTransform(TransformFunction Transform) {
38     this->Transform = std::move(Transform);
39   }
40 
41 private:
42   ObjectLayer &BaseLayer;
43   TransformFunction Transform;
44 };
45 
46 } // end namespace orc
47 } // end namespace llvm
48 
49 #endif // LLVM_EXECUTIONENGINE_ORC_OBJECTTRANSFORMLAYER_H
50