blob: 6bf9cd58e031b802a4148d92159748fa8e25a01e [file] [log] [blame]
Stefan Gränitzb244d1c2021-03-02 10:37:55 +01001//===- ExecutionUtils.h - Utilities for executing code in lli ---*- 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// Contains utilities for executing code in lli.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
14#define LLVM_TOOLS_LLI_EXECUTIONUTILS_H
15
16#include "llvm/ExecutionEngine/JITSymbol.h"
17#include "llvm/ExecutionEngine/Orc/Core.h"
18#include "llvm/ExecutionEngine/Orc/Mangling.h"
19#include "llvm/Support/Error.h"
20#include "llvm/Support/ToolOutputFile.h"
21
22#include <memory>
23#include <utility>
24
25namespace llvm {
26
27enum class BuiltinFunctionKind {
28 DumpDebugDescriptor,
29 DumpDebugObjects,
30};
31
32// Utility class to expose symbols for special-purpose functions to the JIT.
33class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator {
34public:
35 LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled,
36 orc::MangleAndInterner &Mangle);
37
38 Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K,
39 orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags,
40 const orc::SymbolLookupSet &Symbols) override;
41
42 void appendDebugObject(const char *Addr, size_t Size) {
43 TestOut->os().write(Addr, Size);
44 }
45
46private:
47 orc::SymbolMap BuiltinFunctions;
48 std::unique_ptr<ToolOutputFile> TestOut;
49
50 template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) {
Lang Hames6400a472023-03-22 11:45:10 -070051 BuiltinFunctions[Name] = {orc::ExecutorAddr::fromPtr(Handler),
52 JITSymbolFlags::Exported};
Stefan Gränitzb244d1c2021-03-02 10:37:55 +010053 }
54
55 static std::unique_ptr<ToolOutputFile> createToolOutput();
56};
57
58} // end namespace llvm
59
60#endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H