1
1
#! /usr/bin/python3
2
2
3
3
'''
4
- This script is used to generate
5
- test/lit/passes/optimize-instructions-all-casts.wast
4
+ Generate test modules with all interesting casts
6
5
'''
7
6
7
+ import argparse
8
8
import itertools
9
9
10
10
interesting_pairs = [('$super' , '$super' , 'cast-to-self-nonfinal' ),
16
16
('none' , '$super' , 'cast-from-bottom' )]
17
17
18
18
19
- def gen_test_configs ():
19
+ def gen_test_configs (args ):
20
20
for src_heap , cast_heap , heap_name in interesting_pairs :
21
21
for src_nullable , src_exact , cast_nullable , cast_exact in \
22
22
itertools .product ([True , False ], repeat = 4 ):
23
23
if src_exact and src_heap == 'none' :
24
24
continue
25
25
if cast_exact and cast_heap == 'none' :
26
26
continue
27
+ if args .enable_descs != cast_exact :
28
+ continue
27
29
yield heap_name , src_heap , cast_heap , src_nullable , cast_nullable , \
28
30
src_exact , cast_exact
29
31
@@ -62,23 +64,37 @@ def print_test(config):
62
64
print (test )
63
65
64
66
65
- def print_tests ():
66
- for config in gen_test_configs ():
67
+ def print_tests (args ):
68
+ for config in gen_test_configs (args ):
67
69
print_test (config )
68
70
69
71
70
- def print_header ():
71
- header = ''';; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
72
- ;; NOTE: Test has been generated by scripts/test/gen-cast-test.py. Do not edit manually.
72
+ def print_header (args ):
73
+ flags = ''
74
+ if args .enable_descs :
75
+ flags = ' --enable-custom-descs'
76
+ header = f''';; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
77
+ ;; NOTE: Test has been generated by scripts/test/gen-cast-test.py{ flags } . Do not edit manually.
73
78
74
79
;; Exhaustively test optimization of all interesting casts.
80
+ '''
75
81
82
+ if args .enable_descs :
83
+ header += '''
76
84
;; RUN: wasm-opt %s -all --optimize-instructions -S -o - | filecheck %s
85
+ '''
86
+ else :
87
+ header += '''
88
+ ;; RUN: wasm-opt %s -all --optimize-instructions -S -o - | filecheck %s
89
+ ;; RUN: wasm-opt %s -all --disable-custom-descriptors --optimize-instructions -S -o - | filecheck %s --check-prefix=NO_CD
90
+ '''
77
91
92
+ header += '''
78
93
(module
79
94
(type $super (sub (struct)))
80
95
(type $sub (sub $super (struct)))
81
96
(type $sub-final (sub final $super (struct)))'''
97
+
82
98
print (header )
83
99
84
100
@@ -87,8 +103,11 @@ def print_footer():
87
103
88
104
89
105
def main ():
90
- print_header ()
91
- print_tests ()
106
+ parser = argparse .ArgumentParser (description = __doc__ )
107
+ parser .add_argument ('--enable-custom-descs' , action = 'store_true' , dest = 'enable_descs' )
108
+ args = parser .parse_args ()
109
+ print_header (args )
110
+ print_tests (args )
92
111
print_footer ()
93
112
94
113
0 commit comments