Provide inline assembly to the code generator. (#840)

* Directly usable inline assembly.

* Add missing header.
This commit is contained in:
chriseth
2016-08-16 16:27:20 +02:00
committed by GitHub
parent c547f9c24b
commit 77f4424589
5 changed files with 87 additions and 1 deletions
+21 -1
View File
@@ -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();
}