aboutsummaryrefslogtreecommitdiffstats
path: root/libyul
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2019-01-09 23:50:41 +0800
committerchriseth <chris@ethereum.org>2019-01-09 23:57:33 +0800
commitedda79eec546674c8c1f0128c63939921f4ff1f2 (patch)
treec5d1dfc2c5884d761fbd6878325916ce6acf37e0 /libyul
parent63319cfdcd7668a75caaacd0d8f3a83a62c31525 (diff)
downloaddexon-solidity-edda79eec546674c8c1f0128c63939921f4ff1f2.tar.gz
dexon-solidity-edda79eec546674c8c1f0128c63939921f4ff1f2.tar.zst
dexon-solidity-edda79eec546674c8c1f0128c63939921f4ff1f2.zip
Variables are free with regards to code size.
Diffstat (limited to 'libyul')
-rw-r--r--libyul/optimiser/Metrics.cpp16
-rw-r--r--libyul/optimiser/Metrics.h9
2 files changed, 22 insertions, 3 deletions
diff --git a/libyul/optimiser/Metrics.cpp b/libyul/optimiser/Metrics.cpp
index a351f1d1..fb275cc3 100644
--- a/libyul/optimiser/Metrics.cpp
+++ b/libyul/optimiser/Metrics.cpp
@@ -25,6 +25,9 @@
#include <libevmasm/Instruction.h>
+#include <libdevcore/Visitor.h>
+
+using namespace std;
using namespace dev;
using namespace yul;
@@ -45,7 +48,7 @@ size_t CodeSize::codeSize(Expression const& _expression)
size_t CodeSize::codeSize(Block const& _block)
{
CodeSize cs;
- cs(_block);
+ cs.visit(_block);
return cs.m_size;
}
@@ -53,14 +56,21 @@ void CodeSize::visit(Statement const& _statement)
{
if (_statement.type() == typeid(FunctionDefinition))
return;
+ else if (!(
+ _statement.type() == typeid(Block) ||
+ _statement.type() == typeid(ExpressionStatement) ||
+ _statement.type() == typeid(Assignment) ||
+ _statement.type() == typeid(VariableDeclaration)
+ ))
+ ++m_size;
- ++m_size;
ASTWalker::visit(_statement);
}
void CodeSize::visit(Expression const& _expression)
{
- ++m_size;
+ if (_expression.type() != typeid(Identifier))
+ ++m_size;
ASTWalker::visit(_expression);
}
diff --git a/libyul/optimiser/Metrics.h b/libyul/optimiser/Metrics.h
index d8a1b279..03e1b62a 100644
--- a/libyul/optimiser/Metrics.h
+++ b/libyul/optimiser/Metrics.h
@@ -30,6 +30,13 @@ namespace yul
* More specifically, the number of AST nodes.
* Ignores function definitions while traversing the AST.
* If you want to know the size of a function, you have to invoke this on its body.
+ *
+ * As an exception, the following AST elements have a cost of zero:
+ * - expression statement (only the expression inside has a cost)
+ * - block (only the statements inside have a cost)
+ * - variable references
+ * - variable declarations (only the right hand side has a cost)
+ * - assignments (only the value has a cost)
*/
class CodeSize: public ASTWalker
{
@@ -39,6 +46,8 @@ public:
static size_t codeSize(Block const& _block);
private:
+ CodeSize() {}
+
void visit(Statement const& _statement) override;
void visit(Expression const& _expression) override;