|
|
@ -97,22 +97,30 @@ GasMeter::GasMeter(llvm::IRBuilder<>& _builder, llvm::Module* _module): |
|
|
|
m_builder.SetInsertPoint(bb, pt); |
|
|
|
} |
|
|
|
|
|
|
|
void GasMeter::check(Instruction _inst) |
|
|
|
void GasMeter::count(Instruction _inst) |
|
|
|
{ |
|
|
|
if (!m_checkCall) |
|
|
|
{ |
|
|
|
// Create gas check call with mocked block cost at begining of current cost-block
|
|
|
|
m_checkCall = m_builder.CreateCall(m_gasCheckFunc, m_builder.getIntN(256, 0)); |
|
|
|
m_checkCall = m_builder.CreateCall(m_gasCheckFunc, llvm::UndefValue::get(Type::i256)); |
|
|
|
} |
|
|
|
|
|
|
|
m_blockCost += getStepCost(_inst); |
|
|
|
|
|
|
|
if (isCostBlockEnd(_inst)) |
|
|
|
commitCostBlock(); |
|
|
|
} |
|
|
|
|
|
|
|
void GasMeter::commitCostBlock() |
|
|
|
{ |
|
|
|
// If any uncommited block
|
|
|
|
if (m_checkCall) |
|
|
|
{ |
|
|
|
m_checkCall->setArgOperand(0, m_builder.getIntN(256, m_blockCost)); // Update block cost in gas check call
|
|
|
|
m_checkCall = nullptr; // End cost-block
|
|
|
|
m_blockCost = 0; |
|
|
|
} |
|
|
|
assert(m_blockCost == 0); |
|
|
|
} |
|
|
|
|
|
|
|
void GasMeter::checkMemory(llvm::Value* _additionalMemoryInWords, llvm::IRBuilder<>& _builder) |
|
|
|