//SUSPECT: Least legible code in the entire solution. private IEnumerable <Command> CodeWithNewLables(IEnumerable <Command> commands) { if (BranchableLabels.Any()) { yield return(new Comment("; These labels were never hit:")); foreach (var branchedLabel in BranchableLabels) { yield return(new Comment("; " + branchedLabel)); } } var inRunnableCode = false; var codeJustEnded = false; foreach (var command in commands) { if (!string.IsNullOrEmpty(command.Label) && BranchedLabels.Contains(command.Label) && !inRunnableCode) { if (!codeJustEnded) { yield return(new Comment("; Runnable Code Begin")); } inRunnableCode = true; } else if (codeJustEnded && !(command is BlankLine)) { yield return(new Comment("; Runnable Code End")); } if (inRunnableCode && _branchCommands.Contains(command.GetType())) { foreach (var operand in GetOperands(command)) { if (operand is IndirectRegisterOperand indirectOperand) { yield return(new Comment("; Indirect Address Jump")); } } } yield return(command); if (!(command is BlankLine)) { codeJustEnded = false; } if (inRunnableCode && _unconditionalBranchAwayCommands.Contains(command.GetType())) { inRunnableCode = false; codeJustEnded = true; } } }
private void FindBranchableLabels(IEnumerable <Command> commands) { var removedAtLeastOneItem = true; while (BranchableLabels.Any() && removedAtLeastOneItem) { var inRunnableCode = false; removedAtLeastOneItem = false; foreach (var command in commands) { var hasLabel = !string.IsNullOrEmpty(command.Label); if (hasLabel) { if (BranchableLabels.Contains(command.Label)) { inRunnableCode = true; if (BranchableLabels.Contains(command.Label)) { BranchableLabels.Remove(command.Label); removedAtLeastOneItem = true; } } else if (BranchedLabels.Contains(command.Label)) { inRunnableCode = true; } } if (inRunnableCode) { if (hasLabel && !BranchedLabels.Contains(command.Label)) { BranchedLabels.Add(command.Label); } if (_branchCommands.Contains(command.GetType())) { GetLabelsFromOperands(command) .Where(l => !BranchableLabels.Contains(l) && !BranchedLabels.Contains(l)) .ToList() .ForEach(l => BranchableLabels.Add(l)); } if (_unconditionalBranchAwayCommands.Contains(command.GetType())) { inRunnableCode = false; } } } } }