- /* Keep this in sync with System.Reflection.Emit.AssemblyBuilder */
- const AssemblyBuilderAccess COMPILER_ACCESS = (AssemblyBuilderAccess) 0x800;
-#endif
-
- //
- // Initializes the code generator variables for interactive use (repl)
- //
- static public void InitDynamic (CompilerContext ctx, string name)
- {
- current_domain = AppDomain.CurrentDomain;
- AssemblyName an = Assembly.GetAssemblyName (name, name);
-
- Assembly.Builder = current_domain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run | COMPILER_ACCESS);
- RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
- RootContext.ToplevelTypes.Builder = Assembly.Builder.DefineDynamicModule (Basename (name), false);
- Assembly.Name = Assembly.Builder.GetName ();
- }
-
- //
- // Initializes the code generator variables
- //
- static public bool Init (string name, string output, bool want_debugging_support, CompilerContext ctx)
- {
- FileName = output;
- AssemblyName an = Assembly.GetAssemblyName (name, output);
- if (an == null)
- return false;
-
- if (an.KeyPair != null) {
- // If we are going to strong name our assembly make
- // sure all its refs are strong named
- foreach (Assembly a in GlobalRootNamespace.Instance.Assemblies) {
- AssemblyName ref_name = a.GetName ();
- byte [] b = ref_name.GetPublicKeyToken ();
- if (b == null || b.Length == 0) {
- ctx.Report.Error (1577, "Assembly generation failed " +
- "-- Referenced assembly '" +
- ref_name.Name +
- "' does not have a strong name.");
- //Environment.Exit (1);
- }
- }
- }
-
- current_domain = AppDomain.CurrentDomain;
-
- try {
- Assembly.Builder = current_domain.DefineDynamicAssembly (an,
- AssemblyBuilderAccess.RunAndSave | COMPILER_ACCESS, Dirname (name));
- }
- catch (ArgumentException) {
- // specified key may not be exportable outside it's container
- if (RootContext.StrongNameKeyContainer != null) {
- ctx.Report.Error (1548, "Could not access the key inside the container `" +
- RootContext.StrongNameKeyContainer + "'.");
- Environment.Exit (1);
- }
- throw;
- }
- catch (CryptographicException) {
- if ((RootContext.StrongNameKeyContainer != null) || (RootContext.StrongNameKeyFile != null)) {
- ctx.Report.Error (1548, "Could not use the specified key to strongname the assembly.");
- Environment.Exit (1);
- }
- return false;
- }
-
- // Get the complete AssemblyName from the builder
- // (We need to get the public key and token)
- Assembly.Name = Assembly.Builder.GetName ();
-
- //
- // Pass a path-less name to DefineDynamicModule. Wonder how
- // this copes with output in different directories then.
- // FIXME: figure out how this copes with --output /tmp/blah
- //
- // If the third argument is true, the ModuleBuilder will dynamically
- // load the default symbol writer.
- //
- try {
- RootContext.ToplevelTypes.Builder = Assembly.Builder.DefineDynamicModule (
- Basename (name), Basename (output), want_debugging_support);
-
-#if !MS_COMPATIBLE
- // TODO: We should use SymbolWriter from DefineDynamicModule
- if (want_debugging_support && !SymbolWriter.Initialize (RootContext.ToplevelTypes.Builder, output)) {
- ctx.Report.Error (40, "Unexpected debug information initialization error `{0}'",
- "Could not find the symbol writer assembly (Mono.CompilerServices.SymbolWriter.dll)");
- return false;
- }