@@ -285,7 +285,15 @@ void WasmBinaryWriter::writeTypes() {
285
285
}
286
286
}
287
287
if (type.isShared ()) {
288
- o << uint8_t (BinaryConsts::EncodedType::SharedDef);
288
+ o << uint8_t (BinaryConsts::EncodedType::Shared);
289
+ }
290
+ if (auto desc = type.getDescribedType ()) {
291
+ o << uint8_t (BinaryConsts::EncodedType::Describes);
292
+ writeHeapType (*desc);
293
+ }
294
+ if (auto desc = type.getDescriptorType ()) {
295
+ o << uint8_t (BinaryConsts::EncodedType::Descriptor);
296
+ writeHeapType (*desc);
289
297
}
290
298
switch (type.getKind ()) {
291
299
case HeapTypeKind::Func: {
@@ -1680,7 +1688,7 @@ void WasmBinaryWriter::writeHeapType(HeapType type) {
1680
1688
1681
1689
int ret = 0 ;
1682
1690
if (type.isShared ()) {
1683
- o << S32LEB (BinaryConsts::EncodedType::Shared);
1691
+ o << uint8_t (BinaryConsts::EncodedType::Shared);
1684
1692
}
1685
1693
switch (type.getBasic (Unshared)) {
1686
1694
case HeapType::ext:
@@ -2206,7 +2214,7 @@ HeapType WasmBinaryReader::getHeapType() {
2206
2214
return types[type];
2207
2215
}
2208
2216
auto share = Unshared;
2209
- if (type == BinaryConsts::EncodedType::Shared ) {
2217
+ if (type == BinaryConsts::EncodedType::SharedLEB ) {
2210
2218
share = Shared;
2211
2219
type = getS64LEB (); // TODO: Actually s33
2212
2220
}
@@ -2341,7 +2349,7 @@ void WasmBinaryReader::readTypes() {
2341
2349
auto readHeapType = [&]() -> HeapType {
2342
2350
int64_t htCode = getS64LEB (); // TODO: Actually s33
2343
2351
auto share = Unshared;
2344
- if (htCode == BinaryConsts::EncodedType::Shared ) {
2352
+ if (htCode == BinaryConsts::EncodedType::SharedLEB ) {
2345
2353
share = Shared;
2346
2354
htCode = getS64LEB (); // TODO: Actually s33
2347
2355
}
@@ -2467,7 +2475,6 @@ void WasmBinaryReader::readTypes() {
2467
2475
builder.createRecGroup (i, groupSize);
2468
2476
form = getInt8 ();
2469
2477
}
2470
- std::optional<uint32_t > superIndex;
2471
2478
if (form == BinaryConsts::EncodedType::Sub ||
2472
2479
form == BinaryConsts::EncodedType::SubFinal) {
2473
2480
if (form == BinaryConsts::EncodedType::Sub) {
@@ -2479,14 +2486,34 @@ void WasmBinaryReader::readTypes() {
2479
2486
throwError (" Invalid type definition with " + std::to_string (supers) +
2480
2487
" supertypes" );
2481
2488
}
2482
- superIndex = getU32LEB ();
2489
+ auto superIdx = getU32LEB ();
2490
+ if (superIdx >= builder.size ()) {
2491
+ throwError (" invalid supertype index: " + std::to_string (superIdx));
2492
+ }
2493
+ builder[i].subTypeOf (builder[superIdx]);
2483
2494
}
2484
2495
form = getInt8 ();
2485
2496
}
2486
- if (form == BinaryConsts::SharedDef ) {
2497
+ if (form == BinaryConsts::EncodedType::Shared ) {
2487
2498
builder[i].setShared ();
2488
2499
form = getInt8 ();
2489
2500
}
2501
+ if (form == BinaryConsts::EncodedType::Describes) {
2502
+ auto descIdx = getU32LEB ();
2503
+ if (descIdx >= builder.size ()) {
2504
+ throwError (" invalid described type index: " + std::to_string (descIdx));
2505
+ }
2506
+ builder[i].describes (builder[descIdx]);
2507
+ form = getInt8 ();
2508
+ }
2509
+ if (form == BinaryConsts::EncodedType::Descriptor) {
2510
+ auto descIdx = getU32LEB ();
2511
+ if (descIdx >= builder.size ()) {
2512
+ throwError (" invalid descriptor type index: " + std::to_string (descIdx));
2513
+ }
2514
+ builder[i].descriptor (builder[descIdx]);
2515
+ form = getInt8 ();
2516
+ }
2490
2517
if (form == BinaryConsts::EncodedType::Func) {
2491
2518
builder[i] = readSignatureDef ();
2492
2519
} else if (form == BinaryConsts::EncodedType::Cont) {
@@ -2498,13 +2525,6 @@ void WasmBinaryReader::readTypes() {
2498
2525
} else {
2499
2526
throwError (" Bad type form " + std::to_string (form));
2500
2527
}
2501
- if (superIndex) {
2502
- if (*superIndex > builder.size ()) {
2503
- throwError (" Out of bounds supertype index " +
2504
- std::to_string (*superIndex));
2505
- }
2506
- builder[i].subTypeOf (builder[*superIndex]);
2507
- }
2508
2528
}
2509
2529
2510
2530
auto result = builder.build ();
0 commit comments