예제 #1
0
        public static void CallCompiler(string inputAssemblyName, string outputExeName)
        {
            var commandLineParse = CommandLineParse.Instance;

            if (!String.IsNullOrEmpty(inputAssemblyName))
            {
                commandLineParse.ApplicationInputAssembly = inputAssemblyName;
            }
            if (!String.IsNullOrEmpty(outputExeName))
            {
                commandLineParse.ApplicationNativeExe = outputExeName;
                commandLineParse.OutputCpp            = Path.ChangeExtension(commandLineParse.ApplicationNativeExe, ".cpp");
            }
            var dir = Directory.GetCurrentDirectory();

            inputAssemblyName = Path.Combine(dir, commandLineParse.ApplicationInputAssembly);
            var asm        = Assembly.LoadFile(inputAssemblyName);
            var definition = asm.EntryPoint;
            var start      = Environment.TickCount;

            var closureEntities = ClosureEntitiesUtils.BuildClosureEntities(definition, typeof(CrString).Assembly);

            var sb  = closureEntities.BuildFullSourceCode();
            var end = Environment.TickCount - start;

            Console.WriteLine("Compilation time: {0} ms", end);
            var fullPath = commandLineParse.OutputCpp.GetFullFileName();

            sb.ToFile(fullPath);
            NativeCompilationUtils.CompileAppToNativeExe(commandLineParse.OutputCpp,
                                                         commandLineParse.ApplicationNativeExe);
        }
예제 #2
0
        private static int HandleCompilerFlags(string[] args, int i)
        {
            var compilerType = args[i + 1];

            NativeCompilationUtils.SetCompilerOptions(compilerType);
            return(i + 1);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var commandLineParse = CommandLineParse.Instance;

            commandLineParse.Process(args);


            OptimizationLevelBase.Instance = new OptimizationLevels();
            NativeCompilationUtils.SetCompilerOptions("gcc");
            CommandLineParse.OptimizerLevel = 2;
            CallCompiler("", "");
        }
예제 #4
0
        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);
        }
        protected bool EvaluateCSharpToNative(string code, List <OptimizationPass> optimizationPasses = null)
        {
            string       expectedInput;
            var          outputCpp            = GenerateOutputCppFromCode(code, optimizationPasses, out expectedInput);
            const string applicationNativeExe = "a_test.exe";

            NativeCompilationUtils.CompileAppToNativeExe(outputCpp, applicationNativeExe);
            code.DeleteFile();

            var startCpp     = Environment.TickCount;
            var actualOutput = applicationNativeExe.ExecuteCommand(string.Empty, Directory.GetCurrentDirectory());
            var endCpp       = Environment.TickCount - startCpp;

            Console.WriteLine("Time1: {0}", endCpp);
            applicationNativeExe.DeleteFile();
            return(actualOutput == expectedInput);
        }
예제 #6
0
        public static void CallCompiler(string inputAssemblyName, string outputExeName)
        {
            var commandLineParse = CommandLineParse.Instance;

            if (!String.IsNullOrEmpty(inputAssemblyName))
            {
                commandLineParse.ApplicationInputAssembly = inputAssemblyName;
            }
            if (!String.IsNullOrEmpty(outputExeName))
            {
                commandLineParse.ApplicationNativeExe = outputExeName;
                commandLineParse.OutputCpp            = Path.ChangeExtension(commandLineParse.ApplicationNativeExe, ".cpp");
            }
            var dir = Directory.GetCurrentDirectory();

            inputAssemblyName = Path.Combine(dir, commandLineParse.ApplicationInputAssembly);
            var asm        = Assembly.LoadFile(inputAssemblyName);
            var definition = asm.EntryPoint;
            var start      = Environment.TickCount;

            var optimizationsTable = new ProgramOptimizationsTable();

            optimizationsTable.Add(new DevirtualizerIfOneImplemetor());
            optimizationsTable.Add(new CallToFunctionsWithSameConstant());

            var crRuntime = new CrRuntimeLibrary();

            crRuntime.ScanAssembly(typeof(CrString).Assembly);

            var programClosure = new ProgramClosure(definition, crRuntime);

            var sb  = programClosure.BuildFullSourceCode(programClosure.Runtime);
            var end = Environment.TickCount - start;

            Console.WriteLine("Compilation time: {0} ms", end);

            sb.ToFile(commandLineParse.OutputCpp);
            NativeCompilationUtils.CompileAppToNativeExe(commandLineParse.OutputCpp,
                                                         commandLineParse.ApplicationNativeExe);
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
 private void cbxCompiler_SelectedIndexChanged(object sender, EventArgs e)
 {
     NativeCompilationUtils.SetCompilerOptions(cbxCompiler.Text);
     UpdateView();
 }
예제 #9
0
        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)
                {
                }
            }
        }
예제 #10
0
        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);
                }
            }
        }