private static int HandleCompilerFlags(string[] args, int i) { var compilerType = args[i + 1]; NativeCompilationUtils.SetCompilerOptions(compilerType); return(i + 1); }
static void Main(string[] args) { var commandLineParse = CommandLineParse.Instance; commandLineParse.Process(args); OptimizationLevelBase.Instance = new OptimizationLevels(); NativeCompilationUtils.SetCompilerOptions("gcc"); CommandLineParse.OptimizerLevel = 2; CallCompiler("", ""); }
static int HandleCompilerFlags(string[] args, int i) { if (i + 1 >= args.Length) // the compiler type was not given as the extra argument. { throw new ArgumentException("Using a compiler was specified (-compiler), but the name " + "of the compiler was not given: [-compiler gcc|clang]"); } var compilerType = args[i + 1]; NativeCompilationUtils.SetCompilerOptions(compilerType); return(i + 1); }
private void CompileCpp() { CppOutput = String.Empty; var outputcpp = "OpenRuntime/" + LastCompiledExecutable.Replace(".exe", ".cpp"); var fileInfo = new FileInfo(outputcpp); outputcpp = fileInfo.FullName; var outputexe = outputcpp.Replace(".cpp", "_CPP.exe"); try { var sb = new StringBuilder(ViewModel.OutputCode); sb.ToFile(outputcpp); NativeCompilationUtils.SetCompilerOptions("gcc"); NativeCompilationUtils.CompileAppToNativeExe(outputcpp, outputexe); // Start the child process. Process p = new Process(); // Redirect the output stream of the child process. p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.StartInfo.FileName = outputexe; p.StartInfo.WorkingDirectory = Path.GetDirectoryName(outputexe); p.Start(); p.WaitForExit(); var start = Environment.TickCount; // Do not wait for the child process to exit before // reading to the end of its redirected stream. // p.WaitForExit(); // Read the output stream first and then wait. string output = outputexe.ExecuteCommand(""); var end = Environment.TickCount - start; CppOutput = output; Dispatcher.Invoke(() => { ViewModel.CompilerErrors += String.Format("CPP time: {0} ms\n", end) + output + p.StandardError.ReadToEnd(); }); } catch (Exception ex) { Dispatcher.Invoke(() => { ViewModel.CompilerErrors += ex.Message + "\nStackTrace: \n" + ex.StackTrace; }); } finally { File.Delete(outputcpp); File.Delete(outputexe); } }
private void cbxCompiler_SelectedIndexChanged(object sender, EventArgs e) { NativeCompilationUtils.SetCompilerOptions(cbxCompiler.Text); UpdateView(); }
private void CompileD() { // CppOutput = String.Empty; // var outputcpp = "OpenRuntime/" + LastCompiledExecutable.Replace(".exe", ".d"); // var fileInfo = new FileInfo(outputcpp); // outputcpp = fileInfo.FullName; var outputexe = MainWindowViewModel.TempDir + "/" + LastCompiledExecutable.Replace(".exe", ".d").Replace(".d", "_d.exe"); try { var start = DateTime.Now; // var sb = new StringBuilder(ViewModel.OutputCode); var bclDir = Directory.GetParent( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location + "..\\..\\..\\..\\..\\")) + "\\SharpNative\\DCorlib"; //sb.ToFile(outputcpp); // @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat".ExecuteCommand("",@"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\"); var bclFiles = Directory.GetFiles(bclDir, "*.d", SearchOption.AllDirectories) .OrderBy(o => o) .ToList(); NativeCompilationUtils.SetCompilerOptions("dmdwin"); // NativeCompilationUtils.CompilerOptions.OptimizationFlags += " -I " + MainWindowViewModel.TempDir + " -I " + bclDir; NativeCompilationUtils.CompileAppToNativeExe(((List <FileItem>)CppFileList.ItemsSource).Where(j => j.Name.EndsWith(".d")).Select(k => k.Location).Union(bclFiles).ToArray(), outputexe); ViewModel.CompilerErrors += ("\nCompiling to binary took " + (DateTime.Now - start).TotalMilliseconds + " ms\n"); start = DateTime.Now; // Do not wait for the child process to exit before // reading to the end of its redirected stream. // p.WaitForExit(); // Read the output stream first and then wait. string output = outputexe.ExecuteCommand(""); var end = DateTime.Now - start; CppOutput = output; Dispatcher.Invoke(() => { ViewModel.CompilerErrors += String.Format("D time: {0} ms\n", end.TotalMilliseconds) + output; }); } catch (Exception ex) { Dispatcher.Invoke(() => { ViewModel.CompilerErrors += ex.Message + "\nStackTrace: \n" + ex.StackTrace; }); } finally { // File.Delete(outputcpp); try { if (File.Exists(outputexe)) { File.Delete(outputexe); } } catch (Exception) { } } }
private void CompileD() { if (!Directory.Exists(BCLDir)) { InvokeOnMainThread(() => { ViewModel.CompilerErrors += String.Format("Please set correct BCL directory, current value \"{0}\" doesn't exist", BCLDir); }); Console.WriteLine("Please set correct BCL directory, current value {0} doesnt exist", BCLDir); return; } ; //sb.ToFile(outputcpp); // @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat".ExecuteCommand("",@"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\"); var outputexe = MainWindowViewModel.TempDir + "/" + LastCompiledExecutable.Replace(".exe", ".d").Replace(".d", "_d.exe"); try { var start = DateTime.Now; // var sb = new StringBuilder(ViewModel.OutputCode); //var bclDir = BCLDir; //Directory.GetParent( // Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location + "..\\..\\..\\..\\CsNative")) + //"\\CsNative\\Runtime"; //sb.ToFile(outputcpp); // @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat".ExecuteCommand("",@"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\"); var bclFiles = Directory.GetFiles(BCLDir, "*.d", SearchOption.AllDirectories) .OrderBy(o => o) .ToList(); NativeCompilationUtils.SetCompilerOptions("dmdmac"); NativeCompilationUtils.CompilerOptions.OptimizationFlags += " -I" + MainWindowViewModel.TempDir + " -I" + BCLDir; var fileList = ViewModel.FileList; var executableFiles = fileList.Where(j => j.Name.EndsWith(".d", StringComparison.Ordinal)).Select(k => k.Location); NativeCompilationUtils.CompileAppToNativeExe(executableFiles.Union(bclFiles).ToArray(), outputexe); ViewModel.CompilerErrors += ("\nCompiling to binary took " + (DateTime.Now - start).TotalMilliseconds + " ms\n"); start = DateTime.Now; // Do not wait for the child process to exit before // reading to the end of its redirected stream. // p.WaitForExit(); // Read the output stream first and then wait. string output = outputexe.ExecuteCommand(""); var end = DateTime.Now - start; CppOutput = output; InvokeOnMainThread(() => { ViewModel.CompilerErrors += String.Format("D time: {0} ms\n", end.TotalMilliseconds) + output; Console.WriteLine(String.Format("D time: {0} ms\n", end.TotalMilliseconds) + output); }); } catch (Exception ex) { InvokeOnMainThread(() => { ViewModel.CompilerErrors += ex.Message + "\nStackTrace: \n" + ex.StackTrace; Console.WriteLine(ex.Message + "\nStackTrace: \n" + ex.StackTrace); }); } finally { if (File.Exists(outputexe)) { File.Delete(outputexe); } } }