Parcourir la source

CTCBD seems to be working

Yentl Van Tendeloo il y a 7 ans
Parent
commit
170cbddc9f

+ 4 - 0
bootstrap/model_management.alc

@@ -194,6 +194,8 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 			src_name = read_attribute(tracability_model, readAssociationSource(tracability_model, tracability_link), "name")
 			dst_name = read_attribute(tracability_model, readAssociationDestination(tracability_model, tracability_link), "name")
 
+			log("Found TLINK from " + src_name + " to " + dst_name)
+
 			type = read_attribute(tracability_model, tracability_link, "type")
 
 			// Now try to find all possible combinations
@@ -212,9 +214,11 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 						if (dict_in(new_model["model"], dst_model + dst_name)):
 							// Found a match for source and target, so create a link
 							new_name = instantiate_link(new_model, type, "", src_model + src_name, dst_model + dst_name)
+							log("Created!")
 
 							if (new_name == ""):
 								log("ERROR: could not create a tracability link; ignoring")
+		log("Finished all trace links")
 	return new_model!
 	
 Element function model_split(merged_model : Element, models : Element, tracability : Boolean):

+ 1 - 0
bootstrap/ramify.alc

@@ -85,6 +85,7 @@ Element function ramify(model : Element):
 	instantiate_node(new_model, "Class", "PostElement")
 	model_define_attribute(new_model, "PostElement", "label", False, "String")
 	model_define_attribute(new_model, "PostElement", "action", True, "ActionLanguage")
+	model_define_attribute(new_model, "PostElement", "__id__", True, "ActionLanguage")
 
 	// Association RHS_contains (RHS, PostElement) {}
 	instantiate_link(new_model, "Association", "RHS_contains", "RHS", "PostElement")

+ 17 - 3
bootstrap/transform.alc

@@ -359,6 +359,8 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	String value
 	String action
 	Element original_RHS_labels
+	String new_identifier
+	Element func
 
 	Element reverse
 	reverse = make_reverse_dictionary(schedule_model["model"])
@@ -389,6 +391,14 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	while (list_len(labels_to_add) > 0):
 		// Add the elements linked to these labels
 		label = list_pop(labels_to_add, list_len(labels_to_add) - 1)
+
+		// Check if we have any requirement for the ID
+		if (element_eq(read_attribute(schedule_model, RHS_map[label], "__id__"), read_root())):
+			new_identifier = ""
+		else:
+			func = get_func_AL_model(import_node(read_attribute(schedule_model, RHS_map[label], "__id__")))
+			new_identifier = func(host_model, mapping)
+
 		if (is_edge(schedule_model["model"][RHS_map[label]])):
 			// Edge
 			src = read_attribute(schedule_model, reverse[cast_id(read_edge_src(schedule_model["model"][RHS_map[label]]))], "label")
@@ -399,7 +409,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 				// Both are present, so we can make the link
 				typename = read_type(schedule_model, RHS_map[label])
 				original_typename = string_substr(typename, 5, string_len(typename))
-				new_name = instantiate_link(host_model, original_typename, "", new_mapping[src], new_mapping[dst])
+				new_name = instantiate_link(host_model, original_typename, new_identifier, new_mapping[src], new_mapping[dst])
 				dict_add_fast(new_mapping, label, new_name)
 			else:
 				// Delay this a bit, until all are bound
@@ -409,13 +419,12 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 			// Create the node and add it
 			typename = read_type(schedule_model, RHS_map[label])
 			original_typename = string_substr(typename, 5, string_len(typename))
-			new_name = instantiate_node(host_model, original_typename, "")
+			new_name = instantiate_node(host_model, original_typename, new_identifier)
 			dict_add_fast(new_mapping, label, new_name)
 
 	Element attributes
 	String attribute
 	Element result
-	Element func
 
 	while (set_len(original_RHS_labels) > 0):
 		// Perform actions
