-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathOpMethod.cs
More file actions
101 lines (92 loc) · 2.55 KB
/
OpMethod.cs
File metadata and controls
101 lines (92 loc) · 2.55 KB
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
using System;
using System.Reflection;
namespace Cosmos.IL2CPU.ILOpCodes
{
public class OpMethod : ILOpCode
{
public MethodBase Value { get; set; }
public uint ValueUID { get; set; }
public OpMethod(Code aOpCode, int aPos, int aNextPos, MethodBase aValue, _ExceptionRegionInfo aCurrentExceptionRegion)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionRegion)
{
Value = aValue;
}
public override int GetNumberOfStackPops(MethodBase aMethod)
{
switch (OpCode)
{
case Code.Call:
case Code.Callvirt:
if (Value.IsStatic)
{
return Value.GetParameters().Length;
}
else
{
return Value.GetParameters().Length + 1;
}
case Code.Newobj:
return Value.GetParameters().Length;
case Code.Ldftn:
return 0;
case Code.Ldvirtftn:
return 1;
default:
throw new NotImplementedException("OpCode '" + OpCode + "' not implemented!");
}
}
public override int GetNumberOfStackPushes(MethodBase aMethod)
{
switch (OpCode)
{
case Code.Call:
case Code.Callvirt:
var methodInfo = Value as MethodInfo;
if (methodInfo != null && methodInfo.ReturnType != typeof(void))
{
return 1;
}
return 0;
case Code.Newobj:
return 1;
case Code.Ldftn:
return 1;
case Code.Ldvirtftn:
return 1;
default:
throw new NotImplementedException("OpCode '" + OpCode + "' not implemented!");
}
}
protected override void DoInitStackAnalysis(MethodBase aMethod)
{
base.DoInitStackAnalysis(aMethod);
switch (OpCode)
{
case Code.Call:
case Code.Callvirt:
var xMethodInfo = Value as MethodInfo;
if (xMethodInfo != null && xMethodInfo.ReturnType != typeof(void))
{
StackPushTypes[0] = xMethodInfo.ReturnType;
if (StackPushTypes[0].IsEnum)
{
StackPushTypes[0] = StackPushTypes[0].GetEnumUnderlyingType();
}
}
break;
case Code.Newobj:
StackPushTypes[0] = Value.DeclaringType;
break;
case Code.Ldftn:
StackPushTypes[0] = typeof(IntPtr);
return;
case Code.Ldvirtftn:
StackPushTypes[0] = typeof(IntPtr);
return;
default:
break;
}
}
public override void DoInterpretStackTypes() { }
}
}