diff options
| author | chriseth <chris@ethereum.org> | 2016-08-16 22:27:20 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-16 22:27:20 +0800 |
| commit | 77f442458934d2f0d9ffde34784bb58bd177b3ef (patch) | |
| tree | 5443b8b9414fc21c0551dd57ee30b8c3a2ac4762 /libsolidity/inlineasm | |
| parent | c547f9c24b5bd57840ddd5543ab6e5288ddc5563 (diff) | |
| download | dexon-solidity-77f442458934d2f0d9ffde34784bb58bd177b3ef.tar dexon-solidity-77f442458934d2f0d9ffde34784bb58bd177b3ef.tar.gz dexon-solidity-77f442458934d2f0d9ffde34784bb58bd177b3ef.tar.bz2 dexon-solidity-77f442458934d2f0d9ffde34784bb58bd177b3ef.tar.lz dexon-solidity-77f442458934d2f0d9ffde34784bb58bd177b3ef.tar.xz dexon-solidity-77f442458934d2f0d9ffde34784bb58bd177b3ef.tar.zst dexon-solidity-77f442458934d2f0d9ffde34784bb58bd177b3ef.zip | |
Provide inline assembly to the code generator. (#840)
* Directly usable inline assembly.
* Add missing header.
Diffstat (limited to 'libsolidity/inlineasm')
| -rw-r--r-- | libsolidity/inlineasm/AsmStack.cpp | 22 | ||||
| -rw-r--r-- | libsolidity/inlineasm/AsmStack.h | 8 |
2 files changed, 29 insertions, 1 deletions
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 <memory> #include <libevmasm/Assembly.h> #include <libevmasm/SourceLocation.h> +#include <libsolidity/parsing/Scanner.h> #include <libsolidity/inlineasm/AsmParser.h> #include <libsolidity/inlineasm/AsmCodeGen.h> @@ -32,7 +33,7 @@ using namespace dev; using namespace dev::solidity; using namespace dev::solidity::assembly; -bool InlineAssemblyStack::parse(const std::shared_ptr<Scanner>& _scanner) +bool InlineAssemblyStack::parse(shared_ptr<Scanner> const& _scanner) { m_parserResult = make_shared<Block>(); 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<Scanner>(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 <string> #include <functional> #include <libsolidity/interface/Exceptions.h> +#include <libsolidity/inlineasm/AsmCodeGen.h> namespace dev { @@ -47,6 +48,13 @@ public: bool parse(std::shared_ptr<Scanner> 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: |
