Skip to content

Commit ba4e214

Browse files
committed
[WebAssembly] Add ref.test_func handling to AsmParser
1 parent 0eff410 commit ba4e214

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
668668
if (parseFunctionTableOperand(&FunctionTable))
669669
return true;
670670
ExpectFuncType = true;
671+
} else if (Name == "ref.test_func") {
672+
ExpectFuncType = true;
671673
}
672674

673675
// Returns true if the next tokens are a catch clause

llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ multiclass REF_I<WebAssemblyRegClass rc, ValueType vt, string ht> {
3636
Requires<[HasReferenceTypes]>;
3737
}
3838

39+
defm REF_TEST_FUNCREF :
40+
I<(outs I32: $res),
41+
(ins TypeIndex:$type, FUNCREF: $ref),
42+
(outs),
43+
(ins TypeIndex:$type),
44+
[],
45+
"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
46+
3947
defm "" : REF_I<FUNCREF, funcref, "func">;
4048
defm "" : REF_I<EXTERNREF, externref, "extern">;
4149
defm "" : REF_I<EXNREF, exnref, "exn">;

llvm/test/MC/WebAssembly/reference-types.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ ref_null_test:
2727
drop
2828
end_function
2929

30+
# CHECK-LABEL: ref_test_test:
31+
# CHECK: ref.null_func # encoding: [0xd0,0x70]
32+
# CHECK: ref.test () -> () # encoding: [0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
33+
# CHECK: # fixup A - offset: 2, value: .Ltypeindex0@TYPEINDEX, kind: fixup_uleb128_i32
34+
# CHECK: ref.null_func # encoding: [0xd0,0x70]
35+
# CHECK: ref.test () -> (i32) # encoding: [0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
36+
# CHECK: # fixup A - offset: 2, value: .Ltypeindex1@TYPEINDEX, kind: fixup_uleb128_i32
37+
ref_test_test:
38+
.functype ref_test_test () -> (i32, i32)
39+
ref.null_func
40+
ref.test_func () -> ()
41+
ref.null_func
42+
ref.test_func () -> (i32)
43+
end_function
44+
3045
# CHECK-LABEL: ref_sig_test_funcref:
3146
# CHECK-NEXT: .functype ref_sig_test_funcref (funcref) -> (funcref)
3247
ref_sig_test_funcref:

0 commit comments

Comments
 (0)