/// <summary>
		/// This does a shallow copy of all of the members of the
		/// abstract IRInstruction class to the specified instruction.
		/// </summary>
		/// <param name="i">The instruction to copy to.</param>
		/// <param name="newMethod">The method this instruction will be added to.</param>
		/// <returns><see cref="i"/></returns>
		protected IRInstruction CopyTo(IRInstruction i, IRMethod newMethod)
		{
			i.ILOffset = this.ILOffset;
			i.IRIndex = this.IRIndex;
			i.Opcode = this.Opcode;
			i.ParentMethod = newMethod;
			if (Destination != null)
			{
				i.Destination = this.Destination.Clone(i);
			}
			foreach (IRLinearizedLocation t in this.Sources)
			{
				i.Sources.Add(t.Clone(i));
			}
			return i;
		}
Exemple #2
0
		private void LinearizePath(MethodDefData pMethodDefData, IRInstruction pStartInstruction, Stack<IRStackObject> pStack, Queue<Tuple<IRInstruction, Stack<IRStackObject>>> pBranches)
		{
			int stackReturn = pStack.Count;
			IRInstruction currentInstruction = pStartInstruction;
			MethodDefData.MethodDefBodyData.MethodDefBodyExceptionData exceptionData = null;
			while (currentInstruction != null)
			{
				if (currentInstruction.Linearized && pStack.Count == stackReturn) break;

				if ((exceptionData = Array.Find(pMethodDefData.Body.Exceptions, e => e.Flags == 0 && e.HandlerOffset == currentInstruction.ILOffset)) != null)
				{
					IRType exceptionType = Assembly.AppDomain.PresolveType(Assembly.File.ExpandMetadataToken(exceptionData.ClassTokenOrFilterOffset));
					IRStackObject exceptionObj = new IRStackObject();
					exceptionObj.Type = exceptionType;
					exceptionObj.LinearizedTarget = new IRLinearizedLocation(currentInstruction, IRLinearizedLocationType.Local);
					exceptionObj.LinearizedTarget.Local.LocalIndex = currentInstruction.AddLinearizedLocal(pStack, exceptionType);
					pStack.Push(exceptionObj);
				}

				if (currentInstruction.Linearized)
				{
					currentInstruction.Destination = null;
					currentInstruction.Sources.Clear();
				}
				currentInstruction.Linearize(pStack);
				currentInstruction.Linearized = true;
				switch (currentInstruction.Opcode)
				{
					case IROpcode.Branch:
						{
							IRBranchInstruction branchInstruction = (IRBranchInstruction)currentInstruction;
							if (branchInstruction.BranchCondition == IRBranchCondition.Always) currentInstruction = branchInstruction.TargetIRInstruction;
							else
							{
								pBranches.Enqueue(new Tuple<IRInstruction, Stack<IRStackObject>>(branchInstruction.TargetIRInstruction, pStack.Duplicate()));
								currentInstruction = Instructions[currentInstruction.IRIndex + 1];
							}
							break;
						}
					case IROpcode.Switch:
						{
							IRSwitchInstruction switchInstruction = (IRSwitchInstruction)currentInstruction;
							foreach (IRInstruction targetInstruction in switchInstruction.TargetIRInstructions)
							{
								pBranches.Enqueue(new Tuple<IRInstruction, Stack<IRStackObject>>(targetInstruction, pStack.Duplicate()));
							}
							currentInstruction = Instructions[currentInstruction.IRIndex + 1];
							break;
						}
					case IROpcode.Leave:
						{
							IRLeaveInstruction leaveInstruction = (IRLeaveInstruction)currentInstruction;
							currentInstruction = leaveInstruction.TargetIRInstruction;
							break;
						}
					case IROpcode.Jump:
					case IROpcode.Throw:
					case IROpcode.Return: currentInstruction = null; break;
					default: currentInstruction = currentInstruction.IRIndex >= Instructions.Count ? null : Instructions[currentInstruction.IRIndex + 1]; break;
				}
			}
		}
Exemple #3
0
		public void InsertInstruction(int pIRIndex, IRInstruction pInstruction)
		{
			pInstruction.ILOffset = Instructions[pIRIndex].ILOffset;
			pInstruction.ParentMethod = this;
			Instructions.Insert(pInstruction, pIRIndex);
		}
