1*73471bf0Spatrick //===- ExecutionUtils.h - Utilities for executing code in lli ---*- C++ -*-===// 2*73471bf0Spatrick // 3*73471bf0Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*73471bf0Spatrick // See https://llvm.org/LICENSE.txt for license information. 5*73471bf0Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*73471bf0Spatrick // 7*73471bf0Spatrick //===----------------------------------------------------------------------===// 8*73471bf0Spatrick // 9*73471bf0Spatrick // Contains utilities for executing code in lli. 10*73471bf0Spatrick // 11*73471bf0Spatrick //===----------------------------------------------------------------------===// 12*73471bf0Spatrick 13*73471bf0Spatrick #ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H 14*73471bf0Spatrick #define LLVM_TOOLS_LLI_EXECUTIONUTILS_H 15*73471bf0Spatrick 16*73471bf0Spatrick #include "llvm/ExecutionEngine/JITSymbol.h" 17*73471bf0Spatrick #include "llvm/ExecutionEngine/Orc/Core.h" 18*73471bf0Spatrick #include "llvm/ExecutionEngine/Orc/Mangling.h" 19*73471bf0Spatrick #include "llvm/Support/Error.h" 20*73471bf0Spatrick #include "llvm/Support/ToolOutputFile.h" 21*73471bf0Spatrick 22*73471bf0Spatrick #include <memory> 23*73471bf0Spatrick #include <utility> 24*73471bf0Spatrick 25*73471bf0Spatrick namespace llvm { 26*73471bf0Spatrick 27*73471bf0Spatrick enum class BuiltinFunctionKind { 28*73471bf0Spatrick DumpDebugDescriptor, 29*73471bf0Spatrick DumpDebugObjects, 30*73471bf0Spatrick }; 31*73471bf0Spatrick 32*73471bf0Spatrick // Utility class to expose symbols for special-purpose functions to the JIT. 33*73471bf0Spatrick class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator { 34*73471bf0Spatrick public: 35*73471bf0Spatrick LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled, 36*73471bf0Spatrick orc::MangleAndInterner &Mangle); 37*73471bf0Spatrick 38*73471bf0Spatrick Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K, 39*73471bf0Spatrick orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags, 40*73471bf0Spatrick const orc::SymbolLookupSet &Symbols) override; 41*73471bf0Spatrick appendDebugObject(const char * Addr,size_t Size)42*73471bf0Spatrick void appendDebugObject(const char *Addr, size_t Size) { 43*73471bf0Spatrick TestOut->os().write(Addr, Size); 44*73471bf0Spatrick } 45*73471bf0Spatrick 46*73471bf0Spatrick private: 47*73471bf0Spatrick orc::SymbolMap BuiltinFunctions; 48*73471bf0Spatrick std::unique_ptr<ToolOutputFile> TestOut; 49*73471bf0Spatrick expose(orc::SymbolStringPtr Name,T * Handler)50*73471bf0Spatrick template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) { 51*73471bf0Spatrick BuiltinFunctions[Name] = JITEvaluatedSymbol( 52*73471bf0Spatrick pointerToJITTargetAddress(Handler), JITSymbolFlags::Exported); 53*73471bf0Spatrick } 54*73471bf0Spatrick 55*73471bf0Spatrick static std::unique_ptr<ToolOutputFile> createToolOutput(); 56*73471bf0Spatrick }; 57*73471bf0Spatrick 58*73471bf0Spatrick } // end namespace llvm 59*73471bf0Spatrick 60*73471bf0Spatrick #endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H 61