aboutsummaryrefslogtreecommitdiffstats
path: root/liblll
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-11-21 18:42:38 +0800
committerchriseth <c@ethdev.com>2016-11-21 18:42:38 +0800
commitb318366e6f16ed6a4274247d09badac4affff8d5 (patch)
treeef8dac7fe9285c1bc0b24ad042a3cda5565a661d /liblll
parent4633f3def897db0f91237f98cf46e5d84fb05e61 (diff)
parent5ebd31ce2d7447917740088eaa22c8c62c453a94 (diff)
downloaddexon-solidity-b318366e6f16ed6a4274247d09badac4affff8d5.tar.gz
dexon-solidity-b318366e6f16ed6a4274247d09badac4affff8d5.tar.zst
dexon-solidity-b318366e6f16ed6a4274247d09badac4affff8d5.zip
Merge remote-tracking branch 'origin/develop' into release
Diffstat (limited to 'liblll')
-rw-r--r--liblll/CMakeLists.txt3
-rw-r--r--liblll/CodeFragment.cpp20
-rw-r--r--liblll/CodeFragment.h5
-rw-r--r--liblll/Compiler.cpp7
-rw-r--r--liblll/Parser.cpp17
5 files changed, 32 insertions, 20 deletions
diff --git a/liblll/CMakeLists.txt b/liblll/CMakeLists.txt
index b9d220ab..db90025a 100644
--- a/liblll/CMakeLists.txt
+++ b/liblll/CMakeLists.txt
@@ -5,9 +5,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB")
aux_source_directory(. SRC_LIST)
-#include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS})
-#include_directories(${Boost_INCLUDE_DIRS})
-
set(EXECUTABLE lll)
file(GLOB HEADERS "*.h")
diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp
index 0f8f2606..d757dcf1 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)
{
@@ -90,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())
@@ -477,7 +474,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
requireSize(2);
requireDeposit(0, 1);
- auto begin = m_asm.append();
+ auto begin = m_asm.append(m_asm.newTag());
m_asm.append(code[0].m_asm);
if (us == "WHILE")
m_asm.append(Instruction::ISZERO);
@@ -492,7 +489,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
requireDeposit(1, 1);
m_asm.append(code[0].m_asm, 0);
- auto begin = m_asm.append();
+ auto begin = m_asm.append(m_asm.newTag());
m_asm.append(code[1].m_asm);
m_asm.append(Instruction::ISZERO);
auto end = m_asm.appendJumpI();
@@ -523,7 +520,8 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
requireMaxSize(3);
requireDeposit(1, 1);
- auto subPush = m_asm.appendSubSize(code[0].assembly(ns));
+ auto subPush = m_asm.newSub(make_shared<Assembly>(code[0].assembly(ns)));
+ m_asm.append(m_asm.newPushSubSize(subPush.data()));
m_asm.append(Instruction::DUP1);
if (code.size() == 3)
{
@@ -584,10 +582,14 @@ 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 == "BYTECODESIZE")
+ {
+ m_asm.appendProgramSize();
+ }
+ else if (us.find_first_of("1234567890") != 0 && us.find_first_not_of("QWERTYUIOPASDFGHJKLZXCVBNM1234567890_-") == string::npos)
m_asm.append((u256)varAddress(s));
else
- error<InvalidOperation>();
+ error<InvalidOperation>("Unsupported keyword: '" + us + "'");
}
}
diff --git a/liblll/CodeFragment.h b/liblll/CodeFragment.h
index e0d48ab7..637d169f 100644
--- a/liblll/CodeFragment.h
+++ b/liblll/CodeFragment.h
@@ -51,6 +51,11 @@ private:
void finalise(CompilerState const& _cs);
template <class T> void error() const { BOOST_THROW_EXCEPTION(T() ); }
+ template <class T> 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;
diff --git a/liblll/Compiler.cpp b/liblll/Compiler.cpp
index 68499106..4008022f 100644
--- a/liblll/Compiler.cpp
+++ b/liblll/Compiler.cpp
@@ -34,8 +34,7 @@ bytes dev::eth::compileLLL(string const& _src, bool _opt, vector<string>* _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<string>* _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();
}
diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp
index 2754e9f5..219d4f54 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<it, string()> strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))];
qi::rule<it, symbol_type()> symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
qi::rule<it, string()> 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<it, bigint()> integer = intstr;
- qi::rule<it, space_type, sp::utree()> atom = integer[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
+ qi::rule<it, sp::utree()> integer = intstr[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))];
+ qi::rule<it, space_type, sp::utree()> atom = integer[qi::_val = qi::_1] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
qi::rule<it, space_type, sp::utree::list_type()> seq = '{' > *element > '}';
qi::rule<it, space_type, sp::utree::list_type()> mload = '@' > element;
qi::rule<it, space_type, sp::utree::list_type()> sload = qi::lit("@@") > element;
@@ -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<it> 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"));
}
}
-