소스 검색

Add initial code for transformations: make a schedule of LHS elements to visit

Yentl Van Tendeloo 8 년 전
부모
커밋
93b2a8612e
1개의 변경된 파일51개의 추가작업 그리고 0개의 파일을 삭제
  1. 51 0
      bootstrap/transform.alc

+ 51 - 0
bootstrap/transform.alc

@@ -0,0 +1,51 @@
+Element function make_matching_schedule(LHS_model : Element):
+	Element schedule
+	Element workset
+	Element all_elements
+	Integer required_size
+	String new_element
+	Element tmp
+
+	schedule = create_node()
+	workset = create_node()
+
+	all_elements = allInstances(LHS_model, "Pre_Element")
+	//TODO is this completely true?
+	// Calculate the size of the final match
+	required_size = read_nr_out(all_elements)
+
+	while (read_nr_out(schedule) < required_size):
+		// Need to keep adding to the schedule
+
+		// workset is empty, but we still need to add to the list
+		// Therefore, we pick a random, unbound node, and add it to the workset
+		new_element = set_pop(all_elements)
+		while (bool_or(set_in(schedule, new_element), (is_edge(LHS_model["model"][new_element]))):
+			new_element = set_pop(all_elements)
+		set_add(workset, new_element)
+
+		while (read_nr_out(workset) > 0):
+			// Still elements in the workset, so pop from these first
+			next = set_pop(workset)
+
+			if (bool_not(set_in(schedule, next))):
+				list_append(schedule, next)
+
+				if (is_edge(next)):
+					// Add the target/source to the schedule
+					if (bool_not(set_in(schedule, read_edge_src(next)))):
+						// Add source
+						set_add(workset, read_edge_src(next))
+					if (bool_not(set_in(schedule, read_edge_dst(next)))):
+						// Add destination
+						set_add(workset, read_edge_dst(next))
+
+				// Also add all outgoing and incoming elements
+				tmp = allOutgoingAssociations(next)
+				while (read_nr_out(tmp) > 0):
+					set_add(workset, set_pop(tmp))
+				tmp = allIncomingAssociations(next)
+				while (read_nr_out(tmp) > 0):
+					set_add(workset, set_pop(tmp))
+
+	return schedule