public void Emit(OpCode op, Sigil.Local local) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { var l = local.LocalDel(il); il.Emit(op, l); } log.AppendLine(op + " " + local); } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { local } }); }
public void Emit(OpCode op, CallingConventions callConventions, Type returnType, Type[] parameterTypes) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.EmitCalli(op, callConventions, returnType, parameterTypes, null); } log.AppendLine(op + " " + callConventions + " " + returnType + " " + Join(" ", ((LinqArray <Type>)parameterTypes).AsEnumerable())); } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op, MethodReturnType = returnType, MethodParameterTypes = (LinqArray <Type>)parameterTypes }); var paras = new List <object> { callConventions, returnType }; paras.AddRange(parameterTypes); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = paras.ToArray() }); }
public void Emit(OpCode op, FieldInfo field) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.Emit(op, field); } log.AppendLine(op + " " + field); } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { field } }); }
public void Emit(OpCode op, string str) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.Emit(op, str); } log.AppendLine(op + " '" + str.Replace("'", @"\'") + "'"); } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { str } }); }
public void Emit(OpCode op, double d) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.Emit(op, d); } log.AppendLine(op + " " + d.ToString(CultureInfo.InvariantCulture)); }); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { d } }); }
public void Emit(OpCode op, ulong ul) { long asLong; unchecked { asLong = (long)ul; } InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.Emit(op, asLong); } log.AppendLine(op + " " + ul); } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { ul } }); }
public void Emit(OpCode op, uint ui) { int asInt; unchecked { asInt = (int)ui; } InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.Emit(op, asInt); } log.AppendLine(op + " " + ui); } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { ui } }); }
public void Emit(OpCode op, int i) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.Emit(op, i); } if (ExtensionMethods.IsPrefix(op)) { log.Append(op + "" + i + "."); } else { log.AppendLine(op + " " + i); } } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { i } }); }
public void EmitCall(OpCode op, MethodInfo method, IEnumerable <Type> parameterTypes, Type[] arglist) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.EmitCall(op, method, arglist); } var mtdString = method is MethodBuilder ? method.Name : method.ToString(); log.AppendLine(op + " " + mtdString + " __arglist(" + Join(", ", arglist) + ")"); } ); var parameters = new LinqList <Type>(parameterTypes); if (!method.IsStatic) { var declaring = method.DeclaringType; if (TypeHelpers.IsValueType(declaring)) { declaring = declaring.MakePointerType(); } parameters.Insert(0, declaring); } parameters.AddRange(arglist); var paras = new List <object> { method }; paras.AddRange(arglist); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op, MethodReturnType = method.ReturnType, MethodParameterTypes = parameters }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = paras.ToArray() }); }
public void Insert(int ix, OpCode op) { if (ix < 0 || ix > Buffer.Count) { throw new ArgumentOutOfRangeException("ix", "Expected value between 0 and " + Buffer.Count); } LengthCache.Clear(); InstructionSizes.Insert(ix, () => InstructionSize.Get(op)); Buffer.Insert( ix, (il, logOnly, log) => { if (!logOnly) { il.Emit(op); } if (ExtensionMethods.IsPrefix(op)) { log.Append(op.ToString()); } else { log.AppendLine(op.ToString()); } } ); TraversableBuffer.Insert( ix, new BufferedILInstruction { IsInstruction = op } ); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[0] }); }
public void Emit(OpCode op, MethodInfo method, IEnumerable <Type> parameterTypes) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.Emit(op, method); } var mtdString = method is MethodBuilder ? method.Name : method.ToString(); log.AppendLine(op + " " + mtdString); } ); var parameters = new LinqList <Type>(parameterTypes); if (!method.IsStatic) { var declaring = method.DeclaringType; if (declaring.IsValueType) { declaring = declaring.MakePointerType(); } parameters.Insert(0, declaring); } TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op, MethodReturnType = method.ReturnType, MethodParameterTypes = parameters }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { method } }); }
public void Emit(OpCode op, ConstructorInfo cons, IEnumerable <Type> parameterTypes) { InstructionSizes.Add(() => InstructionSize.Get(op)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.Emit(op, cons); } var mtdString = cons is ConstructorBuilder ? cons.Name : cons.ToString(); log.AppendLine(op + " " + mtdString); } ); var parameters = new LinqList <Type>(parameterTypes); var declaring = cons.DeclaringType; if (TypeHelpers.IsValueType(declaring)) { declaring = declaring.MakePointerType(); } parameters.Insert(0, declaring); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op, MethodReturnType = typeof(void), MethodParameterTypes = parameters }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { cons } }); }
public void EmitCalli(CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] arglist) { InstructionSizes.Add(() => InstructionSize.Get(OpCodes.Calli)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { il.EmitCalli(OpCodes.Calli, callingConvention, returnType, parameterTypes, arglist); } log.AppendLine(OpCodes.Calli + " " + callingConvention + " " + returnType + " " + Join(" ", (IEnumerable <Type>)parameterTypes) + " __arglist(" + Join(", ", arglist) + ")"); } ); var ps = new LinqList <Type>(parameterTypes); ps.AddRange(arglist); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = OpCodes.Calli, MethodReturnType = returnType, MethodParameterTypes = ps }); var paras = new List <object>() { callingConvention, returnType }; paras.AddRange(parameterTypes); paras.AddRange(arglist); Operations.Add(new Operation <DelegateType> { OpCode = OpCodes.Calli, Parameters = paras.ToArray() }); }
public void Emit(OpCode op, Sigil.Label[] labels, out UpdateOpCodeDelegate update) { var localOp = op; update = newOpcode => { LengthCache.Clear(); localOp = newOpcode; }; InstructionSizes.Add(() => InstructionSize.Get(localOp, labels)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { var ls = LinqAlternative.Select(labels, l => l.LabelDel(il)).ToArray(); il.Emit(localOp, ls); } log.AppendLine(localOp + " " + Join(", ", ((LinqArray <Label>)labels).AsEnumerable())); } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = labels }); }
public void Emit(OpCode op, Sigil.Label label, out UpdateOpCodeDelegate update) { var localOp = op; update = newOpcode => { LengthCache.Clear(); localOp = newOpcode; }; InstructionSizes.Add(() => InstructionSize.Get(localOp)); LengthCache.Clear(); Buffer.Add( (il, logOnly, log) => { if (!logOnly) { var l = label.LabelDel(il); il.Emit(localOp, l); } log.AppendLine(localOp + " " + label); } ); TraversableBuffer.Add(new BufferedILInstruction { IsInstruction = op }); Operations.Add(new Operation <DelegateType> { OpCode = op, Parameters = new object[] { label } }); }