internal static (string str, IReadOnlyList <Instruction> instructions) GetTACWithOpt( Parser parser, List <int> lstCheck) { ThreeAddressCodeTmp.ResetTmpLabel(); ThreeAddressCodeTmp.ResetTmpName(); var threeAddrCodeVisitor = new ThreeAddrGenVisitor(); parser.root.Visit(threeAddrCodeVisitor); var threeAddressCode = threeAddrCodeVisitor.Instructions; if (lstCheck.Count > 0) { List <Optimization> bBlOpt = new List <Optimization>(), allCodeOpt = new List <Optimization>(), allAllOpt = new List <Optimization>(); var numPos = BasicBlockOptimizations.Count; var numPosFalse = BasicBlockOptimizations.Count + AllCodeOptimizations.Count; foreach (var n in lstCheck.TakeWhile(x => x < numPos)) { bBlOpt.Add(BasicBlockOptimizations[n]); allAllOpt.Add(BasicBlockOptimizations[n]); } foreach (var n in lstCheck.SkipWhile(x => x < numPos).TakeWhile(x => x < numPosFalse)) { allCodeOpt.Add(AllCodeOptimizations[n - numPos]); allAllOpt.Add(AllCodeOptimizations[n - numPos]); } var UCE = lstCheck[^ 1] == numPosFalse;
internal static (string str, IReadOnlyList <Instruction> instructions) GetTACWithOpt( Parser parser, List <int> lstCheck) { ThreeAddressCodeTmp.ResetTmpLabel(); ThreeAddressCodeTmp.ResetTmpName(); var threeAddrCodeVisitor = new ThreeAddrGenVisitor(); parser.root.Visit(threeAddrCodeVisitor); var threeAddressCode = threeAddrCodeVisitor.Instructions; if (lstCheck.Count > 0) { List <Optimization> bBlOpt = new List <Optimization>(), allCodeOpt = new List <Optimization>(), allAllOpt = new List <Optimization>(); var numPos = BasicBlockOptimizations.Count; var numPosFalse = BasicBlockOptimizations.Count + AllCodeOptimizations.Count; foreach (var n in lstCheck.TakeWhile(x => x < numPos)) { bBlOpt.Add(BasicBlockOptimizations[n]); allAllOpt.Add(BasicBlockOptimizations[n]); } foreach (var n in lstCheck.SkipWhile(x => x < numPos).TakeWhile(x => x < numPosFalse)) { allCodeOpt.Add(AllCodeOptimizations[n - numPos]); allAllOpt.Add(AllCodeOptimizations[n - numPos]); } var UCE = lstCheck[lstCheck.Count - 1] == numPosFalse; var result = ThreeAddressCodeOptimizer.Optimize(threeAddressCode, bBlOpt, allCodeOpt, UCE).ToList(); var strR = new StringBuilder(); foreach (var x in result) { strR.AppendLine(x.ToString()); } return(strR.ToString(), threeAddressCode); } var str = new StringBuilder(); foreach (var x in threeAddressCode) { str.AppendLine(x.ToString()); } return(str.ToString(), threeAddressCode); }
protected List <Instruction> GenTAC(string sourceCode) { ThreeAddressCodeTmp.ResetTmpName(); ThreeAddressCodeTmp.ResetTmpLabel(); SymbolTable.vars.Clear(); // oh yeah, all variables are stored in a static dict :D var scanner = new Scanner(); scanner.SetSource(sourceCode, 0); var parser = new Parser(scanner); parser.Parse(); var fillParents = new FillParentsVisitor(); parser.root.Visit(fillParents); var threeAddrCodeVisitor = new ThreeAddrGenVisitor(); parser.root.Visit(threeAddrCodeVisitor); return(threeAddrCodeVisitor.Instructions); }