ExecutionUtils.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===- 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. #ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
  13. #define LLVM_TOOLS_LLI_EXECUTIONUTILS_H
  14. #include "llvm/ExecutionEngine/JITSymbol.h"
  15. #include "llvm/ExecutionEngine/Orc/Core.h"
  16. #include "llvm/ExecutionEngine/Orc/Mangling.h"
  17. #include "llvm/Support/Error.h"
  18. #include "llvm/Support/ToolOutputFile.h"
  19. #include <memory>
  20. #include <utility>
  21. namespace llvm {
  22. enum class BuiltinFunctionKind {
  23. DumpDebugDescriptor,
  24. DumpDebugObjects,
  25. };
  26. // Utility class to expose symbols for special-purpose functions to the JIT.
  27. class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator {
  28. public:
  29. LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled,
  30. orc::MangleAndInterner &Mangle);
  31. Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K,
  32. orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags,
  33. const orc::SymbolLookupSet &Symbols) override;
  34. void appendDebugObject(const char *Addr, size_t Size) {
  35. TestOut->os().write(Addr, Size);
  36. }
  37. private:
  38. orc::SymbolMap BuiltinFunctions;
  39. std::unique_ptr<ToolOutputFile> TestOut;
  40. template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) {
  41. BuiltinFunctions[Name] = JITEvaluatedSymbol(
  42. pointerToJITTargetAddress(Handler), JITSymbolFlags::Exported);
  43. }
  44. static std::unique_ptr<ToolOutputFile> createToolOutput();
  45. };
  46. } // end namespace llvm
  47. #endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H