Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CodeGenerator.cs
Go to the documentation of this file.
7
9
10internal sealed class CodeGenerator
11{
12 internal sealed class WhileState
13 {
15
17
19
21 {
22 StartLabel = ilg.DefineLabel();
23 CondLabel = ilg.DefineLabel();
24 EndLabel = ilg.DefineLabel();
25 }
26 }
27
28 private readonly TypeBuilder _typeBuilder;
29
31
33
35
37
39
41
43
45
46 internal Label retLabel;
47
49
50 private static readonly OpCode[] s_branchCodes = new OpCode[6]
51 {
58 };
59
60 private readonly Stack<Label> _leaveLabels = new Stack<Label>();
61
84
107
130
131 private static readonly OpCode[] s_convOpCodes = new OpCode[19]
132 {
133 OpCodes.Nop,
134 OpCodes.Nop,
135 OpCodes.Nop,
148 OpCodes.Nop,
149 OpCodes.Nop,
150 OpCodes.Nop,
152 };
153
154 private int _initElseIfStack = -1;
155
157
158 private int _initIfStack = -1;
159
161
163
165 {
166 get
167 {
168 if (retLocal == null)
169 {
171 }
172 return retLocal;
173 }
174 }
175
177
178 internal CodeGenerator(TypeBuilder typeBuilder)
179 {
180 _typeBuilder = typeBuilder;
181 }
182
183 internal static bool IsNullableGenericType(Type type)
184 {
185 return type.Name == "Nullable`1";
186 }
187
194
201
202 private void InitILGeneration(Type[] argTypes, string[] argNames, bool isStatic)
203 {
211 if (!isStatic)
212 {
213 _argList.Add("this", new ArgBuilder("this", 0, _typeBuilder.BaseType));
214 }
215 for (int i = 0; i < argTypes.Length; i++)
216 {
217 ArgBuilder argBuilder = new ArgBuilder(argNames[i], _argList.Count, argTypes[i]);
220 }
221 }
222
224 {
226 Ret();
229 _methodBuilder = null;
230 _ilGen = null;
231 _freeLocals = null;
232 _blockStack = null;
233 _whileStack = null;
234 _argList = null;
235 _currentScope = null;
236 retLocal = null;
237 return methodBuilder;
238 }
239
240 internal ArgBuilder GetArg(string name)
241 {
242 return _argList[name];
243 }
244
245 internal LocalBuilder GetLocal(string name)
246 {
247 return _currentScope[name];
248 }
249
251 {
253 {
256 }
257 return value;
258 }
259
260 internal Type GetVariableType(object var)
261 {
262 if (var is ArgBuilder)
263 {
264 return ((ArgBuilder)var).ArgType;
265 }
266 if (var is LocalBuilder)
267 {
268 return ((LocalBuilder)var).LocalType;
269 }
270 return var.GetType();
271 }
272
273 internal object GetVariable(string name)
274 {
275 if (TryGetVariable(name, out var variable))
276 {
277 return variable;
278 }
279 return null;
280 }
281
282 internal bool TryGetVariable(string name, [NotNullWhen(true)] out object variable)
283 {
284 if (_currentScope != null && _currentScope.TryGetValue(name, out var value))
285 {
286 variable = value;
287 return true;
288 }
289 if (_argList != null && _argList.TryGetValue(name, out var value2))
290 {
292 return true;
293 }
294 if (int.TryParse(name, out var result))
295 {
296 variable = result;
297 return true;
298 }
299 variable = null;
300 return false;
301 }
302
308
314
315 private bool TryDequeueLocal(Type type, string name, [NotNullWhen(true)] out LocalBuilder local)
316 {
317 (Type, string) key = (type, name);
319 {
320 local = value.Dequeue();
321 if (value.Count == 0)
322 {
324 }
325 return true;
326 }
327 local = null;
328 return false;
329 }
330
331 internal LocalBuilder DeclareLocal(Type type, string name)
332 {
333 if (!TryDequeueLocal(type, name, out var local))
334 {
336 }
337 _currentScope[name] = local;
338 return local;
339 }
340
342 {
344 {
345 return DeclareLocal(type, name);
346 }
347 return value;
348 }
349
350 internal object For(LocalBuilder local, object start, object end)
351 {
353 if (forState.Index != null)
354 {
355 Load(start);
356 Stloc(forState.Index);
357 Br(forState.TestLabel);
358 }
359 MarkLabel(forState.BeginLabel);
361 return forState;
362 }
363
364 internal void EndFor()
365 {
366 object obj = _blockStack.Pop();
368 if (forState.Index != null)
369 {
370 Ldloc(forState.Index);
371 Ldc(1);
372 Add();
373 Stloc(forState.Index);
374 MarkLabel(forState.TestLabel);
375 Ldloc(forState.Index);
376 Load(forState.End);
378 if (variableType.IsArray)
379 {
380 Ldlen();
381 }
382 else
383 {
384 MethodInfo method = typeof(ICollection).GetMethod("get_Count", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
385 Call(method);
386 }
387 Blt(forState.BeginLabel);
388 }
389 else
390 {
391 Br(forState.BeginLabel);
392 }
393 }
394
395 internal void If()
396 {
397 InternalIf(negate: false);
398 }
399
400 internal void IfNot()
401 {
402 InternalIf(negate: true);
403 }
404
406 {
407 return s_branchCodes[(int)cmp];
408 }
409
410 internal void If(Cmp cmpOp)
411 {
412 IfState ifState = new IfState();
417 }
418
419 internal void If(object value1, Cmp cmpOp, object value2)
420 {
421 Load(value1);
422 Load(value2);
423 If(cmpOp);
424 }
425
426 internal void Else()
427 {
429 Br(ifState.EndIf);
430 MarkLabel(ifState.ElseBegin);
433 }
434
435 internal void EndIf()
436 {
438 if (!ifState.ElseBegin.Equals(ifState.EndIf))
439 {
440 MarkLabel(ifState.ElseBegin);
441 }
442 MarkLabel(ifState.EndIf);
443 }
444
445 internal void BeginExceptionBlock()
446 {
449 }
450
455
456 internal void EndExceptionBlock()
457 {
460 }
461
462 internal void Leave()
463 {
465 }
466
468 {
469 if (methodInfo.IsVirtual && !methodInfo.DeclaringType.IsValueType)
470 {
472 }
473 else
474 {
476 }
477 }
478
479 internal void Call(ConstructorInfo ctor)
480 {
482 }
483
488
489 internal void InitObj(Type valueType)
490 {
492 }
493
494 internal void NewArray(Type elementType, object len)
495 {
496 Load(len);
498 }
499
500 internal void LoadArrayElement(object obj, object arrayIndex)
501 {
503 Load(obj);
506 {
509 }
510 else
511 {
513 }
514 }
515
516 internal void StoreArrayElement(object obj, object arrayIndex, object value)
517 {
519 if (variableType == typeof(Array))
520 {
521 Load(obj);
522 Call(typeof(Array).GetMethod("SetValue", new Type[2]
523 {
524 typeof(object),
525 typeof(int)
526 }));
527 return;
528 }
529 Type elementType = variableType.GetElementType();
530 Load(obj);
533 {
535 }
536 Load(value);
539 {
541 }
542 else
543 {
545 }
546 }
547
548 private static bool IsStruct(Type objType)
549 {
550 if (objType.IsValueType)
551 {
552 return !objType.IsPrimitive;
553 }
554 return false;
555 }
556
557 [RequiresUnreferencedCode("calls LoadMember")]
559 {
560 if (GetVariableType(obj).IsValueType)
561 {
563 }
564 else
565 {
566 Load(obj);
567 }
568 return LoadMember(memberInfo);
569 }
570
571 [RequiresUnreferencedCode("GetProperty on PropertyInfo type's base type")]
573 {
574 Type baseType = propertyInfo.DeclaringType.BaseType;
575 string name = propertyInfo.Name;
576 MethodInfo methodInfo = null;
577 while (baseType != null)
578 {
579 PropertyInfo property = baseType.GetProperty(name);
580 if (property != null)
581 {
582 methodInfo = ((!isGetter) ? property.SetMethod : property.GetMethod);
583 if (methodInfo != null)
584 {
585 break;
586 }
587 }
588 baseType = baseType.BaseType;
589 }
590 return methodInfo;
591 }
592
593 [RequiresUnreferencedCode("calls GetPropertyMethodFromBaseType")]
595 {
596 Type type = null;
598 {
600 type = fieldInfo.FieldType;
601 if (fieldInfo.IsStatic)
602 {
604 }
605 else
606 {
608 }
609 }
610 else
611 {
612 PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
613 type = propertyInfo.PropertyType;
614 if (propertyInfo != null)
615 {
616 MethodInfo methodInfo = propertyInfo.GetMethod;
617 if (methodInfo == null)
618 {
620 }
622 }
623 }
624 return type;
625 }
626
627 [RequiresUnreferencedCode("calls GetPropertyMethodFromBaseType")]
629 {
630 Type type = null;
632 {
634 type = fieldInfo.FieldType;
635 if (fieldInfo.IsStatic)
636 {
638 }
639 else
640 {
642 }
643 }
644 else
645 {
646 PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
647 type = propertyInfo.PropertyType;
648 if (propertyInfo != null)
649 {
650 MethodInfo methodInfo = propertyInfo.GetMethod;
651 if (methodInfo == null)
652 {
654 }
659 }
660 }
661 return type;
662 }
663
664 [RequiresUnreferencedCode("calls GetPropertyMethodFromBaseType")]
666 {
668 {
670 if (fieldInfo.IsStatic)
671 {
673 }
674 else
675 {
677 }
678 return;
679 }
680 PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
681 if (propertyInfo != null)
682 {
683 MethodInfo methodInfo = propertyInfo.SetMethod;
684 if (methodInfo == null)
685 {
686 methodInfo = GetPropertyMethodFromBaseType(propertyInfo, isGetter: false);
687 }
689 }
690 }
691
692 internal void Load(object obj)
693 {
694 if (obj == null)
695 {
697 }
698 else if (obj is ArgBuilder)
699 {
701 }
702 else if (obj is LocalBuilder)
703 {
705 }
706 else
707 {
708 Ldc(obj);
709 }
710 }
711
712 internal void LoadAddress(object obj)
713 {
714 if (obj is ArgBuilder)
715 {
717 }
718 else if (obj is LocalBuilder)
719 {
721 }
722 else
723 {
724 Load(obj);
725 }
726 }
727
728 internal void ConvertAddress(Type source, Type target)
729 {
730 InternalConvert(source, target, isAddress: true);
731 }
732
733 internal void ConvertValue(Type source, Type target)
734 {
735 InternalConvert(source, target, isAddress: false);
736 }
737
738 internal void Castclass(Type target)
739 {
740 _ilGen.Emit(OpCodes.Castclass, target);
741 }
742
743 internal void Box(Type type)
744 {
746 }
747
748 internal void Unbox(Type type)
749 {
751 }
752
754 {
755 return s_ldindOpCodes[(int)typeCode];
756 }
757
758 internal void Ldobj(Type type)
759 {
761 if (!ldindOpCode.Equals(OpCodes.Nop))
762 {
764 }
765 else
766 {
768 }
769 }
770
771 internal void Stobj(Type type)
772 {
774 }
775
776 internal void Ceq()
777 {
779 }
780
781 internal void Clt()
782 {
784 }
785
786 internal void Cne()
787 {
788 Ceq();
789 Ldc(0);
790 Ceq();
791 }
792
793 internal void Ble(Label label)
794 {
796 }
797
798 internal void Throw()
799 {
801 }
802
803 internal void Ldtoken(Type t)
804 {
806 }
807
808 internal void Ldc(object o)
809 {
810 Type type = o.GetType();
811 if (o is Type)
812 {
813 Ldtoken((Type)o);
814 Call(typeof(Type).GetMethod("GetTypeFromHandle", BindingFlags.Static | BindingFlags.Public, new Type[1] { typeof(RuntimeTypeHandle) }));
815 return;
816 }
817 if (type.IsEnum)
818 {
820 return;
821 }
822 switch (Type.GetTypeCode(type))
823 {
824 case TypeCode.Boolean:
825 Ldc((bool)o);
826 return;
827 case TypeCode.Char:
829 case TypeCode.SByte:
830 case TypeCode.Byte:
831 case TypeCode.Int16:
832 case TypeCode.UInt16:
834 return;
835 case TypeCode.Int32:
836 Ldc((int)o);
837 return;
838 case TypeCode.UInt32:
839 Ldc((int)(uint)o);
840 return;
841 case TypeCode.UInt64:
842 Ldc((long)(ulong)o);
843 return;
844 case TypeCode.Int64:
845 Ldc((long)o);
846 return;
847 case TypeCode.Single:
848 Ldc((float)o);
849 return;
850 case TypeCode.Double:
851 Ldc((double)o);
852 return;
853 case TypeCode.String:
854 Ldstr((string)o);
855 return;
856 case TypeCode.Decimal:
857 {
858 ConstructorInfo constructor2 = typeof(decimal).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[5]
859 {
860 typeof(int),
861 typeof(int),
862 typeof(int),
863 typeof(bool),
864 typeof(byte)
865 });
866 int[] bits = decimal.GetBits((decimal)o);
867 Ldc(bits[0]);
868 Ldc(bits[1]);
869 Ldc(bits[2]);
870 Ldc((bits[3] & 0x80000000u) == 2147483648u);
871 Ldc((byte)((bits[3] >> 16) & 0xFF));
873 return;
874 }
875 case TypeCode.DateTime:
876 {
877 ConstructorInfo constructor = typeof(DateTime).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(long) });
878 Ldc(((DateTime)o).Ticks);
880 return;
881 }
882 }
883 if (type == typeof(TimeSpan))
884 {
885 ConstructorInfo constructor3 = typeof(TimeSpan).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(long) }, null);
886 Ldc(((TimeSpan)o).Ticks);
888 return;
889 }
890 if (type == typeof(DateTimeOffset))
891 {
892 ConstructorInfo constructor4 = typeof(DateTimeOffset).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
893 {
894 typeof(long),
895 typeof(TimeSpan)
896 }, null);
897 Ldc(((DateTimeOffset)o).Ticks);
898 Ldc(((DateTimeOffset)o).Offset);
900 return;
901 }
902 throw new NotSupportedException(System.SR.Format(System.SR.UnknownConstantType, type.AssemblyQualifiedName));
903 }
904
905 internal void Ldc(bool boolVar)
906 {
907 if (boolVar)
908 {
910 }
911 else
912 {
914 }
915 }
916
917 internal void Ldc(int intVar)
918 {
920 }
921
922 internal void Ldc(long l)
923 {
925 }
926
927 internal void Ldc(float f)
928 {
930 }
931
932 internal void Ldc(double d)
933 {
935 }
936
937 internal void Ldstr(string strVar)
938 {
939 if (strVar == null)
940 {
942 }
943 else
944 {
946 }
947 }
948
950 {
951 if (localBuilder.LocalType.IsValueType)
952 {
954 }
955 else
956 {
958 }
959 }
960
965
966 internal void Ldloc(string name)
967 {
970 }
971
972 internal void Stloc(Type type, string name)
973 {
974 LocalBuilder value = null;
976 {
977 value = DeclareLocal(type, name);
978 }
979 Stloc(value);
980 }
981
982 internal void Stloc(LocalBuilder local)
983 {
985 }
986
987 internal void Ldloc(Type type, string name)
988 {
991 }
992
997
999 {
1000 if (argBuilder.ArgType.IsValueType)
1001 {
1003 }
1004 else
1005 {
1007 }
1008 }
1009
1010 internal void Ldarg(string arg)
1011 {
1012 Ldarg(GetArg(arg));
1013 }
1014
1015 internal void Ldarg(ArgBuilder arg)
1016 {
1017 Ldarg(arg.Index);
1018 }
1019
1020 internal void Ldarg(int slot)
1021 {
1023 }
1024
1026 {
1027 Ldarga(argBuilder.Index);
1028 }
1029
1030 internal void Ldarga(int slot)
1031 {
1033 }
1034
1035 internal void Ldlen()
1036 {
1039 }
1040
1042 {
1043 return s_ldelemOpCodes[(int)typeCode];
1044 }
1045
1047 {
1048 if (arrayElementType.IsEnum)
1049 {
1051 return;
1052 }
1054 if (ldelemOpCode.Equals(OpCodes.Nop))
1055 {
1057 }
1059 }
1060
1066
1068 {
1069 return s_stelemOpCodes[(int)typeCode];
1070 }
1071
1073 {
1074 if (arrayElementType.IsEnum)
1075 {
1077 return;
1078 }
1080 if (stelemOpCode.Equals(OpCodes.Nop))
1081 {
1083 }
1085 }
1086
1088 {
1089 return _ilGen.DefineLabel();
1090 }
1091
1092 internal void MarkLabel(Label label)
1093 {
1095 }
1096
1097 internal void Nop()
1098 {
1100 }
1101
1102 internal void Add()
1103 {
1105 }
1106
1107 internal void Ret()
1108 {
1110 }
1111
1112 internal void Br(Label label)
1113 {
1115 }
1116
1117 internal void Br_S(Label label)
1118 {
1120 }
1121
1122 internal void Blt(Label label)
1123 {
1125 }
1126
1127 internal void Brfalse(Label label)
1128 {
1130 }
1131
1132 internal void Brtrue(Label label)
1133 {
1135 }
1136
1137 internal void Pop()
1138 {
1140 }
1141
1142 internal void Dup()
1143 {
1145 }
1146
1147 private void InternalIf(bool negate)
1148 {
1149 IfState ifState = new IfState();
1152 if (negate)
1153 {
1154 Brtrue(ifState.ElseBegin);
1155 }
1156 else
1157 {
1158 Brfalse(ifState.ElseBegin);
1159 }
1161 }
1162
1164 {
1165 return s_convOpCodes[(int)typeCode];
1166 }
1167
1168 private void InternalConvert(Type source, Type target, bool isAddress)
1169 {
1170 if (target == source)
1171 {
1172 return;
1173 }
1174 if (target.IsValueType)
1175 {
1176 if (source.IsValueType)
1177 {
1179 if (convOpCode.Equals(OpCodes.Nop))
1180 {
1181 throw new CodeGeneratorConversionException(source, target, isAddress, "NoConversionPossibleTo");
1182 }
1184 return;
1185 }
1186 if (!source.IsAssignableFrom(target))
1187 {
1188 throw new CodeGeneratorConversionException(source, target, isAddress, "IsNotAssignableFrom");
1189 }
1190 Unbox(target);
1191 if (!isAddress)
1192 {
1193 Ldobj(target);
1194 }
1195 }
1196 else if (target.IsAssignableFrom(source))
1197 {
1198 if (source.IsValueType)
1199 {
1200 if (isAddress)
1201 {
1202 Ldobj(source);
1203 }
1204 Box(source);
1205 }
1206 }
1207 else if (source.IsAssignableFrom(target))
1208 {
1209 Castclass(target);
1210 }
1211 else
1212 {
1213 if (!target.IsInterface && !source.IsInterface)
1214 {
1215 throw new CodeGeneratorConversionException(source, target, isAddress, "IsNotAssignableFrom");
1216 }
1217 Castclass(target);
1218 }
1219 }
1220
1222 {
1223 object obj = _blockStack.Pop();
1224 return obj as IfState;
1225 }
1226
1234
1236 {
1237 return assemblyBuilder.DefineDynamicModule(name);
1238 }
1239
1241 {
1242 return moduleBuilder.DefineType("Microsoft.Xml.Serialization.GeneratedAssembly." + name, attributes, parent, interfaces);
1243 }
1244
1252
1253 internal void InitIf()
1254 {
1256 }
1257
1258 internal void AndIf(Cmp cmpOp)
1259 {
1261 {
1262 _initIfStack = -1;
1263 If(cmpOp);
1264 }
1266 {
1267 _initElseIfStack = -1;
1271 }
1272 else
1273 {
1275 _ilGen.Emit(GetBranchCode(cmpOp), ifState.ElseBegin);
1276 }
1277 }
1278
1279 internal void AndIf()
1280 {
1282 {
1283 _initIfStack = -1;
1284 If();
1285 }
1287 {
1288 _initElseIfStack = -1;
1292 }
1293 else
1294 {
1296 Brfalse(ifState.ElseBegin);
1297 }
1298 }
1299
1300 internal void IsInst(Type type)
1301 {
1303 }
1304
1305 internal void Beq(Label label)
1306 {
1308 }
1309
1310 internal void Bne(Label label)
1311 {
1313 }
1314
1315 internal void GotoMethodEnd()
1316 {
1318 }
1319
1320 internal void WhileBegin()
1321 {
1322 WhileState whileState = new WhileState(this);
1323 Ldc(boolVar: true);
1324 Brtrue(whileState.CondLabel);
1325 MarkLabel(whileState.StartLabel);
1326 _whileStack.Push(whileState);
1327 }
1328
1329 internal void WhileEnd()
1330 {
1332 MarkLabel(whileState.EndLabel);
1333 }
1334
1335 internal void WhileContinue()
1336 {
1338 Br(whileState.CondLabel);
1339 }
1340
1341 internal void WhileBeginCondition()
1342 {
1344 Nop();
1345 MarkLabel(whileState.CondLabel);
1346 }
1347
1348 internal void WhileEndCondition()
1349 {
1351 Brtrue(whileState.StartLabel);
1352 }
1353}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
virtual ? object Peek()
Definition Stack.cs:336
virtual void Push(object? obj)
Definition Stack.cs:357
virtual ? object Pop()
Definition Stack.cs:345
static int ToInt32(object? value)
Definition Convert.cs:1320
static ? object ChangeType(object? value, TypeCode typeCode)
Definition Convert.cs:229
static Type GetUnderlyingType(Type enumType)
Definition Enum.cs:309
static CultureInfo InvariantCulture
static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
virtual LocalBuilder DeclareLocal(Type localType)
virtual void MarkLabel(Label loc)
virtual void Emit(OpCode opcode)
virtual void BeginCatchBlock(Type exceptionType)
override MethodAttributes Attributes
ParameterBuilder DefineParameter(int position, ParameterAttributes attributes, string? strParamName)
static readonly OpCode Castclass
Definition OpCodes.cs:235
static readonly OpCode Ldloca
Definition OpCodes.cs:427
static readonly OpCode Ldelem_I2
Definition OpCodes.cs:291
static readonly OpCode Leave
Definition OpCodes.cs:379
static readonly OpCode Ldelem_U2
Definition OpCodes.cs:293
static readonly OpCode Unbox
Definition OpCodes.cs:241
static readonly OpCode Brfalse
Definition OpCodes.cs:117
static readonly OpCode Conv_I4
Definition OpCodes.cs:213
static readonly OpCode Ldsflda
Definition OpCodes.cs:253
static readonly OpCode Ldc_I8
Definition OpCodes.cs:71
static readonly OpCode Blt
Definition OpCodes.cs:129
static readonly OpCode Callvirt
Definition OpCodes.cs:225
static readonly OpCode Ldind_I1
Definition OpCodes.cs:143
static readonly OpCode Brtrue
Definition OpCodes.cs:119
static readonly OpCode Clt
Definition OpCodes.cs:411
static readonly OpCode Br_S
Definition OpCodes.cs:89
static readonly OpCode Conv_I2
Definition OpCodes.cs:211
static readonly OpCode Stloc
Definition OpCodes.cs:429
static readonly OpCode Ldind_R4
Definition OpCodes.cs:159
static readonly OpCode Ldind_I2
Definition OpCodes.cs:147
static readonly OpCode Newobj
Definition OpCodes.cs:233
static readonly OpCode Ldind_I4
Definition OpCodes.cs:151
static readonly OpCode Ldflda
Definition OpCodes.cs:247
static readonly OpCode Ldind_U2
Definition OpCodes.cs:149
static readonly OpCode Bgt
Definition OpCodes.cs:125
static readonly OpCode Conv_I1
Definition OpCodes.cs:209
static readonly OpCode Ldind_U4
Definition OpCodes.cs:153
static readonly OpCode Ldelem_U4
Definition OpCodes.cs:297
static readonly OpCode Add
Definition OpCodes.cs:179
static readonly OpCode Ldind_R8
Definition OpCodes.cs:161
static readonly OpCode Ble
Definition OpCodes.cs:127
static readonly OpCode Ldind_I8
Definition OpCodes.cs:155
static readonly OpCode Ldobj
Definition OpCodes.cs:229
static readonly OpCode Ldc_I4
Definition OpCodes.cs:69
static readonly OpCode Beq
Definition OpCodes.cs:121
static readonly OpCode Stelem_Ref
Definition OpCodes.cs:323
static readonly OpCode Stsfld
Definition OpCodes.cs:255
static readonly OpCode Br
Definition OpCodes.cs:115
static readonly OpCode Initobj
Definition OpCodes.cs:441
static readonly OpCode Conv_U1
Definition OpCodes.cs:357
static readonly OpCode Stelem_I4
Definition OpCodes.cs:315
static readonly OpCode Bne_Un
Definition OpCodes.cs:131
static readonly OpCode Ceq
Definition OpCodes.cs:405
static readonly OpCode Ldfld
Definition OpCodes.cs:245
static readonly OpCode Ldarga
Definition OpCodes.cs:421
static readonly OpCode Bge
Definition OpCodes.cs:123
static readonly OpCode Conv_U4
Definition OpCodes.cs:221
static readonly OpCode Ldelem_Ref
Definition OpCodes.cs:307
static readonly OpCode Ldc_I4_1
Definition OpCodes.cs:51
static readonly OpCode Ldc_I4_0
Definition OpCodes.cs:49
static readonly OpCode Stelem_I8
Definition OpCodes.cs:317
static readonly OpCode Isinst
Definition OpCodes.cs:237
static readonly OpCode Throw
Definition OpCodes.cs:243
static readonly OpCode Ldstr
Definition OpCodes.cs:231
static readonly OpCode Conv_R4
Definition OpCodes.cs:217
static readonly OpCode Pop
Definition OpCodes.cs:79
static readonly OpCode Conv_U2
Definition OpCodes.cs:355
static readonly OpCode Ldelema
Definition OpCodes.cs:285
static readonly OpCode Stobj
Definition OpCodes.cs:257
static readonly OpCode Ldind_U1
Definition OpCodes.cs:145
static readonly OpCode Ldsfld
Definition OpCodes.cs:251
static readonly OpCode Stelem_I1
Definition OpCodes.cs:311
static readonly OpCode Ldelem_I4
Definition OpCodes.cs:295
static readonly OpCode Ldelem_R4
Definition OpCodes.cs:303
static readonly OpCode Ldelem_U1
Definition OpCodes.cs:289
static readonly OpCode Ldtoken
Definition OpCodes.cs:353
static readonly OpCode Call
Definition OpCodes.cs:83
static readonly OpCode Stelem_R4
Definition OpCodes.cs:319
static readonly OpCode Conv_R8
Definition OpCodes.cs:219
static readonly OpCode Nop
Definition OpCodes.cs:5
static readonly OpCode Ret
Definition OpCodes.cs:87
static readonly OpCode Ldloc
Definition OpCodes.cs:425
static readonly OpCode Ldnull
Definition OpCodes.cs:45
static readonly OpCode Ldc_R4
Definition OpCodes.cs:73
static readonly OpCode Box
Definition OpCodes.cs:279
static readonly OpCode Conv_U8
Definition OpCodes.cs:223
static readonly OpCode Ldc_R8
Definition OpCodes.cs:75
static readonly OpCode Stelem_I2
Definition OpCodes.cs:313
static readonly OpCode Stelem_R8
Definition OpCodes.cs:321
static readonly OpCode Dup
Definition OpCodes.cs:77
static readonly OpCode Stfld
Definition OpCodes.cs:249
static readonly OpCode Newarr
Definition OpCodes.cs:281
static readonly OpCode Ldarg
Definition OpCodes.cs:419
static readonly OpCode Ldelem_I1
Definition OpCodes.cs:287
static readonly OpCode Conv_I8
Definition OpCodes.cs:215
static readonly OpCode Ldlen
Definition OpCodes.cs:283
static readonly OpCode Ldelem_R8
Definition OpCodes.cs:305
static readonly OpCode Ldelem_I8
Definition OpCodes.cs:299
static int DefineMethod(QCallModule module, int tkParent, string name, byte[] signature, int sigLength, MethodAttributes attributes)
virtual ? MethodInfo GetMethod
virtual ? MethodInfo SetMethod
static string UnknownConstantType
Definition SR.cs:294
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ArrayTypeIsNotSupported
Definition SR.cs:2140
static string XmlInvalidCharSchemaPrimitive
Definition SR.cs:2136
Definition SR.cs:7
Type? GetElementType()
bool IsInterface
Definition Type.cs:30
virtual bool IsAssignableFrom([NotNullWhen(true)] Type? c)
Definition Type.cs:1561
bool IsValueType
Definition Type.cs:234
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
Type? BaseType
Definition Type.cs:295
static readonly Type[] EmptyTypes
Definition Type.cs:19
void Ldelem(Type arrayElementType)
void Stelem(Type arrayElementType)
Dictionary< string, ArgBuilder > _argList
bool TryDequeueLocal(Type type, string name, [NotNullWhen(true)] out LocalBuilder local)
void Call(ConstructorInfo ctor)
static bool IsNullableGenericType(Type type)
void ConvertAddress(Type source, Type target)
void ConvertValue(Type source, Type target)
Type LoadMemberAddress(MemberInfo memberInfo)
static readonly OpCode[] s_ldindOpCodes
LocalBuilder DeclareLocal(Type type, string name)
void InternalConvert(Type source, Type target, bool isAddress)
LocalBuilder DeclareOrGetLocal(Type type, string name)
void StoreMember(MemberInfo memberInfo)
void Ldelema(Type arrayElementType)
OpCode GetLdindOpCode(TypeCode typeCode)
void New(ConstructorInfo constructorInfo)
OpCode GetConvOpCode(TypeCode typeCode)
void LdargAddress(ArgBuilder argBuilder)
void BeginMethod(Type returnType, MethodBuilderInfo methodBuilderInfo, Type[] argTypes, string[] argNames, MethodAttributes methodAttributes)
static ModuleBuilder CreateModuleBuilder(AssemblyBuilder assemblyBuilder, string name)
void BeginMethod(Type returnType, string methodName, Type[] argTypes, string[] argNames, MethodAttributes methodAttributes)
OpCode GetLdelemOpCode(TypeCode typeCode)
static AssemblyBuilder CreateAssemblyBuilder(string name)
void InitILGeneration(Type[] argTypes, string[] argNames, bool isStatic)
static TypeBuilder CreateTypeBuilder(ModuleBuilder moduleBuilder, string name, TypeAttributes attributes, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type parent, Type[] interfaces)
Type LoadMember(object obj, MemberInfo memberInfo)
void LoadArrayElement(object obj, object arrayIndex)
void Ldloc(Type type, string name)
void Call(MethodInfo methodInfo)
void NewArray(Type elementType, object len)
static readonly OpCode[] s_ldelemOpCodes
void Ldarga(ArgBuilder argBuilder)
static readonly OpCode[] s_stelemOpCodes
OpCode GetStelemOpCode(TypeCode typeCode)
static readonly OpCode[] s_convOpCodes
void If(object value1, Cmp cmpOp, object value2)
void Stloc(Type type, string name)
object For(LocalBuilder local, object start, object end)
Dictionary<(Type, string), Queue< LocalBuilder > > _freeLocals
LocalBuilder GetLocal(string name)
static MethodInfo GetPropertyMethodFromBaseType(PropertyInfo propertyInfo, bool isGetter)
bool TryGetVariable(string name, [NotNullWhen(true)] out object variable)
static bool IsStruct(Type objType)
void StoreArrayElement(object obj, object arrayIndex, object value)
readonly Dictionary< Type, LocalBuilder > _tmpLocals
CodeGenerator(TypeBuilder typeBuilder)
void LdlocAddress(LocalBuilder localBuilder)
readonly Stack< Label > _leaveLabels
void Ldloca(LocalBuilder localBuilder)
void Ldloc(LocalBuilder localBuilder)
static readonly OpCode[] s_branchCodes
Type LoadMember(MemberInfo memberInfo)
bool TryGetValue(string key, [NotNullWhen(true)] out LocalBuilder value)
Definition LocalScope.cs:38
void AddToFreeLocals(Dictionary<(Type, string), Queue< LocalBuilder > > freeLocals)
Definition LocalScope.cs:52
TypeCode
Definition TypeCode.cs:4