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. 6
      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:
{
auto value = ext.caller();
auto value = _runtimeManager.get(RuntimeData::Caller);
stack.push(value);
break;
}
case Instruction::ORIGIN:
{
auto value = ext.origin();
auto value = _runtimeManager.get(RuntimeData::Origin);
stack.push(value);
break;
}
case Instruction::CALLVALUE:
{
auto value = ext.callvalue();
auto value = _runtimeManager.get(RuntimeData::CallValue);
stack.push(value);
break;
}

36
libevmjit/Ext.cpp

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

3
libevmjit/Ext.h

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

6
libevmjit/Runtime.cpp

@ -38,6 +38,9 @@ llvm::Twine getName(RuntimeData::Index _index)
default: return "data";
case RuntimeData::Gas: return "gas";
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;
set(RuntimeData::Gas, _gas);
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()

3
libevmjit/Runtime.h

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

Loading…
Cancel
Save