aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp
blob: a57662e10a7947b587687c25d94b126358df2df7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//===---------- ObjectTransformLayer.cpp - Object Transform Layer ---------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
#include "llvm/Support/MemoryBuffer.h"

namespace llvm {
namespace orc {

ObjectTransformLayer::ObjectTransformLayer(ExecutionSession &ES,
                                            ObjectLayer &BaseLayer,
                                            TransformFunction Transform)
    : ObjectLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}

void ObjectTransformLayer::emit(
    std::unique_ptr<MaterializationResponsibility> R,
    std::unique_ptr<MemoryBuffer> O) {
  assert(O && "Module must not be null");

  // If there is a transform set then apply it.
  if (Transform) {
    if (auto TransformedObj = Transform(std::move(O)))
      O = std::move(*TransformedObj);
    else {
      R->failMaterialization();
      getExecutionSession().reportError(TransformedObj.takeError());
      return;
    }
  }

  BaseLayer.emit(std::move(R), std::move(O));
}

} // End namespace orc.
} // End namespace llvm.