Manager.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===-- examples/clang-interpreter/Manager.h - Clang C Interpreter Example -==//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef CLANG_EXAMPLE_INTERPRETER_MANAGER_H
  10. #define CLANG_EXAMPLE_INTERPRETER_MANAGER_H
  11. #include "llvm/ExecutionEngine/SectionMemoryManager.h"
  12. #if defined(_WIN32) && defined(_WIN64)
  13. #define CLANG_INTERPRETER_COFF_FORMAT
  14. #define CLANG_INTERPRETER_WIN_EXCEPTIONS
  15. #endif
  16. namespace interpreter {
  17. class SingleSectionMemoryManager : public llvm::SectionMemoryManager {
  18. struct Block {
  19. uint8_t *Addr = nullptr, *End = nullptr;
  20. void Reset(uint8_t *Ptr, uintptr_t Size);
  21. uint8_t *Next(uintptr_t Size, unsigned Alignment);
  22. };
  23. Block Code, ROData, RWData;
  24. public:
  25. uint8_t *allocateCodeSection(uintptr_t Size, unsigned Align, unsigned ID,
  26. llvm::StringRef Name) final;
  27. uint8_t *allocateDataSection(uintptr_t Size, unsigned Align, unsigned ID,
  28. llvm::StringRef Name, bool RO) final;
  29. void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
  30. uintptr_t ROSize, uint32_t ROAlign,
  31. uintptr_t RWSize, uint32_t RWAlign) final;
  32. bool needsToReserveAllocationSpace() override { return true; }
  33. #ifdef CLANG_INTERPRETER_WIN_EXCEPTIONS
  34. using llvm::SectionMemoryManager::EHFrameInfos;
  35. SingleSectionMemoryManager();
  36. void deregisterEHFrames() override;
  37. bool finalizeMemory(std::string *ErrMsg) override;
  38. private:
  39. uintptr_t ImageBase = 0;
  40. #endif
  41. };
  42. }
  43. #endif // CLANG_EXAMPLE_INTERPRETER_MANAGER_H