mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Make Yul optimizer not fail for wasm.
This commit is contained in:
@@ -169,93 +169,6 @@ void CodeCost::addInstructionCost(eth::Instruction _instruction)
|
||||
m_cost += 49;
|
||||
}
|
||||
|
||||
size_t GasMeter::costs(Expression const& _expression) const
|
||||
{
|
||||
return combineCosts(GasMeterVisitor::costs(_expression, m_dialect, m_isCreation));
|
||||
}
|
||||
|
||||
size_t GasMeter::instructionCosts(eth::Instruction _instruction) const
|
||||
{
|
||||
return combineCosts(GasMeterVisitor::instructionCosts(_instruction, m_dialect, m_isCreation));
|
||||
}
|
||||
|
||||
size_t GasMeter::combineCosts(std::pair<size_t, size_t> _costs) const
|
||||
{
|
||||
return _costs.first * m_runs + _costs.second;
|
||||
}
|
||||
|
||||
|
||||
pair<size_t, size_t> GasMeterVisitor::costs(
|
||||
Expression const& _expression,
|
||||
EVMDialect const& _dialect,
|
||||
bool _isCreation
|
||||
)
|
||||
{
|
||||
GasMeterVisitor gmv(_dialect, _isCreation);
|
||||
gmv.visit(_expression);
|
||||
return {gmv.m_runGas, gmv.m_dataGas};
|
||||
}
|
||||
|
||||
pair<size_t, size_t> GasMeterVisitor::instructionCosts(
|
||||
dev::eth::Instruction _instruction,
|
||||
EVMDialect const& _dialect,
|
||||
bool _isCreation
|
||||
)
|
||||
{
|
||||
GasMeterVisitor gmv(_dialect, _isCreation);
|
||||
gmv.instructionCostsInternal(_instruction);
|
||||
return {gmv.m_runGas, gmv.m_dataGas};
|
||||
}
|
||||
|
||||
void GasMeterVisitor::operator()(FunctionCall const& _funCall)
|
||||
{
|
||||
ASTWalker::operator()(_funCall);
|
||||
if (BuiltinFunctionForEVM const* f = m_dialect.builtin(_funCall.functionName.name))
|
||||
if (f->instruction)
|
||||
{
|
||||
instructionCostsInternal(*f->instruction);
|
||||
return;
|
||||
}
|
||||
yulAssert(false, "Functions not implemented.");
|
||||
}
|
||||
|
||||
void GasMeterVisitor::operator()(FunctionalInstruction const& _fun)
|
||||
{
|
||||
ASTWalker::operator()(_fun);
|
||||
instructionCostsInternal(_fun.instruction);
|
||||
}
|
||||
|
||||
void GasMeterVisitor::operator()(Literal const& _lit)
|
||||
{
|
||||
m_runGas += dev::eth::GasMeter::runGas(dev::eth::Instruction::PUSH1);
|
||||
m_dataGas +=
|
||||
singleByteDataGas() +
|
||||
size_t(dev::eth::GasMeter::dataGas(dev::toCompactBigEndian(valueOfLiteral(_lit), 1), m_isCreation));
|
||||
}
|
||||
|
||||
void GasMeterVisitor::operator()(Identifier const&)
|
||||
{
|
||||
m_runGas += dev::eth::GasMeter::runGas(dev::eth::Instruction::DUP1);
|
||||
m_dataGas += singleByteDataGas();
|
||||
}
|
||||
|
||||
size_t GasMeterVisitor::singleByteDataGas() const
|
||||
{
|
||||
if (m_isCreation)
|
||||
return dev::eth::GasCosts::txDataNonZeroGas;
|
||||
else
|
||||
return dev::eth::GasCosts::createDataGas;
|
||||
}
|
||||
|
||||
void GasMeterVisitor::instructionCostsInternal(dev::eth::Instruction _instruction)
|
||||
{
|
||||
if (_instruction == eth::Instruction::EXP)
|
||||
m_runGas += dev::eth::GasCosts::expGas + dev::eth::GasCosts::expByteGas(m_dialect.evmVersion());
|
||||
else
|
||||
m_runGas += dev::eth::GasMeter::runGas(_instruction);
|
||||
m_dataGas += singleByteDataGas();
|
||||
}
|
||||
|
||||
void AssignmentCounter::operator()(Assignment const& _assignment)
|
||||
{
|
||||
for (auto const& variable: _assignment.variableNames)
|
||||
|
||||
Reference in New Issue
Block a user