Example #1
0
		public CallIndirect(LIRMethod parent, ISource targetMethod, IEnumerable<ISource> sources = null, IDestination returnValueDest = null) : base(parent, LIROpCode.CallIndirect)
		{
			this.TargetMethod = targetMethod;
			if (sources != null)
				Sources.AddRange(sources);
			this.ReturnValueDestination = returnValueDest;
		}
Example #2
0
		public Unary(LIRMethod parent, ISource src, IDestination dest, UnaryOperation op, LIRType argType) : base(parent, LIROpCode.Unary)
		{
			Source = src;
			Destination = dest;
			Operation = op;
			ArgumentType = argType;
		}
Example #3
0
		public Convert(LIRMethod parent, ISource source, LIRType sourceType, IDestination dest, LIRType destType) : base(parent, LIROpCode.Convert)
		{
			Source = source;
			SourceType = sourceType;
			Destination = dest;
			DestinationType = destType;
		}
Example #4
0
		public Math(LIRMethod parent, ISource srcA, ISource srcB, IDestination dest, MathOperation op, LIRType argType) : base(parent, LIROpCode.Math)
		{
			SourceA = srcA;
			SourceB = srcB;
			Destination = dest;
			Operation = op;
			ArgumentType = argType;
		}
Example #5
0
		public Compare(LIRMethod parent, ISource sourceA, ISource sourceB, IDestination destination, LIRType type, CompareCondition condition) : base(parent, LIROpCode.Compare)
		{
			this.SourceA = sourceA;
			this.SourceB = sourceB;
			this.Destination = destination;
			this.Type = type;
			this.Condition = condition;
		}
Example #6
0
		public override void Run(LIRMethod method)
		{
			for (int i = 0; i < method.mInstructions.Count; i++)
			{
				var curInstr = method.mInstructions[i];
				if (curInstr.OpCode == LIROpCode.Label && ((Label)curInstr).References == 0)
					method.mInstructions[i] = new Instructions.Dead(i);
			}
		}
		public override void Run(LIRMethod method)
		{
			List<LIRInstruction> instrs = new List<LIRInstruction>(method.mInstructions.Count);
			foreach (var i in method.mInstructions)
			{
				if (i.OpCode == LIROpCode.Dead)
					continue;
				i.Index = instrs.Count;
				instrs.Add(i);
			}
			instrs.TrimExcess();
			method.mInstructions = instrs;
		}
		public override void Run(LIRMethod method)
		{
			for (int i = 0; i < method.mInstructions.Count; i++)
			{
				var curInstr = method.mInstructions[i];
				switch (curInstr.OpCode)
				{
					case LIROpCode.Math:
					{
						var curMath = (Instructions.Math)curInstr;
						switch (curMath.Operation)
						{
							case Instructions.MathOperation.Add:
							case Instructions.MathOperation.Subtract:
								if (curMath.SourceA.SourceType == SourceType.Literal && ((LIRImm)curMath.SourceA).IsZero)
								{
									method.mInstructions[i] = new Instructions.Move(i, curMath.SourceB, curMath.Destination, curMath.ArgumentType);
								}
								else if (curMath.SourceB.SourceType == SourceType.Literal && ((LIRImm)curMath.SourceB).IsZero)
								{
									method.mInstructions[i] = new Instructions.Move(i, curMath.SourceA, curMath.Destination, curMath.ArgumentType);
								}
								break;
							case Instructions.MathOperation.Multiply:
								break;
							case Instructions.MathOperation.Divide:
								break;
							case Instructions.MathOperation.And:
								break;
							case Instructions.MathOperation.Or:
								break;
							case Instructions.MathOperation.Xor:
								break;
							case Instructions.MathOperation.ShiftLeft:
								break;
							case Instructions.MathOperation.ShiftRight:
								break;
							case Instructions.MathOperation.ShiftRightSignExtended:
								break;
							default:
								throw new Exception("Unknown MathOperation!");
						}
						break;
					}
					default:
						break;
				}
			}
		}
