Browse Source

Moving the rest word-size data from Ext to Runtime [#81470252]

cl-refactor
Paweł Bylica 10 years ago
parent
commit
088a4efa16
  1. 24
      libevmjit/Compiler.cpp
  2. 40
      libevmjit/Ext.cpp
  3. 9
      libevmjit/Ext.h
  4. 18
      libevmjit/Runtime.cpp
  5. 9
      libevmjit/Runtime.h

24
libevmjit/Compiler.cpp

@ -722,14 +722,14 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
case Instruction::CALLDATASIZE: case Instruction::CALLDATASIZE:
{ {
auto value = ext.calldatasize(); auto value = _runtimeManager.get(RuntimeData::CallDataSize);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::CODESIZE: case Instruction::CODESIZE:
{ {
auto value = ext.codesize(); auto value = _runtimeManager.get(RuntimeData::CodeSize);
stack.push(value); stack.push(value);
break; break;
} }
@ -749,7 +749,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto reqBytes = stack.pop(); auto reqBytes = stack.pop();
auto srcPtr = ext.calldata(); auto srcPtr = ext.calldata();
auto srcSize = ext.calldatasize(); auto srcSize = _runtimeManager.get(RuntimeData::CallDataSize);
memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes); memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes);
break; break;
@ -762,7 +762,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto reqBytes = stack.pop(); auto reqBytes = stack.pop();
auto srcPtr = ext.code(); // TODO: Code & its size are constants, feature #80814234 auto srcPtr = ext.code(); // TODO: Code & its size are constants, feature #80814234
auto srcSize = ext.codesize(); auto srcSize = _runtimeManager.get(RuntimeData::CodeSize);
memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes); memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes);
break; break;
@ -791,50 +791,50 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
} }
case Instruction::GASPRICE: case Instruction::GASPRICE:
{ {
auto value = ext.gasprice(); auto value = _runtimeManager.get(RuntimeData::GasPrice);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::PREVHASH: case Instruction::PREVHASH:
{ {
auto value = ext.prevhash(); auto value = _runtimeManager.get(RuntimeData::PrevHash);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::COINBASE: case Instruction::COINBASE:
{ {
auto value = ext.coinbase(); auto value = _runtimeManager.get(RuntimeData::CoinBase);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::TIMESTAMP: case Instruction::TIMESTAMP:
{ {
auto value = ext.timestamp(); auto value = _runtimeManager.get(RuntimeData::TimeStamp);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::NUMBER: case Instruction::NUMBER:
{ {
auto value = ext.number(); auto value = _runtimeManager.get(RuntimeData::Number);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::DIFFICULTY: case Instruction::DIFFICULTY:
{ {
auto value = ext.difficulty(); auto value = _runtimeManager.get(RuntimeData::Difficulty);
stack.push(value); stack.push(value);
break; break;
} }
case Instruction::GASLIMIT: case Instruction::GASLIMIT:
{ {
auto value = ext.gaslimit(); auto value = _runtimeManager.get(RuntimeData::GasLimit);
stack.push(value); stack.push(value);
break; break;
} }

40
libevmjit/Ext.cpp

@ -27,15 +27,6 @@ inline u256 fromAddress(Address _a)
struct ExtData struct ExtData
{ {
i256 calldatasize;
i256 gasprice;
i256 prevhash;
i256 coinbase;
i256 timestamp;
i256 number;
i256 difficulty;
i256 gaslimit;
i256 codesize;
const byte* calldata; const byte* calldata;
const byte* code; const byte* code;
}; };
@ -61,15 +52,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 calldatasize;
i256Ty, // i256 gasprice;
i256Ty, // i256 prevhash;
i256Ty, // i256 coinbase;
i256Ty, // i256 timestamp;
i256Ty, // i256 number;
i256Ty, // i256 difficulty;
i256Ty, // i256 gaslimit;
i256Ty, // i256 codesize
i8PtrTy, // byte* calldata i8PtrTy, // byte* calldata
i8PtrTy, // byte* code i8PtrTy, // byte* code
@ -118,17 +100,8 @@ Value* Ext::getDataElem(unsigned _index, const Twine& _name)
return m_builder.CreateLoad(valuePtr); return m_builder.CreateLoad(valuePtr);
} }
Value* Ext::calldatasize() { return getDataElem(0, "calldatasize"); } Value* Ext::calldata() { return getDataElem(0, "calldata"); }
Value* Ext::gasprice() { return getDataElem(1, "gasprice"); } Value* Ext::code() { return getDataElem(1, "code"); }
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) Value* Ext::calldataload(Value* _index)
{ {
@ -231,15 +204,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->gasprice = eth2llvm(ext.gasPrice);
_extData->calldatasize = eth2llvm(ext.data.size());
_extData->prevhash = eth2llvm(ext.previousBlock.hash);
_extData->coinbase = eth2llvm(fromAddress(ext.currentBlock.coinbaseAddress));
_extData->timestamp = eth2llvm(ext.currentBlock.timestamp);
_extData->number = eth2llvm(ext.currentBlock.number);
_extData->difficulty = eth2llvm(ext.currentBlock.difficulty);
_extData->gaslimit = eth2llvm(ext.currentBlock.gasLimit);
_extData->codesize = eth2llvm(ext.code.size());
_extData->calldata = ext.data.data(); _extData->calldata = ext.data.data();
_extData->code = ext.code.data(); _extData->code = ext.code.data();
} }

9
libevmjit/Ext.h

@ -20,15 +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* calldatasize();
llvm::Value* gasprice();
llvm::Value* prevhash();
llvm::Value* coinbase();
llvm::Value* timestamp();
llvm::Value* number();
llvm::Value* difficulty();
llvm::Value* gaslimit();
llvm::Value* codesize();
llvm::Value* calldata(); llvm::Value* calldata();
llvm::Value* code(); llvm::Value* code();

18
libevmjit/Runtime.cpp

@ -41,6 +41,15 @@ llvm::Twine getName(RuntimeData::Index _index)
case RuntimeData::Caller: return "caller"; case RuntimeData::Caller: return "caller";
case RuntimeData::Origin: return "origin"; case RuntimeData::Origin: return "origin";
case RuntimeData::CallValue: return "callvalue"; case RuntimeData::CallValue: return "callvalue";
case RuntimeData::CallDataSize: return "calldatasize";
case RuntimeData::GasPrice: return "gasprice";
case RuntimeData::PrevHash: return "prevhash";
case RuntimeData::CoinBase: return "coinbase";
case RuntimeData::TimeStamp: return "timestamp";
case RuntimeData::Number: return "number";
case RuntimeData::Difficulty: return "difficulty";
case RuntimeData::GasLimit: return "gaslimit";
case RuntimeData::CodeSize: return "codesize";
} }
} }
} }
@ -57,6 +66,15 @@ Runtime::Runtime(u256 _gas, ExtVMFace& _ext):
set(RuntimeData::Caller, fromAddress(_ext.caller)); set(RuntimeData::Caller, fromAddress(_ext.caller));
set(RuntimeData::Origin, fromAddress(_ext.origin)); set(RuntimeData::Origin, fromAddress(_ext.origin));
set(RuntimeData::CallValue, _ext.value); set(RuntimeData::CallValue, _ext.value);
set(RuntimeData::CallDataSize, _ext.data.size());
set(RuntimeData::GasPrice, _ext.gasPrice);
set(RuntimeData::PrevHash, _ext.previousBlock.hash);
set(RuntimeData::CoinBase, fromAddress(_ext.currentBlock.coinbaseAddress));
set(RuntimeData::TimeStamp, _ext.currentBlock.timestamp);
set(RuntimeData::Number, _ext.currentBlock.number);
set(RuntimeData::Difficulty, _ext.currentBlock.difficulty);
set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit);
set(RuntimeData::CodeSize, _ext.code.size()); // TODO: Use constant
} }
Runtime::~Runtime() Runtime::~Runtime()

9
libevmjit/Runtime.h

@ -31,6 +31,15 @@ struct RuntimeData
Caller, Caller,
Origin, Origin,
CallValue, CallValue,
CallDataSize,
GasPrice,
PrevHash,
CoinBase,
TimeStamp,
Number,
Difficulty,
GasLimit,
CodeSize,
_size _size
}; };

Loading…
Cancel
Save