1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5#if defined(DEBUG) || defined(SMGEN_COMPILE)
6
7//
8// The array of state-machine-opcode names
9//
10const char* const smOpcodeNames[] = {
11#define SMOPDEF(smname, string) string,
12#include "smopcode.def"
13#undef SMOPDEF
14};
15
16//
17// The code sequences the state machine will look for.
18//
19
20const SM_OPCODE s_CodeSeqs[][MAX_CODE_SEQUENCE_LENGTH] = {
21
22#define SMOPDEF(smname, string) {smname, CODE_SEQUENCE_END},
23// ==== Single opcode states ====
24#include "smopcode.def"
25#undef SMOPDEF
26
27 // ==== Legel prefixed opcode sequences ====
28 {SM_CONSTRAINED, SM_CALLVIRT, CODE_SEQUENCE_END},
29
30 // ==== Interesting patterns ====
31
32 // Fetching of object field
33 {SM_LDARG_0, SM_LDFLD, CODE_SEQUENCE_END},
34 {SM_LDARG_1, SM_LDFLD, CODE_SEQUENCE_END},
35 {SM_LDARG_2, SM_LDFLD, CODE_SEQUENCE_END},
36 {SM_LDARG_3, SM_LDFLD, CODE_SEQUENCE_END},
37
38 // Fetching of struct field
39 {SM_LDARGA_S, SM_LDFLD, CODE_SEQUENCE_END},
40 {SM_LDLOCA_S, SM_LDFLD, CODE_SEQUENCE_END},
41
42 // Fetching of struct field from a normed struct
43 {SM_LDARGA_S_NORMED, SM_LDFLD, CODE_SEQUENCE_END},
44 {SM_LDLOCA_S_NORMED, SM_LDFLD, CODE_SEQUENCE_END},
45
46 // stloc/ldloc --> dup
47 {SM_STLOC_0, SM_LDLOC_0, CODE_SEQUENCE_END},
48 {SM_STLOC_1, SM_LDLOC_1, CODE_SEQUENCE_END},
49 {SM_STLOC_2, SM_LDLOC_2, CODE_SEQUENCE_END},
50 {SM_STLOC_3, SM_LDLOC_3, CODE_SEQUENCE_END},
51
52 // FPU operations
53 {SM_LDC_R4, SM_ADD, CODE_SEQUENCE_END},
54 {SM_LDC_R4, SM_SUB, CODE_SEQUENCE_END},
55 {SM_LDC_R4, SM_MUL, CODE_SEQUENCE_END},
56 {SM_LDC_R4, SM_DIV, CODE_SEQUENCE_END},
57
58 {SM_LDC_R8, SM_ADD, CODE_SEQUENCE_END},
59 {SM_LDC_R8, SM_SUB, CODE_SEQUENCE_END},
60 {SM_LDC_R8, SM_MUL, CODE_SEQUENCE_END},
61 {SM_LDC_R8, SM_DIV, CODE_SEQUENCE_END},
62
63 {SM_CONV_R4, SM_ADD, CODE_SEQUENCE_END},
64 {SM_CONV_R4, SM_SUB, CODE_SEQUENCE_END},
65 {SM_CONV_R4, SM_MUL, CODE_SEQUENCE_END},
66 {SM_CONV_R4, SM_DIV, CODE_SEQUENCE_END},
67
68 // {SM_CONV_R8, SM_ADD, CODE_SEQUENCE_END}, // Removed since it collides with ldelem.r8 in
69 // Math.InternalRound
70 // {SM_CONV_R8, SM_SUB, CODE_SEQUENCE_END}, // Just remove the SM_SUB as well.
71 {SM_CONV_R8, SM_MUL, CODE_SEQUENCE_END},
72 {SM_CONV_R8, SM_DIV, CODE_SEQUENCE_END},
73
74 /* Constant init constructor:
75 L_0006: ldarg.0
76 L_0007: ldc.r8 0
77 L_0010: stfld float64 raytracer.Vec::x
78 */
79
80 {SM_LDARG_0, SM_LDC_I4_0, SM_STFLD, CODE_SEQUENCE_END},
81 {SM_LDARG_0, SM_LDC_R4, SM_STFLD, CODE_SEQUENCE_END},
82 {SM_LDARG_0, SM_LDC_R8, SM_STFLD, CODE_SEQUENCE_END},
83
84 /* Copy constructor:
85 L_0006: ldarg.0
86 L_0007: ldarg.1
87 L_0008: ldfld float64 raytracer.Vec::x
88 L_000d: stfld float64 raytracer.Vec::x
89 */
90
91 {SM_LDARG_0, SM_LDARG_1, SM_LDFLD, SM_STFLD, CODE_SEQUENCE_END},
92
93 /* Field setter:
94
95 [DebuggerNonUserCode]
96 private void CtorClosed(object target, IntPtr methodPtr)
97 {
98 if (target == null)
99 {
100 this.ThrowNullThisInDelegateToInstance();
101 }
102 base._target = target;
103 base._methodPtr = methodPtr;
104 }
105
106
107 .method private hidebysig instance void CtorClosed(object target, native int methodPtr) cil managed
108 {
109 .custom instance void System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor()
110 .maxstack 8
111 L_0000: ldarg.1
112 L_0001: brtrue.s L_0009
113 L_0003: ldarg.0
114 L_0004: call instance void System.MulticastDelegate::ThrowNullThisInDelegateToInstance()
115
116 L_0009: ldarg.0
117 L_000a: ldarg.1
118 L_000b: stfld object System.Delegate::_target
119
120 L_0010: ldarg.0
121 L_0011: ldarg.2
122 L_0012: stfld native int System.Delegate::_methodPtr
123
124 L_0017: ret
125 }
126 */
127
128 {SM_LDARG_0, SM_LDARG_1, SM_STFLD, CODE_SEQUENCE_END},
129 {SM_LDARG_0, SM_LDARG_2, SM_STFLD, CODE_SEQUENCE_END},
130 {SM_LDARG_0, SM_LDARG_3, SM_STFLD, CODE_SEQUENCE_END},
131
132 /* Scale operator:
133
134 L_0000: ldarg.0
135 L_0001: dup
136 L_0002: ldfld float64 raytracer.Vec::x
137 L_0007: ldarg.1
138 L_0008: mul
139 L_0009: stfld float64 raytracer.Vec::x
140 */
141
142 {SM_LDARG_0, SM_DUP, SM_LDFLD, SM_LDARG_1, SM_ADD, SM_STFLD, CODE_SEQUENCE_END},
143 {SM_LDARG_0, SM_DUP, SM_LDFLD, SM_LDARG_1, SM_SUB, SM_STFLD, CODE_SEQUENCE_END},
144 {SM_LDARG_0, SM_DUP, SM_LDFLD, SM_LDARG_1, SM_MUL, SM_STFLD, CODE_SEQUENCE_END},
145 {SM_LDARG_0, SM_DUP, SM_LDFLD, SM_LDARG_1, SM_DIV, SM_STFLD, CODE_SEQUENCE_END},
146
147 /* Add operator
148 L_0000: ldarg.0
149 L_0001: ldfld float64 raytracer.Vec::x
150 L_0006: ldarg.1
151 L_0007: ldfld float64 raytracer.Vec::x
152 L_000c: add
153 */
154
155 {SM_LDARG_0, SM_LDFLD, SM_LDARG_1, SM_LDFLD, SM_ADD, CODE_SEQUENCE_END},
156 {SM_LDARG_0, SM_LDFLD, SM_LDARG_1, SM_LDFLD, SM_SUB, CODE_SEQUENCE_END},
157 // No need for mul and div since there is no mathemetical meaning of it.
158
159 {SM_LDARGA_S, SM_LDFLD, SM_LDARGA_S, SM_LDFLD, SM_ADD, CODE_SEQUENCE_END},
160 {SM_LDARGA_S, SM_LDFLD, SM_LDARGA_S, SM_LDFLD, SM_SUB, CODE_SEQUENCE_END},
161 // No need for mul and div since there is no mathemetical meaning of it.
162
163 // The end:
164 {CODE_SEQUENCE_END}};
165
166#endif // defined(DEBUG) || defined(SMGEN_COMPILE)
167