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 Console.WriteLine ("Setting output: {0}", command_arg);
89 output_file = command_arg;
107 private string GetCommand (string str, out string command_arg)
109 int end_index = str.IndexOfAny (new char[] {':', '='}, 1);
110 string command = str.Substring (1,
111 end_index == -1 ? str.Length - 1 : end_index - 1);
113 if (end_index != -1) {
114 command_arg = str.Substring (end_index+1);
119 return command.ToLower ();
123 /// Get the first file name and make it into an output file name
125 private string CreateOutputFile ()
127 string file_name = (string)il_file_list[0];
128 int ext_index = file_name.LastIndexOf ('.');
131 ext_index = file_name.Length;
133 return String.Format ("{0}.{1}", file_name.Substring (0, ext_index),
134 target.ToString ().ToLower ());
137 private void Usage ()
139 Console.WriteLine ("Mono ILasm compiler\n" +
140 "ilasm [options] source-files\n" +
141 " --about About the Mono ILasm compiler\n" +
142 " /out:file_name Specifies output file.\n" +
143 " /exe Compile to executable.\n" +
144 " /dll Compile to library.\n" +
145 "Options can be of the form -option or /option\n");
148 private void About ()
151 "For more information on Mono, visit the project Web site\n" +
152 " http://www.go-mono.com\n\n");
153 Environment.Exit (0);