2004-02-06 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / ilasm / Driver.cs
index 5896d9987faff11f681eb961fb54882901493b03..6121796e2ff143b310cb91f6b08d0990c1d9d1f4 100644 (file)
@@ -32,15 +32,18 @@ namespace Mono.ILASM {
                                 Console.WriteLine ("Error while compiling.");
                                 return 1;
                         }
-                        Console.Write ("Compilation succeeded");
+                        Console.WriteLine ("Compilation succeeded");
                         return 0;
                 }
 
                 private class DriverMain {
 
                         private ArrayList il_file_list;
+                        private Report report;
                         private string output_file;
                         private Target target = Target.Exe;
+                        private string target_string = "exe";
+                        private bool quiet = false;
                         private bool show_tokens = false;
                         private bool show_method_def = false;
                         private bool show_method_ref = false;
@@ -52,23 +55,26 @@ namespace Mono.ILASM {
                         {
                                 il_file_list = new ArrayList ();
                                 ParseArgs (args);
+                                report = new Report (quiet);
                         }
 
                         public void Run ()
                         {
-                                if (il_file_list.Count == 0) {
-                                        Usage ();
-                                        return;
-                                }
-                                if (output_file == null)
-                                        output_file = CreateOutputFile ();
-                                codegen = new CodeGen (output_file, target == Target.Dll, true);
-                                foreach (string file_path in il_file_list)
-                                        ProcessFile (file_path);
-                                if (scan_only)
-                                        return;
+                                try {
+                                        if (il_file_list.Count == 0)
+                                                Usage ();
+                                        if (output_file == null)
+                                                output_file = CreateOutputFile ();
+                                        codegen = new CodeGen (output_file, target == Target.Dll, true, report);
+                                        foreach (string file_path in il_file_list)
+                                                ProcessFile (file_path);
+                                        if (scan_only)
+                                                return;
 
-                                codegen.Write ();
+                                        codegen.Write ();
+                                } catch {
+                                        throw;
+                                }
                         }
 
                         private void ProcessFile (string file_path)
@@ -78,6 +84,8 @@ namespace Mono.ILASM {
                                                 file_path);
                                         Environment.Exit (2);
                                 }
+                                report.AssembleFile (file_path, null,
+                                                target_string, output_file);
                                 StreamReader reader = File.OpenText (file_path);
                                 ILTokenizer scanner = new ILTokenizer (reader);
 
@@ -96,11 +104,17 @@ namespace Mono.ILASM {
                                         return;
                                 }
 
-                                ILParser parser = new ILParser (codegen);
-                                if (show_parser)
-                                        parser.yyparse (new ScannerAdapter (scanner),  new yydebug.yyDebugSimple ());
-                                else
-                                        parser.yyparse (new ScannerAdapter (scanner),  null);
+                                ILParser parser = new ILParser (codegen, reader);
+                                try {
+                                        if (show_parser)
+                                                parser.yyparse (new ScannerAdapter (scanner),
+                                                                new yydebug.yyDebugSimple ());
+                                        else
+                                                parser.yyparse (new ScannerAdapter (scanner),  null);
+                                } catch {
+                                        Console.WriteLine ("Error at: " + scanner.Reader.Location);
+                                        throw;
+                                }
                         }
 
                         public void ShowToken (object sender, NewTokenEventArgs args)
@@ -138,40 +152,63 @@ namespace Mono.ILASM {
                                                 continue;
                                         }
                                         switch (GetCommand (str, out command_arg)) {
-                                                case "out":
-                                                        output_file = command_arg;
-                                                        break;
-                                                case "exe":
-                                                        target = Target.Exe;
-                                                        break;
-                                                case "dll":
-                                                        target = Target.Dll;
+                                        case "out":
+                                                output_file = command_arg;
+                                                break;
+                                        case "exe":
+                                                target = Target.Exe;
+                                                target_string = "exe";
+                                                break;
+                                        case "dll":
+                                                target = Target.Dll;
+                                                target_string = "dll";
+                                                break;
+                                        case "quiet":
+                                                quiet = true;
+                                                break;
+                                        // Stubs to stay commandline compatible with MS 
+                                        case "listing":
+                                        case "nologo":
+                                        case "debug":
+                                        case "clock":
+                                        case "error":
+                                        case "subsystem":
+                                        case "flags":
+                                        case "alignment":
+                                        case "base":
+                                        case "key":
+                                        case "resource":
+                                                break;
+                                        case "scan_only":
+                                                scan_only = true;
+                                                break;
+                                        case "show_tokens":
+                                                show_tokens = true;
+                                                break;
+                                        case "show_method_def":
+                                                show_method_def = true;
+                                                break;
+                                        case "show_method_ref":
+                                                show_method_ref = true;
+                                                break;
+                                        case "show_parser":
+                                                show_parser = true;
+                                                break;
+                                        case "-about":
+                                                if (str[0] != '-')
                                                         break;
-                                                case "scan_only":
-                                                        scan_only = true;
+                                                About ();
+                                                break;
+                                        case "-version":
+                                                if (str[0] != '-')
                                                         break;
-                                                case "show_tokens":
-                                                        show_tokens = true;
-                                                        break;
-                                                case "show_method_def":
-                                                        show_method_def = true;
-                                                        break;
-                                                case "show_method_ref":
-                                                        show_method_ref = true;
-                                                        break;
-                                                case "show_parser":
-                                                        show_parser = true;
-                                                        break;
-                                                case "-about":
-                                                        if (str[0] != '-')
-                                                                break;
-                                                        About ();
-                                                        break;
-                                                case "-version":
-                                                        if (str[0] != '-')
-                                                                break;
-                                                        Version ();
+                                                Version ();
+                                                break;
+                                        default:
+                                                if (str [0] == '-')
                                                         break;
+                                                il_file_list.Add (str);
+                                                break;
                                         }
                                 }
                         }
@@ -203,7 +240,7 @@ namespace Mono.ILASM {
                                         ext_index = file_name.Length;
 
                                 return String.Format ("{0}.{1}", file_name.Substring (0, ext_index),
-                                        target.ToString ().ToLower ());
+                                        target_string);
                         }
 
                         private void Usage ()
@@ -216,6 +253,7 @@ namespace Mono.ILASM {
                                         "   /exe               Compile to executable.\n" +
                                         "   /dll               Compile to library.\n" +
                                         "Options can be of the form -option or /option\n");
+                                Environment.Exit (1);
                         }
 
                         private void About ()