summaryrefslogtreecommitdiff
path: root/src/wasm-binary.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-08-16 09:40:59 -0700
committerGitHub <noreply@github.com>2016-08-16 09:40:59 -0700
commite5e3bf39f25ed3a2fb45a9ca1f55d6828d81a3eb (patch)
tree834f67d6ebaf295af0e1d6789bc7f52d120dff33 /src/wasm-binary.h
parente268d939b86d8639d014b8036e7664d66b6a32e9 (diff)
parent7851e3a7a3bea679f422116862c5801f1938806d (diff)
downloadbinaryen-e5e3bf39f25ed3a2fb45a9ca1f55d6828d81a3eb.tar.gz
binaryen-e5e3bf39f25ed3a2fb45a9ca1f55d6828d81a3eb.tar.bz2
binaryen-e5e3bf39f25ed3a2fb45a9ca1f55d6828d81a3eb.zip
Merge pull request #668 from WebAssembly/tables_n_memories
Tables and memories
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r--src/wasm-binary.h56
1 files changed, 39 insertions, 17 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index aad142d44..04bebddc5 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -706,7 +706,8 @@ public:
o << U32LEB(num);
for (auto& segment : wasm->memory.segments) {
if (segment.data.size() == 0) continue;
- o << U32LEB(segment.offset);
+ writeExpression(segment.offset);
+ o << int8_t(BinaryConsts::End);
writeInlineBuffer(&segment.data[0], segment.data.size());
}
finishSection(start);
@@ -739,12 +740,19 @@ public:
}
void writeFunctionTable() {
- if (wasm->table.names.size() == 0) return;
+ if (wasm->table.segments.size() == 0) return;
if (debug) std::cerr << "== writeFunctionTable" << std::endl;
auto start = startSection(BinaryConsts::Section::FunctionTable);
- o << U32LEB(wasm->table.names.size());
- for (auto name : wasm->table.names) {
- o << U32LEB(getFunctionIndex(name));
+ o << U32LEB(wasm->table.initial);
+ o << U32LEB(wasm->table.max);
+ o << U32LEB(wasm->table.segments.size());
+ for (auto& segment : wasm->table.segments) {
+ writeExpression(segment.offset);
+ o << int8_t(BinaryConsts::End);
+ o << U32LEB(segment.data.size());
+ for (auto name : segment.data) {
+ o << U32LEB(getFunctionIndex(name));
+ }
}
finishSection(start);
}
@@ -1572,6 +1580,15 @@ public:
}
}
+ Expression* readExpression() {
+ assert(depth == 0);
+ processExpressions();
+ assert(expressionStack.size() == 1);
+ auto* ret = popExpression();
+ assert(depth == 0);
+ return ret;
+ }
+
void readGlobals() {
if (debug) std::cerr << "== readGlobals" << std::endl;
size_t num = getU32LEB();
@@ -1580,11 +1597,7 @@ public:
if (debug) std::cerr << "read one" << std::endl;
auto curr = new Global;
curr->type = getWasmType();
- assert(depth == 0);
- processExpressions();
- assert(expressionStack.size() == 1);
- curr->init = popExpression();
- assert(depth == 0);
+ curr->init = readExpression();
wasm.addGlobal(curr);
}
}
@@ -1638,9 +1651,12 @@ public:
}
}
- for (size_t index : functionTable) {
- assert(index < wasm.functions.size());
- wasm.table.names.push_back(wasm.functions[index]->name);
+ for (auto& pair : functionTable) {
+ auto i = pair.first;
+ auto& indexes = pair.second;
+ for (auto j : indexes) {
+ wasm.table.segments[i].data.push_back(wasm.functions[j]->name);
+ }
}
}
@@ -1649,7 +1665,7 @@ public:
auto num = getU32LEB();
for (size_t i = 0; i < num; i++) {
Memory::Segment curr;
- auto offset = getU32LEB();
+ auto offset = readExpression();
auto size = getU32LEB();
std::vector<char> buffer;
buffer.resize(size);
@@ -1660,14 +1676,20 @@ public:
}
}
- std::vector<size_t> functionTable;
+ std::map<Index, std::vector<Index>> functionTable;
void readFunctionTable() {
if (debug) std::cerr << "== readFunctionTable" << std::endl;
+ wasm.table.initial = getU32LEB();
+ wasm.table.max = getU32LEB();
auto num = getU32LEB();
for (size_t i = 0; i < num; i++) {
- auto index = getU32LEB();
- functionTable.push_back(index);
+ wasm.table.segments.emplace_back(readExpression());
+ auto& temporary = functionTable[i];
+ auto size = getU32LEB();
+ for (Index j = 0; j < size; j++) {
+ temporary.push_back(getU32LEB());
+ }
}
}