@@ -535,6 +544,9 @@ Boolean function transform_atomic(host_model : Element, schedule_model : Element
 	// Execute the atomic transformation
 	Element mappings
 	Element mapping
+
+	log("Executing rule: " + current)
+
 	mappings = full_match(host_model, schedule_model, current, True)
 
 	if (set_len(mappings) > 0):
@@ -543,8 +555,10 @@ Boolean function transform_atomic(host_model : Element, schedule_model : Element
 		String RHS
 		RHS = set_pop(allAssociationDestinations(schedule_model, current, "RHSLink"))
 		rewrite(host_model, schedule_model, RHS, mapping)
+		log("Rewrite OK")
 		return True!
 	else:
+		log("Rewrite failed")
 		return False!
 
 Boolean function transform_forall(host_model : Element, schedule_model : Element, current : String):

+ 20 - 1
models/ctcbd_toPartialRuntime.mvc

@@ -62,9 +62,23 @@ Composite schedule {
             }
             Post_Design/DelayBlock expand_rhs_10 {
                 label = "10"
+                __id__ = $
+                            String function new_id(model : Element, mapping : Element):
+                                String result
+                                result = cast_string(list_read(string_split(mapping["1"], "/"), 1)) + "_" + cast_string(list_read(string_split(mapping["2"], "/"), 1)) + "_D1"
+                                log("Generate new delayblock with ID " + result)
+                                return result!
+                         $
             }
             Post_Design/DelayBlock expand_rhs_11 {
                 label = "11"
+                __id__ = $
+                            String function new_id(model : Element, mapping : Element):
+                                String result
+                                result = cast_string(list_read(string_split(mapping["1"], "/"), 1)) + "_" + cast_string(list_read(string_split(mapping["2"], "/"), 1)) + "_D2"
+                                log("Generate new delayblock with ID " + result)
+                                return result!
+                         $
             }
             Post_Design/ConstantBlock expand_rhs_12 {
                 label = "12"
@@ -387,7 +401,12 @@ Composite schedule {
 
                                 if (set_len(allOutgoingAssociationInstances(model, element_name, "D2P_block")) == 0):
                                     // New design element, so create in partial runtime model as well
-                                    new_element_name = instantiate_node(model, mm_type_name, "")
+                                    String new_name
+                                    if (mm_type_name == "PartialRuntime/DelayBlock"):
+                                        new_name = "PartialRuntime/" + string_replace(element_name, "/", "_")
+                                    else:
+                                        new_name = ""
+                                    new_element_name = instantiate_node(model, mm_type_name, new_name)
                                     instantiate_link(model, "D2P_block", "", element_name, new_element_name)
 
                                 // Always update the value of attributes of PartialRuntime

+ 2 - 0
models/dtcbd_merge.alc

@@ -24,6 +24,7 @@ Boolean function main(model : Element):
 	Float current_time
 	String time_block
 
+	log("Merging!")
 	all_blocks = allInstances(model, "PartialRuntime/Block")
 	while (set_len(all_blocks) > 0):
 		element_name = set_pop(all_blocks)
@@ -56,4 +57,5 @@ Boolean function main(model : Element):
 		if (string_startswith(read_type(model, elem), "PartialRuntime/")):
 			retype(model, elem, "NewFullRuntime/" + cast_string(list_read(string_split_nr(read_type(model, elem), "/", 1), 1)))
 
+	log("Merge OK")
 	return True!

+ 9 - 13
models/dtcbd_simulate.alc

@@ -16,22 +16,17 @@ Boolean function main(model : Element):
 	Float current_time
 
 	String time
-	log("Fetching time...")
 	time = set_pop(allInstances(model, "FullRuntime/Time"))
-	log("Time OK")
 	current_time = read_attribute(model, time, "current_time")
 	log("Fetching time now: " + cast_value(current_time))
 
 	schedule_init = create_schedule(model)
-	log("Schedule OK")
 	schedule_run = read_root()
 
 	Element nodes
 	Element inputs
 	String node
-	log("Compute all blocks")
 	nodes = allInstances(model, "FullRuntime/Block")
-	log("Blocks: " + cast_value(set_len(nodes)))
 	inputs = dict_create()
 	while (set_len(nodes) > 0):
 		node = set_pop(nodes)
@@ -59,15 +54,12 @@ Element function create_schedule(model : Element):
 	String element_name
 	Element incoming_links
 	Element all_blocks
-	log("Create schedule...")
 
 	nodes = allInstances(model, "FullRuntime/Block")
 	successors = dict_create()
 	predecessors = dict_create()
-	log("Got all instances")
 	while (set_len(nodes) > 0):
 		element_name = set_pop(nodes)
-		log("Loop for " + cast_value(element_name))
 		if (bool_not(dict_in(successors, element_name))):
 			dict_add(successors, element_name, create_node())
 		if (bool_not(dict_in(predecessors, element_name))):
@@ -89,7 +81,6 @@ Element function create_schedule(model : Element):
 			set_add(successors[source], element_name)
 			set_add(predecessors[element_name], source)
 	
-	log("Loop done")
 	Element values
 	values = create_node()
 	dict_add(values, "model", model)
@@ -103,10 +94,15 @@ Element function create_schedule(model : Element):
 	dict_add(values, "SCC", create_node())
 
 	log("Toposort")
-	nodes = get_topolist(values)
-	while (list_len(nodes) > 0):
-		log("Strong connect")
-		strongconnect(list_pop_final(nodes), values)
+	//nodes = get_topolist(values)
+	//while (list_len(nodes) > 0):
+	//	log("Strong connect")
+	//	strongconnect(list_pop_final(nodes), values)
+
+	nodes = allInstances(model, "FullRuntime/Block")
+	while (set_len(nodes) > 0):
+		strongconnect(set_pop(nodes), values)
+
 	log("OK")
 
 	return values["SCC"]!