From b269202b73dc6a22c0f6adc849d8fc063119e346 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 26 Oct 2016 13:47:32 +0100 Subject: [PATCH 1/7] LLL: support passing error reasons --- liblll/CodeFragment.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/liblll/CodeFragment.h b/liblll/CodeFragment.h index e0d48ab7b..637d169fb 100644 --- a/liblll/CodeFragment.h +++ b/liblll/CodeFragment.h @@ -51,6 +51,11 @@ private: void finalise(CompilerState const& _cs); template void error() const { BOOST_THROW_EXCEPTION(T() ); } + template void error(std::string const& reason) const { + auto err = T(); + err << errinfo_comment(reason); + BOOST_THROW_EXCEPTION(err); + } void constructOperation(sp::utree const& _t, CompilerState& _s); bool m_finalised = false; From 9b65a79cb35860f4de6c653ded0e6ab58cf6d57e Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 26 Oct 2016 13:48:13 +0100 Subject: [PATCH 2/7] LLL: report back unsupported keywords --- liblll/CodeFragment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 0f8f26061..0ba072a4c 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -587,7 +587,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) else if (us.find_first_of("1234567890") != 0 && us.find_first_not_of("QWERTYUIOPASDFGHJKLZXCVBNM1234567890_") == string::npos) m_asm.append((u256)varAddress(s)); else - error(); + error("Unsupported keyword: '" + us + "'"); } } From b24eed1c3e2f4527444b33cf1bba418480934f64 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 26 Oct 2016 14:27:39 +0100 Subject: [PATCH 3/7] LLL: remove unneeded includes --- liblll/CodeFragment.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 0ba072a4c..ac9eac37a 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -35,9 +35,6 @@ using namespace std; using namespace dev; using namespace dev::eth; -namespace qi = boost::spirit::qi; -namespace px = boost::phoenix; -namespace sp = boost::spirit; void CodeFragment::finalise(CompilerState const& _cs) { From 5be1996ea5bc73ef37df55cdd28504de5ec357c4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 26 Oct 2016 14:28:19 +0100 Subject: [PATCH 4/7] LLL: update exception message --- liblll/Compiler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/liblll/Compiler.cpp b/liblll/Compiler.cpp index 684991061..4008022f8 100644 --- a/liblll/Compiler.cpp +++ b/liblll/Compiler.cpp @@ -34,8 +34,7 @@ bytes dev::eth::compileLLL(string const& _src, bool _opt, vector* _error { CompilerState cs; cs.populateStandard(); - auto f = CodeFragment::compile(_src, cs); - bytes ret = f.assembly(cs).optimise(_opt).assemble().bytecode; + bytes ret = CodeFragment::compile(_src, cs).assembly(cs).optimise(_opt).assemble().bytecode; for (auto i: cs.treesToKill) killBigints(i); return ret; @@ -59,7 +58,7 @@ bytes dev::eth::compileLLL(string const& _src, bool _opt, vector* _error catch (...) { if (_errors) - _errors->push_back("Internal parse exception."); + _errors->push_back("Internal compiler exception."); } return bytes(); } @@ -93,7 +92,7 @@ std::string dev::eth::compileLLLToAsm(std::string const& _src, bool _opt, std::v catch (...) { if (_errors) - _errors->push_back("Internal parse exception."); + _errors->push_back("Internal compiler exception."); } return string(); } From b92bb41be78c4277a16974353ec2e21ea8cd5f7b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 26 Oct 2016 14:29:08 +0100 Subject: [PATCH 5/7] LLL: catch and display spirit::qi errors --- liblll/Parser.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index 2754e9f59..7d594e31e 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -135,10 +135,19 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) s.push_back(i); } auto ret = s.cbegin(); - qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out); + try + { + qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out); + } + catch (qi::expectation_failure const& e) + { + std::string fragment(e.first, e.last); + std::string loc = std::to_string(std::distance(s.cbegin(), e.first) - 1); + std::string reason("Lexer failure at " + loc + ": '" + fragment + "'"); + BOOST_THROW_EXCEPTION(ParserException() << errinfo_comment(reason)); + } for (auto i = ret; i != s.cend(); ++i) if (!isspace(*i)) { BOOST_THROW_EXCEPTION(ParserException() << errinfo_comment("Non-whitespace left in parser")); } } - From dc5e05681dfbacfcdbd875ce48c8839fcab20271 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 1 Nov 2016 01:01:35 +0000 Subject: [PATCH 6/7] LLL: simplify integer parsing --- liblll/Parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index 7d594e31e..219d4f54b 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -101,8 +101,8 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) qi::rule strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))]; qi::rule symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))]; qi::rule intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]]; - qi::rule integer = intstr; - qi::rule atom = integer[qi::_val = px::construct(px::new_(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1]; + qi::rule integer = intstr[qi::_val = px::construct(px::new_(qi::_1))]; + qi::rule atom = integer[qi::_val = qi::_1] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1]; qi::rule seq = '{' > *element > '}'; qi::rule mload = '@' > element; qi::rule sload = qi::lit("@@") > element; From ac3c8a553a0b943984742f6b12d9d0a3cabcb877 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 1 Nov 2016 02:06:40 +0000 Subject: [PATCH 7/7] LLL: properly support dashes (-) as part of variable names --- liblll/CodeFragment.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index ac9eac37a..bc53d7777 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -87,7 +87,7 @@ CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowAS m_asm.append(_s.args.at(s).m_asm); else if (_s.outers.count(s)) m_asm.append(_s.outers.at(s).m_asm); - else if (us.find_first_of("1234567890") != 0 && us.find_first_not_of("QWERTYUIOPASDFGHJKLZXCVBNM1234567890_") == string::npos) + else if (us.find_first_of("1234567890") != 0 && us.find_first_not_of("QWERTYUIOPASDFGHJKLZXCVBNM1234567890_-") == string::npos) { auto it = _s.vars.find(s); if (it == _s.vars.end()) @@ -581,7 +581,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) { m_asm.appendJump(m_asm.errorTag()); } - else if (us.find_first_of("1234567890") != 0 && us.find_first_not_of("QWERTYUIOPASDFGHJKLZXCVBNM1234567890_") == string::npos) + else if (us.find_first_of("1234567890") != 0 && us.find_first_not_of("QWERTYUIOPASDFGHJKLZXCVBNM1234567890_-") == string::npos) m_asm.append((u256)varAddress(s)); else error("Unsupported keyword: '" + us + "'");