Example #9
0
		public BranchTrue(LIRMethod parent, ISource source, Label target) : base(parent, LIROpCode.BranchTrue)
		{
			this.Source = source;
			this.Target = target;
			target.References++;
		}
		public override void Run(LIRMethod method)
		{
			for (int i = 0; i < method.mInstructions.Count; i++)
			{
				var curInstr = method.mInstructions[i];
				switch(curInstr.OpCode)
				{
					case LIROpCode.Move:
					{
						var curMove = (Instructions.Move)curInstr;
						if (curMove.Source.SourceType == SourceType.Local)
						{
							var loc = (LIRLocal)curMove.Source;
							if (loc.Dynamic && loc.AssignedValue != null && 
								(
									loc.AssignedValue.SourceType == SourceType.Local ||
									loc.AssignedValue.SourceType == SourceType.Literal ||
									loc.AssignedValue.SourceType == SourceType.Parameter
								)
							)
							{
								curMove.Source = loc.AssignedValue;
								method.mInstructions[loc.AssignedAt] = new Instructions.Dead(loc.AssignedAt);
							}
						}
						if (curMove.Destination.DestinationType == DestinationType.Local)
						{
							var loc = (LIRLocal)curMove.Destination;
							if (loc.Dynamic)
							{
								loc.AssignedAt = i;
								loc.AssignedValue = curMove.Source;
							}
						}
						break;
					}
					case LIROpCode.Math:
					{
						// Need to do dest
						var curMath = (Instructions.Math)curInstr;
						curMath.SourceA = ProcessSource(curMath.SourceA, method);
						curMath.SourceB = ProcessSource(curMath.SourceB, method);
						break;
					}
					case LIROpCode.Compare:
					{
						// Need to do dest
						var curCompare = (Instructions.Compare)curInstr;
						curCompare.SourceA = ProcessSource(curCompare.SourceA, method);
						curCompare.SourceB = ProcessSource(curCompare.SourceB, method);
						break;
					}
					case LIROpCode.BranchIndirect:
					{
						var curBranch = (Instructions.BranchIndirect)curInstr;
						curBranch.Source = ProcessSource(curBranch.Source, method);
						break;
					}
					case LIROpCode.BranchTrue:
					{
						var curBranch = (Instructions.BranchTrue)curInstr;
						curBranch.Source = ProcessSource(curBranch.Source, method);
						break;
					}
					case LIROpCode.Unary:
					{
						// Need to do dest
						var curUnary = (Instructions.Unary)curInstr;
						curUnary.Source = ProcessSource(curUnary.Source, method);
						break;
					}
					case LIROpCode.Convert:
					{
						// Need to do dest
						var curConvert = (Instructions.Convert)curInstr;
						curConvert.Source = ProcessSource(curConvert.Source, method);
						break;
					}
					case LIROpCode.Return:
					{
						var curReturn = (Instructions.Return)curInstr;
						if (curReturn.Source != null)
							curReturn.Source = ProcessSource(curReturn.Source, method);
						break;
					}
					case LIROpCode.Call:
					{
						// Need to do dest
						var curCall = (Instructions.Call)curInstr;
						for (int i2 = 0; i2 < curCall.Sources.Count; i2++)
						{
							curCall.Sources[i2] = ProcessSource(curCall.Sources[i2], method);
						}
						break;
					}
					case LIROpCode.CallIndirect:
					{
						// Need to do dest
						var curCallIndirect = (Instructions.CallIndirect)curInstr;
						for (int i2 = 0; i2 < curCallIndirect.Sources.Count; i2++)
						{
							curCallIndirect.Sources[i2] = ProcessSource(curCallIndirect.Sources[i2], method);
						}
						break;
					}

					case LIROpCode.Comment:
					case LIROpCode.Dead:
					case LIROpCode.Label:
					case LIROpCode.Nop:
					case LIROpCode.Branch:
						break;
					default:
						throw new Exception("Unknown LIROpCode!");
				}
				if (curInstr.MayHaveSideEffects)
					method.Locals.ForEach(l => { l.AssignedAt = -1; l.AssignedValue = null; });
			}
		}
		private static ISource ProcessSource(ISource src, LIRMethod method)
		{
			if (src.SourceType == SourceType.Local)
			{
				var loc = (LIRLocal)src;
				if (loc.Dynamic && loc.AssignedValue != null && loc.AssignedValue.SourceType == SourceType.Local)
				{
					method.mInstructions[loc.AssignedAt] = new Instructions.Dead(loc.AssignedAt);
					return loc.AssignedValue;
				}
			}
			return src;
		}
Example #12
0
		public Branch(LIRMethod parent)
			: base(parent, LIROpCode.Branch)
		{
		}
Example #13
0
		public Branch(LIRMethod parent, Label target) : base(parent, LIROpCode.Branch)
		{
			this.Target = target;
			target.References++;
		}
Example #14
0
		public Move(LIRMethod parent, ISource src, IDestination dest, LIRType argType) : base(parent, LIROpCode.Move)
		{
			Source = src;
			Destination = dest;
			ArgumentType = argType;
		}
Example #15
0
		public Return(LIRMethod parent, ISource source = null, LIRType sourceType = null) : base(parent, LIROpCode.Return)
		{
			this.Source = source;
			this.SourceType = sourceType;
		}
		public abstract void Run(LIRMethod method);
Example #17
0
		public BranchTrue(LIRMethod parent, ISource source) : base(parent, LIROpCode.BranchTrue)
		{
			this.Source = source;
		}
Example #18
0
		public BranchIndirect(LIRMethod parent, ISource source) : base(parent, LIROpCode.BranchIndirect)
		{
			this.Source = source;
		}
Example #19
0
		public Comment(LIRMethod parent, string text) : base(parent, LIROpCode.Comment)
		{
			this.Text = text;
		}
Example #20
0
		public Nop(LIRMethod parent) : base(parent, LIROpCode.Nop)
		{
		}