newCode.add(header.getTemplateFullStr());
newCode.add(header.getFuncStr() + " {");
// Wrapper function body
- newCode.add(COMMENT("Interface begins"));
+ newCode.add("\t" + COMMENT("Interface begins"));
// Interface begin
String structName = "interface_begin";
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN,
+ newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN,
"interface_begin"));
- newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+ newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
String anno = "annotation_interface_begin";
- 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(semantics, anno));
+ newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
+ newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t" + ANNOTATE(semantics, anno));
// Call original renamed function
if (header.returnType.equals("void")) {
- newCode.add(header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";");
+ newCode.add("\t" + header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";");
} else {
- newCode.add(DECLARE_DEFINE(header.returnType, MACRO_RETURN,
+ newCode.add("\t" + DECLARE_DEFINE(header.returnType, MACRO_RETURN,
header.getRenamedCall(SPEC_INTERFACE_WRAPPER)));
}
// HB conditions
String condition = construct.hbConditions.get(label);
String hbCondNum = Integer.toString(semantics.hbLabel2Num
.get(label));
- newCode.add("if " + BRACE(condition) + " {");
+ newCode.add("\t" + "if " + BRACE(condition) + " {");
structName = "hb_condition";
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
- newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+ newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
- newCode.add(ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum));
anno = "annotation_hb_condition";
- 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(semantics, anno));
- newCode.add("}");
+ newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t\t" + ANNOTATE(semantics, anno));
+ newCode.add("\t" + "}");
newCode.add("");
}
// Also add the true condition if any
if (semantics.containsConditionalInterface(new ConditionalInterface(
interfaceName, ""))) {
structName = "hb_condition";
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
- newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
- newCode.add(ASSIGN_TO_PTR(structName, "hb_condition_num", "0"));
+ newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
+ newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+ newCode.add("\t" + ASSIGN_TO_PTR(structName, "hb_condition_num", "0"));
anno = "annotation_hb_condition";
- 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(semantics, anno));
+ newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
+ newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t" + ANNOTATE(semantics, anno));
newCode.add("");
}
// Interface end
if (!header.returnType.equals("void") || header.args.size() > 0) {
infoStructType = interfaceName + "_info";
infoName = "info";
- newCode.add(DECLARE_DEFINE(infoStructType + "*", infoName,
+ newCode.add("\t" + DECLARE_DEFINE(infoStructType + "*", infoName,
BRACE(infoStructType + "*") + " malloc(sizeof("
+ infoStructType + "))"));
if (!header.returnType.equals("void")) {
- newCode.add(ASSIGN_TO_PTR(infoName, MACRO_RETURN, MACRO_RETURN));
+ newCode.add("\t" + ASSIGN_TO_PTR(infoName, MACRO_RETURN, MACRO_RETURN));
}
for (int i = 0; i < header.args.size(); i++) {
String argName = header.args.get(i).name;
- newCode.add(ASSIGN_TO_PTR(infoName, argName, argName));
+ newCode.add("\t" + ASSIGN_TO_PTR(infoName, argName, argName));
}
} else {
infoName = "NULL";
}
structName = "interface_end";
anno = "annoation_interface_end";
- 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(semantics, anno));
+ newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName));
+ newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+ newCode.add("\t" + ASSIGN_TO_PTR(structName, "info", infoName));
+ newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END));
+ newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t" + ANNOTATE(semantics, anno));
// Return __RET__ if it's not void
if (!header.returnType.equals("void")) {
- newCode.add("return " + MACRO_RETURN + ";");
+ newCode.add("\t" + "return " + MACRO_RETURN + ";");
}
// End of the wrapper function
newCode.add("}");
addAtomicReturn(semantics, construct);
}
// Generate redundant header files
- newCode.add(COMMENT("Automatically generated code for commit point define check: "
+ newCode.add("\t" + COMMENT("Automatically generated code for commit point define check: "
+ construct.label));
newCode.add("");
// Add annotation
- newCode.add("if (" + construct.condition + ") {");
+ newCode.add("\t" + "if (" + construct.condition + ") {");
String structName = "cp_define_check", anno = "annotation_cp_define_check";
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName));
+ newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName));
String labelNum = Integer.toString(semantics.commitPointLabel2Num
.get(construct.label));
- 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(semantics, anno));
- newCode.add("}");
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
+ 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));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t\t" + ANNOTATE(semantics, anno));
+ newCode.add("\t" + "}");
return newCode;
}
SemanticsChecker semantics, CPDefineConstruct construct) {
ArrayList<String> newCode = new ArrayList<String>();
// Generate redundant header files
- newCode.add(COMMENT("Automatically generated code for commit point define check: "
+ newCode.add("\t" + COMMENT("Automatically generated code for commit point define: "
+ construct.label));
newCode.add("");
// Add annotation
- newCode.add("if (" + construct.condition + ") {");
+ newCode.add("\t" + "if (" + construct.condition + ") {");
String structName = "cp_define", anno = "annotation_cp_define";
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName));
+ newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName));
String labelNum = Integer.toString(semantics.commitPointLabel2Num
.get(construct.label));
String potentialLabelNum = Integer
.toString(semantics.commitPointLabel2Num
.get(construct.potentialCPLabel));
- newCode.add(ASSIGN_TO_PTR(structName, "label_num", labelNum));
- newCode.add(ASSIGN_TO_PTR(structName, "potential_cp_label_num",
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "potential_cp_label_num",
potentialLabelNum));
- 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(semantics, anno));
- newCode.add("}");
+ 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));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t\t" + ANNOTATE(semantics, anno));
+ newCode.add("\t" + "}");
return newCode;
}
}