Browse Source

Moving ORIGIN, CALLER & CALLVALUE data from Ext to Runtime [#81470252]

cl-refactor
Paweł Bylica 10 years ago
parent
commit
ae89279c1a
  1. 6
      libevmjit/Compiler.cpp
  2. 36
      libevmjit/Ext.cpp
  3. 3
      libevmjit/Ext.h
  4. 12
      libevmjit/Runtime.cpp
  5. 3
      libevmjit/Runtime.h

6
libevmjit/Compiler.cpp

@ -701,21 +701,21 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
case Instruction::CALLER: case Instruction::CALLER:
{ {
auto value = ext.caller(); auto value = _runtimeManager.get(RuntimeData::Caller);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::ORIGIN: case Instruction::ORIGIN:
{ {
auto value = ext.origin(); auto value = _runtimeManager.get(RuntimeData::Origin);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::CALLVALUE: case Instruction::CALLVALUE:
{ {
auto value = ext.callvalue(); auto value = _runtimeManager.get(RuntimeData::CallValue);
stack.push(value); stack.push(value);
break; break;
} }

36
libevmjit/Ext.cpp

@ -27,10 +27,6 @@ inline u256 fromAddress(Address _a)
struct ExtData struct ExtData
{ {
i256 address;
i256 caller;
i256 origin;
i256 callvalue;
i256 calldatasize; i256 calldatasize;
i256 gasprice; i256 gasprice;
i256 prevhash; i256 prevhash;
@ -65,10 +61,6 @@ Ext::Ext(RuntimeManager& _runtimeManager):
m_arg8 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg8"); m_arg8 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg8");
Type* elements[] = { Type* elements[] = {
i256Ty, // i256 address;
i256Ty, // i256 caller;
i256Ty, // i256 origin;
i256Ty, // i256 callvalue;
i256Ty, // i256 calldatasize; i256Ty, // i256 calldatasize;
i256Ty, // i256 gasprice; i256Ty, // i256 gasprice;
i256Ty, // i256 prevhash; i256Ty, // i256 prevhash;
@ -126,20 +118,17 @@ Value* Ext::getDataElem(unsigned _index, const Twine& _name)
return m_builder.CreateLoad(valuePtr); return m_builder.CreateLoad(valuePtr);
} }
Value* Ext::caller() { return getDataElem(1, "caller"); } Value* Ext::calldatasize() { return getDataElem(0, "calldatasize"); }
Value* Ext::origin() { return getDataElem(2, "origin"); } Value* Ext::gasprice() { return getDataElem(1, "gasprice"); }
Value* Ext::callvalue() { return getDataElem(3, "callvalue"); } Value* Ext::prevhash() { return getDataElem(2, "prevhash"); }
Value* Ext::calldatasize() { return getDataElem(4, "calldatasize"); } Value* Ext::coinbase() { return getDataElem(3, "coinbase"); }
Value* Ext::gasprice() { return getDataElem(5, "gasprice"); } Value* Ext::timestamp() { return getDataElem(4, "timestamp"); }
Value* Ext::prevhash() { return getDataElem(6, "prevhash"); } Value* Ext::number() { return getDataElem(5, "number"); }
Value* Ext::coinbase() { return getDataElem(7, "coinbase"); } Value* Ext::difficulty() { return getDataElem(6, "difficulty"); }
Value* Ext::timestamp() { return getDataElem(8, "timestamp"); } Value* Ext::gaslimit() { return getDataElem(7, "gaslimit"); }
Value* Ext::number() { return getDataElem(9, "number"); } Value* Ext::codesize() { return getDataElem(8, "codesize"); }
Value* Ext::difficulty() { return getDataElem(10, "difficulty"); } Value* Ext::calldata() { return getDataElem(9, "calldata"); }
Value* Ext::gaslimit() { return getDataElem(11, "gaslimit"); } Value* Ext::code() { return getDataElem(10, "code"); }
Value* Ext::codesize() { return getDataElem(12, "codesize"); }
Value* Ext::calldata() { return getDataElem(13, "calldata"); }
Value* Ext::code() { return getDataElem(14, "code"); }
Value* Ext::calldataload(Value* _index) Value* Ext::calldataload(Value* _index)
{ {
@ -242,9 +231,6 @@ using namespace dev::eth::jit;
EXPORT void ext_init(ExtData* _extData) EXPORT void ext_init(ExtData* _extData)
{ {
auto&& ext = Runtime::getExt(); auto&& ext = Runtime::getExt();
_extData->caller = eth2llvm(fromAddress(ext.caller));
_extData->origin = eth2llvm(fromAddress(ext.origin));
_extData->callvalue = eth2llvm(ext.value);
_extData->gasprice = eth2llvm(ext.gasPrice); _extData->gasprice = eth2llvm(ext.gasPrice);
_extData->calldatasize = eth2llvm(ext.data.size()); _extData->calldatasize = eth2llvm(ext.data.size());
_extData->prevhash = eth2llvm(ext.previousBlock.hash); _extData->prevhash = eth2llvm(ext.previousBlock.hash);

3
libevmjit/Ext.h

@ -20,9 +20,6 @@ public:
llvm::Value* store(llvm::Value* _index); llvm::Value* store(llvm::Value* _index);
void setStore(llvm::Value* _index, llvm::Value* _value); void setStore(llvm::Value* _index, llvm::Value* _value);
llvm::Value* caller();
llvm::Value* origin();
llvm::Value* callvalue();
llvm::Value* calldatasize(); llvm::Value* calldatasize();
llvm::Value* gasprice(); llvm::Value* gasprice();
llvm::Value* prevhash(); llvm::Value* prevhash();

12
libevmjit/Runtime.cpp

@ -35,9 +35,12 @@ llvm::Twine getName(RuntimeData::Index _index)
{ {
switch (_index) switch (_index)
{ {
default: return "data"; default: return "data";
case RuntimeData::Gas: return "gas"; case RuntimeData::Gas: return "gas";
case RuntimeData::Address: return "address"; case RuntimeData::Address: return "address";
case RuntimeData::Caller: return "caller";
case RuntimeData::Origin: return "origin";
case RuntimeData::CallValue: return "callvalue";
} }
} }
} }
@ -51,6 +54,9 @@ Runtime::Runtime(u256 _gas, ExtVMFace& _ext):
g_runtime = this; g_runtime = this;
set(RuntimeData::Gas, _gas); set(RuntimeData::Gas, _gas);
set(RuntimeData::Address, fromAddress(_ext.myAddress)); set(RuntimeData::Address, fromAddress(_ext.myAddress));
set(RuntimeData::Caller, fromAddress(_ext.caller));
set(RuntimeData::Origin, fromAddress(_ext.origin));
set(RuntimeData::CallValue, _ext.value);
} }
Runtime::~Runtime() Runtime::~Runtime()

3
libevmjit/Runtime.h

@ -28,6 +28,9 @@ struct RuntimeData
{ {
Gas, Gas,
Address, Address,
Caller,
Origin,
CallValue,
_size _size
}; };

Loading…
Cancel
Save