public void GraphNumeratorTest0() { var code = @"a = 1; goto h; h: b = 1; goto h2; h2: c = 1; d = 1;"; var scanner = new Scanner(); scanner.SetSource(code, 0); var parser = new Parser.Parser(scanner); var b = parser.Parse(); var astRoot = parser.root; var tacodeVisitor = new TACodeVisitor(); astRoot.Visit(tacodeVisitor); var tacodeInstance = tacodeVisitor.Code; tacodeInstance.CreateBasicBlockList(); var cfg = new ControlFlowGraph(tacodeInstance); var numer = GraphNumerator.BackOrder(cfg); Assert.AreEqual(0, numer.GetIndex(cfg.CFGNodes.ElementAt(0))); Assert.AreEqual(1, numer.GetIndex(cfg.CFGNodes.ElementAt(1))); Assert.AreEqual(2, numer.GetIndex(cfg.CFGNodes.ElementAt(2))); }
private static void CFGReducibility_DominatorTree_PrettyPrinter_Demonstration() { string fpath = @"..\..\..\CodeSamples\reducibilityBadSample.txt"; astRoot = AST(fpath); if (astRoot == null) { return; } var tacodeVisitor = new TACodeVisitor(); astRoot.Visit(tacodeVisitor); var prettyPrinter = new PrettyPrintVisitor(); astRoot.Visit(prettyPrinter); var cfg = new ControlFlowGraph(tacodeVisitor.Code); var domTree = new DominatorTree(cfg); Console.WriteLine("###### CFG Reducibility(#59 by APC TEAM) based on DominatorTree(#56 by ДВП)"); Console.WriteLine("###### and PrettyPrinter(#5 by APC TEAM) DEMONSTARTION:"); Console.WriteLine("###### Sample 1:"); Console.WriteLine(prettyPrinter.Text); Console.WriteLine("###### Dominator Tree Matrix:"); Console.WriteLine(domTree.ToString()); Console.WriteLine($"###### CFG is reducible: {cfg.IsReducible}"); Console.WriteLine($"###### CFG depth is: {cfg.Depth}"); fpath = @"..\..\..\CodeSamples\reducibilityGoodSample.txt"; astRoot = null; astRoot = AST(fpath); if (astRoot == null) { return; } tacodeVisitor = new TACodeVisitor(); astRoot.Visit(tacodeVisitor); prettyPrinter = new PrettyPrintVisitor(); astRoot.Visit(prettyPrinter); cfg = new ControlFlowGraph(tacodeVisitor.Code); domTree = new DominatorTree(cfg); Console.WriteLine("###########################################"); Console.WriteLine("###### Sample 2:"); Console.WriteLine("###### Program text from PrettyPrinter:\n"); Console.WriteLine(prettyPrinter.Text); Console.WriteLine("###### Dominator Tree Matrix:"); Console.WriteLine(domTree.ToString()); Console.WriteLine($"###### CFG is reducible: {cfg.IsReducible}"); }
public void GenerateThreeAddrCode(object sender, Parser.AST.BlockNode root) { try { var visitor = new TACodeVisitor(); root.Visit(visitor); TACode code = ApplyOptimizations(visitor.Code); GenerationCompleted(null, code); PostProcess(code); } catch (Exception ex) { GenerationErrored(null, ex); } }
public static void Main() { //TaCodeTest(); //ASTTest(); //Test Moving declarations //var Test = new DeclarationTest(); //Test.DeclarationOptimizationTest(); //Test subexpression tree //var sTest = new SubexprTest(); //sTest.SubexpressionOptimizationTest(); //APC //CFGReducibility_DominatorTree_PrettyPrinter_Demonstration(); string fileName = @"..\..\sample.txt"; astRoot = AST(fileName); if (astRoot == null) { return; } var tacodeVisitor = new TACodeVisitor(); astRoot.Visit(tacodeVisitor); tacodeInstance = tacodeVisitor.Code; var allOpt = new AllOptimizations(); tacodeInstance = allOpt.ApplyAllOptimizations(tacodeInstance); TAcode2ILcodeTranslator trans = new TAcode2ILcodeTranslator(); Console.WriteLine(tacodeInstance.ToString()); trans.Translate(tacodeInstance); var temp = trans.PrintCommands(); trans.RunProgram(); }
public void ILcodeGeneratorTest1() { string fileName = @"sample.txt"; //string temp=System.IO.Directory.GetCurrentDirectory(); var astRoot = AST(fileName); if (astRoot == null) { return; } var tacodeVisitor = new TACodeVisitor(); astRoot.Visit(tacodeVisitor); var tacodeInstance = tacodeVisitor.Code; string tastring = tacodeInstance.ToString(); TAcode2ILcodeTranslator trans = new TAcode2ILcodeTranslator(); trans.Translate(tacodeInstance); var temp = trans.PrintCommands(); trans.RunProgram(); }