New test.
[mono.git] / mono / tests / vararg.il
1 //
2 // vararg.il: Tests for varargs and refany instructions
3 //
4
5 .assembly extern mscorlib {
6 }
7
8 .assembly extern TestDriver {
9 }
10
11 .assembly 'vararg' {
12 }
13
14 .module 'vararg'
15
16 .class public auto ansi Tests extends [mscorlib]System.Object {
17
18         .method public static vararg void varargtest () cil managed {
19                 .maxstack 16
20                 .locals init (
21                         valuetype [mscorlib]System.ArgIterator it
22                 )
23
24                 ldloca.s it
25                 arglist
26                 call instance void [mscorlib]System.ArgIterator::.ctor (valuetype [mscorlib]System.RuntimeArgumentHandle)
27         L0:
28                 ldloca.s it
29                 call instance int32 [mscorlib]System.ArgIterator::GetRemainingCount ()
30                 ldc.i4.0
31                 ceq
32                 brtrue L1
33                 ldloca.s it
34                 call instance typedref [mscorlib]System.ArgIterator::GetNextArg ()
35                 call object [mscorlib]System.TypedReference::ToObject (typedref)
36                 call void [mscorlib]System.Console::WriteLine (object)
37                 br.s L0
38         L1:
39                 ret
40         }
41
42         // Test varargs
43         .method public static int32 test_0_varargs () cil managed {
44                 .maxstack 16
45
46                 ldc.i4.0
47                 ldc.i4.1
48                 call vararg void Tests::varargtest (..., int32, int32)
49                 ldc.i4.0
50                 ret
51         }               
52
53         .method public static vararg int32 varargtest_refany (int32 last) cil managed {
54                 .maxstack 16
55                 .locals init (
56                         valuetype [mscorlib]System.ArgIterator it,
57                         int32 sum
58                 )
59
60                 ldloca.s it
61                 arglist
62                 call instance void [mscorlib]System.ArgIterator::.ctor (valuetype [mscorlib]System.RuntimeArgumentHandle)
63                 ldc.i4.0
64                 stloc.s sum
65         L0:
66                 ldloca.s it
67                 call instance int32 [mscorlib]System.ArgIterator::GetRemainingCount ()
68                 ldc.i4.0
69                 ceq
70                 brtrue L1
71                 ldloca.s it
72                 call instance typedref [mscorlib]System.ArgIterator::GetNextArg ()
73                 ldloc.s sum
74                 call void [mscorlib]System.Console::WriteLine (int32)
75                 refanyval int32
76                 ldind.i4
77                 dup
78                 call void [mscorlib]System.Console::WriteLine (int32)
79                 ldloc.s sum
80                 add
81                 stloc.s sum
82                 br.s L0
83         L1:
84                 ldloc.s sum
85                 ret
86         }       
87
88         // Test varargs
89         .method public static int32 test_85_varargs_refany () cil managed {
90                 .maxstack 16
91
92                 ldc.i4 1
93                 ldc.i4 42
94                 ldc.i4 43
95                 call vararg int32 Tests::varargtest_refany (int32, ..., int32, int32)
96                 ret
97         }
98
99         // Test varargs
100         .method public static int32 test_0_varargs_refany_noargs () cil managed {
101                 .maxstack 16
102
103                 ldc.i4 1
104                 call vararg int32 Tests::varargtest_refany (int32)
105                 ret
106         }
107
108         .method public static int32 test_0_refanytest () cil managed {
109                 .maxstack 16
110                 .locals init (
111                         int32 sum,
112                         typedref ref
113                 )
114
115                 ldloca.s sum
116                 mkrefany int32
117                 stloc.s ref
118
119                 // Test refany with valid type
120                 ldloc.s ref
121                 refanyval int32
122                 ldloca.s sum
123                 ceq
124                 brfalse ERR1
125
126                 // Test refany with invalid type
127                 .try {
128                         ldloc.s ref
129                         refanyval int64
130                         pop
131                         leave ERR2
132                 }
133                 catch [mscorlib]System.InvalidCastException {
134                         pop
135                         leave L_LEAVE
136                 }
137         L_LEAVE:
138
139                 // Test refanytype
140                 ldloc.s ref
141                 refanytype
142                 call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle (valuetype [mscorlib]System.RuntimeTypeHandle)
143                 ldtoken int32
144                 call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle (valuetype [mscorlib]System.RuntimeTypeHandle)
145                 ceq
146                 brfalse ERR3
147
148                 ldc.i4.0
149                 ret
150         ERR1:
151                 ldc.i4.1
152                 ret
153         ERR2:
154                 ldc.i4.2
155                 ret
156         ERR3:
157                 ldc.i4.3
158                 ret
159         }
160
161         .method public static int32 Main () cil managed {
162                 .maxstack 16
163                 .entrypoint
164
165                 ldtoken Tests
166         call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
167         call int32 class [TestDriver]TestDriver::RunTests(class [mscorlib]System.Type)
168         ret
169
170         }
171 }