Allow assembly stack to translate its source.

This commit is contained in:
chriseth
2019-11-28 16:15:15 +01:00
parent c1db89161b
commit ccfc1840a9
4 changed files with 45 additions and 24 deletions
+18
View File
@@ -34,6 +34,7 @@
#include <libyul/backends/evm/EVMMetrics.h>
#include <libyul/backends/wasm/WasmDialect.h>
#include <libyul/backends/wasm/EWasmObjectCompiler.h>
#include <libyul/backends/wasm/EVMToEWasmTranslator.h>
#include <libyul/optimiser/Metrics.h>
#include <libyul/ObjectParser.h>
#include <libyul/optimiser/Suite.h>
@@ -102,6 +103,23 @@ void AssemblyStack::optimize()
solAssert(analyzeParsed(), "Invalid source code after optimization.");
}
void AssemblyStack::translate(AssemblyStack::Language _targetLanguage)
{
if (m_language == _targetLanguage)
return;
solAssert(
m_language == Language::StrictAssembly && _targetLanguage == Language::EWasm,
"Invalid language combination"
);
*m_parserResult = EVMToEWasmTranslator(
languageToDialect(m_language, m_evmVersion)
).run(*parserResult());
m_language = _targetLanguage;
}
bool AssemblyStack::analyzeParsed()
{
solAssert(m_parserResult, "");
+3
View File
@@ -81,6 +81,9 @@ public:
/// If the settings (see constructor) disabled the optimizer, nothing is done here.
void optimize();
/// Translate the source to a different language / dialect.
void translate(Language _targetLanguage);
/// Run the assembly step (should only be called after parseAndAnalyze).
MachineAssemblyObject assemble(Machine _machine) const;