+ // 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);
+ 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_TO_PTR("rule", "rule",
+ "\"" + rule.condition + "\""));
+
+ newCode.add("\t"
+ + ASSIGN_TO_PTR("rule", "condition", conditionFuncName));
+
+ // Assign the rule to the corresponding commutativity table slot
+ newCode.add("\t"
+ + ASSIGN("commutativity_rule_table[" + i + "]", "rule"));
+ }
+