summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs')
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs243
1 files changed, 29 insertions, 214 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs
index 9e1d82986a..cb2667a104 100644
--- a/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs
+++ b/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs
@@ -14,7 +14,6 @@ namespace System.Reflection.Emit
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
- using System.Security.Permissions;
using System.Threading;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
@@ -142,7 +141,6 @@ namespace System.Reflection.Emit
PutInteger4(token);
}
- [System.Runtime.InteropServices.ComVisible(true)]
public override void Emit(OpCode opcode, ConstructorInfo con)
{
if (con == null)
@@ -267,43 +265,6 @@ namespace System.Reflection.Emit
PutInteger4(token);
}
- public override void EmitCalli(OpCode opcode,
- CallingConvention unmanagedCallConv,
- Type returnType,
- Type[] parameterTypes)
- {
- int stackchange = 0;
- int cParams = 0;
- int i;
- SignatureHelper sig;
-
- if (parameterTypes != null)
- cParams = parameterTypes.Length;
-
- sig = SignatureHelper.GetMethodSigHelper(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);
- int token = GetTokenForSig(sig.GetSignature(true));
- PutInteger4(token);
- }
-
public override void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
{
if (methodInfo == null)
@@ -379,19 +340,20 @@ namespace System.Reflection.Emit
// Exception related generation
//
//
- public override Label BeginExceptionBlock()
+ public override void BeginExceptFilterBlock()
{
- return base.BeginExceptionBlock();
- }
+ // Begins an exception filter block. Emits a branch instruction to the end of the current exception block.
- public override void EndExceptionBlock()
- {
- base.EndExceptionBlock();
- }
+ if (CurrExcStackCount == 0)
+ throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
- public override void BeginExceptFilterBlock()
- {
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
+ __ExceptionInfo current = CurrExcStack[CurrExcStackCount - 1];
+
+ Label endLabel = current.GetEndLabel();
+ Emit(OpCodes.Leave, endLabel);
+ UpdateStackSize(OpCodes.Nop, 1);
+
+ current.MarkFilterAddr(ILOffset);
}
public override void BeginCatchBlock(Type exceptionType)
@@ -412,6 +374,8 @@ namespace System.Reflection.Emit
}
this.Emit(OpCodes.Endfilter);
+
+ current.MarkCatchAddr(ILOffset, null);
}
else
{
@@ -427,24 +391,14 @@ namespace System.Reflection.Emit
// if this is a catch block the exception will be pushed on the stack and we need to update the stack info
UpdateStackSize(OpCodes.Nop, 1);
- }
-
- current.MarkCatchAddr(ILOffset, exceptionType);
-
- // this is relying on too much implementation details of the base and so it's highly breaking
- // Need to have a more integreted story for exceptions
- current.m_filterAddr[current.m_currentCatch - 1] = GetTokenFor(rtType);
- }
+ current.MarkCatchAddr(ILOffset, exceptionType);
- public override void BeginFaultBlock()
- {
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
- }
- public override void BeginFinallyBlock()
- {
- base.BeginFinallyBlock();
+ // this is relying on too much implementation details of the base and so it's highly breaking
+ // Need to have a more integrated story for exceptions
+ current.m_filterAddr[current.m_currentCatch - 1] = GetTokenFor(rtType);
+ }
}
//
@@ -520,22 +474,18 @@ namespace System.Reflection.Emit
Type[] parameterTypes,
Type[] optionalParameterTypes)
{
- int cParams;
- int i;
- SignatureHelper sig;
- if (parameterTypes == null)
- cParams = 0;
- else
- cParams = parameterTypes.Length;
- sig = SignatureHelper.GetMethodSigHelper(call, returnType);
- for (i = 0; i < cParams; i++)
- sig.AddArgument(parameterTypes[i]);
+ SignatureHelper sig = SignatureHelper.GetMethodSigHelper(call, returnType);
+ if (parameterTypes != null)
+ {
+ foreach (Type t in parameterTypes)
+ sig.AddArgument(t);
+ }
if (optionalParameterTypes != null && optionalParameterTypes.Length != 0)
{
// add the sentinel
sig.AddSentinel();
- for (i = 0; i < optionalParameterTypes.Length; i++)
- sig.AddArgument(optionalParameterTypes[i]);
+ foreach (Type t in optionalParameterTypes)
+ sig.AddArgument(t);
}
return sig;
}
@@ -811,17 +761,6 @@ namespace System.Reflection.Emit
typeOwner = m_method.m_typeOwner;
-#if FEATURE_COMPRESSEDSTACK
- if (m_method.m_creationContext != null)
- {
- flags |= SecurityControlFlags.HasCreationContext;
- if(m_method.m_creationContext.CanSkipEvaluation)
- {
- flags |= SecurityControlFlags.CanSkipCSEvaluation;
- }
- }
-
-#endif // FEATURE_COMPRESSEDSTACK
securityControlFlags = (int)flags;
@@ -904,12 +843,6 @@ namespace System.Reflection.Emit
internal override String GetStringLiteral(int token) { return m_scope.GetString(token); }
-#if FEATURE_COMPRESSEDSTACK
- internal override CompressedStack GetSecurityContext()
- {
- return m_method.m_creationContext;
- }
-#endif // FEATURE_COMPRESSEDSTACK
internal override void ResolveToken(int token, out IntPtr typeHandle, out IntPtr methodHandle, out IntPtr fieldHandle)
{
@@ -991,8 +924,7 @@ namespace System.Reflection.Emit
}
- [System.Runtime.InteropServices.ComVisible(true)]
- public class DynamicILInfo
+ internal class DynamicILInfo
{
#region Private Data Members
private DynamicMethod m_method;
@@ -1004,18 +936,6 @@ namespace System.Reflection.Emit
private int m_methodSignature;
#endregion
- #region Constructor
- internal DynamicILInfo(DynamicScope scope, DynamicMethod method, byte[] methodSignature)
- {
- m_method = method;
- m_scope = scope;
- m_methodSignature = m_scope.GetTokenFor(methodSignature);
- m_exceptions = EmptyArray<Byte>.Value;
- m_code = EmptyArray<Byte>.Value;
- m_localSignature = EmptyArray<Byte>.Value;
- }
- #endregion
-
#region Internal Methods
internal void GetCallableMethod(RuntimeModule module, DynamicMethod dm)
{
@@ -1042,113 +962,8 @@ namespace System.Reflection.Emit
public DynamicMethod DynamicMethod { get { return m_method; } }
internal DynamicScope DynamicScope { get { return m_scope; } }
- public void SetCode(byte[] code, int maxStackSize)
- {
- m_code = (code != null) ? (byte[])code.Clone() : EmptyArray<Byte>.Value;
- m_maxStackSize = maxStackSize;
- }
-
- [CLSCompliant(false)]
- public unsafe void SetCode(byte* code, int codeSize, int maxStackSize)
- {
- if (codeSize < 0)
- throw new ArgumentOutOfRangeException(nameof(codeSize), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
-
- if (codeSize > 0 && code == null)
- throw new ArgumentNullException(nameof(code));
- Contract.EndContractBlock();
-
- m_code = new byte[codeSize];
- for (int i = 0; i < codeSize; i++)
- {
- m_code[i] = *code;
- code++;
- }
-
- m_maxStackSize = maxStackSize;
- }
-
- public void SetExceptions(byte[] exceptions)
- {
- m_exceptions = (exceptions != null) ? (byte[])exceptions.Clone() : EmptyArray<Byte>.Value;
- }
-
- [CLSCompliant(false)]
- public unsafe void SetExceptions(byte* exceptions, int exceptionsSize)
- {
- if (exceptionsSize < 0)
- throw new ArgumentOutOfRangeException(nameof(exceptionsSize), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
-
- if (exceptionsSize > 0 && exceptions == null)
- throw new ArgumentNullException(nameof(exceptions));
- Contract.EndContractBlock();
-
- m_exceptions = new byte[exceptionsSize];
-
- for (int i = 0; i < exceptionsSize; i++)
- {
- m_exceptions[i] = *exceptions;
- exceptions++;
- }
- }
-
- public void SetLocalSignature(byte[] localSignature)
- {
- m_localSignature = (localSignature != null) ? (byte[])localSignature.Clone() : EmptyArray<Byte>.Value;
- }
-
- [CLSCompliant(false)]
- public unsafe void SetLocalSignature(byte* localSignature, int signatureSize)
- {
- if (signatureSize < 0)
- throw new ArgumentOutOfRangeException(nameof(signatureSize), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
-
- if (signatureSize > 0 && localSignature == null)
- throw new ArgumentNullException(nameof(localSignature));
- Contract.EndContractBlock();
-
- m_localSignature = new byte[signatureSize];
- for (int i = 0; i < signatureSize; i++)
- {
- m_localSignature[i] = *localSignature;
- localSignature++;
- }
- }
- #endregion
-
- #region Public Scope Methods
- public int GetTokenFor(RuntimeMethodHandle method)
- {
- return DynamicScope.GetTokenFor(method);
- }
- public int GetTokenFor(DynamicMethod method)
- {
- return DynamicScope.GetTokenFor(method);
- }
- public int GetTokenFor(RuntimeMethodHandle method, RuntimeTypeHandle contextType)
- {
- return DynamicScope.GetTokenFor(method, contextType);
- }
- public int GetTokenFor(RuntimeFieldHandle field)
- {
- return DynamicScope.GetTokenFor(field);
- }
- public int GetTokenFor(RuntimeFieldHandle field, RuntimeTypeHandle contextType)
- {
- return DynamicScope.GetTokenFor(field, contextType);
- }
- public int GetTokenFor(RuntimeTypeHandle type)
- {
- return DynamicScope.GetTokenFor(type);
- }
- public int GetTokenFor(string literal)
- {
- return DynamicScope.GetTokenFor(literal);
- }
- public int GetTokenFor(byte[] signature)
- {
- return DynamicScope.GetTokenFor(signature);
- }
+#endregion
+#region Public Scope Methods
#endregion
}