Exemplo n.º 1
0
		public void Emit ()
		{
			if (RootContext.Target == Target.Module) {
				module_target_attrs = new AssemblyAttributesPlaceholder (module, name);
				module_target_attrs.CreateType ();
				module_target_attrs.DefineType ();
				module_target_attrs.Define ();
				module.AddCompilerGeneratedClass (module_target_attrs);
			} else if (added_modules != null) {
				ReadModulesAssemblyAttributes ();
			}

			module.Emit ();

			if (module.HasExtensionMethod) {
				var pa = Compiler.PredefinedAttributes.Extension;
				if (pa.IsDefined) {
					SetCustomAttribute (pa.Constructor, AttributeEncoder.Empty);
				}
			}

			if (!wrap_non_exception_throws_custom) {
				PredefinedAttribute pa = Compiler.PredefinedAttributes.RuntimeCompatibility;
				if (pa.IsDefined && pa.ResolveBuilder ()) {
					var prop = pa.GetProperty ("WrapNonExceptionThrows", TypeManager.bool_type, Location.Null);
					if (prop != null) {
						AttributeEncoder encoder = new AttributeEncoder (false);
						encoder.EncodeNamedPropertyArgument (prop, new BoolLiteral (true, Location.Null));
						SetCustomAttribute (pa.Constructor, encoder.ToArray ());
					}
				}
			}

			if (declarative_security != null) {

				MethodInfo add_permission = typeof (AssemblyBuilder).GetMethod ("AddPermissionRequests", BindingFlags.Instance | BindingFlags.NonPublic);
				object builder_instance = Builder;

				try {
					// Microsoft runtime hacking
					if (add_permission == null) {
						var assembly_builder = typeof (AssemblyBuilder).Assembly.GetType ("System.Reflection.Emit.AssemblyBuilderData");
						add_permission = assembly_builder.GetMethod ("AddPermissionRequests", BindingFlags.Instance | BindingFlags.NonPublic);

						FieldInfo fi = typeof (AssemblyBuilder).GetField ("m_assemblyData", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
						builder_instance = fi.GetValue (Builder);
					}

					var args = new PermissionSet [3];
					declarative_security.TryGetValue (SecurityAction.RequestMinimum, out args [0]);
					declarative_security.TryGetValue (SecurityAction.RequestOptional, out args [1]);
					declarative_security.TryGetValue (SecurityAction.RequestRefuse, out args [2]);
					add_permission.Invoke (builder_instance, args);
				} catch {
					Report.RuntimeMissingSupport (Location.Null, "assembly permission setting");
				}
			}

			CheckReferencesPublicToken ();

			SetEntryPoint ();
		}
Exemplo n.º 2
0
        public virtual void Emit()
        {
            if (Compiler.Settings.Target == Target.Module)
            {
                module_target_attrs = new AssemblyAttributesPlaceholder(module, name);
                module_target_attrs.CreateContainer();
                module_target_attrs.DefineContainer();
                module_target_attrs.Define();
                module.AddCompilerGeneratedClass(module_target_attrs);
            }
            else if (added_modules != null)
            {
                ReadModulesAssemblyAttributes();
            }

            if (Compiler.Settings.GenerateDebugInfo)
            {
                symbol_writer = new MonoSymbolFile();
            }

            module.EmitContainer();

            if (module.HasExtensionMethod)
            {
                var pa = module.PredefinedAttributes.Extension;
                if (pa.IsDefined)
                {
                    SetCustomAttribute(pa.Constructor, AttributeEncoder.Empty);
                }
            }

            if (!IsSatelliteAssembly)
            {
                if (!wrap_non_exception_throws_custom)
                {
                    PredefinedAttribute pa = module.PredefinedAttributes.RuntimeCompatibility;
                    if (pa.IsDefined && pa.ResolveBuilder())
                    {
                        var prop = module.PredefinedMembers.RuntimeCompatibilityWrapNonExceptionThrows.Get();
                        if (prop != null)
                        {
                            AttributeEncoder encoder = new AttributeEncoder();
                            encoder.EncodeNamedPropertyArgument(prop, new BoolLiteral(Compiler.BuiltinTypes, true, Location.Null));
                            SetCustomAttribute(pa.Constructor, encoder.ToArray());
                        }
                    }
                }

                if (declarative_security != null)
                {
#if STATIC
                    foreach (var entry in declarative_security)
                    {
                        Builder.__AddDeclarativeSecurity(entry);
                    }
#else
                    throw new NotSupportedException("Assembly-level security");
#endif
                }
            }

            CheckReferencesPublicToken();

            SetEntryPoint();
        }
Exemplo n.º 3
0
        public virtual void Emit()
        {
            if (Compiler.Settings.Target == Target.Module)
            {
                module_target_attrs = new AssemblyAttributesPlaceholder(module, name);
                module_target_attrs.CreateType();
                module_target_attrs.DefineType();
                module_target_attrs.Define();
                module.AddCompilerGeneratedClass(module_target_attrs);
            }
            else if (added_modules != null)
            {
                ReadModulesAssemblyAttributes();
            }

            if (Compiler.Settings.GenerateDebugInfo)
            {
                symbol_writer = new MonoSymbolWriter(file_name);

                // Register all source files with symbol writer
                foreach (var source in Compiler.SourceFiles)
                {
                    source.DefineSymbolInfo(symbol_writer);
                }

                // TODO: global variables
                SymbolWriter.symwriter = symbol_writer;
            }

            module.Emit();

            if (module.HasExtensionMethod)
            {
                var pa = module.PredefinedAttributes.Extension;
                if (pa.IsDefined)
                {
                    SetCustomAttribute(pa.Constructor, AttributeEncoder.Empty);
                }
            }

            if (!wrap_non_exception_throws_custom)
            {
                PredefinedAttribute pa = module.PredefinedAttributes.RuntimeCompatibility;
                if (pa.IsDefined && pa.ResolveBuilder())
                {
                    var prop = module.PredefinedMembers.RuntimeCompatibilityWrapNonExceptionThrows.Get();
                    if (prop != null)
                    {
                        AttributeEncoder encoder = new AttributeEncoder();
                        encoder.EncodeNamedPropertyArgument(prop, new BoolLiteral(Compiler.BuiltinTypes, true, Location.Null));
                        SetCustomAttribute(pa.Constructor, encoder.ToArray());
                    }
                }
            }

            if (declarative_security != null)
            {
#if STATIC
                foreach (var entry in declarative_security)
                {
                    Builder.__AddDeclarativeSecurity(entry);
                }
#else
                var args = new PermissionSet[3];
                declarative_security.TryGetValue(SecurityAction.RequestMinimum, out args[0]);
                declarative_security.TryGetValue(SecurityAction.RequestOptional, out args[1]);
                declarative_security.TryGetValue(SecurityAction.RequestRefuse, out args[2]);
                builder_extra.AddPermissionRequests(args);
#endif
            }

            CheckReferencesPublicToken();

            SetEntryPoint();
        }