Browse Source

Group instructions that access runtime data [#81470252]

cl-refactor
Paweł Bylica 10 years ago
parent
commit
916f5abaae
  1. 103
      libevmjit/Compiler.cpp
  2. 22
      libevmjit/Runtime.cpp
  3. 1
      libevmjit/Runtime.h

103
libevmjit/Compiler.cpp

@ -679,57 +679,29 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
} }
case Instruction::GAS: case Instruction::GAS:
{
stack.push(_runtimeManager.getGas());
break;
}
case Instruction::ADDRESS: case Instruction::ADDRESS:
{
auto value = _runtimeManager.get(RuntimeData::Address);
stack.push(value);
break;
}
case Instruction::BALANCE:
{
auto address = stack.pop();
auto value = ext.balance(address);
stack.push(value);
break;
}
case Instruction::CALLER: case Instruction::CALLER:
{
auto value = _runtimeManager.get(RuntimeData::Caller);
stack.push(value);
break;
}
case Instruction::ORIGIN: case Instruction::ORIGIN:
{
auto value = _runtimeManager.get(RuntimeData::Origin);
stack.push(value);
break;
}
case Instruction::CALLVALUE: case Instruction::CALLVALUE:
{
auto value = _runtimeManager.get(RuntimeData::CallValue);
stack.push(value);
break;
}
case Instruction::CALLDATASIZE: case Instruction::CALLDATASIZE:
case Instruction::CODESIZE:
case Instruction::GASPRICE:
case Instruction::PREVHASH:
case Instruction::COINBASE:
case Instruction::TIMESTAMP:
case Instruction::NUMBER:
case Instruction::DIFFICULTY:
case Instruction::GASLIMIT:
{ {
auto value = _runtimeManager.get(RuntimeData::CallDataSize); // Pushes an element of runtime data on stack
stack.push(value); stack.push(_runtimeManager.get(inst));
break; break;
} }
case Instruction::CODESIZE: case Instruction::BALANCE:
{ {
auto value = _runtimeManager.get(RuntimeData::CodeSize); auto address = stack.pop();
auto value = ext.balance(address);
stack.push(value); stack.push(value);
break; break;
} }
@ -790,55 +762,6 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
break; break;
} }
case Instruction::GASPRICE:
{
auto value = _runtimeManager.get(RuntimeData::GasPrice);
stack.push(value);
break;
}
case Instruction::PREVHASH:
{
auto value = _runtimeManager.get(RuntimeData::PrevHash);
stack.push(value);
break;
}
case Instruction::COINBASE:
{
auto value = _runtimeManager.get(RuntimeData::CoinBase);
stack.push(value);
break;
}
case Instruction::TIMESTAMP:
{
auto value = _runtimeManager.get(RuntimeData::TimeStamp);
stack.push(value);
break;
}
case Instruction::NUMBER:
{
auto value = _runtimeManager.get(RuntimeData::Number);
stack.push(value);
break;
}
case Instruction::DIFFICULTY:
{
auto value = _runtimeManager.get(RuntimeData::Difficulty);
stack.push(value);
break;
}
case Instruction::GASLIMIT:
{
auto value = _runtimeManager.get(RuntimeData::GasLimit);
stack.push(value);
break;
}
case Instruction::CREATE: case Instruction::CREATE:
{ {
auto endowment = stack.pop(); auto endowment = stack.pop();

22
libevmjit/Runtime.cpp

@ -135,6 +135,28 @@ llvm::Value* RuntimeManager::get(RuntimeData::Index _index)
return m_builder.CreateLoad(ptr, getName(_index)); return m_builder.CreateLoad(ptr, getName(_index));
} }
llvm::Value* RuntimeManager::get(Instruction _inst)
{
switch (_inst)
{
default: assert(false); return nullptr;
case Instruction::GAS: return get(RuntimeData::Gas);
case Instruction::ADDRESS: return get(RuntimeData::Address);
case Instruction::CALLER: return get(RuntimeData::Caller);
case Instruction::ORIGIN: return get(RuntimeData::Origin);
case Instruction::CALLVALUE: return get(RuntimeData::CallValue);
case Instruction::CALLDATASIZE: return get(RuntimeData::CallDataSize);
case Instruction::GASPRICE: return get(RuntimeData::GasPrice);
case Instruction::PREVHASH: return get(RuntimeData::PrevHash);
case Instruction::COINBASE: return get(RuntimeData::CoinBase);
case Instruction::TIMESTAMP: return get(RuntimeData::TimeStamp);
case Instruction::NUMBER: return get(RuntimeData::Number);
case Instruction::DIFFICULTY: return get(RuntimeData::Difficulty);
case Instruction::GASLIMIT: return get(RuntimeData::GasLimit);
case Instruction::CODESIZE: return get(RuntimeData::CodeSize);
}
}
llvm::Value* RuntimeManager::getGas() llvm::Value* RuntimeManager::getGas()
{ {
return get(RuntimeData::Gas); return get(RuntimeData::Gas);

1
libevmjit/Runtime.h

@ -88,6 +88,7 @@ public:
llvm::Value* getRuntimePtr(); llvm::Value* getRuntimePtr();
llvm::Value* get(RuntimeData::Index _index); llvm::Value* get(RuntimeData::Index _index);
llvm::Value* get(Instruction _inst);
llvm::Value* getGas(); llvm::Value* getGas();
void setGas(llvm::Value* _gas); void setGas(llvm::Value* _gas);

Loading…
Cancel
Save