aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/AssemblyStack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/interface/AssemblyStack.cpp')
-rw-r--r--libsolidity/interface/AssemblyStack.cpp46
1 files changed, 40 insertions, 6 deletions
diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp
index b027ac3c..7dc1edc7 100644
--- a/libsolidity/interface/AssemblyStack.cpp
+++ b/libsolidity/interface/AssemblyStack.cpp
@@ -26,10 +26,14 @@
#include <libsolidity/inlineasm/AsmPrinter.h>
#include <libsolidity/inlineasm/AsmParser.h>
#include <libsolidity/inlineasm/AsmAnalysis.h>
+#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
#include <libsolidity/inlineasm/AsmCodeGen.h>
#include <libevmasm/Assembly.h>
+#include <libjulia/backends/evm/EVMCodeTransform.h>
+#include <libjulia/backends/evm/EVMAssembly.h>
+
using namespace std;
using namespace dev;
using namespace dev::solidity;
@@ -43,6 +47,7 @@ Scanner const& AssemblyStack::scanner() const
bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string const& _source)
{
+ m_errors.clear();
m_analysisSuccessful = false;
m_scanner = make_shared<Scanner>(CharStream(_source), _sourceName);
m_parserResult = assembly::Parser(m_errorReporter, m_language == Language::JULIA).parse(m_scanner);
@@ -50,13 +55,29 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
return false;
solAssert(m_parserResult, "");
+ return analyzeParsed();
+}
+
+bool AssemblyStack::analyze(assembly::Block const& _block, Scanner const* _scanner)
+{
+ m_errors.clear();
+ m_analysisSuccessful = false;
+ if (_scanner)
+ m_scanner = make_shared<Scanner>(*_scanner);
+ m_parserResult = make_shared<assembly::Block>(_block);
+
+ return analyzeParsed();
+}
+
+bool AssemblyStack::analyzeParsed()
+{
m_analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
assembly::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter);
m_analysisSuccessful = analyzer.analyze(*m_parserResult);
return m_analysisSuccessful;
}
-eth::LinkerObject AssemblyStack::assemble(Machine _machine)
+MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
{
solAssert(m_analysisSuccessful, "");
solAssert(m_parserResult, "");
@@ -66,19 +87,32 @@ eth::LinkerObject AssemblyStack::assemble(Machine _machine)
{
case Machine::EVM:
{
- auto assembly = assembly::CodeGenerator(m_errorReporter).assemble(*m_parserResult, *m_analysisInfo);
- return assembly.assemble();
+ MachineAssemblyObject object;
+ eth::Assembly assembly;
+ assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
+ object.bytecode = make_shared<eth::LinkerObject>(assembly.assemble());
+ ostringstream tmp;
+ assembly.stream(tmp);
+ object.assembly = tmp.str();
+ return object;
}
case Machine::EVM15:
- solUnimplemented("EVM 1.5 backend is not yet implemented.");
+ {
+ MachineAssemblyObject object;
+ julia::EVMAssembly assembly(true);
+ julia::CodeTransform(assembly, *m_analysisInfo, true).run(*m_parserResult);
+ object.bytecode = make_shared<eth::LinkerObject>(assembly.finalize());
+ /// TOOD: fill out text representation
+ return object;
+ }
case Machine::eWasm:
solUnimplemented("eWasm backend is not yet implemented.");
}
// unreachable
- return eth::LinkerObject();
+ return MachineAssemblyObject();
}
-string AssemblyStack::print()
+string AssemblyStack::print() const
{
solAssert(m_parserResult, "");
return assembly::AsmPrinter(m_language == Language::JULIA)(*m_parserResult);