mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Use iterators in basic block compilation
This commit is contained in:
parent
098632804d
commit
be7713ac33
1 changed files with 11 additions and 19 deletions
|
|
@ -212,9 +212,12 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
m_builder.SetInsertPoint(_basicBlock.llvm());
|
m_builder.SetInsertPoint(_basicBlock.llvm());
|
||||||
auto& stack = _basicBlock.localStack();
|
auto& stack = _basicBlock.localStack();
|
||||||
|
|
||||||
for (auto currentPC = _basicBlock.begin(); currentPC != _basicBlock.end(); ++currentPC)
|
auto begin = _bytecode.begin() + _basicBlock.begin();
|
||||||
|
auto end = _bytecode.begin() + _basicBlock.end();
|
||||||
|
|
||||||
|
for (auto it = begin; it != end; ++it)
|
||||||
{
|
{
|
||||||
auto inst = static_cast<Instruction>(_bytecode[currentPC]);
|
auto inst = Instruction(*it);
|
||||||
|
|
||||||
_gasMeter.count(inst);
|
_gasMeter.count(inst);
|
||||||
|
|
||||||
|
|
@ -476,10 +479,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
|
|
||||||
case Instruction::ANY_PUSH:
|
case Instruction::ANY_PUSH:
|
||||||
{
|
{
|
||||||
auto curr = _bytecode.begin() + currentPC; // TODO: replace currentPC with iterator
|
auto value = readPushData(it, end);
|
||||||
auto value = readPushData(curr, _bytecode.end());
|
|
||||||
currentPC = curr - _bytecode.begin();
|
|
||||||
|
|
||||||
stack.push(Constant::get(value));
|
stack.push(Constant::get(value));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -554,24 +554,16 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
if (auto constant = llvm::dyn_cast<llvm::ConstantInt>(target))
|
if (auto constant = llvm::dyn_cast<llvm::ConstantInt>(target))
|
||||||
{
|
{
|
||||||
auto&& c = constant->getValue();
|
auto&& c = constant->getValue();
|
||||||
if (c.ult(_bytecode.size()))
|
auto targetIdx = c.getActiveBits() <= 64 ? c.getZExtValue() : -1;
|
||||||
{
|
auto it = m_basicBlocks.find(targetIdx);
|
||||||
auto v = c.getZExtValue();
|
targetBlock = (it != m_basicBlocks.end() && it->second.isJumpDest()) ? it->second.llvm() : getBadJumpBlock();
|
||||||
auto it = m_basicBlocks.find(v);
|
|
||||||
if (it != m_basicBlocks.end() && it->second.isJumpDest())
|
|
||||||
targetBlock = it->second.llvm();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!targetBlock)
|
|
||||||
targetBlock = getBadJumpBlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Improve; check for constants
|
||||||
if (inst == Instruction::JUMP)
|
if (inst == Instruction::JUMP)
|
||||||
{
|
{
|
||||||
if (targetBlock)
|
if (targetBlock)
|
||||||
{
|
{
|
||||||
// The target address is computed at compile time,
|
|
||||||
// just pop it without looking...
|
|
||||||
m_builder.CreateBr(targetBlock);
|
m_builder.CreateBr(targetBlock);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -607,7 +599,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
|
|
||||||
case Instruction::PC:
|
case Instruction::PC:
|
||||||
{
|
{
|
||||||
auto value = Constant::get(currentPC);
|
auto value = Constant::get(it - _bytecode.begin());
|
||||||
stack.push(value);
|
stack.push(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue