Enable translation of i32 Yul variables/literals to i32 wasm variables/literals

- Until now they were being translated to i64
This commit is contained in:
Kamil Śliwak
2020-06-16 15:36:47 +02:00
parent 50e8d6850f
commit d9ca02b47a
2 changed files with 105 additions and 28 deletions
+12 -4
View File
@@ -24,6 +24,9 @@
#include <libyul/AsmDataForward.h>
#include <libyul/Dialect.h>
#include <libyul/optimiser/NameDispenser.h>
#include <libyul/optimiser/TypeInfo.h>
#include <libsolutil/Common.h>
#include <stack>
#include <map>
@@ -56,10 +59,12 @@ public:
private:
WasmCodeTransform(
Dialect const& _dialect,
Block const& _ast
Block const& _ast,
TypeInfo& _typeInfo
):
m_dialect(_dialect),
m_nameDispenser(_dialect, _ast)
m_nameDispenser(_dialect, _ast),
m_typeInfo(_typeInfo)
{}
std::unique_ptr<wasm::Expression> visit(yul::Expression const& _expression);
@@ -80,10 +85,12 @@ private:
wasm::FunctionDefinition translateFunction(yul::FunctionDefinition const& _funDef);
std::string newLabel();
/// Makes sure that there are at least @a _amount global variables.
void allocateGlobals(size_t _amount);
/// Selects a subset of global variables matching specified sequence of variable types.
/// Defines more global variables of a given type if there's not enough.
std::vector<size_t> allocateGlobals(std::vector<wasm::Type> const& _typesForGlobals);
static wasm::Type translatedType(yul::Type _yulType);
static wasm::Literal makeLiteral(wasm::Type _type, u256 _value);
Dialect const& m_dialect;
NameDispenser m_nameDispenser;
@@ -93,6 +100,7 @@ private:
std::map<YulString, wasm::FunctionImport> m_functionsToImport;
std::string m_functionBodyLabel;
std::stack<std::pair<std::string, std::string>> m_breakContinueLabelNames;
TypeInfo& m_typeInfo;
};
}