[ewasm] Clarify custom section handling in BinaryTransform

This commit is contained in:
Alex Beregszaszi 2020-11-09 17:43:41 +00:00
parent 9230ddf110
commit e41700e5f7
2 changed files with 9 additions and 5 deletions

View File

@ -305,13 +305,15 @@ bytes BinaryTransform::run(Module const& _module)
ret += exportSection(functionIDs);
map<string, pair<size_t, size_t>> subModulePosAndSize;
for (auto const& sub: _module.subModules)
for (auto const& [name, module]: _module.subModules)
{
// TODO should we prefix and / or shorten the name?
bytes data = BinaryTransform::run(sub.second);
size_t length = data.size();
ret += customSection(sub.first, move(data));
subModulePosAndSize[sub.first] = {ret.size() - length, length};
bytes data = BinaryTransform::run(module);
size_t const length = data.size();
ret += customSection(name, move(data));
// Skip all the previous sections and the size field of this current custom section.
size_t const offset = ret.size() - length;
subModulePosAndSize[name] = {offset, length};
}
BinaryTransform bt(

View File

@ -112,6 +112,8 @@ private:
std::map<std::string, size_t> const m_globalIDs;
std::map<std::string, size_t> const m_functionIDs;
std::map<std::string, size_t> const m_functionTypes;
/// The map of submodules, where the pair refers to the [offset, length]. The offset is
/// an absolute offset within the resulting assembled bytecode.
std::map<std::string, std::pair<size_t, size_t>> const m_subModulePosAndSize;
std::map<std::string, size_t> m_locals;