Skip to content

Commit

Permalink
Added EmitCalli overload (dotnet#15040)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cronan authored and jkotas committed Nov 16, 2017
1 parent a7cf54f commit 658bc65
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,51 @@ public virtual void EmitCalli(OpCode opcode, CallingConventions callingConventio
PutInteger4(modBuilder.GetSignatureToken(sig).Token);
}

public virtual void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes)
{
int stackchange = 0;
int cParams = 0;
int i;
SignatureHelper sig;

ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;

if (parameterTypes != null)
{
cParams = parameterTypes.Length;
}

sig = SignatureHelper.GetMethodSigHelper(
modBuilder,
unmanagedCallConv,
returnType);

if (parameterTypes != null)
{
for (i = 0; i < cParams; i++)
{
sig.AddArgument(parameterTypes[i]);
}
}

// If there is a non-void return type, push one.
if (returnType != typeof(void))
stackchange++;

// Pop off arguments if any.
if (parameterTypes != null)
stackchange -= cParams;

// Pop the native function pointer.
stackchange--;
UpdateStackSize(OpCodes.Calli, stackchange);

EnsureCapacity(7);
Emit(OpCodes.Calli);
RecordTokenFixup();
PutInteger4(modBuilder.GetSignatureToken(sig).Token);
}

public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
{
if (methodInfo == null)
Expand Down

0 comments on commit 658bc65

Please sign in to comment.