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