/ libevmjit / RuntimeManager.h
RuntimeManager.h
 1  #pragma once
 2  
 3  #include <array>
 4  
 5  #include "CompilerHelper.h"
 6  #include "Type.h"
 7  #include "Instruction.h"
 8  
 9  namespace dev
10  {
11  namespace eth
12  {
13  namespace jit
14  {
15  using namespace evmjit;
16  
17  class RuntimeManager: public CompilerHelper
18  {
19  public:
20  	RuntimeManager(IRBuilder& _builder, code_iterator _codeBegin, code_iterator _codeEnd);
21  
22  	llvm::Value* getRuntimePtr();
23  	llvm::Value* getDataPtr();
24  	llvm::Value* getEnvPtr();
25  
26  	llvm::Value* getAddress();
27  	llvm::Value* getSender();
28  	llvm::Value* getValue();
29  	llvm::Value* getGas();
30  	llvm::Value* getGasPtr();
31  	llvm::Value* getCallData();
32  	llvm::Value* getCode();
33  	llvm::Value* getCodeSize();
34  	llvm::Value* getCallDataSize();
35  	llvm::Value* getDepth();
36  	llvm::Value* getJmpBuf() { return m_jmpBuf; }
37  	void setGas(llvm::Value* _gas);
38  
39  	llvm::Value* getMem();
40  
41  	void registerReturnData(llvm::Value* _index, llvm::Value* _size); // TODO: Move to Memory.
42  
43  	void exit(ReturnCode _returnCode);
44  
45  	void abort(llvm::Value* _jmpBuf);
46  
47  	llvm::Value* getStackBase() const { return m_stackBase; }
48  	llvm::Value* getStackSize() const { return m_stackSize; }
49  
50  	llvm::Value* getReturnBufDataPtr() const { return m_returnBufDataPtr; }
51  	llvm::Value* getReturnBufSizePtr() const { return m_returnBufSizePtr; }
52  
53  	/// Reset RETURNDATA buffer (before calls).
54  	/// This effectively only sets the buffer size to 0.
55  	void resetReturnBuf();
56  
57  	void setJmpBuf(llvm::Value* _jmpBuf) { m_jmpBuf = _jmpBuf; }
58  	void setExitBB(llvm::BasicBlock* _bb) { m_exitBB = _bb; }
59  
60  	static llvm::StructType* getRuntimeType();
61  	static llvm::StructType* getRuntimeDataType();
62  	llvm::StructType* getTxContextType();
63  
64  	llvm::Value* getTxContextItem(unsigned _index);
65  
66  	//TODO Move to schedule
67  	static const size_t stackSizeLimit = 1024;
68  
69  private:
70  	llvm::Value* getPtr(RuntimeData::Index _index);
71  	void set(RuntimeData::Index _index, llvm::Value* _value);
72  
73  	llvm::Value* m_jmpBuf = nullptr;
74  	llvm::Value* m_dataPtr = nullptr;
75  	llvm::Value* m_gasPtr = nullptr;
76  	llvm::Value* m_memPtr = nullptr;
77  	llvm::Value* m_envPtr = nullptr;
78  	llvm::Value* m_returnBufDataPtr = nullptr;
79  	llvm::Value* m_returnBufSizePtr = nullptr;
80  
81  	llvm::Value* m_txCtxLoaded = nullptr;
82  	llvm::Value* m_txCtx = nullptr;
83  	llvm::Function* m_loadTxCtxFn = nullptr;
84  
85  	std::array<llvm::Value*, RuntimeData::numElements> m_dataElts;
86  
87  	llvm::Value* m_stackBase = nullptr;
88  	llvm::Value* m_stackSize = nullptr;
89  
90  	llvm::BasicBlock* m_exitBB = nullptr;
91  
92  	code_iterator m_codeBegin = {};
93  	code_iterator m_codeEnd = {};
94  	llvm::Value* m_codePtr = nullptr;
95  };
96  
97  }
98  }
99  }