System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
DriverMain driver = new DriverMain (args);
- if (!driver.Run ()) {
- Console.WriteLine ();
- Console.WriteLine ("***** FAILURE *****");
- return 1;
- }
- Console.WriteLine ("Operation completed successfully");
+ if (!driver.Run ())
+ return 1;
+ Report.Message ("Operation completed successfully");
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;
private CodeGen codegen;
private bool keycontainer = false;
private string keyname;
+ private StrongName sn;
public DriverMain (string[] args)
{
il_file_list = new ArrayList ();
ParseArgs (args);
- report = new Report (quiet);
}
public bool Run ()
{
- if (il_file_list.Count == 0)
- Usage ();
- if (output_file == null)
- output_file = CreateOutputFile ();
- codegen = new CodeGen (output_file, target == Target.Dll, true, debugging_info, report);
- foreach (string file_path in il_file_list)
+ if (il_file_list.Count == 0)
+ Usage ();
+ if (output_file == null)
+ output_file = CreateOutputFilename ();
+ try {
+ codegen = new CodeGen (output_file, target == Target.Dll, debugging_info);
+ foreach (string file_path in il_file_list) {
+ Report.FilePath = file_path;
ProcessFile (file_path);
+ }
if (scan_only)
return true;
- if (report.ErrorCount > 0)
+ if (Report.ErrorCount > 0)
return false;
- codegen.Write ();
+
+ if (target != Target.Dll && !codegen.HasEntryPoint)
+ Report.Error ("No entry point found.");
+
+ // if we have a key and aren't assembling a netmodule
+ if ((keyname != null) && !codegen.IsThisAssembly (null)) {
+ LoadKey ();
+ // this overrides any attribute or .publickey directive in the source
+ codegen.ThisAssembly.SetPublicKey (sn.PublicKey);
+ }
+
+ try {
+ codegen.Write ();
+ } catch {
+ File.Delete (output_file);
+ throw;
+ }
+ } catch (ILAsmException e) {
+ Error (e.ToString ());
+ return false;
+ } catch (PEAPI.PEFileException pe) {
+ Error ("Error : " + pe.Message);
+ return false;
+ }
try {
- if (keyname != null) {
- Console.WriteLine ("Signing assembly with the specified strongname keypair");
+ if (sn != null) {
+ Report.Message ("Signing assembly with the specified strongname keypair");
return Sign (output_file);
}
} catch {
return true;
}
- private bool Sign (string filename)
+ private void Error (string message)
+ {
+ Console.WriteLine (message + "\n");
+ Console.WriteLine ("***** FAILURE *****\n");
+ }
+
+ private void LoadKey ()
{
- // note: if the file cannot be signed (no public key in it) then
- // we do not show an error, or a warning, if the key file doesn't
- // exists
- StrongName sn = null;
if (keycontainer) {
CspParameters csp = new CspParameters ();
csp.KeyContainerName = keyname;
}
sn = new StrongName (data);
}
+ }
+
+ private bool Sign (string filename)
+ {
+ // note: if the file cannot be signed (no public key in it) then
+ // we do not show an error, or a warning, if the key file doesn't
+ // exists
return sn.Sign (filename);
}
file_path);
Environment.Exit (2);
}
- report.AssembleFile (file_path, null,
+ Report.AssembleFile (file_path, null,
target_string, output_file);
StreamReader reader = File.OpenText (file_path);
ILTokenizer scanner = new ILTokenizer (reader);
else
parser.yyparse (new ScannerAdapter (scanner), null);
} catch (ILTokenizingException ilte) {
- report.Error (file_path + "(" + ilte.Location.line + ") : error : " +
- "syntax error at token '" + ilte.Token + "'.");
- } catch {
- Console.WriteLine ("Error at: " + scanner.Reader.Location);
+ Report.Error (ilte.Location, "syntax error at token '" + ilte.Token + "'");
+ } catch (Mono.ILASM.yyParser.yyException ye) {
+ Report.Error (scanner.Reader.Location, ye.Message);
+ } catch (ILAsmException ie) {
+ ie.FilePath = file_path;
+ ie.Location = scanner.Reader.Location;
+ throw;
+ } catch (Exception e){
+ Console.Write ("{0} ({1}, {2}): ",file_path, scanner.Reader.Location.line, scanner.Reader.Location.column);
throw;
} finally {
codegen.EndSourceFile ();
target_string = "dll";
break;
case "quiet":
- quiet = true;
+ Report.Quiet = true;
break;
case "debug":
case "deb":
- if (str[0] != '-')
- break;
debugging_info = true;
break;
// Stubs to stay commandline compatible with MS
/// <summary>
/// Get the first file name and makes it into an output file name
/// </summary>
- private string CreateOutputFile ()
+ private string CreateOutputFilename ()
{
string file_name = (string)il_file_list[0];
int ext_index = file_name.LastIndexOf ('.');
private void Version ()
{
- string version = Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
+ string version = System.Reflection.Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
Console.WriteLine ("Mono ILasm compiler version {0}", version);
Environment.Exit (0);
}