Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ enum MemoryAccess {
NaturalAlignment = 0
};

enum TypeForms {
Basic = 0x40
};

} // namespace BinaryConsts

int8_t binaryWasmType(WasmType type) {
Expand Down Expand Up @@ -520,11 +524,17 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
o << U32LEB(wasm->functionTypes.size());
for (auto* type : wasm->functionTypes) {
if (debug) std::cerr << "write one" << std::endl;
o << int8_t(BinaryConsts::TypeForms::Basic);
o << U32LEB(type->params.size());
o << binaryWasmType(type->result);
for (auto param : type->params) {
o << binaryWasmType(param);
}
if (type->result == none) {
o << U32LEB(0);
} else {
o << U32LEB(1);
o << binaryWasmType(type->result);
}
}
finishSection(start);
}
Expand Down Expand Up @@ -1338,12 +1348,20 @@ class WasmBinaryBuilder {
for (size_t i = 0; i < numTypes; i++) {
if (debug) std::cerr << "read one" << std::endl;
auto curr = allocator.alloc<FunctionType>();
auto form = getInt8();
assert(form == BinaryConsts::TypeForms::Basic);
size_t numParams = getU32LEB();
if (debug) std::cerr << "num params: " << numParams << std::endl;
curr->result = getWasmType();
for (size_t j = 0; j < numParams; j++) {
curr->params.push_back(getWasmType());
}
auto numResults = getU32LEB();
if (numResults == 0) {
curr->result = none;
} else {
assert(numResults == 1);
curr->result = getWasmType();
}
wasm.addFunctionType(curr);
}
}
Expand Down