xref: /llvm-project/llvm/test/MC/WebAssembly/type-index.s (revision 9647a6f719ee4b1c23eea7aef368c1dcd5317949)
1# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types,+simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s
2# Check that it converts to .o without errors:
3# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+reference-types,+simd128,+nontrapping-fptoint,+exception-handling < %s | obj2yaml | FileCheck -check-prefix=BIN %s
4
5# Minimal test for type indices and table references in call_indirect.
6
7test0:
8    .functype   test0 (i32) -> (i32)
9    f64.const 1.0
10    local.get 0
11    call_indirect (f64) -> (i32)
12    end_function
13
14# CHECK:	.text
15# CHECK-LABEL: test0:
16# CHECK-NEXT:	.functype	test0 (i32) -> (i32)
17# CHECK:	    call_indirect	__indirect_function_table, (f64) -> (i32)
18# CHECK-NEXT:	end_function
19
20# BIN:      --- !WASM
21# BIN-NEXT: FileHeader:
22# BIN-NEXT:   Version:         0x1
23# BIN-NEXT: Sections:
24# BIN-NEXT:   - Type:            TYPE
25# BIN-NEXT:     Signatures:
26# BIN-NEXT:       - Index:           0
27# BIN-NEXT:         ParamTypes:
28# BIN-NEXT:           - I32
29# BIN-NEXT:         ReturnTypes:
30# BIN-NEXT:           - I32
31# BIN-NEXT:       - Index:           1
32# BIN-NEXT:         ParamTypes:
33# BIN-NEXT:           - F64
34# BIN-NEXT:         ReturnTypes:
35# BIN-NEXT:           - I32
36# BIN-NEXT:   - Type:            IMPORT
37# BIN-NEXT:     Imports:
38# BIN-NEXT:       - Module:          env
39# BIN-NEXT:         Field:           __linear_memory
40# BIN-NEXT:         Kind:            MEMORY
41# BIN-NEXT:         Memory:
42# BIN-NEXT:           Minimum:         0x0
43# BIN-NEXT:       - Module:          env
44# BIN-NEXT:         Field:           __indirect_function_table
45# BIN-NEXT:         Kind:            TABLE
46# BIN-NEXT:         Table:
47# BIN-NEXT:           Index:           0
48# BIN-NEXT:           ElemType:        FUNCREF
49# BIN-NEXT:           Limits:
50# BIN-NEXT:             Minimum:         0x0
51# BIN-NEXT:   - Type:            FUNCTION
52# BIN-NEXT:     FunctionTypes:   [ 0 ]
53# BIN-NEXT:   - Type:            CODE
54# BIN-NEXT:     Relocations:
55# BIN-NEXT:       - Type:            R_WASM_TYPE_INDEX_LEB
56# BIN-NEXT:         Index:           1
57# BIN-NEXT:         Offset:          0xF
58# BIN-NEXT:       - Type:            R_WASM_TABLE_NUMBER_LEB
59# BIN-NEXT:         Index:           1
60# BIN-NEXT:         Offset:          0x14
61# BIN-NEXT:     Functions:
62# BIN-NEXT:       - Index:           0
63# BIN-NEXT:         Locals:          []
64# BIN-NEXT:         Body:            44000000000000F03F200011818080800080808080000B
65# BIN-NEXT:   - Type:            CUSTOM
66# BIN-NEXT:     Name:            linking
67# BIN-NEXT:     Version:         2
68# BIN-NEXT:     SymbolTable:
69# BIN-NEXT:       - Index:           0
70# BIN-NEXT:         Kind:            FUNCTION
71# BIN-NEXT:         Name:            test0
72# BIN-NEXT:         Flags:           [ BINDING_LOCAL ]
73# BIN-NEXT:         Function:        0
74# BIN-NEXT:       - Index:           1
75# BIN-NEXT:         Kind:            TABLE
76# BIN-NEXT:         Name:            __indirect_function_table
77# BIN-NEXT:         Flags:           [ UNDEFINED ]
78# BIN-NEXT:         Table:           0
79# BIN-NEXT: ...
80