diff options
author | Maryam Ariyan <maryam.ariyan@microsoft.com> | 2019-01-12 17:44:06 -0800 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2019-01-12 17:44:06 -0800 |
commit | 908891ce9df8d94f28ec6a53a012d39d00c8e65d (patch) | |
tree | 8a0099a30e5c7985d13a7e74a10256f7a24aaa4f | |
parent | c4e4036761771bdc3fad060e6ce70daa5b85fe2a (diff) | |
download | coreclr-908891ce9df8d94f28ec6a53a012d39d00c8e65d.tar.gz coreclr-908891ce9df8d94f28ec6a53a012d39d00c8e65d.tar.bz2 coreclr-908891ce9df8d94f28ec6a53a012d39d00c8e65d.zip |
Add System.Reflection.Emit.DynamicILInfo (#21945)
* Making DynamicILInfo and its API impls public
* Remove DynamicScope input from ctor args
-rw-r--r-- | src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs | 98 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs | 11 |
2 files changed, 108 insertions, 1 deletions
diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs index 0160fce4f0..c0712822e4 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs @@ -863,7 +863,7 @@ namespace System.Reflection.Emit } - internal class DynamicILInfo + public class DynamicILInfo { #region Private Data Members private DynamicMethod m_method; @@ -875,6 +875,18 @@ namespace System.Reflection.Emit private int m_methodSignature; #endregion + #region Constructor + internal DynamicILInfo(DynamicMethod method, byte[] methodSignature) + { + m_scope = new DynamicScope(); + m_method = method; + m_methodSignature = m_scope.GetTokenFor(methodSignature); + m_exceptions = Array.Empty<byte>(); + m_code = Array.Empty<byte>(); + m_localSignature = Array.Empty<byte>(); + } + #endregion + #region Internal Methods internal void GetCallableMethod(RuntimeModule module, DynamicMethod dm) { @@ -901,8 +913,92 @@ 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() : Array.Empty<byte>(); + m_maxStackSize = maxStackSize; + } + + [CLSCompliant(false)] + public unsafe void SetCode(byte* code, int codeSize, int maxStackSize) + { + if (codeSize < 0) + throw new ArgumentOutOfRangeException(nameof(codeSize), SR.ArgumentOutOfRange_GenericPositive); + if (codeSize > 0 && code == null) + throw new ArgumentNullException(nameof(code)); + + m_code = new Span<byte>(code, codeSize).ToArray(); + m_maxStackSize = maxStackSize; + } + + public void SetExceptions(byte[] exceptions) + { + m_exceptions = (exceptions != null) ? (byte[])exceptions.Clone() : Array.Empty<byte>(); + } + + [CLSCompliant(false)] + public unsafe void SetExceptions(byte* exceptions, int exceptionsSize) + { + if (exceptionsSize < 0) + throw new ArgumentOutOfRangeException(nameof(exceptionsSize), SR.ArgumentOutOfRange_GenericPositive); + + if (exceptionsSize > 0 && exceptions == null) + throw new ArgumentNullException(nameof(exceptions)); + + m_exceptions = new Span<byte>(exceptions, exceptionsSize).ToArray(); + } + + public void SetLocalSignature(byte[] localSignature) + { + m_localSignature = (localSignature != null) ? (byte[])localSignature.Clone() : Array.Empty<byte>(); + } + + [CLSCompliant(false)] + public unsafe void SetLocalSignature(byte* localSignature, int signatureSize) + { + if (signatureSize < 0) + throw new ArgumentOutOfRangeException(nameof(signatureSize), SR.ArgumentOutOfRange_GenericPositive); + + if (signatureSize > 0 && localSignature == null) + throw new ArgumentNullException(nameof(localSignature)); + + m_localSignature = new Span<byte>(localSignature, signatureSize).ToArray(); + } #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 } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs index af3f5ebfdf..c425a6f832 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs @@ -513,6 +513,17 @@ namespace System.Reflection.Emit return null; } + public DynamicILInfo GetDynamicILInfo() + { + if (m_DynamicILInfo == null) + { + byte[] methodSignature = SignatureHelper.GetMethodSigHelper( + null, CallingConvention, ReturnType, null, null, m_parameterTypes, null, null).GetSignature(true); + m_DynamicILInfo = new DynamicILInfo(this, methodSignature); + } + return m_DynamicILInfo; + } + public ILGenerator GetILGenerator() { return GetILGenerator(64); |