Increase code cost for branching statements.

This commit is contained in:
chriseth
2019-04-25 17:08:11 +02:00
parent 6292adbde6
commit bf104f718f
5 changed files with 107 additions and 27 deletions
+10
View File
@@ -63,6 +63,16 @@ void CodeSize::visit(Statement const& _statement)
{
if (_statement.type() == typeid(FunctionDefinition) && m_ignoreFunctions)
return;
else if (
_statement.type() == typeid(If) ||
_statement.type() == typeid(Break) ||
_statement.type() == typeid(Continue)
)
m_size += 2;
else if (_statement.type() == typeid(ForLoop))
m_size += 3;
else if (_statement.type() == typeid(Switch))
m_size += 1 + 2 * boost::get<Switch>(_statement).cases.size();
else if (!(
_statement.type() == typeid(Block) ||
_statement.type() == typeid(ExpressionStatement) ||
+5
View File
@@ -37,6 +37,11 @@ namespace yul
* - variable references
* - variable declarations (only the right hand side has a cost)
* - assignments (only the value has a cost)
*
* As another exception, each statement incurs and additional cost of one
* per jump/branch. This means if, break and continue statements have a cost of 2,
* switch statements have a cost of 1 plus the number of cases times two,
* and for loops cost 3.
*/
class CodeSize: public ASTWalker
{