Пример #1
0
        public static void RunOptimizer(ref Module module, Compiler.OptimizeLevel opLevel)
        {
            Block mainModule = (Block)module;

            if (ConstantTracking)
            {
                ConstantsOptimizer.Optimize(ref mainModule);
            }
            if (RemoveCrapMath)
            {
                RemoveUselessMath.Optimize(module);
            }
            if (VariableReduction)
            {
                VariableReducer.Optimize(ref module);
            }
            if (DeadCodeOptimization)
            {
                DeadCodeOptimizer.Optimize(ref module);
            }
            if (ReuseVariables)
            {
                VariableReuse.Optimize(ref module);
                if (DeadCodeOptimization)
                {
                    DeadCodeOptimizer.Optimize(ref module);
                }
            }
            if (DeadVariableRemoval)
            {
                DeadVariableOptimizer.Optimize(ref module);
            }
            if (UseCSE)
            {
                bool hasChanged;
                do
                {
                    hasChanged  = false;
                    hasChanged |= CSE.Optimize(ref module);
                    if (hasChanged)
                    {
                        if (ReuseVariables)
                        {
                            VariableReuse.Optimize(ref module);
                            if (DeadCodeOptimization)
                            {
                                DeadCodeOptimizer.Optimize(ref module);
                            }
                        }
                    }
                }while (hasChanged);
                if (DeadVariableRemoval)
                {
                    DeadVariableOptimizer.Optimize(ref module);
                }
            }
        }
Пример #2
0
 public static void RunOptimizer(ref Module module, Compiler.OptimizeLevel opLevel)
 {
     if (WabbitC.Optimizer.Optimizer.ConstantTracking)
     {
         Loop.ConstantsOptimizer.Optimize(ref module);
     }
     if (LoopInvarianceReduction)
     {
         Loop.LoopInvarianceReduction.Optimize(ref module);
     }
 }
Пример #3
0
        public static Compiler.OptimizeLevel ParseCommandLine(string[] args)
        {
            Compiler.OptimizeLevel opLevel = Compiler.OptimizeLevel.OptimizeNone;

            foreach (string arg in args)
            {
                opLevel = ParseCommandLine(arg);
                if (opLevel != Compiler.OptimizeLevel.OptimizeNone)
                {
                    break;
                }
            }

            return(opLevel);
        }
Пример #4
0
 static void Main(string[] args)
 {
     Compiler.OptimizeLevel opLevel = Optimizer.Optimizer.ParseCommandLine(args);
     foreach (string arg in args)
     {
         if (string.IsNullOrEmpty(arg))
         {
             continue;
         }
         else
         {
             if (string.IsNullOrEmpty(InputFile))
             {
                 InputFile = arg;
             }
             else
             {
                 OutputFile = arg;
             }
         }
     }
     IncludeDirs.LocalIncludes.Insert(0, Environment.CurrentDirectory);
     Compiler.DoCompileFile(InputFile, opLevel);
 }
Пример #5
0
        private void RunIntermediateTest(string name, string args = "")
        {
            var passCount = Compiler.PassCount.PassAlls;

            if (testContextInstance.DataRow != null)
            {
                if (Boolean.Parse(testContextInstance.DataRow["Enabled"].ToString()) == false)
                {
                    Assert.IsTrue(true);
                    Debug.WriteLine("Test was skipped because this mode is disabled.");
                    return;
                }

                args = testContextInstance.DataRow["Args"].ToString();
                int passNum = int.Parse(testContextInstance.DataRow["PassCount"].ToString());
                if (passNum == -1)
                {
                    passCount = Compiler.PassCount.PassAlls;
                }
                else
                {
                    passCount = (Compiler.PassCount)passNum;
                }
                Debug.WriteLine("Running config " + testContextInstance.DataRow["Name"] + ": " + args);
            }

            string CurDir   = Environment.CurrentDirectory;
            var    compiler = new Compiler();

            Compiler.OptimizeLevel opLevel = WabbitC.Optimizer.Optimizer.ParseCommandLine(args);
            Compiler.DoCompileFile(CurDir + @"\..\..\..\WabbitC Tests\C Files\" + name + "_expected.c", opLevel, passCount);

            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.WorkingDirectory = CurDir + @"\..\..\..\WabbitC Tests";
            p.StartInfo.FileName         = p.StartInfo.WorkingDirectory + @"\build-intermediates.bat";
            p.StartInfo.Arguments        = name + " " + passCount;
            p.StartInfo.UseShellExecute  = true;
            p.StartInfo.CreateNoWindow   = true;
            p.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;

            p.Start();
            p.WaitForExit();

            File.Copy(CurDir + @"\..\..\..\WabbitC Tests\C Files\" + name + "_actual.c", name + opLevel.ToString() + "Pass" + passCount + ".c");
            Assert.AreEqual(p.ExitCode, 0, "Failed to build");

            p.StartInfo.FileName  = Path.Combine(p.StartInfo.WorkingDirectory, name + "_expected.exe");
            p.StartInfo.Arguments = "7";
            p.Start();
            p.WaitForExit();

            int ExpectedValue = p.ExitCode;

            p.StartInfo.FileName  = Path.Combine(p.StartInfo.WorkingDirectory, name + "_actual.exe");
            p.StartInfo.Arguments = "7";
            p.Start();
            p.WaitForExit();

            int ActualValue = p.ExitCode;

            Assert.AreEqual(ExpectedValue, ActualValue);
        }