MCPcopy Create free account
hub / github.com/WasmVM/WasmVM / parse_referenceinstr

Method parse_referenceinstr

src/lib/parse/instr_parse.cpp:301–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299}
300
301WasmInstr ParseContext::parse_referenceinstr(const std::string& name) {
302 if (name == "ref.is_null") return Instr::Ref_is_null();
303 if (name == "ref.func") return Instr::Ref_func(parse_funcidx());
304 if (name == "ref.eq") return Instr::Ref_eq();
305 if (name == "ref.as_non_null") return Instr::Ref_as_non_null();
306 if (name == "ref.i31") return Instr::Ref_i31();
307 if (name == "i31.get_s") return Instr::I31_get_s();
308 if (name == "i31.get_u") return Instr::I31_get_u();
309 if (name == "any.convert_extern") return Instr::Any_convert_extern();
310 if (name == "extern.convert_any") return Instr::Extern_convert_any();
311 if (name == "br_on_null") return Instr::Br_on_null(parse_labelidx());
312 if (name == "br_on_non_null") return Instr::Br_on_non_null(parse_labelidx());
313 if (name == "ref.test") {
314 auto [nullable, ht] = parse_reftype_annot();
315 return nullable ? WasmInstr(Instr::Ref_test_null(ht)) : WasmInstr(Instr::Ref_test(ht));
316 }
317 if (name == "ref.cast") {
318 auto [nullable, ht] = parse_reftype_annot();
319 return nullable ? WasmInstr(Instr::Ref_cast_null(ht)) : WasmInstr(Instr::Ref_cast(ht));
320 }
321 if (name == "br_on_cast" || name == "br_on_cast_fail") {
322 index_t labelidx = parse_labelidx();
323 auto [src_nullable, src_ht] = parse_reftype_annot();
324 auto [dst_nullable, dst_ht] = parse_reftype_annot();
325 if (name == "br_on_cast")
326 return Instr::Br_on_cast(labelidx, src_nullable, dst_nullable, src_ht, dst_ht);
327 return Instr::Br_on_cast_fail(labelidx, src_nullable, dst_nullable, src_ht, dst_ht);
328 }
329 // ref.null — heaptype keyword
330 Token ref = tok_.expect(TokenType::Keyword, "heap type");
331 if (ref.text == "func") return Instr::Ref_null(RefType::funcref);
332 if (ref.text == "extern") return Instr::Ref_null(RefType::externref);
333 throw Exception::Parse("expected heap type after ref.null", {ref.line, ref.column});
334}
335
336// ── Parametric instructions ───────────────────────────────────────────────────
337

Callers

nothing calls this directly

Calls 10

WasmInstrClass · 0.85
Ref_test_nullClass · 0.85
Ref_testClass · 0.85
Ref_cast_nullClass · 0.85
Ref_castClass · 0.85
Br_on_castClass · 0.85
Br_on_cast_failClass · 0.85
Ref_nullClass · 0.85
ParseClass · 0.85
expectMethod · 0.80

Tested by

no test coverage detected