2008-01-17 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / verifier / make_switch_test.sh
1 #! /bin/sh
2
3 TEST_NAME=$1
4 TEST_VALIDITY=$2
5 TEST_POS=$3
6 TEST_EXTRA=$4
7 TEST_OP=$5
8 TEST_FIN=$6
9
10 if [ "$TEST_FIN" == "" ]; then
11         TEST_FIN="finally";
12 fi
13
14 declare BRANCH_${TEST_POS}="$TEST_OP"
15 declare BRANCH_EXTRA_${TEST_POS}="$TEST_EXTRA"
16
17 TEST_NAME=${TEST_VALIDITY}_${TEST_NAME}
18 TEST_FILE=${TEST_NAME}_generated.il
19 echo $TEST_FILE
20
21 sed -e "s/VALIDITY/${TEST_VALIDITY}/g" -e "s/OPCODE/${TEST_OP}/g" -e "s/FINALLY/${TEST_FIN}/g" > $TEST_FILE <<//EOF
22
23 // VALIDITY CIL which breaks the ECMA-335 rules. 
24 // this CIL should fail verification by a conforming CLI verifier.
25
26 .assembly '${TEST_NAME}_generated'
27 {
28   .hash algorithm 0x00008004
29   .ver  0:0:0:0
30 }
31
32 .class ClassA
33         extends [mscorlib]System.Object
34 {
35 }
36
37 .class sealed MyValueType
38         extends [mscorlib]System.ValueType
39 {
40         .field private int32 v
41 }
42
43 .class public Template\`1<T>
44         extends [mscorlib]System.Object
45 {
46 }
47
48 .class sealed public ValueTypeTemplate\`1<T>
49         extends [mscorlib]System.ValueType
50 {
51         .field private int32 v
52 }
53
54 .method public static int32 Main() cil managed
55 {
56         .entrypoint
57         .maxstack 8
58         .locals init ( int32 V0, native int V1)
59  
60         ${BRANCH_EXTRA_1}
61         ${BRANCH_1}
62         ldc.i4 0x7FFFFFFF
63         pop
64
65         ldloca 0
66         unaligned. 1
67 AFTER_FIRST_PREFIX:
68         volatile.
69 AFTER_SECOND_PREFIX:
70         ldind.i4
71         pop
72
73         nop
74         ldc.i4.0
75 INVALID_MERGE_POINT:
76         nop
77         pop
78
79
80 BLOCK_1:
81         nop
82 BLOCK_1_B:
83         nop
84         .try {
85                 nop
86                 ${BRANCH_EXTRA_2}
87                 ${BRANCH_2}
88                 nop
89 IN_TRY:
90
91 BLOCK_2:
92                 nop
93 BLOCK_2_B:
94                 nop
95                 leave END
96         } catch [mscorlib]System.Exception {
97                 pop
98                 ${BRANCH_EXTRA_3}
99                 ${BRANCH_3}
100                 nop
101 IN_CATCH:
102 BLOCK_3:
103                 nop
104 BLOCK_3_B:
105                 nop
106                 leave END
107         }
108
109         .try {
110                 leave END
111         } FINALLY {
112                 nop
113                 ${BRANCH_EXTRA_4}
114                 ${BRANCH_4}
115                 nop
116 IN_FINALLY:
117 BLOCK_4:
118                 nop
119 BLOCK_4_B:
120                 nop
121                 endfinally
122         }
123
124         .try {
125                 leave END
126         } filter {
127                 pop
128                 nop
129                 ${BRANCH_EXTRA_5}
130                 ${BRANCH_5}
131                 nop
132 IN_FILTER:
133 BLOCK_5:
134                 nop
135 BLOCK_5_B:
136                 nop
137                 ldc.i4.0
138                 endfilter
139         }
140         {
141                 pop
142                 nop
143                 ${BRANCH_EXTRA_6}
144                 ${BRANCH_6}
145                 nop
146 IN_HANDLER:
147 BLOCK_6:
148                 nop
149 BLOCK_6_B:
150                 nop
151                 leave END
152         }
153
154 END:
155         ldc.i4.0
156         ret
157 }
158 //EOF