diff options
-rw-r--r-- | libsolidity/inlineasm/AsmAnalysis.cpp | 31 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmAnalysis.h | 2 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmCodeGen.cpp | 20 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmData.h | 4 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmParser.cpp | 36 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmPrinter.cpp | 6 | ||||
-rw-r--r-- | test/libsolidity/InlineAssembly.cpp | 10 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 27 |
8 files changed, 4 insertions, 132 deletions
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index a21c50d1..4296d3a7 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -127,36 +127,7 @@ bool AsmAnalyzer::operator()(Label const& _item) )); return false; } - bool success = true; - if (!_item.stackInfo.empty()) - { - Scope::Label& label = boost::get<Scope::Label>(m_currentScope->identifiers[_item.name]); - if (_item.stackInfo.size() == 1) - try - { - label.stackAdjustment = boost::lexical_cast<int>(_item.stackInfo[0]); - label.resetStackHeight = false; - return true; - } - catch (boost::bad_lexical_cast const&) - { - // Interpret as variable name - } - label.resetStackHeight = true; - for (auto const& stackItem: _item.stackInfo) - if (!stackItem.empty()) - if (!m_currentScope->registerVariable(stackItem)) - { - //@TODO secondary location - m_errors.push_back(make_shared<Error>( - Error::Type::DeclarationError, - "Variable name " + stackItem + " already taken in this scope.", - _item.location - )); - success = false; - } - } - return success; + return true; } bool AsmAnalyzer::operator()(FunctionalAssignment const& _assignment) diff --git a/libsolidity/inlineasm/AsmAnalysis.h b/libsolidity/inlineasm/AsmAnalysis.h index cd46cd73..9726210d 100644 --- a/libsolidity/inlineasm/AsmAnalysis.h +++ b/libsolidity/inlineasm/AsmAnalysis.h @@ -82,8 +82,6 @@ struct Scope struct Label { size_t id = unassignedLabelId; - int stackAdjustment = 0; - bool resetStackHeight = false; static const size_t errorLabelId = -1; static const size_t unassignedLabelId = 0; }; diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index 69ce9507..78a9ee27 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -188,26 +188,6 @@ public: solAssert(m_scope.identifiers.count(_label.name), ""); Scope::Label& label = boost::get<Scope::Label>(m_scope.identifiers[_label.name]); assignLabelIdIfUnset(label); - if (label.resetStackHeight) - { - size_t numVariables = boost::range::count_if( - m_scope.identifiers | boost::adaptors::map_values, - [](Scope::Identifier const& var) { return var.type() == typeid(Scope::Variable) && boost::get<Scope::Variable>(var).active; } - ); - numVariables += boost::count_if(_label.stackInfo, [](string const& s) { return !s.empty(); }); - m_state.assembly.setDeposit(m_initialDeposit + numVariables); - } - else if (label.stackAdjustment != 0) - m_state.assembly.adjustDeposit(label.stackAdjustment); - int height = m_state.assembly.deposit(); - for (auto const& identifier: _label.stackInfo | boost::adaptors::reversed) - if (!identifier.empty()) - { - solAssert(m_scope.identifiers.count(identifier), ""); - Scope::Variable& var = boost::get<Scope::Variable>(m_scope.identifiers[identifier]); - var.active = true; - var.stackHeight = --height; - } m_state.assembly.append(eth::AssemblyItem(eth::Tag, label.id)); } void operator()(assembly::Assignment const& _assignment) diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h index 5969bf96..d61b5803 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libsolidity/inlineasm/AsmData.h @@ -42,8 +42,8 @@ struct Literal { SourceLocation location; bool isNumber; std::string value; }; /// External / internal identifier or label reference struct Identifier { SourceLocation location; std::string name; }; struct FunctionalInstruction; -/// Jump label ("name:" or "name [x, y, z]:" or "name [-3]:") -struct Label { SourceLocation location; std::string name; std::vector<std::string> stackInfo; }; +/// Jump label ("name:") +struct Label { SourceLocation location; std::string name; }; /// Assignemnt (":= x", moves stack top into x, potentially multiple slots) struct Assignment { SourceLocation location; Identifier variableName; }; struct FunctionalAssignment; diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index 9f24d9fb..0fc0a34f 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -121,42 +121,6 @@ assembly::Statement Parser::parseStatement() return label; } } - case Token::LBrack: - { - if (statement.type() != typeid(assembly::Identifier)) - fatalParserError("Label name must precede \"[\"."); - assembly::Identifier const& identifier = boost::get<assembly::Identifier>(statement); - Label label = createWithLocation<Label>(identifier.location); - label.name = identifier.name; - m_scanner->next(); - if (m_scanner->currentToken() == Token::Number) - { - label.stackInfo.push_back(m_scanner->currentLiteral()); - m_scanner->next(); - } - else if (m_scanner->currentToken() == Token::Sub) - { - m_scanner->next(); - label.stackInfo.push_back("-" + m_scanner->currentLiteral()); - expectToken(Token::Number); - } - else if (m_scanner->currentToken() != Token::RBrack) - while (true) - { - label.stackInfo.push_back(expectAsmIdentifier()); - if (m_scanner->currentToken() == Token::RBrack) - break; - expectToken(Token::Comma); - } - // Push an empty string to signify that there were brackets, like in - // "name[]:", which just resets the stack height to the height of the local variables. - if (label.stackInfo.empty()) - label.stackInfo.push_back(""); - expectToken(Token::RBrack); - label.location.end = endPosition(); - expectToken(Token::Colon); - return label; - } default: break; } diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index 5ec83281..a70b0b78 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -94,11 +94,7 @@ string AsmPrinter::operator()(assembly::FunctionalInstruction const& _functional string AsmPrinter::operator()(assembly::Label const& _label) { - return _label.name + ( - !_label.stackInfo.empty() ? - "[" + boost::algorithm::join(_label.stackInfo, ", ") + "]" : - string() - ) + ":"; + return _label.name + ":"; } string AsmPrinter::operator()(assembly::Assignment const& _assignment) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 824fce95..9035599b 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -200,11 +200,6 @@ BOOST_AUTO_TEST_CASE(blocks) BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }")); } -BOOST_AUTO_TEST_CASE(labels_with_stack_info) -{ - BOOST_CHECK(successParse("{ x[-1]: y[a]: z[d, e]: h[100]: g[]: }")); -} - BOOST_AUTO_TEST_CASE(function_definitions) { BOOST_CHECK(successParse("{ function f() { } function g(a) -> (x) { } }")); @@ -249,11 +244,6 @@ BOOST_AUTO_TEST_CASE(print_label) parsePrintCompare("{\n loop:\n jump(loop)\n}"); } -BOOST_AUTO_TEST_CASE(print_label_with_stack) -{ - parsePrintCompare("{\n loop[x, y]:\n other[-2]:\n third[10]:\n}"); -} - BOOST_AUTO_TEST_CASE(print_assignments) { parsePrintCompare("{\n let x := mul(2, 3)\n 7\n =: x\n x := add(1, 2)\n}"); diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index d2028344..cb0cc168 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7418,33 +7418,6 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_access) BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(10))); } -BOOST_AUTO_TEST_CASE(inline_assembly_labels_with_stack_info) -{ - char const* sourceCode = R"( - contract C { - function f(uint y) { - assembly { - y 7 - jump(fun) - exit[-1]: - y add - 0 mstore - return(0, 0x20) - fun: - { - entry[a, b]: - a := div(a, b) - pop - jump(exit) - } - } - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - BOOST_CHECK(callContractFunction("f(uint256)", u256(15)) == encodeArgs(15 / 7 + 15)); -} - BOOST_AUTO_TEST_CASE(index_access_with_type_conversion) { // Test for a bug where higher order bits cleanup was not done for array index access. |