Browse Source

Merge branch 'develop-evmcc' of github.com:imapp-pl/ethereum into develop-evmcc

cl-refactor
artur-zawlocki 10 years ago
parent
commit
895d0aa3ca
  1. 1
      evmcc/test/jump/jumpi_at_the_end.evm
  2. 1
      evmcc/test/jump/jumpi_at_the_end.lll
  3. 41
      evmcc/test/vmtests/vm_jump.json
  4. 22
      libevmjit/Compiler.cpp
  5. 3
      libevmjit/Memory.cpp

1
evmcc/test/jump/jumpi_at_the_end.evm

@ -0,0 +1 @@
600a6000545d6000536001900380600054600659

1
evmcc/test/jump/jumpi_at_the_end.lll

@ -0,0 +1 @@
(asm 10 0 MSTORE JUMPDEST 0 MLOAD 1 SWAP1 SUB DUP1 0 MSTORE 6 JUMPI)

41
evmcc/test/vmtests/vm_jump.json

@ -0,0 +1,41 @@
{
"jumpi_at_the_end" : {
"callcreates" : [ ],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "10000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "(asm 10 0 MSTORE JUMPDEST 0 MLOAD 1 SWAP1 SUB DUP1 0 MSTORE 6 JUMPI)",
"data" : "0x",
"gas" : "1000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "895",
"out" : "0x0",
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "(asm 10 0 MSTORE JUMPDEST 0 MLOAD 1 SWAP1 SUB DUP1 0 MSTORE 6 JUMPI)",
"nonce" : "0",
"storage" : {}
}
},
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "(asm 10 0 MSTORE JUMPDEST 0 MLOAD 1 SWAP1 SUB DUP1 0 MSTORE 6 JUMPI)",
"nonce" : "0",
"storage" : {}
}
}
}
}

22
libevmjit/Compiler.cpp

@ -554,16 +554,15 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
case Instruction::ANY_PUSH: case Instruction::ANY_PUSH:
{ {
auto numBytes = static_cast<size_t>(inst) - static_cast<size_t>(Instruction::PUSH1) + 1; const auto numBytes = static_cast<size_t>(inst) - static_cast<size_t>(Instruction::PUSH1) + 1;
auto value = llvm::APInt(256, 0); auto value = llvm::APInt(256, 0);
for (decltype(numBytes) i = 0; i < numBytes; ++i) // TODO: Use pc as iterator for (auto lastPC = currentPC + numBytes; currentPC < lastPC;)
{ {
++currentPC;
value <<= 8; value <<= 8;
value |= bytecode[currentPC]; value |= bytecode[++currentPC];
} }
auto c = m_builder.getInt(value);
stack.push(c); stack.push(m_builder.getInt(value));
break; break;
} }
@ -641,10 +640,8 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
{ {
auto pairIter = m_directJumpTargets.find(currentPC); auto pairIter = m_directJumpTargets.find(currentPC);
if (pairIter != m_directJumpTargets.end()) if (pairIter != m_directJumpTargets.end())
{
targetBlock = pairIter->second; targetBlock = pairIter->second;
} }
}
if (inst == Instruction::JUMP) if (inst == Instruction::JUMP)
{ {
@ -656,10 +653,8 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
m_builder.CreateBr(targetBlock); m_builder.CreateBr(targetBlock);
} }
else else
{
m_builder.CreateBr(m_jumpTableBlock->llvm()); m_builder.CreateBr(m_jumpTableBlock->llvm());
} }
}
else // JUMPI else // JUMPI
{ {
stack.swap(1); stack.swap(1);
@ -667,8 +662,9 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto zero = Constant::get(0); auto zero = Constant::get(0);
auto cond = m_builder.CreateICmpNE(val, zero, "nonzero"); auto cond = m_builder.CreateICmpNE(val, zero, "nonzero");
// Assume the basic blocks are properly ordered:
assert(nextBasicBlock); // FIXME: JUMPI can be last instruction if (!nextBasicBlock) // In case JUMPI is the last instruction
nextBasicBlock = m_stopBB;
if (targetBlock) if (targetBlock)
{ {
@ -676,10 +672,8 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
m_builder.CreateCondBr(cond, targetBlock, nextBasicBlock); m_builder.CreateCondBr(cond, targetBlock, nextBasicBlock);
} }
else else
{
m_builder.CreateCondBr(cond, m_jumpTableBlock->llvm(), nextBasicBlock); m_builder.CreateCondBr(cond, m_jumpTableBlock->llvm(), nextBasicBlock);
} }
}
break; break;
} }

3
libevmjit/Memory.cpp

@ -74,7 +74,8 @@ llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _
m_builder.SetInsertPoint(resizeBB); m_builder.SetInsertPoint(resizeBB);
// Check gas first // Check gas first
auto wordsRequired = m_builder.CreateUDiv(m_builder.CreateAdd(sizeRequired, Constant::get(31)), Constant::get(32), "wordsRequired"); auto wordsRequired = m_builder.CreateUDiv(m_builder.CreateAdd(sizeRequired, Constant::get(31)), Constant::get(32), "wordsRequired");
auto words = m_builder.CreateUDiv(m_builder.CreateAdd(size, Constant::get(31)), Constant::get(32), "words"); sizeRequired = m_builder.CreateMul(wordsRequired, Constant::get(32), "roundedSizeRequired");
auto words = m_builder.CreateUDiv(size, Constant::get(32), "words"); // size is always 32*k
auto newWords = m_builder.CreateSub(wordsRequired, words, "addtionalWords"); auto newWords = m_builder.CreateSub(wordsRequired, words, "addtionalWords");
_gasMeter.checkMemory(newWords, m_builder); _gasMeter.checkMemory(newWords, m_builder);
// Resize // Resize

Loading…
Cancel
Save