1// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef sw_RoutineManager_hpp
16#define sw_RoutineManager_hpp
17
18#include "llvm/GlobalValue.h"
19#include "llvm/ExecutionEngine/JITMemoryManager.h"
20
21namespace sw
22{
23	class Routine;
24
25	class RoutineManager : public llvm::JITMemoryManager
26	{
27	public:
28		RoutineManager();
29
30		virtual ~RoutineManager();
31
32		virtual void AllocateGOT();
33
34		virtual uint8_t *allocateStub(const llvm::GlobalValue *function, unsigned stubSize, unsigned alignment);
35		virtual uint8_t *startFunctionBody(const llvm::Function *function, uintptr_t &actualSize);
36		virtual void endFunctionBody(const llvm::Function *function, uint8_t *functionStart, uint8_t *functionEnd);
37		virtual uint8_t *startExceptionTable(const llvm::Function *function, uintptr_t &ActualSize);
38		virtual void endExceptionTable(const llvm::Function *function, uint8_t *tableStart, uint8_t *tableEnd, uint8_t *frameRegister);
39		virtual uint8_t *getGOTBase() const;
40		virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment);
41		virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned int Alignment);
42		virtual void deallocateFunctionBody(void *Body);
43		virtual void deallocateExceptionTable(void *ET);
44		virtual void setMemoryWritable();
45		virtual void setMemoryExecutable();
46		virtual void setPoisonMemory(bool poison);
47
48		Routine *acquireRoutine(void *entry);
49
50	private:
51		Routine *routine;
52
53		static volatile int averageInstructionSize;
54	};
55}
56
57#endif   // sw_RoutineManager_hpp
58