Example #1
0
		private List<InExactInstructionOverrideDescription> ExpandInExactOverride(InExactInstructionOverrideDescription desc)
		{
			var ret = new List<InExactInstructionOverrideDescription>(4);
			for (int i = 0; i < 3; i++)
			{
				InstructionArg newForm = desc.NewForm[i];
				if (newForm.ArgType.ExpandsTo.Count > 0)
				{
					foreach (InstructionArgType exToTp in newForm.ArgType.ExpandsTo)
					{
						var o = desc.DeepCopy();
						var a = o.NewForm[i];
						o.ArgSetToOverride[i] = exToTp;
						a.ArgType = exToTp;
						o.NewForm[i] = a;
						ret.Add(o);
					}
				}
			}
			return ret;
		}
			public CodeExpression GetConditionExpression(InExactInstructionOverrideDescription ParentDesc, InstructionForm formOverriding)
			{
				switch (Condition)
				{
					case ConditionType.Fits:
						switch(ParentDesc.NewForm[ArgIndexToCheck].ArgType.ID)
						{
							case InstructionArgType.Dis8_ID:
							case InstructionArgType.Imm8_ID:
								return new CodeMethodInvokeExpression(
									StaticTypeReferences.Stream_InSByteRange,
									new CodeCastExpression(
										StaticTypeReferences.Int,
										new CodeFieldReferenceExpression(
											new CodeThisReferenceExpression(),
											formOverriding.GetArgName(FieldTypeRegistry.UInt.ID, 1, ArgIndexToCheck)
										)
									)
								);
							case InstructionArgType.Dis16_ID:
							case InstructionArgType.Imm16_ID:
								return new CodeMethodInvokeExpression(
									StaticTypeReferences.Stream_InShortRange,
									new CodeCastExpression(
										StaticTypeReferences.Int,
										new CodeFieldReferenceExpression(
											new CodeThisReferenceExpression(),
											formOverriding.GetArgName(FieldTypeRegistry.UInt.ID, 1, ArgIndexToCheck)
										)
									)
								);

							default:
								throw new Exception("Unknown arg type!");
						}
					case ConditionType.Compare_Imm:
						if (ParentDesc.NewForm[ArgIndexToCheck].ArgType == InstructionArgType.Imm8)
						{
							return new CodeBinaryOperatorExpression(
								new CodeFieldReferenceExpression(
									new CodeThisReferenceExpression(),
									formOverriding.GetArgName(FieldTypeRegistry.UInt.ID, 1, ArgIndexToCheck)
								),
								CodeBinaryOperatorType.ValueEquality,
								new CodePrimitiveExpression(ImmValueToCompareTo)
							);
						}
						else
						{
							return new CodeBinaryOperatorExpression(
								ParentDesc.NewForm[ArgIndexToCheck].ArgType.AsArgOperation.GetExpression(ParentDesc.NewForm, ArgIndexToCheck, null),
								CodeBinaryOperatorType.ValueEquality,
								new CodePrimitiveExpression(ImmValueToCompareTo)
							);
						}
					case ConditionType.Compare_Reg:
						// Yikes....
						var enu = formOverriding[ArgIndexToCheck].ArgType.Parameters.Values.GetEnumerator();
						enu.MoveNext();
						int argType = enu.Current.ArgType;
						return new CodeBinaryOperatorExpression(
							new CodeFieldReferenceExpression(
								new CodeThisReferenceExpression(),
								formOverriding.GetArgName(argType, 1, ArgIndexToCheck)
							),
							CodeBinaryOperatorType.ValueEquality,
							new CodeFieldReferenceExpression(
								new CodeTypeReferenceExpression(FieldTypeRegistry.Fields[argType].Name),
								RegisterToCompareTo
							)
						);
					case ConditionType.Compare_Segment:
						return new CodeBinaryOperatorExpression(
							new CodeFieldReferenceExpression(
								new CodeThisReferenceExpression(),
								formOverriding.GetArgName(FieldTypeRegistry.Segment.ID, 1, ArgIndexToCheck)
							),
							CodeBinaryOperatorType.ValueEquality,
							new CodeFieldReferenceExpression(StaticTypeReferences.SegmentExpression, RegisterToCompareTo)
						);
					default:
						throw new Exception("Unknown Condition!");
				}
			}
		public InExactInstructionOverrideDescription DeepCopy()
		{
			var v = new InExactInstructionOverrideDescription();
			v.NewForm = NewForm.DeepCopy();
			v.ArgSetToOverride = ArgSetToOverride;
			v.Conditions = Conditions;
			return v;
		}
Example #4
0
		private bool NeedsExpand(InExactInstructionOverrideDescription desc)
		{
			return 
				desc.NewForm.Arg1.ArgType.ExpandsTo.Count > 0 ||
				desc.NewForm.Arg2.ArgType.ExpandsTo.Count > 0 ||
				desc.NewForm.Arg3.ArgType.ExpandsTo.Count > 0;
		}