xref: /netbsd-src/external/apache2/llvm/dist/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
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
26     : public RTTIExtends<ObjectTransformLayer, ObjectLayer> {
27 public:
28   static char ID;
29 
30   using TransformFunction =
31       std::function<Expected<std::unique_ptr<MemoryBuffer>>(
32           std::unique_ptr<MemoryBuffer>)>;
33 
34   ObjectTransformLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
35                        TransformFunction Transform = TransformFunction());
36 
37   void emit(std::unique_ptr<MaterializationResponsibility> R,
38             std::unique_ptr<MemoryBuffer> O) override;
39 
setTransform(TransformFunction Transform)40   void setTransform(TransformFunction Transform) {
41     this->Transform = std::move(Transform);
42   }
43 
44 private:
45   ObjectLayer &BaseLayer;
46   TransformFunction Transform;
47 };
48 
49 } // end namespace orc
50 } // end namespace llvm
51 
52 #endif // LLVM_EXECUTIONENGINE_ORC_OBJECTTRANSFORMLAYER_H
53