/// <summary> /// Retrieves the local stack operand at the specified <paramref name="index"/>. /// </summary> /// <param name="index">The index of the stack operand to retrieve.</param> /// <returns>The operand at the specified index.</returns> /// <exception cref="System.ArgumentOutOfRangeException">The <paramref name="index"/> is not valid.</exception> public Operand GetLocalOperand(int index) { // HACK: Returning a new instance here breaks object identity. We should reuse operands, // which represent the same memory location. If we need to move a variable in an optimization // stage to a different memory location, it should actually be a new one so sharing object // only saves runtime space/perf. // PG: Isn't that implemented below? Comment seems out of date with code Debug.Assert(localsSig != null, @"Method doesn't have locals."); Debug.Assert(index < localsSig.Locals.Length, @"Invalid local index requested."); if (localsSig == null || localsSig.Locals.Length < index) throw new ArgumentOutOfRangeException(@"index", index, @"Invalid parameter index"); Operand local = locals[index]; if (local == null) { VariableSignature localVariable = localsSig.Locals[index]; //ScheduleDependencyForCompilation(localVariable.Type); local = new LocalVariableOperand(architecture.StackFrameRegister, String.Format("L_{0}", index), index, localVariable.Type); locals[index] = local; } return local; }
/// <summary> /// Allocates the stack operand. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public StackOperand AllocateStackOperand(SigType type, bool localVariable) { int stackSlot = stack.Count + 1; StackOperand stackOperand; if (localVariable) { stackOperand = new LocalVariableOperand(architecture.StackFrameRegister, String.Format("V_{0}", stackSlot), stackSlot, type); } else { stackOperand = new StackTemporaryOperand(architecture.StackFrameRegister, String.Format("T_{0}", stackSlot), stackSlot, type); } stack.Add(stackOperand); return stackOperand; }
/// <summary> /// Allocates the stack operand. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public StackOperand AllocateStackOperand(SigType type) { int stackSlot = stack.Count + 1; LocalVariableOperand local = new LocalVariableOperand(architecture.StackFrameRegister, String.Format("L_{0}", stackSlot), stackSlot, type); stack.Add(local); return local; }