diff --git a/libyul/backends/wasm/BinaryTransform.cpp b/libyul/backends/wasm/BinaryTransform.cpp index 669701471..660ddf44f 100644 --- a/libyul/backends/wasm/BinaryTransform.cpp +++ b/libyul/backends/wasm/BinaryTransform.cpp @@ -255,13 +255,13 @@ bytes BinaryTransform::run(Module const& _module) { map> const types = typeToFunctionMap(_module.imports, _module.functions); - map const globals = enumerateGlobals(_module); - map const functions = enumerateFunctions(_module); + map const globalIDs = enumerateGlobals(_module); + map const functionIDs = enumerateFunctions(_module); map const functionTypes = enumerateFunctionTypes(types); - yulAssert(globals.size() == _module.globals.size(), ""); - yulAssert(functions.size() == _module.imports.size() + _module.functions.size(), ""); - yulAssert(functionTypes.size() == functions.size(), ""); + yulAssert(globalIDs.size() == _module.globals.size(), ""); + yulAssert(functionIDs.size() == _module.imports.size() + _module.functions.size(), ""); + yulAssert(functionTypes.size() == functionIDs.size(), ""); yulAssert(functionTypes.size() >= types.size(), ""); bytes ret{0, 'a', 's', 'm'}; @@ -272,7 +272,7 @@ bytes BinaryTransform::run(Module const& _module) ret += functionSection(_module.functions, functionTypes); ret += memorySection(); ret += globalSection(_module.globals); - ret += exportSection(functions); + ret += exportSection(functionIDs); map> subModulePosAndSize; for (auto const& sub: _module.subModules) @@ -285,8 +285,8 @@ bytes BinaryTransform::run(Module const& _module) } BinaryTransform bt( - move(globals), - move(functions), + move(globalIDs), + move(functionIDs), move(functionTypes), move(subModulePosAndSize) ); @@ -313,7 +313,7 @@ bytes BinaryTransform::operator()(LocalVariable const& _variable) bytes BinaryTransform::operator()(GlobalVariable const& _variable) { - return toBytes(Opcode::GlobalGet) + lebEncode(m_globals.at(_variable.name)); + return toBytes(Opcode::GlobalGet) + lebEncode(m_globalIDs.at(_variable.name)); } bytes BinaryTransform::operator()(BuiltinCall const& _call) @@ -359,7 +359,7 @@ bytes BinaryTransform::operator()(BuiltinCall const& _call) bytes BinaryTransform::operator()(FunctionCall const& _call) { - return visit(_call.arguments) + toBytes(Opcode::Call) + lebEncode(m_functions.at(_call.functionName)); + return visit(_call.arguments) + toBytes(Opcode::Call) + lebEncode(m_functionIDs.at(_call.functionName)); } bytes BinaryTransform::operator()(LocalAssignment const& _assignment) @@ -375,7 +375,7 @@ bytes BinaryTransform::operator()(GlobalAssignment const& _assignment) return std::visit(*this, *_assignment.value) + toBytes(Opcode::GlobalSet) + - lebEncode(m_globals.at(_assignment.variableName)); + lebEncode(m_globalIDs.at(_assignment.variableName)); } bytes BinaryTransform::operator()(If const& _if) @@ -623,11 +623,11 @@ bytes BinaryTransform::globalSection(vector con return makeSection(Section::GLOBAL, std::move(result)); } -bytes BinaryTransform::exportSection(map const& _functions) +bytes BinaryTransform::exportSection(map const& _functionIDs) { bytes result = lebEncode(2); result += encodeName("memory") + toBytes(Export::Memory) + lebEncode(0); - result += encodeName("main") + toBytes(Export::Function) + lebEncode(_functions.at("main")); + result += encodeName("main") + toBytes(Export::Function) + lebEncode(_functionIDs.at("main")); return makeSection(Section::EXPORT, std::move(result)); } diff --git a/libyul/backends/wasm/BinaryTransform.h b/libyul/backends/wasm/BinaryTransform.h index 58ced6a43..f4444b2fd 100644 --- a/libyul/backends/wasm/BinaryTransform.h +++ b/libyul/backends/wasm/BinaryTransform.h @@ -56,13 +56,13 @@ public: private: BinaryTransform( - std::map _globals, - std::map _functions, + std::map _globalIDs, + std::map _functionIDs, std::map _functionTypes, std::map> _subModulePosAndSize ): - m_globals(std::move(_globals)), - m_functions(std::move(_functions)), + m_globalIDs(std::move(_globalIDs)), + m_functionIDs(std::move(_functionIDs)), m_functionTypes(std::move(_functionTypes)), m_subModulePosAndSize(std::move(_subModulePosAndSize)) {} @@ -96,7 +96,7 @@ private: ); static bytes memorySection(); static bytes globalSection(std::vector const& _globals); - static bytes exportSection(std::map const& _functions); + static bytes exportSection(std::map const& _functionIDs); static bytes customSection(std::string const& _name, bytes _data); bytes codeSection(std::vector const& _functions); @@ -107,8 +107,8 @@ private: static bytes encodeName(std::string const& _name); - std::map const m_globals; - std::map const m_functions; + std::map const m_globalIDs; + std::map const m_functionIDs; std::map const m_functionTypes; std::map> const m_subModulePosAndSize;