Browse Source

Prealloc memory and count gas for CALL instruction

[#79942174]
cl-refactor
Paweł Bylica 10 years ago
parent
commit
1c70f3d099
  1. 12
      evmcc/Compiler.cpp

12
evmcc/Compiler.cpp

@ -745,9 +745,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
auto srcDataIdx = stack.pop();
auto reqBytes = stack.pop();
// FIXME: ensure memory size reqMemSize.
auto reqMemSize = builder.CreateAdd(destMemIdx, reqBytes, "req_mem_size");
memory.require(reqMemSize);
memory.require(destMemIdx, reqBytes);
auto memPtr = memory.getData();
auto destPtr = builder.CreateGEP(memPtr, destMemIdx, "dest_mem_ptr");
@ -856,6 +854,14 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
auto outSize = stack.pop();
gasMeter.commitCostBlock(gas);
// Require memory for the max of in and out buffers
auto inSizeReq = builder.CreateAdd(inOff, inSize, "inSizeReq");
auto outSizeReq = builder.CreateAdd(outOff, outSize, "outSizeReq");
auto cmp = builder.CreateICmpUGT(inSizeReq, outSizeReq);
auto sizeReq = builder.CreateSelect(cmp, inSizeReq, outSizeReq, "sizeReq");
memory.require(sizeReq);
auto ret = ext.call(gas, receiveAddress, value, inOff, inSize, outOff, outSize);
gasMeter.giveBack(gas);
stack.push(ret);

Loading…
Cancel
Save