From 77f442458934d2f0d9ffde34784bb58bd177b3ef Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 16 Aug 2016 16:27:20 +0200 Subject: Provide inline assembly to the code generator. (#840) * Directly usable inline assembly. * Add missing header. --- libsolidity/inlineasm/AsmStack.cpp | 22 +++++++++++++++++++++- libsolidity/inlineasm/AsmStack.h | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'libsolidity/inlineasm') diff --git a/libsolidity/inlineasm/AsmStack.cpp b/libsolidity/inlineasm/AsmStack.cpp index c891678b..11c6e28f 100644 --- a/libsolidity/inlineasm/AsmStack.cpp +++ b/libsolidity/inlineasm/AsmStack.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -32,7 +33,7 @@ using namespace dev; using namespace dev::solidity; using namespace dev::solidity::assembly; -bool InlineAssemblyStack::parse(const std::shared_ptr& _scanner) +bool InlineAssemblyStack::parse(shared_ptr const& _scanner) { m_parserResult = make_shared(); Parser parser(m_errors); @@ -49,3 +50,22 @@ eth::Assembly InlineAssemblyStack::assemble() return codeGen.assemble(); } +bool InlineAssemblyStack::parseAndAssemble( + string const& _input, + eth::Assembly& _assembly, + CodeGenerator::IdentifierAccess const& _identifierAccess +) +{ + ErrorList errors; + auto scanner = make_shared(CharStream(_input), "--CODEGEN--"); + auto parserResult = Parser(errors).parse(scanner); + if (!errors.empty()) + return false; + + CodeGenerator(*parserResult, errors).assemble(_assembly, _identifierAccess); + + // At this point, the assembly might be messed up, but we should throw an + // internal compiler error anyway. + return errors.empty(); +} + diff --git a/libsolidity/inlineasm/AsmStack.h b/libsolidity/inlineasm/AsmStack.h index 8a860e46..521f5fe7 100644 --- a/libsolidity/inlineasm/AsmStack.h +++ b/libsolidity/inlineasm/AsmStack.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace dev { @@ -47,6 +48,13 @@ public: bool parse(std::shared_ptr const& _scanner); eth::Assembly assemble(); + /// Parse and assemble a string in one run - for use in Solidity code generation itself. + bool parseAndAssemble( + std::string const& _input, + eth::Assembly& _assembly, + CodeGenerator::IdentifierAccess const& _identifierAccess = CodeGenerator::IdentifierAccess() + ); + ErrorList const& errors() const { return m_errors; } private: -- cgit v1.2.3