2004-08-21 Zoltan Varga <vargaz@freemail.hu>
[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 () 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 42
93                 ldc.i4 43
94                 call vararg int32 Tests::varargtest_refany (..., int32, int32)
95                 ret
96         }
97
98         .method public static int32 test_0_refanytest () cil managed {
99                 .maxstack 16
100                 .locals init (
101                         int32 sum,
102                         typedref ref
103                 )
104
105                 ldloca.s sum
106                 mkrefany int32
107                 stloc.s ref
108
109                 // Test refany with valid type
110                 ldloc.s ref
111                 refanyval int32
112                 ldloca.s sum
113                 ceq
114                 brfalse ERR1
115
116                 // Test refany with invalid type
117                 .try {
118                         ldloc.s ref
119                         refanyval int64
120                         pop
121                         leave ERR2
122                 }
123                 catch [mscorlib]System.InvalidCastException {
124                         pop
125                         leave L_LEAVE
126                 }
127         L_LEAVE:
128
129                 // Test refanytype
130                 ldloc.s ref
131                 refanytype
132                 call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle (valuetype [mscorlib]System.RuntimeTypeHandle)
133                 ldtoken int32
134                 call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle (valuetype [mscorlib]System.RuntimeTypeHandle)
135                 ceq
136                 brfalse ERR3
137
138                 ldc.i4.0
139                 ret
140         ERR1:
141                 ldc.i4.1
142                 ret
143         ERR2:
144                 ldc.i4.2
145                 ret
146         ERR3:
147                 ldc.i4.3
148                 ret
149         }
150
151         .method public static int32 Main () cil managed {
152                 .maxstack 16
153                 .entrypoint
154
155                 ldtoken Tests
156         call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
157         call int32 class [TestDriver]TestDriver::RunTests(class [mscorlib]System.Type)
158         ret
159
160         }
161 }