- newCode.add(COMMENT(left + " -> " + right));
-
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT, structVarName));
- newCode.add(ASSIGN_TO_PTR(structVarName, "interface_num_before",
- interfaceNumBefore));
- newCode.add(ASSIGN_TO_PTR(structVarName, "hb_condition_num_before",
- hbLabelNumBefore));
- newCode.add(ASSIGN_TO_PTR(structVarName, "interface_num_after",
- interfaceNumAfter));
- newCode.add(ASSIGN_TO_PTR(structVarName, "hb_condition_num_after",
- hbLabelNumAfter));
-
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, annotationVarName));
- newCode.add(ASSIGN_TO_PTR(annotationVarName,
- SPEC_ANNOTATION_FIELD_TYPE, SPEC_ANNO_TYPE_HB_INIT));
- newCode.add(ASSIGN_TO_PTR(annotationVarName,
- SPEC_ANNOTATION_FIELD_ANNO, structVarName));
- newCode.add(ANNOTATE(annotationVarName));
+ newCode.add("\t" + COMMENT(left + " -> " + right));
+
+ newCode.add("\t"
+ + STRUCT_NEW_DECLARE_DEFINE(HB_RULE, structVarName));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structVarName, "interface_num_before",
+ interfaceNumBefore)
+ + SHORT_COMMENT(left.interfaceName));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structVarName,
+ "hb_condition_num_before", hbLabelNumBefore)
+ + SHORT_COMMENT(left.hbConditionLabel));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structVarName, "interface_num_after",
+ interfaceNumAfter)
+ + SHORT_COMMENT(right.interfaceName));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structVarName,
+ "hb_condition_num_after", hbLabelNumAfter)
+ + SHORT_COMMENT(right.hbConditionLabel));
+ }
+ }
+ // Init hb_rule_table
+ newCode.add("\t" + COMMENT("Init hb_rule_table"));
+ newCode.add("\t"
+ + ASSIGN("hb_rule_table", "(" + HB_RULE
+ + "**) malloc(sizeof(" + HB_RULE + "*) * "
+ + hbConditionInitIdx + ")"));
+ // Define HB_RULE_TABLE_SIZE
+ newCode.add("\t"
+ + DEFINE("HB_RULE_TABLE_SIZE",
+ Integer.toString(hbConditionInitIdx)));
+ for (int i = 0; i < hbConditionInitIdx; i++) {
+ newCode.add("\t"
+ + ASSIGN("hb_rule_table[" + i + "]", "hbConditionInit" + i));
+ }
+ return newCode;
+ }
+
+ private static ArrayList<String> generateCommutativityAnnotation(
+ SemanticsChecker semantics) {
+ ArrayList<String> newCode = new ArrayList<String>();
+ ArrayList<CommutativityRule> rules = semantics.getGlobalConstruct().commutativityRules;
+
+ // 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("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);
+ Integer method = semantics.interface2Num.get(rule.method1);
+ if (method == null) {
+ System.out.println("Wrong method label in commutativity rule: " + rule.method1);