Exemple #4
0
		public void AddInstruction(uint pILOffset, IRInstruction pInstruction)
		{
			pInstruction.ILOffset = (int)pILOffset;
			pInstruction.ParentMethod = this;
			Instructions.Add(pInstruction);
		}
		public void SetParentInstruction(IRInstruction newParent)
		{
			ParentInstruction = newParent;
			switch (Type)
			{
				case IRLinearizedLocationType.Field:
					Field.FieldLocation.SetParentInstruction(newParent);
					break;
				case IRLinearizedLocationType.FieldAddress:
					FieldAddress.FieldLocation.SetParentInstruction(newParent);
					break;
				case IRLinearizedLocationType.Indirect:
					Indirect.AddressLocation.SetParentInstruction(newParent);
					break;
				case IRLinearizedLocationType.ArrayElement:
					ArrayElement.ArrayLocation.SetParentInstruction(newParent);
					ArrayElement.IndexLocation.SetParentInstruction(newParent);
					break;
				case IRLinearizedLocationType.ArrayElementAddress:
					ArrayElementAddress.ArrayLocation.SetParentInstruction(newParent);
					ArrayElementAddress.IndexLocation.SetParentInstruction(newParent);
					break;
				case IRLinearizedLocationType.ArrayLength:
					ArrayLength.ArrayLocation.SetParentInstruction(newParent);
					break;
				case IRLinearizedLocationType.FunctionAddress:
					if (FunctionAddress.InstanceLocation != null)
						FunctionAddress.InstanceLocation.SetParentInstruction(newParent);
					break;
				case IRLinearizedLocationType.Phi:
					Phi.SourceLocations.ForEach(l => l.SetParentInstruction(newParent));
					break;
				default: break;
			}
		}
		public IRLinearizedLocation Clone(IRInstruction pNewInstruction) { return new IRLinearizedLocation(pNewInstruction, this); }
		public IRLinearizedLocation(IRInstruction pParentInstruction, IRLinearizedLocation pLinearizedTarget)
		{
			mTempID = sTempID++;
			ParentInstruction = pParentInstruction;
			Type = pLinearizedTarget.Type;
			switch (Type)
			{
				case IRLinearizedLocationType.Null: break;
				case IRLinearizedLocationType.Local: Local = pLinearizedTarget.Local; break;
				case IRLinearizedLocationType.LocalAddress: LocalAddress = pLinearizedTarget.LocalAddress; break;
				case IRLinearizedLocationType.Parameter: Parameter = pLinearizedTarget.Parameter; break;
				case IRLinearizedLocationType.ParameterAddress: ParameterAddress = pLinearizedTarget.ParameterAddress; break;
				case IRLinearizedLocationType.ConstantI4: ConstantI4 = pLinearizedTarget.ConstantI4; break;
				case IRLinearizedLocationType.ConstantI8: ConstantI8 = pLinearizedTarget.ConstantI8; break;
				case IRLinearizedLocationType.ConstantR4: ConstantR4 = pLinearizedTarget.ConstantR4; break;
				case IRLinearizedLocationType.ConstantR8: ConstantR8 = pLinearizedTarget.ConstantR8; break;
				case IRLinearizedLocationType.Field:
					Field = pLinearizedTarget.Field;
					Field.FieldLocation = pLinearizedTarget.Field.FieldLocation.Clone(pParentInstruction);
					break;
				case IRLinearizedLocationType.FieldAddress:
					FieldAddress = pLinearizedTarget.FieldAddress;
					FieldAddress.FieldLocation = pLinearizedTarget.FieldAddress.FieldLocation.Clone(pParentInstruction);
					break;
				case IRLinearizedLocationType.StaticField: StaticField = pLinearizedTarget.StaticField; break;
				case IRLinearizedLocationType.StaticFieldAddress: StaticFieldAddress = pLinearizedTarget.StaticFieldAddress; break;
				case IRLinearizedLocationType.Indirect:
					Indirect = pLinearizedTarget.Indirect;
					Indirect.AddressLocation = pLinearizedTarget.Indirect.AddressLocation.Clone(pParentInstruction);
					break;
				case IRLinearizedLocationType.SizeOf: SizeOf = pLinearizedTarget.SizeOf; break;
				case IRLinearizedLocationType.ArrayElement:
					ArrayElement = pLinearizedTarget.ArrayElement;
					ArrayElement.ArrayLocation = pLinearizedTarget.ArrayElement.ArrayLocation.Clone(pParentInstruction);
					ArrayElement.IndexLocation = pLinearizedTarget.ArrayElement.IndexLocation.Clone(pParentInstruction);
					break;
				case IRLinearizedLocationType.ArrayElementAddress:
					ArrayElementAddress = pLinearizedTarget.ArrayElementAddress;
					ArrayElementAddress.ArrayLocation = pLinearizedTarget.ArrayElementAddress.ArrayLocation.Clone(pParentInstruction);
					ArrayElementAddress.IndexLocation = pLinearizedTarget.ArrayElementAddress.IndexLocation.Clone(pParentInstruction);
					break;
				case IRLinearizedLocationType.ArrayLength:
					ArrayLength = pLinearizedTarget.ArrayLength;
					ArrayLength.ArrayLocation = pLinearizedTarget.ArrayLength.ArrayLocation.Clone(pParentInstruction);
					break;
				case IRLinearizedLocationType.FunctionAddress:
					FunctionAddress = pLinearizedTarget.FunctionAddress;
					if (FunctionAddress.InstanceLocation != null) FunctionAddress.InstanceLocation = pLinearizedTarget.FunctionAddress.InstanceLocation.Clone(pParentInstruction);
					break;
				case IRLinearizedLocationType.RuntimeHandle: RuntimeHandle = pLinearizedTarget.RuntimeHandle; break;
				case IRLinearizedLocationType.String: String = pLinearizedTarget.String; break;
				case IRLinearizedLocationType.Phi:
					Phi = pLinearizedTarget.Phi;
					Phi.SourceLocations = new List<IRLinearizedLocation>(pLinearizedTarget.Phi.SourceLocations.Count);
					pLinearizedTarget.Phi.SourceLocations.ForEach(l => Phi.SourceLocations.Add(l.Clone(pParentInstruction)));
					break;
				default: throw new ArgumentException("Type");
			}
		}
		public IRLinearizedLocation(IRInstruction pParentInstruction, IRLinearizedLocationType pType)
		{
			mTempID = sTempID++;
			ParentInstruction = pParentInstruction;
			Type = pType;
		}
		public IRControlFlowGraphNode FindInstructionNode(IRInstruction pInstruction)
		{
			foreach (IRControlFlowGraphNode node in Nodes)
			{
				foreach (IRInstruction instruction in node.Instructions)
				{
					if (pInstruction == instruction) return node;
				}
			}
			throw new NullReferenceException();
		}
Exemple #10
0
			public IRLocalReductionData(IRInstruction pLifeEnds, IRLocal pLocal) { LifeEnds = pLifeEnds; Local = pLocal; }