mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[ewasm] Support compiling data subobjects
This commit is contained in:
parent
e41700e5f7
commit
6e11754c8b
@ -315,6 +315,14 @@ bytes BinaryTransform::run(Module const& _module)
|
|||||||
size_t const offset = ret.size() - length;
|
size_t const offset = ret.size() - length;
|
||||||
subModulePosAndSize[name] = {offset, length};
|
subModulePosAndSize[name] = {offset, length};
|
||||||
}
|
}
|
||||||
|
for (auto const& [name, data]: _module.customSections)
|
||||||
|
{
|
||||||
|
size_t const length = data.size();
|
||||||
|
ret += customSection(name, 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(
|
BinaryTransform bt(
|
||||||
move(globalIDs),
|
move(globalIDs),
|
||||||
|
@ -44,6 +44,11 @@ string TextTransform::run(wasm::Module const& _module)
|
|||||||
" ;; sub-module \"" +
|
" ;; sub-module \"" +
|
||||||
sub.first +
|
sub.first +
|
||||||
"\" will be encoded as custom section in binary here, but is skipped in text mode.\n";
|
"\" will be encoded as custom section in binary here, but is skipped in text mode.\n";
|
||||||
|
for (auto const& data: _module.customSections)
|
||||||
|
ret +=
|
||||||
|
" ;; custom-section \"" +
|
||||||
|
data.first +
|
||||||
|
"\" will be encoded as custom section in binary here, but is skipped in text mode.\n";
|
||||||
for (wasm::FunctionImport const& imp: _module.imports)
|
for (wasm::FunctionImport const& imp: _module.imports)
|
||||||
{
|
{
|
||||||
ret += " (import \"" + imp.module + "\" \"" + imp.externalName + "\" (func $" + imp.internalName;
|
ret += " (import \"" + imp.module + "\" \"" + imp.externalName + "\" (func $" + imp.internalName;
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <libsolutil/Common.h>
|
||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -108,6 +110,7 @@ struct Module
|
|||||||
std::vector<FunctionImport> imports;
|
std::vector<FunctionImport> imports;
|
||||||
std::vector<FunctionDefinition> functions;
|
std::vector<FunctionDefinition> functions;
|
||||||
std::map<std::string, Module> subModules;
|
std::map<std::string, Module> subModules;
|
||||||
|
std::map<std::string, bytes> customSections;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,10 @@ wasm::Module WasmObjectCompiler::run(Object& _object)
|
|||||||
for (auto& subNode: _object.subObjects)
|
for (auto& subNode: _object.subObjects)
|
||||||
if (Object* subObject = dynamic_cast<Object*>(subNode.get()))
|
if (Object* subObject = dynamic_cast<Object*>(subNode.get()))
|
||||||
module.subModules[subObject->name.str()] = run(*subObject);
|
module.subModules[subObject->name.str()] = run(*subObject);
|
||||||
|
else if (Data* subObject = dynamic_cast<Data*>(subNode.get()))
|
||||||
|
module.customSections[subObject->name.str()] = subObject->data;
|
||||||
else
|
else
|
||||||
yulAssert(false, "Data is not yet supported for Wasm.");
|
yulAssert(false, "");
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user