Example #1
0
 private AssemblyGen GetOrCreateAssembly(bool emitSymbols, bool isUnsafe, ref AssemblyGen assembly) {
     if (assembly == null) {
         string suffix = (emitSymbols) ? ".debug" : "" + (isUnsafe ? ".unsafe" : "");
         Interlocked.CompareExchange(ref assembly, CreateNewAssembly(suffix, emitSymbols, isUnsafe), null);
     }
     return assembly;
 }
Example #2
0
 private AssemblyGen GetOrCreateAssembly(bool emitSymbols, bool isUnsafe, ref AssemblyGen assembly)
 {
     if (assembly == null)
     {
         string suffix = (emitSymbols) ? ".debug" : "" + (isUnsafe ? ".unsafe" : "");
         Interlocked.CompareExchange(ref assembly, CreateNewAssembly(suffix, emitSymbols, isUnsafe), null);
     }
     return(assembly);
 }
Example #3
0
        private static Type MakeNewCustomDelegate(Type[] types)
        {
            Type returnType = types[types.Length - 1];

            Type[]      parameterTypes = types.RemoveLast <Type>();
            TypeBuilder builder        = AssemblyGen.DefineDelegateType("Delegate" + types.Length);

            builder.DefineConstructor(MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public, CallingConventions.Standard, _DelegateCtorSignature).SetImplementationFlags(MethodImplAttributes.CodeTypeMask);
            builder.DefineMethod("Invoke", MethodAttributes.NewSlot | MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.Public, returnType, parameterTypes).SetImplementationFlags(MethodImplAttributes.CodeTypeMask);
            return(builder.CreateType());
        }
Example #4
0
        private static Type MakeNewCustomDelegate(Type[] types)
        {
            var returnType = types[types.Length - 1];
            var parameters = types.RemoveLast();

            var builder = AssemblyGen.DefineDelegateType("Delegate" + types.Length);

            builder.DefineConstructor(_ctorAttributes, CallingConventions.Standard, _delegateCtorSignature).SetImplementationFlags(_implAttributes);
            builder.DefineMethod("Invoke", _invokeAttributes, returnType, parameters).SetImplementationFlags(_implAttributes);
            return(builder.CreateType());
        }
Example #5
0
        internal TypeBuilder DefineDelegateType(string name)
        {
            AssemblyGen assembly = GetAssembly(false, false);

            return(assembly.DefineType(
                       name,
                       typeof(MulticastDelegate),
                       TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.AnsiClass | TypeAttributes.AutoClass,
                       false
                       ));
        }
Example #6
0
        private static Type MakeNewCustomDelegate(Type[] types)
        {
#if FEATURE_CORECLR
            Type   returnType = types[types.Length - 1];
            Type[] parameters = types.RemoveLast();

            TypeBuilder builder = AssemblyGen.DefineDelegateType("Delegate" + types.Length);
            builder.DefineConstructor(CtorAttributes, CallingConventions.Standard, s_delegateCtorSignature).SetImplementationFlags(ImplAttributes);
            builder.DefineMethod("Invoke", InvokeAttributes, returnType, parameters).SetImplementationFlags(ImplAttributes);
            return(builder.CreateTypeInfo().AsType());
#else
            throw new PlatformNotSupportedException();
#endif
        }
Example #7
0
        //return the assembly locations that need to be verified
        private string[] DumpAssemblies()
        {
            if (!_saveSnippets)
            {
                return(new string[0]);
            }

            List <string> assemlyLocations = new List <string>();

            // first save all assemblies to disk:
            if (_assembly != null)
            {
                string assemblyLocation = _assembly.SaveAssembly();
                if (assemblyLocation != null)
                {
                    assemlyLocations.Add(assemblyLocation);
                }
                _assembly = null;
            }

            if (_debugAssembly != null)
            {
                string debugAssemblyLocation = _debugAssembly.SaveAssembly();
                if (debugAssemblyLocation != null)
                {
                    assemlyLocations.Add(debugAssemblyLocation);
                }
                _debugAssembly = null;
            }

            if (_unsafeAssembly != null)
            {
                _unsafeAssembly.SaveAssembly();
            }

            if (_unsafeDebugAssembly != null)
            {
                _unsafeDebugAssembly.SaveAssembly();
            }

            _unsafeDebugAssembly = null;

            return(assemlyLocations.ToArray());
        }
