diff options
Diffstat (limited to 'Compiler.cpp')
-rw-r--r-- | Compiler.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/Compiler.cpp b/Compiler.cpp index e691394c..2f75d2ea 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -74,6 +74,7 @@ void Compiler::initializeContext(ContractDefinition const& _contract, m_context.setCompiledContracts(_contracts); m_context.setInheritanceHierarchy(_contract.getLinearizedBaseContracts()); registerStateVariables(_contract); + m_context.resetVisitedNodes(&_contract); } void Compiler::packIntoContractCreator(ContractDefinition const& _contract, CompilerContext const& _runtimeContext) @@ -128,6 +129,7 @@ void Compiler::packIntoContractCreator(ContractDefinition const& _contract, Comp void Compiler::appendBaseConstructorCall(FunctionDefinition const& _constructor, vector<ASTPointer<Expression>> const& _arguments) { + CompilerContext::LocationSetter locationSetter(m_context, &_constructor); FunctionType constructorType(_constructor); eth::AssemblyItem returnLabel = m_context.pushNewTag(); for (unsigned i = 0; i < _arguments.size(); ++i) @@ -138,6 +140,7 @@ void Compiler::appendBaseConstructorCall(FunctionDefinition const& _constructor, void Compiler::appendConstructorCall(FunctionDefinition const& _constructor) { + CompilerContext::LocationSetter locationSetter(m_context, &_constructor); eth::AssemblyItem returnTag = m_context.pushNewTag(); // copy constructor arguments from code to memory and then to stack, they are supplied after the actual program unsigned argumentSize = 0; @@ -247,7 +250,7 @@ void Compiler::appendReturnValuePacker(TypePointers const& _typeParameters) for (TypePointer const& type: _typeParameters) { CompilerUtils(m_context).copyToStackTop(stackDepth, *type); - ExpressionCompiler::appendTypeConversion(m_context, *type, *type, true); + ExpressionCompiler(m_context, m_optimize).appendTypeConversion(*type, *type, true); bool const c_padToWords = true; dataOffset += CompilerUtils(m_context).storeInMemory(dataOffset, *type, c_padToWords); stackDepth -= type->getSizeOnStack(); @@ -267,25 +270,27 @@ void Compiler::initializeStateVariables(ContractDefinition const& _contract) { for (ASTPointer<VariableDeclaration> const& variable: _contract.getStateVariables()) if (variable->getValue()) - ExpressionCompiler::appendStateVariableInitialization(m_context, *variable); + ExpressionCompiler(m_context, m_optimize).appendStateVariableInitialization(*variable); } bool Compiler::visit(VariableDeclaration const& _variableDeclaration) { solAssert(_variableDeclaration.isStateVariable(), "Compiler visit to non-state variable declaration."); + CompilerContext::LocationSetter locationSetter(m_context, &_variableDeclaration); m_context.startFunction(_variableDeclaration); m_breakTags.clear(); m_continueTags.clear(); m_context << m_context.getFunctionEntryLabel(_variableDeclaration); - ExpressionCompiler::appendStateVariableAccessor(m_context, _variableDeclaration); + ExpressionCompiler(m_context, m_optimize).appendStateVariableAccessor(_variableDeclaration); return false; } bool Compiler::visit(FunctionDefinition const& _function) { + CompilerContext::LocationSetter locationSetter(m_context, &_function); //@todo to simplify this, the calling convention could by changed such that // caller puts: [retarg0] ... [retargm] [return address] [arg0] ... [argn] // although note that this reduces the size of the visible stack @@ -355,7 +360,7 @@ bool Compiler::visit(FunctionDefinition const& _function) bool Compiler::visit(IfStatement const& _ifStatement) { StackHeightChecker checker(m_context); - + CompilerContext::LocationSetter locationSetter(m_context, &_ifStatement); compileExpression(_ifStatement.getCondition()); eth::AssemblyItem trueTag = m_context.appendConditionalJump(); if (_ifStatement.getFalseStatement()) @@ -372,7 +377,7 @@ bool Compiler::visit(IfStatement const& _ifStatement) bool Compiler::visit(WhileStatement const& _whileStatement) { StackHeightChecker checker(m_context); - + CompilerContext::LocationSetter locationSetter(m_context, &_whileStatement); eth::AssemblyItem loopStart = m_context.newTag(); eth::AssemblyItem loopEnd = m_context.newTag(); m_continueTags.push_back(loopStart); @@ -398,7 +403,7 @@ bool Compiler::visit(WhileStatement const& _whileStatement) bool Compiler::visit(ForStatement const& _forStatement) { StackHeightChecker checker(m_context); - + CompilerContext::LocationSetter locationSetter(m_context, &_forStatement); eth::AssemblyItem loopStart = m_context.newTag(); eth::AssemblyItem loopEnd = m_context.newTag(); m_continueTags.push_back(loopStart); @@ -433,15 +438,17 @@ bool Compiler::visit(ForStatement const& _forStatement) return false; } -bool Compiler::visit(Continue const&) +bool Compiler::visit(Continue const& _continueStatement) { + CompilerContext::LocationSetter locationSetter(m_context, &_continueStatement); if (!m_continueTags.empty()) m_context.appendJumpTo(m_continueTags.back()); return false; } -bool Compiler::visit(Break const&) +bool Compiler::visit(Break const& _breakStatement) { + CompilerContext::LocationSetter locationSetter(m_context, &_breakStatement); if (!m_breakTags.empty()) m_context.appendJumpTo(m_breakTags.back()); return false; @@ -449,6 +456,7 @@ bool Compiler::visit(Break const&) bool Compiler::visit(Return const& _return) { + CompilerContext::LocationSetter locationSetter(m_context, &_return); //@todo modifications are needed to make this work with functions returning multiple values if (Expression const* expression = _return.getExpression()) { @@ -467,6 +475,7 @@ bool Compiler::visit(Return const& _return) bool Compiler::visit(VariableDeclarationStatement const& _variableDeclarationStatement) { StackHeightChecker checker(m_context); + CompilerContext::LocationSetter locationSetter(m_context, &_variableDeclarationStatement); if (Expression const* expression = _variableDeclarationStatement.getExpression()) { compileExpression(*expression, _variableDeclarationStatement.getDeclaration().getType()); @@ -479,6 +488,7 @@ bool Compiler::visit(VariableDeclarationStatement const& _variableDeclarationSta bool Compiler::visit(ExpressionStatement const& _expressionStatement) { StackHeightChecker checker(m_context); + CompilerContext::LocationSetter locationSetter(m_context, &_expressionStatement); Expression const& expression = _expressionStatement.getExpression(); compileExpression(expression); CompilerUtils(m_context).popStackElement(*expression.getType()); @@ -486,9 +496,10 @@ bool Compiler::visit(ExpressionStatement const& _expressionStatement) return false; } -bool Compiler::visit(PlaceholderStatement const&) +bool Compiler::visit(PlaceholderStatement const& _placeholderStatement) { StackHeightChecker checker(m_context); + CompilerContext::LocationSetter locationSetter(m_context, &_placeholderStatement); ++m_modifierDepth; appendModifierOrFunctionCode(); --m_modifierDepth; @@ -504,8 +515,8 @@ void Compiler::appendModifierOrFunctionCode() else { ASTPointer<ModifierInvocation> const& modifierInvocation = m_currentFunction->getModifiers()[m_modifierDepth]; - ModifierDefinition const& modifier = m_context.getFunctionModifier(modifierInvocation->getName()->getName()); + CompilerContext::LocationSetter locationSetter(m_context, &modifier); solAssert(modifier.getParameters().size() == modifierInvocation->getArguments().size(), ""); for (unsigned i = 0; i < modifier.getParameters().size(); ++i) { @@ -530,9 +541,10 @@ void Compiler::appendModifierOrFunctionCode() void Compiler::compileExpression(Expression const& _expression, TypePointer const& _targetType) { - ExpressionCompiler::compileExpression(m_context, _expression, m_optimize); + ExpressionCompiler expressionCompiler(m_context, m_optimize); + expressionCompiler.compile(_expression); if (_targetType) - ExpressionCompiler::appendTypeConversion(m_context, *_expression.getType(), *_targetType); + expressionCompiler.appendTypeConversion(*_expression.getType(), *_targetType); } } |