[vala] Generate reverse postorder instead of preorder list in flow analyzer



commit ae18e9b49e837dc09ace876e413a269780592a8a
Author: Jürg Billeter <j bitron ch>
Date:   Wed Dec 23 20:46:41 2009 +0100

    Generate reverse postorder instead of preorder list in flow analyzer

 vala/valabasicblock.vala   |    2 ++
 vala/valaflowanalyzer.vala |    6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/vala/valabasicblock.vala b/vala/valabasicblock.vala
index 498622c..c69f6c6 100644
--- a/vala/valabasicblock.vala
+++ b/vala/valabasicblock.vala
@@ -40,6 +40,8 @@ public class Vala.BasicBlock {
 
 	Set<PhiFunction> phi_functions = new HashSet<PhiFunction> ();
 
+	public bool postorder_visited { get; set; }
+
 	public BasicBlock () {
 	}
 
diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala
index 870a9e1..5cb8f1f 100644
--- a/vala/valaflowanalyzer.vala
+++ b/vala/valaflowanalyzer.vala
@@ -181,6 +181,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
 		check_variables (entry_block);
 	}
 
+	// generates reverse postorder list
 	List<BasicBlock> get_depth_first_list (BasicBlock entry_block) {
 		var list = new ArrayList<BasicBlock> ();
 		depth_first_traverse (entry_block, list);
@@ -188,13 +189,14 @@ public class Vala.FlowAnalyzer : CodeVisitor {
 	}
 
 	void depth_first_traverse (BasicBlock current, List<BasicBlock> list) {
-		if (current in list) {
+		if (current.postorder_visited) {
 			return;
 		}
-		list.add (current);
+		current.postorder_visited = true;
 		foreach (BasicBlock succ in current.get_successors ()) {
 			depth_first_traverse (succ, list);
 		}
+		list.insert (0, current);
 	}
 
 	void build_dominator_tree (List<BasicBlock> block_list, BasicBlock entry_block) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]