summaryrefslogtreecommitdiff
path: root/src/ir/module-utils.h
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-04-02 10:36:19 -0700
committerGitHub <noreply@github.com>2020-04-02 10:36:19 -0700
commit80c5164e1f50ed26e6fab373a563fd7a84135429 (patch)
treeac944407ac6bf1b26e524d31a3db8c410e4599e7 /src/ir/module-utils.h
parent702b99508487bc5f56c409d890644b3b9212ae81 (diff)
downloadbinaryen-80c5164e1f50ed26e6fab373a563fd7a84135429.tar.gz
binaryen-80c5164e1f50ed26e6fab373a563fd7a84135429.tar.bz2
binaryen-80c5164e1f50ed26e6fab373a563fd7a84135429.zip
Tuple globals (#2718)
Since it wasn't easy to support tuples in Asyncify's call support using temporary functions, we decided to allow tuple-typed globals after all. This PR adds support for parsing, printing, lowering, and interpreting tuple globals and also adds validation ensuring that imported and exported globals do not have tuple types.
Diffstat (limited to 'src/ir/module-utils.h')
-rw-r--r--src/ir/module-utils.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h
index be924f742..485bc4833 100644
--- a/src/ir/module-utils.h
+++ b/src/ir/module-utils.h
@@ -35,8 +35,8 @@ namespace ModuleUtils {
// just use them directly).
struct BinaryIndexes {
std::unordered_map<Name, Index> functionIndexes;
- std::unordered_map<Name, Index> globalIndexes;
std::unordered_map<Name, Index> eventIndexes;
+ std::unordered_map<Name, Index> globalIndexes;
BinaryIndexes(Module& wasm) {
auto addIndexes = [&](auto& source, auto& indexes) {
@@ -56,8 +56,27 @@ struct BinaryIndexes {
}
};
addIndexes(wasm.functions, functionIndexes);
- addIndexes(wasm.globals, globalIndexes);
addIndexes(wasm.events, eventIndexes);
+
+ // Globals may have tuple types in the IR, in which case they lower to
+ // multiple globals, one for each tuple element, in the binary. Tuple
+ // globals therefore occupy multiple binary indices, and we have to take
+ // that into account when calculating indices.
+ Index globalCount = 0;
+ auto addGlobal = [&](auto* curr) {
+ globalIndexes[curr->name] = globalCount;
+ globalCount += curr->type.size();
+ };
+ for (auto& curr : wasm.globals) {
+ if (curr->imported()) {
+ addGlobal(curr.get());
+ }
+ }
+ for (auto& curr : wasm.globals) {
+ if (!curr->imported()) {
+ addGlobal(curr.get());
+ }
+ }
}
};