public static int Main(string[] args) { // Parse command-line options. var parser = new GnuOptionSetParser( Options.All, Options.Input); var recLog = new RecordingLog(ioLog); parsedOptions = parser.Parse(args, recLog); if (recLog.Contains(Pixie.Severity.Error)) { // Stop the program if the command-line arguments // are half baked. The parser will report an error. return(1); } if (parsedOptions.GetValue <bool>(Options.Help)) { // Wrap the help message into a log entry and send it to the log. rawLog.Log( new LogEntry( Pixie.Severity.Info, new HelpMessage( "unit-tests is a command-line tool that runs Flame's unit tests.", "unit-tests [all|0|1|2|3|4|5|6...] [options...]", Options.All))); return(0); } var positionalArgs = parsedOptions .GetValue <IEnumerable <string> >(Options.Input) .ToArray(); if (positionalArgs.Length == 0) { // Workaround for MS bug: Assert(false) will not fire in debugger Debug.Listeners.Clear(); Debug.Listeners.Add(new DefaultTraceListener()); if (RunMenu(Menu) > 0) { // Let the outside world know that something went wrong (e.g. Travis CI) return(1); } else { return(0); } } else { int errorCount = 0; foreach (var arg in positionalArgs) { if (arg.Equals("all", StringComparison.InvariantCultureIgnoreCase)) { errorCount += RunAllTests(Menu); } else { int testIndex; if (int.TryParse(arg, NumberStyles.Integer, CultureInfo.InvariantCulture, out testIndex) && testIndex > 0 && testIndex <= Menu.Count) { errorCount += errorCount += Menu[testIndex - 1].Value(); } else { ioLog.Log( new LogEntry( Pixie.Severity.Error, "ill-formed positional argument", $"positional argument '{arg} does not name a test suite.'")); errorCount += 1; } } } return(errorCount == 0 ? 0 : 1); } }
public static int Main(string[] args) { // Acquire a log. var rawLog = TerminalLog.Acquire(); log = new TransformLog( rawLog, new Func <LogEntry, LogEntry>[] { MakeDiagnostic }); // Parse command-line options. var parser = new GnuOptionSetParser( Options.All, Options.Input); var recLog = new RecordingLog(log); var parsedOptions = parser.Parse(args, recLog); if (recLog.Contains(Severity.Error)) { // Stop the program if the command-line arguments // are half baked. return(1); } if (parsedOptions.GetValue <bool>(Options.Help)) { // Wrap the help message into a log entry and send it to the log. TerminalLog.AcquireStandardOutput().Log( new LogEntry( Severity.Info, new HelpMessage( "il2llvm is a command-line tool that compiles CIL assemblies to LLVM modules.", "il2llvm path [options...]", Options.All))); return(0); } var inputPath = parsedOptions.GetValue <string>(Options.Input); if (string.IsNullOrEmpty(inputPath)) { log.Log( new LogEntry( Severity.Error, "nothing to compile", "no input file")); return(1); } var outputPath = parsedOptions.GetValue <string>(Options.Output); if (string.IsNullOrEmpty(outputPath)) { outputPath = Path.GetFileNameWithoutExtension(inputPath) + ".ll"; } var printIr = parsedOptions.GetValue <bool>(Options.PrintIr); // Read the assembly from disk. Mono.Cecil.AssemblyDefinition cecilAsm; try { cecilAsm = Mono.Cecil.AssemblyDefinition.ReadAssembly( inputPath, new Mono.Cecil.ReaderParameters { ReadWrite = false }); } catch (Exception) { log.Log( new LogEntry( Severity.Error, "unreadable assembly", Quotation.QuoteEvenInBold( "cannot read assembly at ", inputPath, "."))); return(1); } if (cecilAsm.EntryPoint == null) { log.Log( new LogEntry( Severity.Error, "unsuitable assembly", "input assembly does not define an entry point.")); return(1); } try { // Wrap the CIL assembly in a Flame assembly. var flameAsm = ClrAssembly.Wrap(cecilAsm); // Compile the assembly to an LLVM module. var module = CompileAsync(flameAsm).Result; // Write the LLVM module to disk. string error; if (LLVM.PrintModuleToFile(module, outputPath, out error)) { log.Log(new LogEntry(Severity.Error, "cannot write module", error)); } LLVM.DisposeModule(module); } finally { // Be sure to dispose the assembly after we've used it. cecilAsm.Dispose(); } return(0); }
public static int Main(string[] args) { // Acquire a log. var rawLog = TerminalLog.Acquire(); log = new TransformLog( rawLog, new Func <LogEntry, LogEntry>[] { MakeDiagnostic }); // Parse command-line options. var parser = new GnuOptionSetParser( Options.All, Options.Input); var recLog = new RecordingLog(log); var parsedOptions = parser.Parse(args, recLog); if (recLog.Contains(Severity.Error)) { // Stop the program if the command-line arguments // are half baked. return(1); } if (parsedOptions.GetValue <bool>(Options.Help)) { // Wrap the help message into a log entry and send it to the log. TerminalLog.AcquireStandardOutput().Log( new LogEntry( Severity.Info, new HelpMessage( "ilopt is a command-line tool that optimizes CIL assemblies.", "ilopt path [options...]", Options.All))); return(0); } var inputPath = parsedOptions.GetValue <string>(Options.Input); if (string.IsNullOrEmpty(inputPath)) { log.Log( new LogEntry( Severity.Error, "nothing to optimize", "no input file")); return(1); } var outputPath = parsedOptions.GetValue <string>(Options.Output); if (string.IsNullOrEmpty(outputPath)) { outputPath = Path.GetFileNameWithoutExtension(inputPath) + ".opt" + Path.GetExtension(inputPath); } var printIr = parsedOptions.GetValue <bool>(Options.PrintIr); // Read the assembly from disk. Mono.Cecil.AssemblyDefinition cecilAsm; try { cecilAsm = Mono.Cecil.AssemblyDefinition.ReadAssembly( inputPath, new Mono.Cecil.ReaderParameters { ReadWrite = false }); } catch (Exception) { log.Log( new LogEntry( Severity.Error, "unreadable assembly", Quotation.QuoteEvenInBold( "cannot read assembly at ", inputPath, "."))); return(1); } try { // Make all non-public types, methods and fields in the assembly // internal if the user requests it. This will work to // our advantage. if (parsedOptions.GetValue <bool>(Options.Internalize)) { MakeInternal(cecilAsm); } // Wrap the CIL assembly in a Flame assembly. var flameAsm = ClrAssembly.Wrap(cecilAsm); // Optimize the assembly. OptimizeAssemblyAsync( flameAsm, printIr, parsedOptions.GetValue <bool>(Options.Parallel)).Wait(); // Write the optimized assembly to disk. cecilAsm.Write(outputPath); } finally { // Be sure to dispose the assembly after we've used it. cecilAsm.Dispose(); } return(0); }
public static int Main(string[] args) { // Acquire a log for printing output. var rawLog = new RecordingLog(TerminalLog.Acquire()); // Create a derived log for printing diagnostics. var log = CreateDiagnosticLog(rawLog); // Parse command-line arguments. var optParser = new GnuOptionSetParser(Options.All, Options.Url); // Actually parse the options. var parsedOptions = optParser.Parse(args, log); if (rawLog.Contains(Severity.Error)) { // Ouch. Command-line arguments were bad. Stop testing now. return(1); } if (parsedOptions.ContainsOption(Options.Color)) { if (parsedOptions.GetValue <bool>(Options.Color)) { rawLog = new RecordingLog( TerminalLog.AcquireStandardError( new AnsiStyleManager(Console.Error))); } else { rawLog = new RecordingLog( TerminalLog.AcquireStandardError( NoStyleManager.Instance)); } log = CreateDiagnosticLog(rawLog); } if (parsedOptions.GetValue <bool>(Options.Help)) { // Print a cute little help message (to stdout instead of stderr). var helpLog = TerminalLog.AcquireStandardOutput(); helpLog.Log( new Pixie.LogEntry( Severity.Message, new HelpMessage( "Runs UnSHACLed's functional tests.", "selenium-tests [url-or-options...]", Options.All))); return(0); } string testUrl = parsedOptions.GetValue <string>(Options.Url); bool noUrl = string.IsNullOrWhiteSpace(testUrl); if ((noUrl && !parsedOptions.ContainsOption(Options.BuildApplication)) || parsedOptions.GetValue <bool>(Options.BuildApplication)) { // Build the application if there's no URL and `--no-build-app` // was not specified or if `--build-app` was specified. log.Log( new Pixie.LogEntry( Severity.Info, "status", "building UnSHACLed...")); BuildUnSHACLed(); log.Log( new Pixie.LogEntry( Severity.Info, "status", "UnSHACLed built successfully!")); } Process serverProcess = null; if (noUrl) { // If nobody bothered to specify a URL, then we'll just have to // host it ourselves. serverProcess = HostUnSHACLed(8080, log); if (serverProcess == null) { return(1); } testUrl = "http://localhost:8080/index.html"; } var browserNames = parsedOptions.ContainsOption(Options.Browsers) ? parsedOptions.GetValue <IReadOnlyList <string> >(Options.Browsers) : new[] { "firefox" }; var browsersToUse = ParseBrowserNames(browserNames, log); if (rawLog.Contains(Severity.Error)) { // Couldn't parse the command-line args. Better quit now. return(1); } if (parsedOptions.GetValue <bool>(Options.PrintApplicationUrl)) { log.Log( new Pixie.LogEntry( Severity.Message, "application url", Quotation.QuoteEvenInBold( "the absolute app url is ", testUrl, "."))); } try { Run(testUrl, browsersToUse, log, rawLog); } finally { if (serverProcess != null) { serverProcess.Kill(); serverProcess.Dispose(); } } // If things went swimmingly, then return a zero exit code. // Otherwise, let the world know that something is wrong. return(rawLog.Contains(Severity.Error) ? 1 : 0); }
public static int Main(string[] args) { // Acquire a log. var rawLog = TerminalLog.Acquire(); var log = new TransformLog( rawLog, new Func <LogEntry, LogEntry>[] { MakeDiagnostic }); // Parse command-line options. var parser = new GnuOptionSetParser( Options.All, Options.Input); var recLog = new RecordingLog(log); var parsedOptions = parser.Parse(args, recLog); if (recLog.Contains(Severity.Error)) { // Stop the program if the command-line arguments // are half baked. return(1); } if (parsedOptions.GetValue <bool>(Options.Help)) { // Wrap the help message into a log entry and send it to the log. rawLog.Log( new LogEntry( Severity.Info, new HelpMessage( "fbfc is a compiler that turns Brainfuck code into CIL assemblies.", "fbfc path [options...]", Options.All))); return(0); } var inputPath = parsedOptions.GetValue <string>(Options.Input); if (string.IsNullOrEmpty(inputPath)) { log.Log( new LogEntry( Severity.Error, "nothing to compile", "no input file")); return(1); } var outputPath = parsedOptions.GetValue <string>(Options.Output); if (string.IsNullOrEmpty(outputPath)) { outputPath = Path.GetFileNameWithoutExtension(inputPath) + ".exe"; } // Read the Brainfuck source code from disk. SourceDocument source; try { source = new StringDocument(inputPath, File.ReadAllText(inputPath)); } catch (Exception) { log.Log( new LogEntry( Severity.Error, "invalid source path", Quotation.QuoteEvenInBold( "cannot read Brainfuck source code at ", inputPath, "."))); return(1); } var asmName = Path.GetFileNameWithoutExtension(outputPath); var cecilAsm = Mono.Cecil.AssemblyDefinition.CreateAssembly( new Mono.Cecil.AssemblyNameDefinition(asmName, new Version(1, 0, 0, 0)), asmName, Mono.Cecil.ModuleKind.Console); var flameAsm = ClrAssembly.Wrap(cecilAsm); var typeEnv = flameAsm.Resolver.TypeEnvironment; var compiler = new Compiler( flameAsm, Dependencies.Resolve( typeEnv, new ReadOnlyTypeResolver(typeEnv.Object.Parent.Assembly), log), log, parsedOptions); compiler.Compile(source); cecilAsm.Write(outputPath); return(0); }