| 360 | // ── Table instructions ──────────────────────────────────────────────────────── |
| 361 | |
| 362 | WasmInstr ParseContext::parse_tableinstr(const std::string& name) { |
| 363 | if (name == "elem.drop") return Instr::Elem_drop(parse_elemidx()); |
| 364 | if (name == "table.copy") { |
| 365 | index_t dst = 0, src = 0; |
| 366 | if (tok_.peek().type == TokenType::Integer || tok_.peek().type == TokenType::Id) { |
| 367 | dst = parse_tableidx(); |
| 368 | src = parse_tableidx(); |
| 369 | } |
| 370 | return Instr::Table_copy(dst, src); |
| 371 | } |
| 372 | index_t tableidx = 0; |
| 373 | if (name != "table.init") { |
| 374 | if (tok_.peek().type == TokenType::Integer || tok_.peek().type == TokenType::Id) |
| 375 | tableidx = parse_tableidx(); |
| 376 | } else { |
| 377 | // table.init tableidx? elemidx — need to distinguish |
| 378 | // If two indices follow, first is tableidx; if one, it's elemidx |
| 379 | if (tok_.peek().type == TokenType::Integer || tok_.peek().type == TokenType::Id) { |
| 380 | tableidx = parse_u32(); // tentative: first index |
| 381 | // peek to see if another index follows (then the first was tableidx) |
| 382 | if (tok_.peek().type == TokenType::Integer || tok_.peek().type == TokenType::Id) { |
| 383 | // two indices: tableidx elemidx |
| 384 | return Instr::Table_init((index_t)tableidx, parse_elemidx()); |
| 385 | } |
| 386 | // only one index: it was the elemidx |
| 387 | return Instr::Table_init(0, (index_t)tableidx); |
| 388 | } |
| 389 | return Instr::Table_init(0, 0); |
| 390 | } |
| 391 | if (name == "table.get") return Instr::Table_get(tableidx); |
| 392 | if (name == "table.set") return Instr::Table_set(tableidx); |
| 393 | if (name == "table.size") return Instr::Table_size(tableidx); |
| 394 | if (name == "table.grow") return Instr::Table_grow(tableidx); |
| 395 | if (name == "table.fill") return Instr::Table_fill(tableidx); |
| 396 | return Instr::Table_fill(tableidx); // fallback |
| 397 | } |
| 398 | |
| 399 | // ── Memarg ──────────────────────────────────────────────────────────────────── |
| 400 |
nothing calls this directly
no test coverage detected