mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Introduce MachineAssemblyObject
This commit is contained in:
parent
fe3b46554a
commit
f0d213e6b5
@ -77,7 +77,7 @@ bool AssemblyStack::analyzeParsed()
|
|||||||
return m_analysisSuccessful;
|
return m_analysisSuccessful;
|
||||||
}
|
}
|
||||||
|
|
||||||
eth::LinkerObject AssemblyStack::assemble(Machine _machine) const
|
MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
||||||
{
|
{
|
||||||
solAssert(m_analysisSuccessful, "");
|
solAssert(m_analysisSuccessful, "");
|
||||||
solAssert(m_parserResult, "");
|
solAssert(m_parserResult, "");
|
||||||
@ -87,21 +87,27 @@ eth::LinkerObject AssemblyStack::assemble(Machine _machine) const
|
|||||||
{
|
{
|
||||||
case Machine::EVM:
|
case Machine::EVM:
|
||||||
{
|
{
|
||||||
|
MachineAssemblyObject object;
|
||||||
eth::Assembly assembly;
|
eth::Assembly assembly;
|
||||||
assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
|
assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
|
||||||
return assembly.assemble();
|
object.bytecode = make_shared<eth::LinkerObject>(assembly.assemble());
|
||||||
|
/// TODO: fill out text representation
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
case Machine::EVM15:
|
case Machine::EVM15:
|
||||||
{
|
{
|
||||||
|
MachineAssemblyObject object;
|
||||||
julia::EVMAssembly assembly(true);
|
julia::EVMAssembly assembly(true);
|
||||||
julia::CodeTransform(assembly, *m_analysisInfo, true).run(*m_parserResult);
|
julia::CodeTransform(assembly, *m_analysisInfo, true).run(*m_parserResult);
|
||||||
return assembly.finalize();
|
object.bytecode = make_shared<eth::LinkerObject>(assembly.finalize());
|
||||||
|
/// TOOD: fill out text representation
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
case Machine::eWasm:
|
case Machine::eWasm:
|
||||||
solUnimplemented("eWasm backend is not yet implemented.");
|
solUnimplemented("eWasm backend is not yet implemented.");
|
||||||
}
|
}
|
||||||
// unreachable
|
// unreachable
|
||||||
return eth::LinkerObject();
|
return MachineAssemblyObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
string AssemblyStack::print() const
|
string AssemblyStack::print() const
|
||||||
|
@ -38,6 +38,12 @@ struct AsmAnalysisInfo;
|
|||||||
struct Block;
|
struct Block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MachineAssemblyObject
|
||||||
|
{
|
||||||
|
std::shared_ptr<eth::LinkerObject> bytecode;
|
||||||
|
std::string assembly;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Full assembly stack that can support EVM-assembly and JULIA as input and EVM, EVM1.5 and
|
* Full assembly stack that can support EVM-assembly and JULIA as input and EVM, EVM1.5 and
|
||||||
* eWasm as output.
|
* eWasm as output.
|
||||||
@ -64,7 +70,7 @@ public:
|
|||||||
bool analyze(assembly::Block const& _block, Scanner const* _scanner = nullptr);
|
bool analyze(assembly::Block const& _block, Scanner const* _scanner = nullptr);
|
||||||
|
|
||||||
/// Run the assembly step (should only be called after parseAndAnalyze).
|
/// 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).
|
/// @returns the errors generated during parsing, analysis (and potentially assembly).
|
||||||
ErrorList const& errors() const { return m_errors; }
|
ErrorList const& errors() const { return m_errors; }
|
||||||
|
@ -1082,9 +1082,10 @@ bool CommandLineInterface::assemble(
|
|||||||
"eWasm";
|
"eWasm";
|
||||||
cout << endl << "======= " << src.first << " (" << machine << ") =======" << endl;
|
cout << endl << "======= " << src.first << " (" << machine << ") =======" << endl;
|
||||||
AssemblyStack& stack = assemblyStacks[src.first];
|
AssemblyStack& stack = assemblyStacks[src.first];
|
||||||
|
MachineAssemblyObject object;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cout << stack.assemble(_targetMachine).toHex() << endl;
|
object = stack.assemble(_targetMachine);
|
||||||
}
|
}
|
||||||
catch (Exception const& _exception)
|
catch (Exception const& _exception)
|
||||||
{
|
{
|
||||||
@ -1096,6 +1097,10 @@ bool CommandLineInterface::assemble(
|
|||||||
cerr << "Unknown exception while assembling." << endl;
|
cerr << "Unknown exception while assembling." << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (object.bytecode)
|
||||||
|
cout << object.bytecode->toHex() << endl;
|
||||||
|
else
|
||||||
|
cerr << "No binary representation found." << endl;
|
||||||
cout << stack.print() << endl;
|
cout << stack.print() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user