aboutsummaryrefslogtreecommitdiffstats
path: root/ExpressionCompiler.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-12 00:35:23 +0800
committerChristian <c@ethdev.com>2014-12-12 00:48:44 +0800
commit66d95abfd9d0a1c3d6516dec39d085d7d96cccbf (patch)
tree53e5437546d139627742a77df25c41bafb9e0005 /ExpressionCompiler.cpp
parent6fcdfdc353cb4100f8a1a3c139e0fa9dc9302397 (diff)
downloaddexon-solidity-66d95abfd9d0a1c3d6516dec39d085d7d96cccbf.tar.gz
dexon-solidity-66d95abfd9d0a1c3d6516dec39d085d7d96cccbf.tar.zst
dexon-solidity-66d95abfd9d0a1c3d6516dec39d085d7d96cccbf.zip
Swap literals to the end if optimizing.
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r--ExpressionCompiler.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index a0b0a54a..a19c9cfd 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -33,9 +33,9 @@ using namespace std;
namespace dev {
namespace solidity {
-void ExpressionCompiler::compileExpression(CompilerContext& _context, Expression const& _expression)
+void ExpressionCompiler::compileExpression(CompilerContext& _context, Expression const& _expression, bool _optimize)
{
- ExpressionCompiler compiler(_context);
+ ExpressionCompiler compiler(_context, _optimize);
_expression.accept(compiler);
}
@@ -145,10 +145,24 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
if (Token::isCompareOp(op) || op == Token::DIV || op == Token::MOD)
cleanupNeeded = true;
- rightExpression.accept(*this);
- appendTypeConversion(*rightExpression.getType(), commonType, cleanupNeeded);
- leftExpression.accept(*this);
- appendTypeConversion(*leftExpression.getType(), commonType, cleanupNeeded);
+ // for commutative operators, push the literal as late as possible to allow improved optimization
+ //@todo this has to be extended for literal expressions
+ bool swap = (m_optimize && Token::isCommutativeOp(op) && dynamic_cast<Literal const*>(&rightExpression)
+ && !dynamic_cast<Literal const*>(&leftExpression));
+ if (swap)
+ {
+ leftExpression.accept(*this);
+ appendTypeConversion(*leftExpression.getType(), commonType, cleanupNeeded);
+ rightExpression.accept(*this);
+ appendTypeConversion(*rightExpression.getType(), commonType, cleanupNeeded);
+ }
+ else
+ {
+ rightExpression.accept(*this);
+ appendTypeConversion(*rightExpression.getType(), commonType, cleanupNeeded);
+ leftExpression.accept(*this);
+ appendTypeConversion(*leftExpression.getType(), commonType, cleanupNeeded);
+ }
if (Token::isCompareOp(op))
appendCompareOperatorCode(op, commonType);
else