Example #8
0
        internal DynamicILGen CreateDynamicMethod(string methodName, Type returnType, Type[] parameterTypes,
                                                  bool isDebuggable)
        {
            ContractUtils.RequiresNotEmpty(methodName, "methodName");
            ContractUtils.RequiresNotNull(returnType, "returnType");
            ContractUtils.RequiresNotNullItems(parameterTypes, "parameterTypes");

            if (_saveSnippets)
            {
                AssemblyGen   assembly = GetAssembly(isDebuggable, false);
                TypeBuilder   tb       = assembly.DefinePublicType(methodName, typeof(object), false);
                MethodBuilder mb       = tb.DefineMethod(methodName, TypeUtils.PublicStatic, returnType, parameterTypes);
                return(new DynamicILGenType(tb, mb, mb.GetILGenerator()));
            }
            else
            {
                DynamicMethod dm = Helpers.CreateDynamicMethod(methodName, returnType, parameterTypes);
                return(new DynamicILGenMethod(dm, dm.GetILGenerator()));
            }
        }
Example #9
0
        private static Type MakeNewCustomDelegate(Type[] types)
        {
            if (RuntimeFeature.IsDynamicCodeSupported)
            {
                Type   returnType            = types[types.Length - 1];
                Type[] parameters            = types.RemoveLast();
                Type[] delegateCtorSignature = { typeof(object), typeof(IntPtr) };

                const MethodAttributes     ctorAttributes   = MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public;
                const MethodImplAttributes implAttributes   = MethodImplAttributes.Runtime | MethodImplAttributes.Managed;
                const MethodAttributes     invokeAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual;

                TypeBuilder builder = AssemblyGen.DefineDelegateType("Delegate" + types.Length);
                builder.DefineConstructor(ctorAttributes, CallingConventions.Standard, delegateCtorSignature).SetImplementationFlags(implAttributes);
                builder.DefineMethod("Invoke", invokeAttributes, returnType, parameters).SetImplementationFlags(implAttributes);
                return(builder.CreateTypeInfo());
            }
            else
            {
                throw new PlatformNotSupportedException();
            }
        }
Example #10
0
        //return the assembly locations that need to be verified
        private string[] DumpAssemblies() {
            if (!_saveSnippets) {
                return new string[0];
            }

            List<string> assemlyLocations = new List<string>();

            // first save all assemblies to disk:
            if (_assembly != null) {
                string assemblyLocation = _assembly.SaveAssembly();
                if (assemblyLocation != null) {
                    assemlyLocations.Add(assemblyLocation);
                }
                _assembly = null;
            }

            if (_debugAssembly != null) {
                string debugAssemblyLocation = _debugAssembly.SaveAssembly();
                if (debugAssemblyLocation != null) {
                    assemlyLocations.Add(debugAssemblyLocation);
                }
                _debugAssembly = null;
            }

            if (_unsafeAssembly != null) {
                _unsafeAssembly.SaveAssembly();
            }

            if (_unsafeDebugAssembly != null) {
                _unsafeDebugAssembly.SaveAssembly();
            }

            _unsafeDebugAssembly = null;

            return assemlyLocations.ToArray();
        }
Example #11
0
        internal static string[] SaveAssembliesToDisk() {
            if (!_saveAssemblies) {
                return new string[0];
            }

            var assemlyLocations = new List<string>();

            // first save all assemblies to disk:
            if (_assembly != null) {
                string assemblyLocation = _assembly.SaveAssembly();
                if (assemblyLocation != null) {
                    assemlyLocations.Add(assemblyLocation);
                }
                _assembly = null;
            }

            return assemlyLocations.ToArray();
        }
Example #12
0
        internal TypeBuilder DefineType(string name, Type parent, bool preserveName, bool isUnsafe, bool emitDebugSymbols)
        {
            AssemblyGen ag = GetAssembly(emitDebugSymbols, isUnsafe);

            return(ag.DefinePublicType(name, parent, preserveName));
        }