aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm16/tools/lli/ExecutionUtils.h
blob: fcd1db05cca326465ccb7a6a473d5ab266a738cf (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//===- ExecutionUtils.h - Utilities for executing code in lli ---*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// Contains utilities for executing code in lli.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
#define LLVM_TOOLS_LLI_EXECUTIONUTILS_H

#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/Mangling.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ToolOutputFile.h"

#include <memory>
#include <utility>

namespace llvm {

enum class BuiltinFunctionKind {
  DumpDebugDescriptor,
  DumpDebugObjects,
};

// Utility class to expose symbols for special-purpose functions to the JIT.
class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator {
public:
  LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled,
                              orc::MangleAndInterner &Mangle);

  Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K,
                      orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags,
                      const orc::SymbolLookupSet &Symbols) override;

  void appendDebugObject(const char *Addr, size_t Size) {
    TestOut->os().write(Addr, Size);
  }

private:
  orc::SymbolMap BuiltinFunctions;
  std::unique_ptr<ToolOutputFile> TestOut;

  template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) {
    BuiltinFunctions[Name] = JITEvaluatedSymbol(
        pointerToJITTargetAddress(Handler), JITSymbolFlags::Exported);
  }

  static std::unique_ptr<ToolOutputFile> createToolOutput();
};

} // end namespace llvm

#endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H