|
1 |
| -use crate::{encode_section, Encode, HeapType, Section, SectionId, ValType}; |
| 1 | +use crate::{encode_section, Encode, HeapType, RefType, Section, SectionId, ValType}; |
2 | 2 | use std::borrow::Cow;
|
3 | 3 |
|
4 | 4 | /// An encoder for the code section.
|
@@ -523,6 +523,33 @@ pub enum Instruction<'a> {
|
523 | 523 | RefAsNonNull,
|
524 | 524 |
|
525 | 525 | // GC types instructions.
|
| 526 | + StructNew(u32), |
| 527 | + StructNewDefault(u32), |
| 528 | + StructGet(u32, u32), |
| 529 | + StructGetS(u32, u32), |
| 530 | + StructGetU(u32, u32), |
| 531 | + StructSet(u32, u32), |
| 532 | + |
| 533 | + ArrayNew(u32), |
| 534 | + ArrayNewDefault(u32), |
| 535 | + ArrayNewFixed(u32, u32), |
| 536 | + ArrayNewData(u32, u32), |
| 537 | + ArrayNewElem(u32, u32), |
| 538 | + ArrayGet(u32), |
| 539 | + ArrayGetS(u32), |
| 540 | + ArrayGetU(u32), |
| 541 | + ArraySet(u32), |
| 542 | + ArrayLen, |
| 543 | + ArrayFill(u32), |
| 544 | + ArrayCopy(u32), |
| 545 | + ArrayInitData(u32, u32), |
| 546 | + ArrayInitElem(u32, u32), |
| 547 | + |
| 548 | + RefTest(RefType), |
| 549 | + RefCast(RefType), |
| 550 | + AnyConvertExtern, |
| 551 | + ExternConvertAny, |
| 552 | + |
526 | 553 | RefI31,
|
527 | 554 | I31GetS,
|
528 | 555 | I31GetU,
|
@@ -1321,6 +1348,155 @@ impl Encode for Instruction<'_> {
|
1321 | 1348 | Instruction::RefAsNonNull => sink.push(0xd4),
|
1322 | 1349 |
|
1323 | 1350 | // GC instructions.
|
| 1351 | + Instruction::StructNew(type_index) => { |
| 1352 | + sink.push(0xfb); |
| 1353 | + sink.push(0x00); |
| 1354 | + type_index.encode(sink) |
| 1355 | + } |
| 1356 | + Instruction::StructNewDefault(type_index) => { |
| 1357 | + sink.push(0xfb); |
| 1358 | + sink.push(0x01); |
| 1359 | + type_index.encode(sink) |
| 1360 | + } |
| 1361 | + Instruction::StructGet(type_index, field_index) => { |
| 1362 | + sink.push(0xfb); |
| 1363 | + sink.push(0x02); |
| 1364 | + type_index.encode(sink); |
| 1365 | + field_index.encode(sink) |
| 1366 | + } |
| 1367 | + Instruction::StructGetS(type_index, field_index) => { |
| 1368 | + sink.push(0xfb); |
| 1369 | + sink.push(0x03); |
| 1370 | + type_index.encode(sink); |
| 1371 | + field_index.encode(sink) |
| 1372 | + } |
| 1373 | + Instruction::StructGetU(type_index, field_index) => { |
| 1374 | + sink.push(0xfb); |
| 1375 | + sink.push(0x04); |
| 1376 | + type_index.encode(sink); |
| 1377 | + field_index.encode(sink) |
| 1378 | + } |
| 1379 | + Instruction::StructSet(type_index, field_index) => { |
| 1380 | + sink.push(0xfb); |
| 1381 | + sink.push(0x05); |
| 1382 | + type_index.encode(sink); |
| 1383 | + field_index.encode(sink) |
| 1384 | + } |
| 1385 | + |
| 1386 | + Instruction::ArrayNew(type_index) => { |
| 1387 | + sink.push(0xfb); |
| 1388 | + sink.push(0x06); |
| 1389 | + type_index.encode(sink) |
| 1390 | + } |
| 1391 | + Instruction::ArrayNewDefault(type_index) => { |
| 1392 | + sink.push(0xfb); |
| 1393 | + sink.push(0x07); |
| 1394 | + type_index.encode(sink) |
| 1395 | + } |
| 1396 | + Instruction::ArrayNewFixed(type_index, size) => { |
| 1397 | + sink.push(0xfb); |
| 1398 | + sink.push(0x08); |
| 1399 | + type_index.encode(sink); |
| 1400 | + size.encode(sink) |
| 1401 | + } |
| 1402 | + Instruction::ArrayNewData(type_index, data_index) => { |
| 1403 | + sink.push(0xfb); |
| 1404 | + sink.push(0x09); |
| 1405 | + type_index.encode(sink); |
| 1406 | + data_index.encode(sink) |
| 1407 | + } |
| 1408 | + Instruction::ArrayNewElem(type_index, elem_index) => { |
| 1409 | + sink.push(0xfb); |
| 1410 | + sink.push(0x0a); |
| 1411 | + type_index.encode(sink); |
| 1412 | + elem_index.encode(sink) |
| 1413 | + } |
| 1414 | + Instruction::ArrayGet(type_index) => { |
| 1415 | + sink.push(0xfb); |
| 1416 | + sink.push(0x0b); |
| 1417 | + type_index.encode(sink) |
| 1418 | + } |
| 1419 | + Instruction::ArrayGetS(type_index) => { |
| 1420 | + sink.push(0xfb); |
| 1421 | + sink.push(0x0c); |
| 1422 | + type_index.encode(sink) |
| 1423 | + } |
| 1424 | + Instruction::ArrayGetU(type_index) => { |
| 1425 | + sink.push(0xfb); |
| 1426 | + sink.push(0x0d); |
| 1427 | + type_index.encode(sink) |
| 1428 | + } |
| 1429 | + Instruction::ArraySet(type_index) => { |
| 1430 | + sink.push(0xfb); |
| 1431 | + sink.push(0x0e); |
| 1432 | + type_index.encode(sink) |
| 1433 | + } |
| 1434 | + Instruction::ArrayLen => { |
| 1435 | + sink.push(0xfb); |
| 1436 | + sink.push(0x0f) |
| 1437 | + } |
| 1438 | + Instruction::ArrayFill(type_index) => { |
| 1439 | + sink.push(0xfb); |
| 1440 | + sink.push(0x10); |
| 1441 | + type_index.encode(sink) |
| 1442 | + } |
| 1443 | + Instruction::ArrayCopy(type_index) => { |
| 1444 | + sink.push(0xfb); |
| 1445 | + sink.push(0x11); |
| 1446 | + type_index.encode(sink) |
| 1447 | + } |
| 1448 | + Instruction::ArrayInitData(type_index, data_index) => { |
| 1449 | + sink.push(0xfb); |
| 1450 | + sink.push(0x12); |
| 1451 | + type_index.encode(sink); |
| 1452 | + data_index.encode(sink) |
| 1453 | + } |
| 1454 | + Instruction::ArrayInitElem(type_index, elem_index) => { |
| 1455 | + sink.push(0xfb); |
| 1456 | + sink.push(0x13); |
| 1457 | + type_index.encode(sink); |
| 1458 | + elem_index.encode(sink) |
| 1459 | + } |
| 1460 | + Instruction::RefTest(RefType { |
| 1461 | + nullable: false, |
| 1462 | + heap_type, |
| 1463 | + }) => { |
| 1464 | + sink.push(0xfb); |
| 1465 | + sink.push(0x14); |
| 1466 | + heap_type.encode(sink) |
| 1467 | + } |
| 1468 | + Instruction::RefTest(RefType { |
| 1469 | + nullable: true, |
| 1470 | + heap_type, |
| 1471 | + }) => { |
| 1472 | + sink.push(0xfb); |
| 1473 | + sink.push(0x15); |
| 1474 | + heap_type.encode(sink) |
| 1475 | + } |
| 1476 | + Instruction::RefCast(RefType { |
| 1477 | + nullable: false, |
| 1478 | + heap_type, |
| 1479 | + }) => { |
| 1480 | + sink.push(0xfb); |
| 1481 | + sink.push(0x16); |
| 1482 | + heap_type.encode(sink) |
| 1483 | + } |
| 1484 | + Instruction::RefCast(RefType { |
| 1485 | + nullable: true, |
| 1486 | + heap_type, |
| 1487 | + }) => { |
| 1488 | + sink.push(0xfb); |
| 1489 | + sink.push(0x17); |
| 1490 | + heap_type.encode(sink) |
| 1491 | + } |
| 1492 | + Instruction::AnyConvertExtern => { |
| 1493 | + sink.push(0xfb); |
| 1494 | + sink.push(0x1a) |
| 1495 | + } |
| 1496 | + Instruction::ExternConvertAny => { |
| 1497 | + sink.push(0xfb); |
| 1498 | + sink.push(0x1b) |
| 1499 | + } |
1324 | 1500 | Instruction::RefI31 => {
|
1325 | 1501 | sink.push(0xfb);
|
1326 | 1502 | sink.push(0x1c)
|
|
0 commit comments