[bugpoint] set Message after tool configuration
[oota-llvm.git] / tools / lli / RecordingMemoryManager.cpp
1 //===- RecordingMemoryManager.cpp - Recording memory manager --------------===//
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 // This memory manager allocates local storage and keeps a record of each
11 // allocation. Iterators are provided for all data and code allocations.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "RecordingMemoryManager.h"
16 using namespace llvm;
17
18 RecordingMemoryManager::~RecordingMemoryManager() {
19   for (SmallVectorImpl<Allocation>::iterator
20          I = AllocatedCodeMem.begin(), E = AllocatedCodeMem.end();
21        I != E; ++I)
22     free(I->first.base());
23   for (SmallVectorImpl<Allocation>::iterator
24          I = AllocatedDataMem.begin(), E = AllocatedDataMem.end();
25        I != E; ++I)
26     free(I->first.base());
27 }
28
29 uint8_t *RecordingMemoryManager::
30 allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) {
31   // The recording memory manager is just a local copy of the remote target.
32   // The alignment requirement is just stored here for later use. Regular
33   // heap storage is sufficient here.
34   void *Addr = malloc(Size);
35   assert(Addr && "malloc() failure!");
36   sys::MemoryBlock Block(Addr, Size);
37   AllocatedCodeMem.push_back(Allocation(Block, Alignment));
38   return (uint8_t*)Addr;
39 }
40
41 uint8_t *RecordingMemoryManager::
42 allocateDataSection(uintptr_t Size, unsigned Alignment,
43                     unsigned SectionID, bool IsReadOnly) {
44   // The recording memory manager is just a local copy of the remote target.
45   // The alignment requirement is just stored here for later use. Regular
46   // heap storage is sufficient here.
47   void *Addr = malloc(Size);
48   assert(Addr && "malloc() failure!");
49   sys::MemoryBlock Block(Addr, Size);
50   AllocatedDataMem.push_back(Allocation(Block, Alignment));
51   return (uint8_t*)Addr;
52 }
53 void RecordingMemoryManager::setMemoryWritable() { llvm_unreachable("Unexpected!"); }
54 void RecordingMemoryManager::setMemoryExecutable() { llvm_unreachable("Unexpected!"); }
55 void RecordingMemoryManager::setPoisonMemory(bool poison) { llvm_unreachable("Unexpected!"); }
56 void RecordingMemoryManager::AllocateGOT() { llvm_unreachable("Unexpected!"); }
57 uint8_t *RecordingMemoryManager::getGOTBase() const {
58   llvm_unreachable("Unexpected!");
59   return 0;
60 }
61 uint8_t *RecordingMemoryManager::startFunctionBody(const Function *F, uintptr_t &ActualSize){
62   llvm_unreachable("Unexpected!");
63   return 0;
64 }
65 uint8_t *RecordingMemoryManager::allocateStub(const GlobalValue* F, unsigned StubSize,
66                                               unsigned Alignment) {
67   llvm_unreachable("Unexpected!");
68   return 0;
69 }
70 void RecordingMemoryManager::endFunctionBody(const Function *F, uint8_t *FunctionStart,
71                                              uint8_t *FunctionEnd) {
72   llvm_unreachable("Unexpected!");
73 }
74 uint8_t *RecordingMemoryManager::allocateSpace(intptr_t Size, unsigned Alignment) {
75   llvm_unreachable("Unexpected!");
76   return 0;
77 }
78 uint8_t *RecordingMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment) {
79   llvm_unreachable("Unexpected!");
80   return 0;
81 }
82 void RecordingMemoryManager::deallocateFunctionBody(void *Body) {
83   llvm_unreachable("Unexpected!");
84 }
85 uint8_t* RecordingMemoryManager::startExceptionTable(const Function* F, uintptr_t &ActualSize) {
86   llvm_unreachable("Unexpected!");
87   return 0;
88 }
89 void RecordingMemoryManager::endExceptionTable(const Function *F, uint8_t *TableStart,
90                                                uint8_t *TableEnd, uint8_t* FrameRegister) {
91   llvm_unreachable("Unexpected!");
92 }
93 void RecordingMemoryManager::deallocateExceptionTable(void *ET) {
94   llvm_unreachable("Unexpected!");
95 }
96
97 static int jit_noop() {
98   return 0;
99 }
100
101 void *RecordingMemoryManager::getPointerToNamedFunction(const std::string &Name,
102                                                         bool AbortOnFailure) {
103   // We should not invoke parent's ctors/dtors from generated main()!
104   // On Mingw and Cygwin, the symbol __main is resolved to
105   // callee's(eg. tools/lli) one, to invoke wrong duplicated ctors
106   // (and register wrong callee's dtors with atexit(3)).
107   // We expect ExecutionEngine::runStaticConstructorsDestructors()
108   // is called before ExecutionEngine::runFunctionAsMain() is called.
109   if (Name == "__main") return (void*)(intptr_t)&jit_noop;
110
111   return NULL;
112 }