/// <summary> /// csi.exe and vbi.exe entry point. /// </summary> private static int RunInteractiveCore(CommonCompiler compiler, TextWriter consoleOutput, ErrorLogger errorLogger) { Debug.Assert(compiler.Arguments.IsInteractive); var hasScriptFiles = compiler.Arguments.SourceFiles.Any(file => file.IsScript); if (compiler.Arguments.DisplayLogo && !hasScriptFiles) { compiler.PrintLogo(consoleOutput); } if (compiler.Arguments.DisplayHelp) { compiler.PrintHelp(consoleOutput); return(0); } // TODO (tomat): // When we have command line REPL enabled we'll launch it if there are no input files. IEnumerable <Diagnostic> errors = compiler.Arguments.Errors; if (!hasScriptFiles) { errors = errors.Concat(new[] { Diagnostic.Create(compiler.MessageProvider, compiler.MessageProvider.ERR_NoScriptsSpecified) }); } if (compiler.ReportErrors(errors, consoleOutput, errorLogger)) { return(CommonCompiler.Failed); } // arguments are always available when executing script code: Debug.Assert(compiler.Arguments.ScriptArguments != null); var compilation = compiler.CreateCompilation(consoleOutput, touchedFilesLogger: null, errorLogger: errorLogger); if (compilation == null) { return(CommonCompiler.Failed); } byte[] compiledAssembly; using (MemoryStream output = new MemoryStream()) { EmitResult emitResult = compilation.Emit(output); if (compiler.ReportErrors(emitResult.Diagnostics, consoleOutput, errorLogger)) { return(CommonCompiler.Failed); } compiledAssembly = output.ToArray(); } var assembly = CorLightup.Desktop.LoadAssembly(compiledAssembly); return(Execute(assembly, compilation.GetEntryPoint(default(CancellationToken)), compiler.Arguments.ScriptArguments.ToArray())); }
/// <summary> /// csi.exe and vbi.exe entry point. /// </summary> private static int RunInteractiveCore(CommonCompiler compiler, TextWriter consoleOutput, ErrorLogger errorLogger) { Debug.Assert(compiler.Arguments.IsInteractive); var hasScriptFiles = compiler.Arguments.SourceFiles.Any(file => file.IsScript); if (compiler.Arguments.DisplayLogo && !hasScriptFiles) { compiler.PrintLogo(consoleOutput); } if (compiler.Arguments.DisplayHelp) { compiler.PrintHelp(consoleOutput); return 0; } // TODO (tomat): // When we have command line REPL enabled we'll launch it if there are no input files. IEnumerable<Diagnostic> errors = compiler.Arguments.Errors; if (!hasScriptFiles) { errors = errors.Concat(new[] { Diagnostic.Create(compiler.MessageProvider, compiler.MessageProvider.ERR_NoScriptsSpecified) }); } if (compiler.ReportErrors(errors, consoleOutput, errorLogger)) { return CommonCompiler.Failed; } // arguments are always available when executing script code: Debug.Assert(compiler.Arguments.ScriptArguments != null); var compilation = compiler.CreateCompilation(consoleOutput, touchedFilesLogger: null, errorLogger: errorLogger); if (compilation == null) { return CommonCompiler.Failed; } byte[] compiledAssembly; using (MemoryStream output = new MemoryStream()) { EmitResult emitResult = compilation.Emit(output); if (compiler.ReportErrors(emitResult.Diagnostics, consoleOutput, errorLogger)) { return CommonCompiler.Failed; } compiledAssembly = output.ToArray(); } var assembly = Assembly.Load(compiledAssembly); return Execute(assembly, compiler.Arguments.ScriptArguments.ToArray()); }
private void VerifyRoundTrip(CommonCompiler commonCompiler, string peFilePath, string?pdbFilePath = null, CancellationToken cancellationToken = default) { Assert.True(commonCompiler.Arguments.CompilationOptions.Deterministic); var(result, output) = commonCompiler.Run(cancellationToken); TestOutputHelper.WriteLine(output); Assert.Equal(0, result); var peStream = FilePathToStreamMap[peFilePath].GetStream(); var pdbStream = pdbFilePath is object?FilePathToStreamMap[pdbFilePath].GetStream() : null; using var writer = new StringWriter(); var compilation = commonCompiler.CreateCompilation( writer, touchedFilesLogger: null, errorLoggerOpt: null, analyzerConfigOptions: default,