From b75c7b577583721a853a01a070f5497d702d17f0 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 31 May 2017 12:39:50 +0200 Subject: Move inline assembly to new abstraction and test both backends. --- test/libsolidity/InlineAssembly.cpp | 39 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 88b2d584..4de2ea81 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -22,7 +22,7 @@ #include "../TestHelper.h" -#include +#include #include #include #include @@ -47,15 +47,20 @@ namespace test namespace { -boost::optional parseAndReturnFirstError(string const& _source, bool _assemble = false, bool _allowWarnings = true) +boost::optional parseAndReturnFirstError( + string const& _source, + bool _assemble = false, + bool _allowWarnings = true, + AssemblyStack::Machine _machine = AssemblyStack::Machine::EVM +) { - assembly::InlineAssemblyStack stack; + AssemblyStack stack; bool success = false; try { - success = stack.parse(std::make_shared(CharStream(_source))); + success = stack.parseAndAnalyze("", _source); if (success && _assemble) - stack.assemble(); + stack.assemble(_machine); } catch (FatalError const&) { @@ -82,14 +87,20 @@ boost::optional parseAndReturnFirstError(string const& _source, bool _ass return {}; } -bool successParse(std::string const& _source, bool _assemble = false, bool _allowWarnings = true) +bool successParse( + string const& _source, + bool _assemble = false, + bool _allowWarnings = true, + AssemblyStack::Machine _machine = AssemblyStack::Machine::EVM +) { - return !parseAndReturnFirstError(_source, _assemble, _allowWarnings); + return !parseAndReturnFirstError(_source, _assemble, _allowWarnings, _machine); } bool successAssemble(string const& _source, bool _allowWarnings = true) { - return successParse(_source, true, _allowWarnings); + return successParse(_source, true, _allowWarnings, AssemblyStack::Machine::EVM) && + successParse(_source, true, _allowWarnings, AssemblyStack::Machine::EVM15); } Error expectError(std::string const& _source, bool _assemble, bool _allowWarnings = false) @@ -102,10 +113,10 @@ Error expectError(std::string const& _source, bool _assemble, bool _allowWarning void parsePrintCompare(string const& _source) { - assembly::InlineAssemblyStack stack; - BOOST_REQUIRE(stack.parse(std::make_shared(CharStream(_source)))); + AssemblyStack stack; + BOOST_REQUIRE(stack.parseAndAnalyze("", _source)); BOOST_REQUIRE(stack.errors().empty()); - BOOST_CHECK_EQUAL(stack.toString(), _source); + BOOST_CHECK_EQUAL(stack.print(), _source); } } @@ -376,10 +387,10 @@ BOOST_AUTO_TEST_CASE(print_string_literal_unicode) { string source = "{ let x := \"\\u1bac\" }"; string parsed = "{\n let x := \"\\xe1\\xae\\xac\"\n}"; - assembly::InlineAssemblyStack stack; - BOOST_REQUIRE(stack.parse(std::make_shared(CharStream(source)))); + AssemblyStack stack; + BOOST_REQUIRE(stack.parseAndAnalyze("", source)); BOOST_REQUIRE(stack.errors().empty()); - BOOST_CHECK_EQUAL(stack.toString(), parsed); + BOOST_CHECK_EQUAL(stack.print(), parsed); parsePrintCompare(parsed); } -- cgit v1.2.3