String val) {
return structName + "->" + field + " = " + val + ";";
}
+
+ private static String ASSIGN_PTR_TO_PTR(String structName, String field, String val) {
+ return structName + "->" + field + " = &" + val + ";";
+ }
+ private static String STRUCT_NEW_DECLARE_DEFINE(String type, String name) {
+ return "struct " + type + " *" + name + " = (struct " + type + "*) malloc(sizeof(struct " + type + "));";
+ }
+
private static String DECLARE(String type, String name) {
return type + " " + name + ";";
}
}
private static String ANNOTATE(String structName) {
- return CDSAnnotate + "(" + CDSAnnotateType + ", &" + structName + ");";
+ return CDSAnnotate + "(" + CDSAnnotateType + ", " + structName + ");";
}
private static ArrayList<String> DEFINE_INFO_STRUCT(String interfaceName,
// Pass function table info
newCode.add(COMMENT("Pass function table info"));
String structName = "anno_func_table_init", anno = "func_init";
- newCode.add(DECLARE(ANNO_FUNC_TABLE_INIT, structName));
- newCode.add(ASSIGN(structName, "size", "INTERFACE_SIZE"));
- newCode.add(ASSIGN(structName, "table", "func_ptr_table"));
- newCode.add(DECLARE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_FUNC_TABLE_INIT));
- newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_FUNC_TABLE_INIT, structName));
+ newCode.add(ASSIGN_TO_PTR(structName, "size", "INTERFACE_SIZE"));
+ newCode.add(ASSIGN_TO_PTR(structName, "table", "func_ptr_table"));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_FUNC_TABLE_INIT));
+ newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
newCode.add(ANNOTATE(anno));
// Pass Happens-before relationship
.get(right.hbConditionLabel));
newCode.add(COMMENT(left + " -> " + right));
- newCode.add(ANNO_HB_INIT + " " + structVarName + ";");
- newCode.add(ASSIGN(structVarName, "interface_num_before",
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT, structVarName));
+ newCode.add(ASSIGN_TO_PTR(structVarName, "interface_num_before",
interfaceNumBefore));
- newCode.add(ASSIGN(structVarName, "hb_condition_num_before",
+ newCode.add(ASSIGN_TO_PTR(structVarName, "hb_condition_num_before",
hbLabelNumBefore));
- newCode.add(ASSIGN(structVarName, "interface_num_after",
+ newCode.add(ASSIGN_TO_PTR(structVarName, "interface_num_after",
interfaceNumAfter));
- newCode.add(ASSIGN(structVarName, "hb_condition_num_after",
+ newCode.add(ASSIGN_TO_PTR(structVarName, "hb_condition_num_after",
hbLabelNumAfter));
- newCode.add(DECLARE(SPEC_ANNOTATION, annotationVarName));
- newCode.add(ASSIGN(annotationVarName,
+ 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_PTR(annotationVarName,
+ newCode.add(ASSIGN_TO_PTR(annotationVarName,
SPEC_ANNOTATION_FIELD_ANNO, structVarName));
newCode.add(ANNOTATE(annotationVarName));
}
newCode.add(COMMENT("Interface begins"));
// Interface begin
String structName = "interface_begin";
- newCode.add(DECLARE(ANNO_INTERFACE_BEGIN, "interface_begin"));
- newCode.add(ASSIGN(structName, "interface_num", interfaceNum));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN, "interface_begin"));
+ newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
String anno = "annotation_interface_begin";
- newCode.add(DECLARE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
- newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
+ newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
newCode.add(ANNOTATE(anno));
// Call original renamed function
if (header.returnType.equals("void")) {
.get(label));
newCode.add("if " + BRACE(condition) + " {");
structName = "hb_condition";
- newCode.add(DECLARE(ANNO_HB_CONDITION, structName));
- newCode.add(ASSIGN(structName, "interface_num", interfaceNum));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
+ newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
- newCode.add(ASSIGN(structName, "hb_condition_num", hbCondNum));
+ newCode.add(ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum));
anno = "annotation_hb_condition";
- newCode.add(DECLARE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
- newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
+ newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
newCode.add(ANNOTATE(anno));
newCode.add("}");
newCode.add("");
}
structName = "interface_end";
anno = "annoation_interface_end";
- newCode.add(DECLARE(ANNO_INTERFACE_END, structName));
- newCode.add(ASSIGN(structName, "interface_num", interfaceNum));
- newCode.add(ASSIGN(structName, "info", infoName));
- newCode.add(DECLARE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END));
- newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName));
+ newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+ newCode.add(ASSIGN_TO_PTR(structName, "info", infoName));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END));
+ newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
newCode.add(ANNOTATE(anno));
// Return __RET__ if it's not void
if (!header.returnType.equals("void")) {
// Add annotation
newCode.add("if (" + construct.condition + ") {");
String structName = "potential_cp_define", anno = "annotation_potential_cp_define";
- newCode.add(DECLARE(ANNO_POTENTIAL_CP_DEFINE, structName));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_POTENTIAL_CP_DEFINE, structName));
String labelNum = Integer.toString(semantics.commitPointLabel2Num
.get(construct.label));
- newCode.add(ASSIGN(structName, "label_num", labelNum));
- newCode.add(DECLARE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE));
- newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(ASSIGN_TO_PTR(structName, "label_num", labelNum));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE));
+ newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
newCode.add(ANNOTATE(anno));
newCode.add("}");
return newCode;
// Add annotation
newCode.add("if (" + construct.condition + ") {");
String structName = "cp_define_check", anno = "annotation_cp_define_check";
- newCode.add(DECLARE(ANNO_CP_DEFINE_CHECK, structName));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName));
String labelNum = Integer.toString(semantics.commitPointLabel2Num
.get(construct.label));
- newCode.add(ASSIGN(structName, "label_num", labelNum));
- newCode.add(DECLARE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK));
- newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(ASSIGN_TO_PTR(structName, "label_num", labelNum));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK));
+ newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
newCode.add(ANNOTATE(anno));
newCode.add("}");
return newCode;
// Add annotation
newCode.add("if (" + construct.condition + ") {");
String structName = "cp_define", anno = "annotation_cp_define";
- newCode.add(DECLARE(ANNO_CP_DEFINE, structName));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName));
String labelNum = Integer.toString(semantics.commitPointLabel2Num
.get(construct.label));
- newCode.add(ASSIGN(structName, "label_num", labelNum));
- newCode.add(DECLARE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE));
- newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(ASSIGN_TO_PTR(structName, "label_num", labelNum));
+ newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE));
+ newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
newCode.add(ANNOTATE(anno));
newCode.add("}");
return newCode;