GetEngineOptions() public méthode

public GetEngineOptions ( ) : EngineOptions
Résultat SharpOS.AOT.IR.EngineOptions
Exemple #1
0
		static int Main (string [] args)
		{
			Options opts = new Options (args);
			Engine engine = null;

			opts.ShowBanner ();

			if (opts.RemainingArguments.Length == 0) {
				Console.WriteLine ("Error: too few arguments");

				return 1;
			} else {
				bool stop = false;
				List<string> assemFiles = new List<string> ();

				foreach (string argStr in opts.RemainingArguments) {
					if (!File.Exists (argStr)) {
						Console.Error.WriteLine ("{0}: File not found",
									 argStr);
						stop = true;
					}

					assemFiles.Add (argStr);
				}

				if (stop)
					return 1;

				opts.Assemblies = assemFiles.ToArray ();
			}

			if (opts.OutputFilename == null) {
				string suffix = "bin";

				if (opts.Assemblies [0].EndsWith (".dll"))
					opts.OutputFilename = opts.Assemblies [0].Substring (0,
						opts.Assemblies [0].LastIndexOf ('.'))
						+ "." + suffix;
				else
					opts.OutputFilename = opts.Assemblies [0] + ".bin";
			}

			opts.BinaryFilename = opts.OutputFilename;

			bool debuggerAttached = false;

			// Prevent a Mono error if one occurs.
			try {
				debuggerAttached = System.Diagnostics.Debugger.IsAttached;
			} catch {
			}

			if (debuggerAttached) {
				engine = new Engine (opts.GetEngineOptions ());
				engine.Run ();
			} else
				try {
					engine = new Engine (opts.GetEngineOptions ());
					engine.Run ();
				} catch (Exception e) {
					AssemblyDefinition assembly;
					ModuleDefinition module;
					TypeReference type;
					MethodReference method;

					// Error handling

					engine.GetStatusInformation (out assembly, out module, out type, out method);

					if (e is EngineException) {
						Console.Error.WriteLine ("Error: {0}", e.ToString ());
					} else {
						Console.Error.WriteLine ("Caught exception: " + e);
					}

					switch (engine.CurrentStatus) {
					case Engine.Status.AssemblyLoading:
						Console.Error.WriteLine ("While loading assembly `{0}'", engine.ProcessingAssemblyFile);
						break;

					case Engine.Status.IRProcessing:
						Console.Error.WriteLine ();
						Console.Error.WriteLine ("While performing IR processing");
						break;

					case Engine.Status.IRGeneration:
						Console.Error.WriteLine ("While generating IR code for assembly `{0}'",
									engine.ProcessingAssemblyFile);
						break;

					case Engine.Status.Encoding:
						Console.Error.WriteLine ("While encoding the output assembly.");
						break;
					}

					if (method != null) {
						Console.Error.WriteLine ("Method:  {0}", (method == null ? "?" : method.ToString ()));
						Console.Error.WriteLine ("  in module:  {0}", (module == null ? "?" : module.ToString ()));
						Console.Error.WriteLine ("  of assembly:  {0}", (assembly == null ? "?" :
							assembly.ToString ()));
						Console.Error.WriteLine ("  loaded from:  {0}", (engine.ProcessingAssemblyFile == null ?
							"?" : engine.ProcessingAssemblyFile));
						Console.Error.WriteLine ();
					} else {
						Console.Error.WriteLine ("* Status information is not available.");
					}

					return 1;
				}

			return 0;
		}
Exemple #2
0
        static int Main(string [] args)
        {
            Options opts   = new Options(args);
            Engine  engine = null;

            opts.ShowBanner();

            if (opts.RemainingArguments.Length == 0)
            {
                Console.WriteLine("Error: too few arguments");

                return(1);
            }
            else
            {
                bool          stop       = false;
                List <string> assemFiles = new List <string> ();

                foreach (string argStr in opts.RemainingArguments)
                {
                    if (!File.Exists(argStr))
                    {
                        Console.Error.WriteLine("{0}: File not found",
                                                argStr);
                        stop = true;
                    }

                    assemFiles.Add(argStr);
                }

                if (stop)
                {
                    return(1);
                }

                opts.Assemblies = assemFiles.ToArray();
            }

            if (opts.OutputFilename == null)
            {
                string suffix = "bin";

                if (opts.Assemblies [0].EndsWith(".dll"))
                {
                    opts.OutputFilename = opts.Assemblies [0].Substring(0,
                                                                        opts.Assemblies [0].LastIndexOf('.'))
                                          + "." + suffix;
                }
                else
                {
                    opts.OutputFilename = opts.Assemblies [0] + ".bin";
                }
            }

            opts.BinaryFilename = opts.OutputFilename;

            bool debuggerAttached = false;

            // Prevent a Mono error if one occurs.
            try {
                debuggerAttached = System.Diagnostics.Debugger.IsAttached;
            } catch {
            }

            if (debuggerAttached)
            {
                engine = new Engine(opts.GetEngineOptions());
                engine.Run();
            }
            else
            {
                try {
                    engine = new Engine(opts.GetEngineOptions());
                    engine.Run();
                } catch (Exception e) {
                    AssemblyDefinition assembly;
                    ModuleDefinition   module;
                    TypeReference      type;
                    MethodReference    method;

                    // Error handling

                    engine.GetStatusInformation(out assembly, out module, out type, out method);

                    if (e is EngineException)
                    {
                        Console.Error.WriteLine("Error: {0}", e.ToString());
                    }
                    else
                    {
                        Console.Error.WriteLine("Caught exception: " + e);
                    }

                    switch (engine.CurrentStatus)
                    {
                    case Engine.Status.AssemblyLoading:
                        Console.Error.WriteLine("While loading assembly `{0}'", engine.ProcessingAssemblyFile);
                        break;

                    case Engine.Status.IRProcessing:
                        Console.Error.WriteLine();
                        Console.Error.WriteLine("While performing IR processing");
                        break;

                    case Engine.Status.IRGeneration:
                        Console.Error.WriteLine("While generating IR code for assembly `{0}'",
                                                engine.ProcessingAssemblyFile);
                        break;

                    case Engine.Status.Encoding:
                        Console.Error.WriteLine("While encoding the output assembly.");
                        break;
                    }

                    if (method != null)
                    {
                        Console.Error.WriteLine("Method:  {0}", (method == null ? "?" : method.ToString()));
                        Console.Error.WriteLine("  in module:  {0}", (module == null ? "?" : module.ToString()));
                        Console.Error.WriteLine("  of assembly:  {0}", (assembly == null ? "?" :
                                                                        assembly.ToString()));
                        Console.Error.WriteLine("  loaded from:  {0}", (engine.ProcessingAssemblyFile == null ?
                                                                        "?" : engine.ProcessingAssemblyFile));
                        Console.Error.WriteLine();
                    }
                    else
                    {
                        Console.Error.WriteLine("* Status information is not available.");
                    }

                    return(1);
                }
            }

            return(0);
        }