1 //===- ExecutionUtils.h - Utilities for executing code in lli ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Contains utilities for executing code in lli.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
14 #define LLVM_TOOLS_LLI_EXECUTIONUTILS_H
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"
27 enum class BuiltinFunctionKind
{
32 // Utility class to expose symbols for special-purpose functions to the JIT.
33 class LLIBuiltinFunctionGenerator
: public orc::DefinitionGenerator
{
35 LLIBuiltinFunctionGenerator(std::vector
<BuiltinFunctionKind
> Enabled
,
36 orc::MangleAndInterner
&Mangle
);
38 Error
tryToGenerate(orc::LookupState
&LS
, orc::LookupKind K
,
39 orc::JITDylib
&JD
, orc::JITDylibLookupFlags JDLookupFlags
,
40 const orc::SymbolLookupSet
&Symbols
) override
;
42 void appendDebugObject(const char *Addr
, size_t Size
) {
43 TestOut
->os().write(Addr
, Size
);
47 orc::SymbolMap BuiltinFunctions
;
48 std::unique_ptr
<ToolOutputFile
> TestOut
;
50 template <typename T
> void expose(orc::SymbolStringPtr Name
, T
*Handler
) {
51 BuiltinFunctions
[Name
] = {orc::ExecutorAddr::fromPtr(Handler
),
52 JITSymbolFlags::Exported
};
55 static std::unique_ptr
<ToolOutputFile
> createToolOutput();
58 } // end namespace llvm
60 #endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H