3 // Main Command line interface for Mono ILasm Compiler
6 // Jackson Harper (Jackson@LatitudeGeo.com)
8 // (C) 2003 Jackson Harper, All rights reserved
13 using System.Collections;
15 namespace Mono.ILASM {
24 public static int Main (string[] args)
26 DriverMain driver = new DriverMain (args);
31 private class DriverMain {
33 private ArrayList il_file_list;
34 private string output_file;
35 private Target target = Target.Exe;
36 private bool scan_only = false;
37 private CodeGen codegen;
39 public DriverMain (string[] args)
41 il_file_list = new ArrayList ();
47 if (il_file_list.Count == 0) {
51 if (output_file == null)
52 output_file = CreateOutputFile ();
53 codegen = new CodeGen (output_file);
54 foreach (string file_path in il_file_list)
55 ProcessFile (file_path);
61 private void ProcessFile (string file_path)
63 StreamReader reader = File.OpenText (file_path);
64 ILTokenizer scanner = new ILTokenizer (reader);
68 while ((tok = scanner.NextToken) != ILToken.EOF) {
69 Console.WriteLine (tok);
74 ILParser parser = new ILParser (codegen);
75 parser.yyparse (new ScannerAdapter (scanner), null);
78 private void ParseArgs (string[] args)
81 foreach (string str in args) {
82 if ((str[0] != '-') && (str[0] != '/')) {
83 il_file_list.Add (str);
86 switch (GetCommand (str, out command_arg)) {
88 output_file = command_arg;
106 private string GetCommand (string str, out string command_arg)
108 int end_index = str.IndexOfAny (new char[] {':', '='}, 1);
109 string command = str.Substring (1,
110 end_index == -1 ? str.Length - 1 : end_index - 1);
112 if (end_index != -1) {
113 command_arg = str.Substring (end_index+1);
118 return command.ToLower ();
122 /// Get the first file name and make it into an output file name
124 private string CreateOutputFile ()
126 string file_name = (string)il_file_list[0];
127 int ext_index = file_name.LastIndexOf ('.');
130 ext_index = file_name.Length;
132 return String.Format ("{0}.{1}", file_name.Substring (0, ext_index),
133 target.ToString ().ToLower ());
136 private void Usage ()
138 Console.WriteLine ("Mono ILasm compiler\n" +
139 "ilasm [options] source-files\n" +
140 " --about About the Mono ILasm compiler\n" +
141 " /out:file_name Specifies output file.\n" +
142 " /exe Compile to executable.\n" +
143 " /dll Compile to library.\n" +
144 "Options can be of the form -option or /option\n");
147 private void About ()
150 "For more information on Mono, visit the project Web site\n" +
151 " http://www.go-mono.com\n\n");
152 Environment.Exit (0);