Example #1
0
        public void EmitReturn(Type returnType)
        {
            if (returnType == typeof(void))
            {
                for (int i = stackCount; i > 0; i--)
                {
                    Emit(OpCodes.Pop);
                }
                ilSize += InstructionSize.Get(OpCodes.Ret);
                AdjustStack(OpCodes.Ret, 0);
            }
            else
            {
                for (int i = stackCount - 1; i > 0; i--)
                {
                    Emit(OpCodes.Pop);
                }
                if (stackCount == 0)
                {
                    Emit(OpCodes.Ldc_I4_0);
                }
                ilSize += InstructionSize.Get(OpCodes.Ret);
                AdjustStack(OpCodes.Ret, 1);
            }

            commands.Add(new ILCommand {
                opCode = OpCodes.Ret, args = $"<type>{returnType}"
            });
        }
Example #2
0
 public void Emit(OpCode opCode, string arg)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode);
     commands.Add(new ILCommand {
         opCode = opCode, args = arg
     });
 }
Example #3
0
 public void Emit(OpCode opCode, double arg)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode);
     commands.Add(new ILCommand {
         opCode = opCode, args = arg.ToString("E", CultureInfo.InvariantCulture)
     });
 }
Example #4
0
 public void EmitCall(OpCode opCode, MethodInfo methodInfo, int argumentCount)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode, argumentCount, methodInfo.ReturnType != typeof(void) ? 1 : 0);
     commands.Add(new ILCommand {
         opCode = opCode, args = $"<method>{methodInfo.Name}"
     });
 }
Example #5
0
 public void EmitPtr(OpCode opCode, MethodInfo methodInfo)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode);
     commands.Add(new ILCommand {
         opCode = opCode, args = $"<method>{methodInfo}"
     });
 }
Example #6
0
 public void Emit(OpCode opCode, Type type, int?argumentCount = null, int?resultCount = null)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode, argumentCount, resultCount);
     commands.Add(new ILCommand {
         opCode = opCode, args = $"<type>{type}"
     });
 }
Example #7
0
 public void Emit(OpCode opCode, FieldInfo field)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode);
     commands.Add(new ILCommand {
         opCode = opCode, args = $"<field>{field.Name}"
     });
 }
Example #8
0
 public void Emit(OpCode opCode, LabelRef labelRef)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode);
     commands.Add(new ILCommand {
         opCode = opCode, args = $"<label>{labelRef.label.GetHashCode()}"
     });
 }
Example #9
0
 public void Emit(OpCode opCode, ILocalRef localBuilder)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode);
     commands.Add(new ILCommand {
         opCode = opCode, args = $"<local>{localBuilder.LocalIndex}"
     });
 }
Example #10
0
        public void Emit(OpCode opCode, IEnumerable <LabelRef> labels)
        {
            var labelRefs = labels.ToList();

            ilSize += InstructionSize.Get(opCode, labelRefs.Count());
            AdjustStack(opCode);
            commands.Add(new ILCommand {
                opCode = opCode,
                args   = String.Join(", ", labelRefs.Select(label => $"<label>{label.label.GetHashCode()}"))
            });
        }
Example #11
0
 public void EmitNew(OpCode opCode, ConstructorInfo constructor, int?argumentCount = null,
                     int?resultCount = null)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode, argumentCount ?? constructor.GetParameters().Length, resultCount);
 }