2 // driver.cs: The compiler command line driver.
4 // Author: Rafael Teixeira (rafaelteixeirabr@hotmail.com)
5 // Based on mcs by : Miguel de Icaza (miguel@gnu.org)
7 // Licensed under the terms of the GNU GPL
9 // (C) 2002, 2003, 2004 Rafael Teixeira
12 namespace Mono.Languages {
15 using System.Collections;
16 using System.Diagnostics;
19 using System.Globalization;
20 using System.Reflection;
21 using System.Reflection.Emit;
24 using Mono.GetOptions;
27 Library, Exe, Module, WinExe
34 struct FileToCompile {
35 public string Filename;
36 public Encoding Encoding;
38 public FileToCompile(string filename, Encoding encoding)
40 this.Filename = filename;
41 this.Encoding = encoding;
46 GenericParser.Parse(this.Filename, this.Encoding);
51 /// The compiler driver.
53 public class Driver : Options {
55 //------------------------------------------------------------------
56 [Option("[Mono] Only parses the source file (for debugging the tokenizer)", "parse", SecondLevelHelp = true)]
57 public bool parse_only = false;
59 [Option("[IGNORED] Only tokenizes source files", SecondLevelHelp = true)]
60 public bool tokenize = false;
62 [Option("[Mono] Shows stack trace at Error location", SecondLevelHelp = true)]
63 public bool stacktrace { set { Report.Stacktrace = value; } }
65 [Option("[Mono] Displays time stamps of various compiler events", SecondLevelHelp = true)]
66 public bool timestamp {
70 last_time = DateTime.Now;
71 debug_arglist.Add("timestamp");
75 [Option("[Mono] Makes errors fatal", "fatal", SecondLevelHelp = true)]
76 public bool Fatal { set { Report.Fatal = value; } }
79 // Mono-specific options
80 //------------------------------------------------------------------
81 [Option("About the MonoBASIC compiler", "about")]
82 public override WhatToDoNext DoAbout()
84 return base.DoAbout();
87 [Option("Show usage syntax and exit", "usage", SecondLevelHelp = true)]
88 public override WhatToDoNext DoUsage()
90 return base.DoUsage();
93 [Option(-1, "[Mono] References packages listed. {packagelist}=package,...", "pkg")]
94 public WhatToDoNext ReferenceSomePackage(string packageName)
96 return ReferencePackage(packageName)?WhatToDoNext.GoAhead:WhatToDoNext.AbandonProgram;
99 private Encoding currentEncoding = null;
101 [Option(-1, "Select codepage by {ID} (number, 'utf8' or 'reset') to process following source files", "codepage")]
102 public string CurrentCodepage {
104 switch (value.ToLower()) {
106 currentEncoding = null;
108 case "utf8": case "utf-8":
109 currentEncoding = Encoding.UTF8;
113 currentEncoding = Encoding.GetEncoding(int.Parse(value));
114 } catch (NotSupportedException) {
115 Console.WriteLine("Ignoring unsupported codepage number {0}.", value);
116 } catch (Exception) {
117 Console.WriteLine("Ignoring unsupported codepage ID {0}.", value);
126 [Option("[Mono] Don\'t assume the standard library", "nostdlib", SecondLevelHelp = true)]
127 public bool NoStandardLibraries { set { RootContext.StdLib = !value; } }
129 [Option("[Mono] Disables implicit references to assemblies", "noconfig", SecondLevelHelp = true)]
130 public bool NoConfig { set { load_default_config = !value; } }
132 [Option("[Mono] Allows unsafe code", "unsafe", SecondLevelHelp = true)]
133 public bool AllowUnsafeCode { set { RootContext.Unsafe = value; } }
135 [Option("[Mono] Debugger {arguments}", "debug-args", SecondLevelHelp = true)]
136 public WhatToDoNext SetDebugArgs(string args)
138 debug_arglist.AddRange(args.Split(','));
139 return WhatToDoNext.GoAhead;
142 [Option("[Mono] Ignores warning number {XXXX}", "ignorewarn", SecondLevelHelp = true)]
143 public WhatToDoNext SetIgnoreWarning(int warn)
145 Report.SetIgnoreWarning(warn);
146 return WhatToDoNext.GoAhead;
149 [Option("[Mono] Sets warning {level} (the highest is 4, the default)", "wlevel", SecondLevelHelp = true)]
150 public int WarningLevel { set { RootContext.WarningLevel = value; } }
152 // Output file options
153 //------------------------------------------------------------------
154 [Option("Specifies the output {file} name", 'o', "out")]
155 public string OutputFileName = null;
157 [Option("Specifies the target {type} for the output file (exe [default], winexe, library, module)", 't', "target")]
158 public WhatToDoNext SetTarget(string type)
160 switch (type.ToLower()) {
162 target = Target.Library;
172 target = Target.WinExe;
177 target = Target.Module;
178 target_ext = ".netmodule";
181 return WhatToDoNext.GoAhead;
184 [Option("Specifies the {name} of the Class or Module that contains Sub Main or inherits from System.Windows.Forms.Form.\tNeeded to select among many entry-points for a program (target=exe|winexe)",
186 public string main { set { RootContext.MainClass = value; } }
188 // TODO: force option to accept number in hex format
189 // [Option("[NOT IMPLEMENTED YET]The base {address} for a library or module (hex)", SecondLevelHelp = true)]
190 public int baseaddress;
192 // input file options
193 //------------------------------------------------------------------
194 [Option(-1, "Imports all type information from files in the {module-list}. {module-list}:module,...", "addmodule")]
195 public string AddedModule { set { foreach(string module in value.Split(',')) addedNetModules.Add(module); } }
197 // [Option("[NOT IMPLEMENTED YET]Include all files in the current directory and subdirectories according to the {wildcard}", "recurse")]
198 public WhatToDoNext Recurse(string wildcard)
200 //AddFiles (DirName, true); // TODO wrong semantics
201 return WhatToDoNext.GoAhead;
204 [Option(-1, "References metadata from the specified {assembly}", 'r', "reference")]
205 public string AddedReference { set { references.Add(value); } }
207 [Option("List of directories to search for metadata references. {path-list}:path,...", "libpath", "lib")]
208 public string AddedLibPath { set { foreach(string path in value.Split(',')) libpath.Add(path); } }
210 // support for the Compact Framework
211 //------------------------------------------------------------------
212 // [Option("[NOT IMPLEMENTED YET]Sets the compiler to target the Compact Framework", "netcf")]
213 public bool CompileForCompactFramework = false;
215 // [Option("[NOT IMPLEMENTED YET]Specifies the {path} to the location of mscorlib.dll and microsoft.visualbasic.dll", "sdkpath")]
216 public string SDKPath = null;
219 //------------------------------------------------------------------
220 public ArrayList EmbeddedResources = new ArrayList();
222 [Option(-1, "Adds the specified {file} as an embedded assembly resource", "resource", "res")]
223 public string AddedResource { set { EmbeddedResources.Add(value); } }
225 public ArrayList LinkedResources = new ArrayList();
227 // [Option(-1, "[NOT IMPLEMENTED YET]Adds the specified {file} as a linked assembly resource", "linkresource", "linkres")]
228 public string AddedLinkresource { set { LinkedResources.Add(value); } }
230 public ArrayList Win32Resources = new ArrayList();
232 // [Option(-1, "[NOT IMPLEMENTED YET]Specifies a Win32 resource {file} (.res)", "win32resource")]
233 public string AddedWin32resource { set { Win32Resources.Add(value); } }
235 public ArrayList Win32Icons = new ArrayList();
237 // [Option(-1, "[NOT IMPLEMENTED YET]Specifies a Win32 icon {file} (.ico) for the default Win32 resources", "win32icon")]
238 public string AddedWin32icon { set { Win32Icons.Add(value); } }
240 // code generation options
241 //------------------------------------------------------------------
243 // [Option("[NOT IMPLEMENTED YET]Enable optimizations", "optimize", VBCStyleBoolean = true)]
244 public bool optimize = false;
246 [Option("Remove integer checks. Default off.", SecondLevelHelp = true, VBCStyleBoolean = true)]
247 public bool removeintchecks { set { RootContext.Checked = !value; } }
249 [Option("Emit debugging information", 'g', "debug", VBCStyleBoolean = true)]
250 public bool want_debugging_support = false;
252 [Option("Emit full debugging information (default)", "debug:full", SecondLevelHelp = true)]
253 public bool fullDebugging = false;
255 [Option("[IGNORED] Emit PDB file only", "debug:pdbonly", SecondLevelHelp = true)]
256 public bool pdbOnly = false;
258 // errors and warnings options
259 //------------------------------------------------------------------
261 [Option("Treat warnings as errors", "warnaserror", SecondLevelHelp = true)]
262 public bool WarningsAreErrors { set { Report.WarningsAreErrors = value; } }
264 [Option("Disable warnings", "nowarn", SecondLevelHelp = true)]
265 public bool NoWarnings { set { if (value) RootContext.WarningLevel = 0; } }
269 //------------------------------------------------------------------
270 public Hashtable Defines = new Hashtable();
272 [Option(-1, "Declares global conditional compilation symbol(s). {symbol-list}:name=value,...", 'd', "define")]
273 public string define {
275 foreach(string item in value.Split(',')) {
276 string[] dados = item.Split('=');
278 if (dados.Length > 1)
279 Defines.Add(dados[0], dados[1]);
281 Defines.Add(dados[0], string.Empty);
284 Error ("Could not define symbol" + dados[0]);
291 //------------------------------------------------------------------
293 // [Option("[NOT IMPLEMENTED YET]Require explicit declaration of variables", VBCStyleBoolean = true)]
294 public bool optionexplicit { set { Mono.MonoBASIC.Parser.InitialOptionExplicit = value; } }
296 // [Option("[NOT IMPLEMENTED YET]Enforce strict language semantics", VBCStyleBoolean = true)]
297 public bool optionstrict { set { Mono.MonoBASIC.Parser.InitialOptionStrict = value; } }
299 // [Option("[NOT IMPLEMENTED YET]Specifies binary-style string comparisons. This is the default", "optioncompare:binary")]
300 public bool optioncomparebinary { set { Mono.MonoBASIC.Parser.InitialOptionCompareBinary = true; } }
302 // [Option("[NOT IMPLEMENTED YET]Specifies text-style string comparisons.", "optioncompare:text")]
303 public bool optioncomparetext { set { Mono.MonoBASIC.Parser.InitialOptionCompareBinary = false; } }
305 [Option(-1, "Declare global Imports for listed namespaces. {import-list}:namespace,...", "imports")]
306 public string imports
309 foreach(string importedNamespace in value.Split(','))
310 Mono.MonoBASIC.Parser.ImportsList.Add(importedNamespace);
314 [Option("Specifies the root {namespace} for all type declarations", SecondLevelHelp = true)]
315 public string rootnamespace { set { RootContext.RootNamespace = value; } }
318 //------------------------------------------------------------------
319 // [Option("[NOT IMPLEMENTED YET]Delay-sign the assembly using only the public portion of the strong name key", VBCStyleBoolean = true)]
320 public bool delaysign;
322 // [Option("[NOT IMPLEMENTED YET]Specifies a strong name key {container}")]
323 public string keycontainer;
325 // [Option("[NOT IMPLEMENTED YET]Specifies a strong name key {file}")]
326 public string keyfile;
328 // Compiler output options
329 //------------------------------------------------------------------
331 [Option("Do not display compiler copyright banner")]
332 public bool nologo = false;
334 //TODO: Correct semantics
335 [Option("Commands the compiler to show only error messages for syntax-related errors and warnings", 'q', "quiet", SecondLevelHelp = true)]
336 public bool SuccintErrorDisplay = false;
338 // TODO: semantics are different and should be adjusted
339 [Option("Display verbose messages", 'v', SecondLevelHelp = true)]
340 public bool verbose { set { GenericParser.yacc_verbose_flag = value ? 1 : 0; } }
342 [Option("[IGNORED] Emit compiler output in UTF8 character encoding", SecondLevelHelp = true, VBCStyleBoolean = true)]
343 public bool utf8output;
345 // [Option("[NOT IMPLEMENTED YET]Create bug report {file}")]
346 public string bugreport;
349 public void AddFile(string fileName)
352 if (firstSourceFile == null)
355 if (source_files.Contains(f))
356 Report.Error(1516, "Source file '" + f + "' specified multiple times");
358 source_files.Add(f, new FileToCompile(fileName, currentEncoding));
361 ArrayList defines = new ArrayList();
362 ArrayList references = new ArrayList();
363 ArrayList soft_references = new ArrayList();
364 ArrayList addedNetModules = new ArrayList();
365 ArrayList libpath = new ArrayList();
367 string firstSourceFile = null;
368 Target target = Target.Exe;
369 string target_ext = ".exe";
370 ArrayList debug_arglist = new ArrayList ();
371 bool timestamps = false;
372 Hashtable source_files = new Hashtable ();
373 bool load_default_config = true;
376 // Last time we took the time
379 void ShowTime (string msg)
381 DateTime now = DateTime.Now;
382 TimeSpan span = now - last_time;
386 "[{0:00}:{1:000}] {2}",
387 (int) span.TotalSeconds, span.Milliseconds, msg);
390 public int LoadAssembly (string assembly, bool soft)
393 string total_log = "";
396 char[] path_chars = { '/', '\\' };
398 if (assembly.IndexOfAny (path_chars) != -1)
399 a = Assembly.LoadFrom(assembly);
401 string ass = assembly;
402 if (ass.EndsWith (".dll"))
403 ass = assembly.Substring (0, assembly.Length - 4);
404 a = Assembly.Load (ass);
406 TypeManager.AddAssembly (a);
409 catch (FileNotFoundException) {
410 if (libpath != null) {
411 foreach (string dir in libpath) {
412 string full_path = dir + "/" + assembly + ".dll";
415 a = Assembly.LoadFrom (full_path);
416 TypeManager.AddAssembly (a);
419 catch (FileNotFoundException ff) {
420 total_log += ff.FusionLog;
428 catch (BadImageFormatException f) {
429 Error ("// Bad file format while loading assembly");
430 Error ("Log: " + f.FusionLog);
432 } catch (FileLoadException f){
433 Error ("File Load Exception: " + assembly);
434 Error ("Log: " + f.FusionLog);
436 } catch (ArgumentNullException){
437 Error ("// Argument Null exception ");
441 Report.Error (6, "Can not find assembly `" + assembly + "'" );
442 Console.WriteLine ("Log: \n" + total_log);
447 public bool ReferencePackage(string packageName)
449 if (packageName == ""){
454 ProcessStartInfo pi = new ProcessStartInfo ();
455 pi.FileName = "pkg-config";
456 pi.RedirectStandardOutput = true;
457 pi.UseShellExecute = false;
458 pi.Arguments = "--libs " + packageName;
461 p = Process.Start (pi);
462 } catch (Exception e) {
463 Report.Error (-27, "Couldn't run pkg-config: " + e.Message);
467 if (p.StandardOutput == null){
468 Report.Warning (-27, "Specified package did not return any information");
470 string pkgout = p.StandardOutput.ReadToEnd ();
472 if (p.ExitCode != 0) {
473 Report.Error (-27, "Error running pkg-config. Check the above output.");
478 if (pkgout != null) {
479 string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}).
480 Split (new Char [] { ' ', '\t'});
481 foreach(string arg in xargs) {
482 string[] zargs = arg.Split(':', '=');
484 if (zargs.Length > 1)
485 AddedReference = zargs[1];
487 AddedReference = arg;
488 } catch (Exception e) {
489 Report.Error (-27, "Something wrong with argument (" + arg + ") in 'pkg-config --libs' output: " + e.Message);
498 public void LoadModule (MethodInfo adder_method, string module)
500 System.Reflection.Module m;
501 string total_log = "";
505 m = (System.Reflection.Module)adder_method.Invoke (CodeGen.AssemblyBuilder, new object [] { module });
507 catch (TargetInvocationException ex) {
508 throw ex.InnerException;
510 TypeManager.AddModule (m);
513 catch (FileNotFoundException) {
514 foreach (string dir in libpath) {
515 string full_path = Path.Combine (dir, module);
516 if (!module.EndsWith (".netmodule"))
517 full_path += ".netmodule";
521 m = (System.Reflection.Module) adder_method.Invoke (CodeGen.AssemblyBuilder, new object [] { full_path });
523 catch (TargetInvocationException ex) {
524 throw ex.InnerException;
526 TypeManager.AddModule (m);
529 catch (FileNotFoundException ff) {
530 total_log += ff.FusionLog;
534 Report.Error (6, "Cannot find module `" + module + "'" );
535 Console.WriteLine ("Log: \n" + total_log);
537 catch (BadImageFormatException f) {
538 Report.Error(6, "Cannot load module (bad file format)" + f.FusionLog);
540 catch (FileLoadException f) {
541 Report.Error(6, "Cannot load module " + f.FusionLog);
543 catch (ArgumentNullException) {
544 Report.Error(6, "Cannot load module (null argument)");
548 void Error(string message)
550 Console.WriteLine(message);
554 /// Loads all assemblies referenced on the command line
556 public int LoadReferences ()
560 foreach (string r in references)
561 errors += LoadAssembly (r, false);
563 foreach (string r in soft_references)
564 errors += LoadAssembly (r, true);
569 void SetupDefaultDefines ()
571 defines = new ArrayList ();
572 defines.Add ("__MonoBASIC__");
575 void SetupDefaultImports()
577 Mono.MonoBASIC.Parser.ImportsList = new ArrayList();
578 Mono.MonoBASIC.Parser.ImportsList.Add("Microsoft.VisualBasic");
582 // Given a path specification, splits the path from the file/pattern
584 void SplitPathAndPattern (string spec, out string path, out string pattern)
586 int p = spec.LastIndexOf ("/");
589 // Windows does not like /file.cs, switch that to:
594 pattern = spec.Substring (1);
596 path = spec.Substring (0, p);
597 pattern = spec.Substring (p + 1);
602 p = spec.LastIndexOf ("\\");
604 path = spec.Substring (0, p);
605 pattern = spec.Substring (p + 1);
613 bool AddFiles (string spec, bool recurse)
615 string path, pattern;
617 SplitPathAndPattern(spec, out path, out pattern);
618 if (pattern.IndexOf("*") == -1) {
623 string [] files = null;
625 files = Directory.GetFiles(path, pattern);
626 } catch (System.IO.DirectoryNotFoundException) {
627 Report.Error (2001, "Source file `" + spec + "' could not be found");
629 } catch (System.IO.IOException){
630 Report.Error (2001, "Source file `" + spec + "' could not be found");
633 foreach (string f in files)
639 string [] dirs = null;
642 dirs = Directory.GetDirectories(path);
646 foreach (string d in dirs) {
648 // Don't include path in this string, as each
649 // directory entry already does
650 AddFiles (d + "/" + pattern, true);
656 void DefineDefaultConfig ()
659 // For now the "default config" is harcoded into the compiler
660 // we can move this outside later
662 string [] default_config =
667 "Microsoft.VisualBasic" ,
668 #if EXTRA_DEFAULT_REFS
670 // Is it worth pre-loading all this stuff?
673 "System.Configuration.Install",
675 "System.DirectoryServices",
676 "System.Drawing.Design",
678 "System.EnterpriseServices",
681 "System.Runtime.Remoting",
682 "System.Runtime.Serialization.Formatters.Soap",
684 "System.ServiceProcess",
686 "System.Web.RegularExpressions",
687 "System.Web.Services" ,
688 "System.Windows.Forms"
692 foreach (string def in default_config)
693 if (!(references.Contains(def) || references.Contains (def + ".dll")))
694 soft_references.Add(def);
697 string outputFile_Name = null;
699 string outputFileName {
702 if (outputFile_Name == null) {
703 if (OutputFileName == null) {
704 int pos = firstSourceFile.LastIndexOf(".");
707 OutputFileName = firstSourceFile.Substring(0, pos);
709 OutputFileName = firstSourceFile;
711 string bname = CodeGen.Basename(OutputFileName);
712 if (bname.IndexOf(".") == -1)
713 OutputFileName += target_ext;
714 outputFile_Name = OutputFileName;
716 return outputFile_Name;
720 bool ParseAll() // Phase 1
725 foreach(FileToCompile file in source_files.Values)
728 if (parse_only || (Report.Errors > 0))
731 return true; // everything went well go ahead
734 void InitializeDebuggingSupport()
736 string[] debug_args = new string [debug_arglist.Count];
737 debug_arglist.CopyTo(debug_args);
738 CodeGen.Init(outputFileName, outputFileName, want_debugging_support, debug_args);
739 TypeManager.AddModule(CodeGen.ModuleBuilder);
742 public bool ResolveAllTypes() // Phase 2
744 // Load Core Library for default compilation
745 if (RootContext.StdLib)
746 references.Insert(0, "mscorlib");
748 if (load_default_config)
749 DefineDefaultConfig();
752 ShowTime("Loading references");
754 // Load assemblies required
755 if (LoadReferences() > 0) {
756 Error ("Could not load one or more assemblies");
761 ShowTime("References loaded");
763 InitializeDebuggingSupport();
766 if (target == Target.Module) {
767 PropertyInfo module_only = typeof (AssemblyBuilder).GetProperty ("IsModuleOnly", BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic);
768 if (module_only == null) {
769 Report.Error (0, new Location (-1, -1), "Cannot use /target:module on this runtime: try the Mono runtime instead.");
770 Environment.Exit (1);
773 MethodInfo set_method = module_only.GetSetMethod (true);
774 set_method.Invoke (CodeGen.AssemblyBuilder, BindingFlags.Default, null, new object[]{true}, null);
776 TypeManager.AddModule (CodeGen.ModuleBuilder);
779 if (addedNetModules.Count > 0) {
780 MethodInfo adder_method = typeof (AssemblyBuilder).GetMethod ("AddModule", BindingFlags.Instance|BindingFlags.NonPublic);
781 if (adder_method == null) {
782 Report.Error (0, new Location (-1, -1), "Cannot use /addmodule on this runtime: Try the Mono runtime instead.");
783 Environment.Exit (1);
786 foreach (string module in addedNetModules)
787 LoadModule (adder_method, module);
792 // Before emitting, we need to get the core
793 // types emitted from the user defined types
794 // or from the system ones.
797 ShowTime ("Initializing Core Types");
799 if (!RootContext.StdLib)
800 RootContext.ResolveCore ();
801 if (Report.Errors > 0)
804 TypeManager.InitCoreTypes();
805 if (Report.Errors > 0)
809 ShowTime (" Core Types done");
812 ShowTime ("Resolving tree");
814 // The second pass of the compiler
815 RootContext.ResolveTree ();
816 if (Report.Errors > 0)
820 ShowTime ("Populate tree");
822 if (!RootContext.StdLib)
823 RootContext.BootCorlib_PopulateCoreTypes();
824 if (Report.Errors > 0)
827 RootContext.PopulateTypes();
828 if (Report.Errors > 0)
831 TypeManager.InitCodeHelpers();
832 if (Report.Errors > 0)
840 string mainclass = GetFQMainClass();
842 if (mainclass != null) {
843 foreach (string r in references) {
844 if (r.IndexOf ("System.Windows.Forms") >= 0) {
845 Type t = TypeManager.LookupType(mainclass);
847 return t.IsSubclassOf (TypeManager.LookupType("System.Windows.Forms.Form"));
855 string GetFQMainClass()
857 if (RootContext.RootNamespace != "")
858 return RootContext.RootNamespace + "." + RootContext.MainClass;
860 return RootContext.MainClass;
865 if (target == Target.Exe || target == Target.WinExe) {
866 MethodInfo ep = RootContext.EntryPoint;
869 // If we don't have a valid entry point yet
870 // AND if System.Windows.Forms is included
871 // among the dependencies, we have to build
872 // a new entry point on-the-fly. Otherwise we
873 // won't be able to compile SWF code out of the box.
876 Type t = TypeManager.LookupType(GetFQMainClass());
879 TypeBuilder tb = t as TypeBuilder;
880 MethodBuilder mb = tb.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard,
881 typeof(void), new Type[0]);
883 Type SWFA = TypeManager.LookupType("System.Windows.Forms.Application");
884 Type SWFF = TypeManager.LookupType("System.Windows.Forms.Form");
885 Type[] args = new Type[1];
887 MethodInfo mi = SWFA.GetMethod("Run", args);
888 ILGenerator ig = mb.GetILGenerator();
889 ConstructorInfo ci = TypeManager.GetConstructor (TypeManager.LookupType(t.FullName), new Type[0]);
891 ig.Emit (OpCodes.Newobj, ci);
892 ig.Emit (OpCodes.Call, mi);
893 ig.Emit (OpCodes.Ret);
895 RootContext.EntryPoint = mb as MethodInfo;
902 bool GenerateAssembly()
905 // The code generator
908 ShowTime ("Emitting code");
912 RootContext.EmitCode();
914 if (Report.Errors > 0)
922 ShowTime ("Closing types");
924 RootContext.CloseTypes ();
925 if (Report.Errors > 0)
931 PEFileKinds k = PEFileKinds.ConsoleApplication;
933 if (target == Target.Library || target == Target.Module)
935 else if (target == Target.Exe)
936 k = PEFileKinds.ConsoleApplication;
937 else if (target == Target.WinExe)
938 k = PEFileKinds.WindowApplication;
940 if (target == Target.Exe || target == Target.WinExe) {
941 MethodInfo ep = RootContext.EntryPoint;
944 Report.Error (30737, "Program " + outputFileName +
945 " does not have an entry point defined");
949 CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);
953 if (EmbeddedResources != null)
954 foreach (string file in EmbeddedResources)
955 CodeGen.AssemblyBuilder.AddResourceFile (file, file);
957 CodeGen.Save(outputFileName);
960 ShowTime ("Saved output");
963 if (want_debugging_support) {
964 CodeGen.SaveSymbols ();
966 ShowTime ("Saved symbols");
972 public void CompileAll()
976 VB.NET expects the default namespace to be "" (empty string)
978 if (RootContext.RootNamespace == "") {
979 RootContext.RootNamespace = System.IO.Path.GetFileNameWithoutExtension(outputFileName);
982 if (!ParseAll()) // Phase 1
985 if (!ResolveAllTypes()) // Phase 2
988 GenerateAssembly(); // Phase 3
990 } catch (Exception ex) {
991 Error("Exception: " + ex.ToString());
995 private bool quiet { get { return nologo || SuccintErrorDisplay; } }
997 private void Banner()
1001 // TODO: remove next lines when the compiler has matured enough
1002 Console.WriteLine ("--------");
1003 Console.WriteLine ("THIS IS AN ALPHA SOFTWARE.");
1004 Console.WriteLine ("--------");
1008 protected void SetupDefaults()
1010 SetupDefaultDefines();
1011 SetupDefaultImports();
1012 Report.Stacktrace = false;
1013 RootContext.Checked = true;
1017 /// Parses the arguments, and calls the compilation process.
1019 int MainDriver(string [] args)
1024 if (firstSourceFile == null) {
1032 return Report.ProcessResults(quiet);
1035 public static int Main (string[] args)
1037 Driver Exec = new Driver();
1039 return Exec.MainDriver(args);