aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/interface')
-rw-r--r--libsolidity/interface/AssemblyStack.cpp29
-rw-r--r--libsolidity/interface/AssemblyStack.h9
2 files changed, 31 insertions, 7 deletions
diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp
index fbfb3472..b97e00ae 100644
--- a/libsolidity/interface/AssemblyStack.cpp
+++ b/libsolidity/interface/AssemblyStack.cpp
@@ -32,6 +32,7 @@
#include <libyul/backends/evm/EVMObjectCompiler.h>
#include <libyul/backends/evm/EVMCodeTransform.h>
#include <libyul/backends/evm/EVMAssembly.h>
+#include <libyul/backends/evm/EVMDialect.h>
#include <libyul/ObjectParser.h>
#include <libevmasm/Assembly.h>
@@ -45,14 +46,14 @@ using namespace dev::solidity;
namespace
{
-yul::Dialect languageToDialect(AssemblyStack::Language _language)
+shared_ptr<yul::Dialect> languageToDialect(AssemblyStack::Language _language)
{
switch (_language)
{
case AssemblyStack::Language::Assembly:
- return yul::Dialect::looseAssemblyForEVM();
+ return yul::EVMDialect::looseAssemblyForEVM();
case AssemblyStack::Language::StrictAssembly:
- return yul::Dialect::strictAssemblyForEVMObjects();
+ return yul::EVMDialect::strictAssemblyForEVMObjects();
case AssemblyStack::Language::Yul:
return yul::Dialect::yul();
}
@@ -112,6 +113,22 @@ bool AssemblyStack::analyzeParsed(yul::Object& _object)
return success;
}
+void AssemblyStack::compileEVM(yul::AbstractAssembly& _assembly, bool _evm15, bool _optimize) const
+{
+ shared_ptr<yul::EVMDialect> dialect;
+
+ if (m_language == Language::Assembly)
+ dialect = yul::EVMDialect::looseAssemblyForEVM();
+ else if (m_language == AssemblyStack::Language::StrictAssembly)
+ dialect = yul::EVMDialect::strictAssemblyForEVMObjects();
+ else if (m_language == AssemblyStack::Language::Yul)
+ dialect = yul::EVMDialect::yulForEVM();
+ else
+ solAssert(false, "Invalid language.");
+
+ yul::EVMObjectCompiler::compile(*m_parserResult, _assembly, *dialect, _evm15, _optimize);
+}
+
void AssemblyStack::optimize(yul::Object& _object)
{
solAssert(_object.code, "");
@@ -122,7 +139,7 @@ void AssemblyStack::optimize(yul::Object& _object)
yul::OptimiserSuite::run(*_object.code, *_object.analysisInfo);
}
-MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
+MachineAssemblyObject AssemblyStack::assemble(Machine _machine, bool _optimize) const
{
solAssert(m_analysisSuccessful, "");
solAssert(m_parserResult, "");
@@ -136,7 +153,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
MachineAssemblyObject object;
eth::Assembly assembly;
EthAssemblyAdapter adapter(assembly);
- yul::EVMObjectCompiler::compile(*m_parserResult, adapter, m_language == Language::Yul, false);
+ compileEVM(adapter, false, _optimize);
object.bytecode = make_shared<eth::LinkerObject>(assembly.assemble());
object.assembly = assembly.assemblyString();
return object;
@@ -145,7 +162,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
{
MachineAssemblyObject object;
yul::EVMAssembly assembly(true);
- yul::EVMObjectCompiler::compile(*m_parserResult, assembly, m_language == Language::Yul, true);
+ compileEVM(assembly, true, _optimize);
object.bytecode = make_shared<eth::LinkerObject>(assembly.finalize());
/// TODO: fill out text representation
return object;
diff --git a/libsolidity/interface/AssemblyStack.h b/libsolidity/interface/AssemblyStack.h
index 485ec1e7..c8e3d35a 100644
--- a/libsolidity/interface/AssemblyStack.h
+++ b/libsolidity/interface/AssemblyStack.h
@@ -36,6 +36,10 @@ namespace langutil
{
class Scanner;
}
+namespace yul
+{
+class AbstractAssembly;
+}
namespace dev
{
@@ -73,7 +77,8 @@ public:
void optimize();
/// Run the assembly step (should only be called after parseAndAnalyze).
- MachineAssemblyObject assemble(Machine _machine) const;
+ /// @param _optimize does not run the optimizer but performs optimized code generation.
+ MachineAssemblyObject assemble(Machine _machine, bool _optimize = false) const;
/// @returns the errors generated during parsing, analysis (and potentially assembly).
langutil::ErrorList const& errors() const { return m_errors; }
@@ -85,6 +90,8 @@ private:
bool analyzeParsed();
bool analyzeParsed(yul::Object& _object);
+ void compileEVM(yul::AbstractAssembly& _assembly, bool _evm15, bool _optimize) const;
+
void optimize(yul::Object& _object);
Language m_language = Language::Assembly;