From f0d213e6b56da5be8088008bf2ceadb7fd0030f7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 29 May 2017 23:50:46 +0100 Subject: Introduce MachineAssemblyObject --- libsolidity/interface/AssemblyStack.cpp | 14 ++++++++++---- libsolidity/interface/AssemblyStack.h | 8 +++++++- solc/CommandLineInterface.cpp | 7 ++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp index 75877881..6a5e5494 100644 --- a/libsolidity/interface/AssemblyStack.cpp +++ b/libsolidity/interface/AssemblyStack.cpp @@ -77,7 +77,7 @@ bool AssemblyStack::analyzeParsed() return m_analysisSuccessful; } -eth::LinkerObject AssemblyStack::assemble(Machine _machine) const +MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const { solAssert(m_analysisSuccessful, ""); solAssert(m_parserResult, ""); @@ -87,21 +87,27 @@ eth::LinkerObject AssemblyStack::assemble(Machine _machine) const { case Machine::EVM: { + MachineAssemblyObject object; eth::Assembly assembly; assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly); - return assembly.assemble(); + object.bytecode = make_shared(assembly.assemble()); + /// TODO: fill out text representation + return object; } case Machine::EVM15: { + MachineAssemblyObject object; julia::EVMAssembly assembly(true); julia::CodeTransform(assembly, *m_analysisInfo, true).run(*m_parserResult); - return assembly.finalize(); + object.bytecode = make_shared(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() const diff --git a/libsolidity/interface/AssemblyStack.h b/libsolidity/interface/AssemblyStack.h index ee2a334c..2ae596ed 100644 --- a/libsolidity/interface/AssemblyStack.h +++ b/libsolidity/interface/AssemblyStack.h @@ -38,6 +38,12 @@ struct AsmAnalysisInfo; struct Block; } +struct MachineAssemblyObject +{ + std::shared_ptr bytecode; + std::string assembly; +}; + /* * Full assembly stack that can support EVM-assembly and JULIA as input and EVM, EVM1.5 and * eWasm as output. @@ -64,7 +70,7 @@ public: bool analyze(assembly::Block const& _block, Scanner const* _scanner = nullptr); /// Run the assembly step (should only be called after parseAndAnalyze). - eth::LinkerObject assemble(Machine _machine) const; + MachineAssemblyObject assemble(Machine _machine) const; /// @returns the errors generated during parsing, analysis (and potentially assembly). ErrorList const& errors() const { return m_errors; } diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index b2e257ee..e755c3b5 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -1082,9 +1082,10 @@ bool CommandLineInterface::assemble( "eWasm"; cout << endl << "======= " << src.first << " (" << machine << ") =======" << endl; AssemblyStack& stack = assemblyStacks[src.first]; + MachineAssemblyObject object; try { - cout << stack.assemble(_targetMachine).toHex() << endl; + object = stack.assemble(_targetMachine); } catch (Exception const& _exception) { @@ -1096,6 +1097,10 @@ bool CommandLineInterface::assemble( cerr << "Unknown exception while assembling." << endl; return false; } + if (object.bytecode) + cout << object.bytecode->toHex() << endl; + else + cerr << "No binary representation found." << endl; cout << stack.print() << endl; } -- cgit From ca92bda886740f7c59aaf44aaa8a15e25136c9dc Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 29 May 2017 23:58:03 +0100 Subject: Supply text representation of assembly --- libsolidity/interface/AssemblyStack.cpp | 4 +++- solc/CommandLineInterface.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp index 6a5e5494..7dc1edc7 100644 --- a/libsolidity/interface/AssemblyStack.cpp +++ b/libsolidity/interface/AssemblyStack.cpp @@ -91,7 +91,9 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const eth::Assembly assembly; assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly); object.bytecode = make_shared(assembly.assemble()); - /// TODO: fill out text representation + ostringstream tmp; + assembly.stream(tmp); + object.assembly = tmp.str(); return object; } case Machine::EVM15: diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index e755c3b5..7509d1f2 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -1101,6 +1101,10 @@ bool CommandLineInterface::assemble( cout << object.bytecode->toHex() << endl; else cerr << "No binary representation found." << endl; + if (!object.assembly.empty()) + cout << object.assembly << endl; + else + cerr << "No text representation found." << endl; cout << stack.print() << endl; } -- cgit From 762bec9116d74a1022e4d06bd7112e4758a64b10 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 30 May 2017 00:12:38 +0100 Subject: Nicer machine output in CLI --- solc/CommandLineInterface.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 7509d1f2..a79f1633 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -1082,6 +1082,10 @@ bool CommandLineInterface::assemble( "eWasm"; cout << endl << "======= " << src.first << " (" << machine << ") =======" << endl; AssemblyStack& stack = assemblyStacks[src.first]; + + cout << endl << "Pretty printed source:" << endl; + cout << stack.print() << endl; + MachineAssemblyObject object; try { @@ -1097,15 +1101,18 @@ bool CommandLineInterface::assemble( cerr << "Unknown exception while assembling." << endl; return false; } + + cout << endl << "Binary representation:" << endl; if (object.bytecode) cout << object.bytecode->toHex() << endl; else cerr << "No binary representation found." << endl; + + cout << endl << "Text representation:" << endl; if (!object.assembly.empty()) cout << object.assembly << endl; else cerr << "No text representation found." << endl; - cout << stack.print() << endl; } return true; -- cgit