public static final String SPEC_ANNO_TYPE = "spec_anno_type";
public static final String SPEC_ANNO_TYPE_INIT = "INIT";
- public static final String SPEC_ANNO_TYPE_HB_INIT = "HB_INIT";
+ public static final String SPEC_ANNO_TYPE_HB_RULE = "HB_RULE";
public static final String SPEC_ANNO_TYPE_INTERFACE_BEGIN = "INTERFACE_BEGIN";
public static final String SPEC_ANNO_TYPE_HB_CONDITION = "HB_CONDITION";
public static final String SPEC_ANNO_TYPE_INTERFACE_END = "INTERFACE_END";
public static final String SPEC_ANNOTATION_FIELD_ANNO = "annotation";
public static final String ANNO_INIT = "anno_init";
- public static final String ANNO_HB_INIT = "anno_hb_init";
- public static final String ANNO_COMMUTATIVITY_RULE = "anno_commutativity_rule";
+ public static final String HB_RULE = "hb_rule";
+ public static final String COMMUTATIVITY_RULE = "commutativity_rule";
public static final String ANNO_INTERFACE_BEGIN = "anno_interface_begin";
public static final String ANNO_INTERFACE_END = "anno_interface_end";
public static final String ANNO_POTENTIAL_CP_DEFINE = "anno_potential_cp_define";
newCode.add("static " + DECLARE("void**", "func_ptr_table"));
// Happens-before initialization rules
// Should make it static
- newCode.add("static " + DECLARE(ANNO_HB_INIT + "**", "hb_init_table"));
-
+ newCode.add("static " + DECLARE(HB_RULE + "**", "hb_rule_table"));
+
// Declare the Commutativity Rule table
- newCode.add("static " + DECLARE(ANNO_COMMUTATIVITY_RULE + "**", "commutativity_rule_table"));
+ newCode.add("static "
+ + DECLARE(COMMUTATIVITY_RULE + "**", "commutativity_rule_table"));
// Define the Commutativity Rule condition functions
ArrayList<CommutativityRule> rules = semantics.getGlobalConstruct().commutativityRules;
for (int i = 0; i < rules.size(); i++) {
String infoStructType1 = rule.method1 + "_info";
String infoStructType2 = rule.method2 + "_info";
String condition = rule.condition;
-
- // Declare
-
+ String conditionFuncName = "CommutativityCondition"
+ + Integer.toString(i);
+
// Replace the "_M1." and "_M2." with the actual info struct
- condition.replaceAll("_M1\\.", infoStructType1 + "->");
- condition.replaceAll("_M2\\.", infoStructType2 + "->");
-
+ condition = condition.replaceAll("_Method1 \\.", "_info1->");
+ condition = condition.replaceAll("_Method2 \\.", "_info2->");
+
+ // Declare the signature of the condition function
+ newCode.add("inline static bool " + conditionFuncName
+ + "(void *info1, void *info2) {");
+
// Cast the "void*" type to the actual info type
-
- newCode.add(e)
+ newCode.add("\t"
+ + DECLARE_DEFINE(infoStructType1, "*_info1", "("
+ + infoStructType1 + "*) info1"));
+ newCode.add("\t"
+ + DECLARE_DEFINE(infoStructType2, "*_info2", "("
+ + infoStructType2 + "*) info2"));
+ newCode.add("\treturn " + condition + ";");
+
+ // End of the condition function
+ newCode.add("}");
}
-
newCode.add("");
-
+
// Beginning initialization
// Define the __SPEC_INIT__ function to initialize user-defined
// variables
addAllCodeWithIndent(newCode, construct.code.cleanupCode, "\t");
newCode.add("}");
newCode.add("");
-
+
newCode.add(COMMENT("Define function for sequential code initialization"));
newCode.add("inline static void __sequential_init() {");
-
+
// Init func_ptr_table
newCode.add("\t" + COMMENT("Init func_ptr_table"));
newCode.add("\t"
+ ASSIGN("func_ptr_table[2 * " + interfaceNum + " + 1]",
"(void*) &" + interfaceName + "_check_action"));
}
-
- // Init Commutativity rules table
-
-
+
// Init Happens-before rules table
newCode.addAll(generateHBInitAnnotation(semantics));
-
+
// Init Commutativity rules table
newCode.addAll(generateCommutativityAnnotation(semantics));
String structName = "anno_init", anno = "init";
newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INIT, structName));
newCode.add("\t"
- + ASSIGN_TO_PTR(structName, "init_func", "(void*) __SPEC_INIT__"));
+ + ASSIGN_TO_PTR(structName, "init_func",
+ "(void_func_t*) __SPEC_INIT__"));
newCode.add("\t"
- + ASSIGN_TO_PTR(structName, "cleanup_func", "(void*) __SPEC_CLEANUP__"));
+ + ASSIGN_TO_PTR(structName, "cleanup_func",
+ "(void_func_t*) __SPEC_CLEANUP__"));
newCode.add("\t"
+ ASSIGN_TO_PTR(structName, "func_table", "func_ptr_table"));
newCode.add("\t"
+ ASSIGN_TO_PTR(structName, "func_table_size", "INTERFACE_SIZE"));
newCode.add("\t"
- + ASSIGN_TO_PTR(structName, "hb_init_table", "hb_init_table"));
+ + ASSIGN_TO_PTR(structName, "hb_rule_table", "hb_rule_table"));
newCode.add("\t"
- + ASSIGN_TO_PTR(structName, "hb_init_table_size",
- "HB_INIT_TABLE_SIZE"));
-
+ + ASSIGN_TO_PTR(structName, "hb_rule_table_size",
+ "HB_RULE_TABLE_SIZE"));
newCode.add("\t"
- + ASSIGN_TO_PTR(structName, "commutativity_rule_table", "hb_init_table"));
+ + ASSIGN_TO_PTR(structName, "commutativity_rule_table",
+ "commutativity_rule_table"));
newCode.add("\t"
- + ASSIGN_TO_PTR(structName, "hb_init_table_size",
- "HB_INIT_TABLE_SIZE"));
-
+ + ASSIGN_TO_PTR(structName, "commutativity_rule_table_size",
+ Integer.toString(rules.size())));
+
newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INIT));
newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
String templateDecl = semantics.getTemplateFullStr();
if (templateList == null) {
newCode.add(DECLARE("void**", varPrefix + "func_ptr_table"));
- newCode.add(DECLARE("anno_hb_init**", varPrefix + "hb_init_table"));
+ newCode.add(DECLARE("hb_rule**", varPrefix + "hb_rule_table"));
for (int i = 0; i < construct.code.declareVar.size(); i++) {
VariableDeclaration varDecl = construct.code.declareVar.get(i);
newCode.add(DECLARE(varDecl.type, varPrefix + varDecl.name));
newCode.add(templateDecl);
newCode.add(DECLARE("void**", varPrefix + "func_ptr_table"));
newCode.add(templateDecl);
- newCode.add(DECLARE("anno_hb_init**", varPrefix + "hb_init_table"));
+ newCode.add(DECLARE("hb_rule**", varPrefix + "hb_rule_table"));
for (int i = 0; i < construct.code.declareVar.size(); i++) {
VariableDeclaration varDecl = construct.code.declareVar.get(i);
newCode.add(templateDecl);
for (ConditionalInterface right : semantics.getHBConditions().get(
left)) {
String structVarName = "hbConditionInit" + hbConditionInitIdx;
- // String annotationVarName = "hb_init" + hbConditionInitIdx;
+ // String annotationVarName = "hb_rule" + hbConditionInitIdx;
hbConditionInitIdx++;
String interfaceNumBefore = Integer
.toString(semantics.interface2Num
newCode.add("\t" + COMMENT(left + " -> " + right));
newCode.add("\t"
- + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT, structVarName));
+ + STRUCT_NEW_DECLARE_DEFINE(HB_RULE, structVarName));
newCode.add("\t"
+ ASSIGN_TO_PTR(structVarName, "interface_num_before",
interfaceNumBefore)
+ SHORT_COMMENT(right.hbConditionLabel));
}
}
- // Init hb_init_table
- newCode.add("\t" + COMMENT("Init hb_init_table"));
+ // Init hb_rule_table
+ newCode.add("\t" + COMMENT("Init hb_rule_table"));
newCode.add("\t"
- + ASSIGN("hb_init_table", "(" + ANNO_HB_INIT
- + "**) malloc(sizeof(" + ANNO_HB_INIT + "*) * "
+ + ASSIGN("hb_rule_table", "(" + HB_RULE
+ + "**) malloc(sizeof(" + HB_RULE + "*) * "
+ hbConditionInitIdx + ")"));
- // Define HB_INIT_TABLE_SIZE
+ // Define HB_RULE_TABLE_SIZE
newCode.add("\t"
- + DEFINE("HB_INIT_TABLE_SIZE",
+ + DEFINE("HB_RULE_TABLE_SIZE",
Integer.toString(hbConditionInitIdx)));
for (int i = 0; i < hbConditionInitIdx; i++) {
newCode.add("\t"
- + ASSIGN("hb_init_table[" + i + "]", "hbConditionInit" + i));
+ + ASSIGN("hb_rule_table[" + i + "]", "hbConditionInit" + i));
}
return newCode;
}
SemanticsChecker semantics) {
ArrayList<String> newCode = new ArrayList<String>();
ArrayList<CommutativityRule> rules = semantics.getGlobalConstruct().commutativityRules;
- for (CommutativityRule rule : rules) {
-
- }
// Init commutativity_rule_table
newCode.add("\t" + COMMENT("Init commutativity_rule_table"));
+
+ // Users have not defined any commutativity rules
+ if (rules.size() == 0)
+ return newCode;
+
newCode.add("\t"
- + ASSIGN("hb_init_table", "(" + ANNO_HB_INIT
- + "**) malloc(sizeof(" + ANNO_HB_INIT + "*) * "
- + hbConditionInitIdx + ")"));
- // Define HB_INIT_TABLE_SIZE
- newCode.add("\t"
- + DEFINE("HB_INIT_TABLE_SIZE",
- Integer.toString(hbConditionInitIdx)));
- for (int i = 0; i < hbConditionInitIdx; i++) {
+ + ASSIGN("commutativity_rule_table", "(" + COMMUTATIVITY_RULE
+ + "**) malloc(sizeof(" + COMMUTATIVITY_RULE + "*) * "
+ + rules.size() + ")"));
+
+ // Declare a rule pointer
+ newCode.add("\t" + DECLARE("commutativity_rule*", "rule"));
+
+ for (int i = 0; i < rules.size(); i++) {
+ CommutativityRule rule = rules.get(i);
+ String interfaceNumBefore = Integer
+ .toString(semantics.interface2Num.get(rule.method1));
+ String interfaceNumAfter = Integer.toString(semantics.interface2Num
+ .get(rule.method2));
+ String conditionFuncName = "CommutativityCondition" + i;
+
+ // Construct a new rule
+ newCode.add("\t"
+ + ASSIGN("rule",
+ "(commutativity_rule*) malloc (sizeof(commutativity_rule))"));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR("rule", "interface_num_before",
+ interfaceNumBefore));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR("rule", "interface_num_after",
+ interfaceNumAfter));
newCode.add("\t"
- + ASSIGN("hb_init_table[" + i + "]", "hbConditionInit" + i));
+ + ASSIGN_TO_PTR("rule", "condition", conditionFuncName));
+
+ // Assign the rule to the corresponding commutativity table slot
+ newCode.add("\t"
+ + ASSIGN("commutativity_rule_table[" + i + "]", "rule"));
}
+
return newCode;
}
newCode.add("\t\t"
+ ASSIGN_TO_PTR(structName, "label_name", "\""
+ construct.label + "\""));
- if (construct.isAdditionalOrderingPoint) {
- newCode.add("\t\t"
- + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
- } else {
- newCode.add("\t\t"
- + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
- }
+
newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
newCode.add("\t\t"
+ ASSIGN_TO_PTR(anno, "type",
+ construct.label + "\""));
newCode.add("\t\t"
+ ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
- if (construct.isAdditionalOrderingPoint) {
- newCode.add("\t\t"
- + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
- } else {
- newCode.add("\t\t"
- + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
- }
+
newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
newCode.add("\t\t"
+ ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK));
+ construct.potentialCPLabel + "\""));
newCode.add("\t\t"
+ ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
- if (construct.isAdditionalOrderingPoint) {
- newCode.add("\t\t"
- + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
- } else {
- newCode.add("\t\t"
- + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
- }
newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
newCode.add("\t\t"
+ ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE));