blob: d1b146151dede40450379d1cc1e837407eee8af7 [file] [log] [blame]
Frederich Munch529ce722018-03-14 16:04:45 +00001//===-- 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
10#ifndef CLANG_EXAMPLE_INTERPRETER_MANAGER_H
11#define CLANG_EXAMPLE_INTERPRETER_MANAGER_H
12
13#include "llvm/ExecutionEngine/SectionMemoryManager.h"
14
15#if defined(LLVM_ON_WIN32) && defined(_WIN64)
16#define CLANG_INTERPRETER_COFF_FORMAT
17#define CLANG_INTERPRETER_WIN_EXCEPTIONS
18#endif
19
20namespace interpreter {
21
22class SingleSectionMemoryManager : public llvm::SectionMemoryManager {
23 struct Block {
24 uint8_t *Addr = nullptr, *End = nullptr;
25 void Reset(uint8_t *Ptr, uintptr_t Size);
26 uint8_t *Next(uintptr_t Size, unsigned Alignment);
27 };
28 Block Code, ROData, RWData;
29
30public:
31 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Align, unsigned ID,
32 llvm::StringRef Name) final;
33
34 uint8_t *allocateDataSection(uintptr_t Size, unsigned Align, unsigned ID,
35 llvm::StringRef Name, bool RO) final;
36
37 void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
38 uintptr_t ROSize, uint32_t ROAlign,
39 uintptr_t RWSize, uint32_t RWAlign) final;
40
41 bool needsToReserveAllocationSpace() override { return true; }
42
43#ifdef CLANG_INTERPRETER_WIN_EXCEPTIONS
44 using llvm::SectionMemoryManager::EHFrameInfos;
45
46 SingleSectionMemoryManager();
47
48 void deregisterEHFrames() override;
49
50 bool finalizeMemory(std::string *ErrMsg) override;
51
52private:
53 uintptr_t ImageBase = 0;
54#endif
55};
56
57}
58
59#endif // CLANG_EXAMPLE_INTERPRETER_MANAGER_H