import edu.uci.eecs.specCompiler.grammerParser.utilParser.UtilParser;
import edu.uci.eecs.specCompiler.grammerParser.utilParser.ParseException;
+import edu.uci.eecs.specCompiler.specExtraction.CPClearConstruct;
import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
+/**
+ * <p>
+ * Defines a list of commonly used constant strings.
+ * </p>
+ *
+ * @author peizhaoo
+ *
+ */
public class CodeVariables {
// C++ code or library
public static final String HEADER_STDLIB = "<stdlib.h>";
public static final String SPEC_ANNO_TYPE_INTERFACE_END = "INTERFACE_END";
public static final String SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE = "POTENTIAL_CP_DEFINE";
public static final String SPEC_ANNO_TYPE_CP_DEFINE_CHECK = "CP_DEFINE_CHECK";
+ public static final String SPEC_ANNO_TYPE_CP_CLEAR = "CP_CLEAR";
public static final String SPEC_ANNO_TYPE_CP_DEFINE = "CP_DEFINE";
public static final String SPEC_ANNOTATION = "spec_annotation";
public static final String SPEC_ANNOTATION_FIELD_TYPE = "type";
public static final String ANNO_POTENTIAL_CP_DEFINE = "anno_potential_cp_define";
public static final String ANNO_CP_DEFINE = "anno_cp_define";
public static final String ANNO_CP_DEFINE_CHECK = "anno_cp_define_check";
+ public static final String ANNO_CP_CLEAR = "anno_cp_clear";
public static final String ANNO_HB_CONDITION = "anno_hb_condition";
// Specification variables
return "/* " + comment + " */";
}
+ private static String SHORT_COMMENT(String comment) {
+ return " // " + comment;
+ }
+
private static String INCLUDE(String header) {
return "#include " + header;
}
newCode.add("static " + DECLARE(ANNO_HB_INIT + "**", "hb_init_table"));
newCode.add("");
+
+ // Define the __SPEC_INIT__ function to initialize user-defined
+ // variables
+ newCode.add(COMMENT("Initialization of sequential varialbes"));
+ newCode.add("static void __SPEC_INIT__() {");
+ addAllCodeWithIndent(newCode, construct.code.initVar, "\t");
+ newCode.add("}");
+ newCode.add("");
+
+ // Define the __SPEC_CLEAN__ function for clean-up
+ newCode.add(COMMENT("Cleanup routine of sequential variables"));
+ newCode.add("static void __SPEC_CLEANUP__() {");
+ 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", "(void**) malloc(sizeof(void*) * "
- + semantics.interface2Num.size() + " * 2)"));
+ newCode.add("\t"
+ + ASSIGN("func_ptr_table", "(void**) malloc(sizeof(void*) * "
+ + semantics.interface2Num.size() + " * 2)"));
for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
String interfaceNum = Integer.toString(semantics.interface2Num
.get(interfaceName));
- newCode.add("\t" + ASSIGN("func_ptr_table[2 * " + interfaceNum + "]",
- "(void*) &" + interfaceName + "_id"));
- newCode.add("\t" + ASSIGN("func_ptr_table[2 * " + interfaceNum + " + 1]",
- "(void*) &" + interfaceName + "_check_action"));
+ newCode.add("\t"
+ + ASSIGN("func_ptr_table[2 * " + interfaceNum + "]",
+ "(void*) &" + interfaceName + "_id"));
+ newCode.add("\t"
+ + ASSIGN("func_ptr_table[2 * " + interfaceNum + " + 1]",
+ "(void*) &" + interfaceName + "_check_action"));
}
// Init Happens-before rules table
newCode.addAll(generateHBInitAnnotation(semantics));
// Pass init info, including function table info & HB rules
- newCode.add("\t" + COMMENT("Pass init info, including function table info & HB rules"));
+ newCode.add("\t"
+ + COMMENT("Pass init info, including function table info & HB rules"));
String structName = "anno_init", anno = "init";
newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INIT, structName));
- 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"));
- newCode.add("\t" + ASSIGN_TO_PTR(structName, "hb_init_table_size",
- "HB_INIT_TABLE_SIZE"));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structName, "init_func", "__SPEC_INIT__"));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structName, "cleanup_func", "__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"));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structName, "hb_init_table_size",
+ "HB_INIT_TABLE_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));
newCode.add("\t" + ANNOTATE(semantics, anno));
newCode.add("");
- // Init user-defined variables
- addAllCodeWithIndent(newCode, construct.code.initVar, "\t");
-
newCode.add("}");
+ newCode.add("");
+
newCode.add(COMMENT("End of Global construct generation in class"));
- //printCode(newCode);
+ // printCode(newCode);
return newCode;
}
.get(right.hbConditionLabel));
newCode.add("\t" + COMMENT(left + " -> " + right));
- newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT,
- structVarName));
- newCode.add("\t" + ASSIGN_TO_PTR(structVarName,
- "interface_num_before", interfaceNumBefore));
- newCode.add("\t" + ASSIGN_TO_PTR(structVarName,
- "hb_condition_num_before", hbLabelNumBefore));
- newCode.add("\t" + ASSIGN_TO_PTR(structVarName, "interface_num_after",
- interfaceNumAfter));
- newCode.add("\t" + 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"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT, 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_init_table
newCode.add("\t" + COMMENT("Init hb_init_table"));
- newCode.add("\t" + ASSIGN("hb_init_table", "(" + ANNO_HB_INIT
- + "**) malloc(sizeof(" + ANNO_HB_INIT + "*) * "
- + hbConditionInitIdx + ")"));
+ 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)));
+ newCode.add("\t"
+ + DEFINE("HB_INIT_TABLE_SIZE",
+ Integer.toString(hbConditionInitIdx)));
for (int i = 0; i < hbConditionInitIdx; i++) {
- newCode.add("\t" + ASSIGN("hb_init_table[" + i + "]", "hbConditionInit"
- + i));
+ newCode.add("\t"
+ + ASSIGN("hb_init_table[" + i + "]", "hbConditionInit" + i));
}
return newCode;
}
public static ArrayList<String> generateEntryPointInitCall() {
ArrayList<String> newCode = new ArrayList<String>();
- newCode.add("__sequential_init();");
+ newCode.add("\t" + "__sequential_init();");
return newCode;
}
- // Only generate the declaration of the wrapper, don't do any renaming
- // public static ArrayList<String> generateInterfaceWrapperDeclaration(
- // SemanticsChecker semantics, InterfaceConstruct construct) {
- // ArrayList<String> newCode = new ArrayList<String>();
- // FunctionHeader header = getFunctionHeader(semantics, construct);
- // newCode.add(COMMENT("Declaration of the wrapper"));
- // String templateStr = header.getTemplateFullStr();
- // newCode.add(templateStr);
- // newCode.add(header.getFuncStr() + ";");
- // newCode.add("");
- //
- // return newCode;
- // }
-
public static ArrayList<String> generateInterfaceWrapperDeclaration(
SemanticsChecker semantics, InterfaceConstruct construct) {
FunctionHeader header = getFunctionHeader(semantics, construct);
newCode.add("\t" + COMMENT("Interface begins"));
// Interface begin
String structName = "interface_begin";
- newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN,
- "interface_begin"));
- newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+ newCode.add("\t"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN,
+ "interface_begin"));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
+ + SHORT_COMMENT(construct.name));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(structName, "interface_name", "\""
+ + construct.name + "\""));
String anno = "annotation_interface_begin";
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, "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("\t" + header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";");
+ newCode.add("\t" + header.getRenamedCall(SPEC_INTERFACE_WRAPPER)
+ + ";");
} else {
- newCode.add("\t" + DECLARE_DEFINE(header.returnType, MACRO_RETURN,
- header.getRenamedCall(SPEC_INTERFACE_WRAPPER)));
+ newCode.add("\t"
+ + DECLARE_DEFINE(header.returnType, MACRO_RETURN,
+ header.getRenamedCall(SPEC_INTERFACE_WRAPPER)));
}
// HB conditions
for (String label : construct.hbConditions.keySet()) {
.get(label));
newCode.add("\t" + "if " + BRACE(condition) + " {");
structName = "hb_condition";
- 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("\t\t" + ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum));
+ newCode.add("\t\t"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
+ + SHORT_COMMENT(construct.name));
+
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum));
anno = "annotation_hb_condition";
- 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"
+ + 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" + "}");
if (semantics.containsConditionalInterface(new ConditionalInterface(
interfaceName, ""))) {
structName = "hb_condition";
- 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"));
+ newCode.add("\t"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
+ + SHORT_COMMENT(construct.name));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structName, "hb_condition_num", "0"));
anno = "annotation_hb_condition";
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, "type", SPEC_ANNO_TYPE_HB_CONDITION));
newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
newCode.add("\t" + ANNOTATE(semantics, anno));
newCode.add("");
if (!header.returnType.equals("void") || header.args.size() > 0) {
infoStructType = interfaceName + "_info";
infoName = "info";
- newCode.add("\t" + DECLARE_DEFINE(infoStructType + "*", infoName,
- BRACE(infoStructType + "*") + " malloc(sizeof("
- + infoStructType + "))"));
+ newCode.add("\t"
+ + DECLARE_DEFINE(infoStructType + "*", infoName,
+ BRACE(infoStructType + "*") + " malloc(sizeof("
+ + infoStructType + "))"));
if (!header.returnType.equals("void")) {
- newCode.add("\t" + 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;
}
structName = "interface_end";
anno = "annoation_interface_end";
- newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName));
- newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+ newCode.add("\t"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName));
+ newCode.add("\t"
+ + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
+ + SHORT_COMMENT(construct.name));
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, "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
}
String newLine = header.getRenamedHeader(SPEC_INTERFACE_WRAPPER)
.toString();
+ String oldLine = content.get(lineNum + 1);
if (construct instanceof InterfaceConstruct) {
InterfaceConstruct iConstruct = (InterfaceConstruct) construct;
newLine = newLine + " ;";
renameInterface(semantics, defineConstruct);
} else { // This is a declare & define construct
- newLine = newLine + " {";
+ if (oldLine.indexOf('{') != -1)
+ newLine = newLine + " {";
}
} else {
- newLine = newLine + " {";
+ if (oldLine.indexOf('{') != -1)
+ newLine = newLine + " {";
}
- content.set(lineNum, newLine);
+
+ content.set(lineNum + 1, newLine);
}
public static void addAtomicReturn(SemanticsChecker semantics,
addAtomicReturn(semantics, construct);
}
// Generate redundant header files
- newCode.add(COMMENT("Automatically generated code for potential commit point: "
- + construct.label));
+ newCode.add("\t"
+ + COMMENT("Automatically generated code for potential commit point: "
+ + construct.label));
newCode.add("");
// Add annotation
- newCode.add("if (" + construct.condition + ") {");
+ newCode.add("\t" + "if (" + construct.condition + ") {");
String structName = "potential_cp_define", anno = "annotation_potential_cp_define";
- newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_POTENTIAL_CP_DEFINE,
- structName));
+ newCode.add("\t\t"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_POTENTIAL_CP_DEFINE,
+ 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_POTENTIAL_CP_DEFINE));
- 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"
+ + 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",
+ SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t\t" + ANNOTATE(semantics, anno));
+ newCode.add("\t" + "}");
return newCode;
}
+ public static String getCPInterfaceNum(SemanticsChecker semantics,
+ String commitPointLabel) {
+ HashMap<String, InterfaceConstruct> cp2Interface = semantics.CPLabel2InterfaceConstruct;
+ InterfaceConstruct iConstruct = cp2Interface.get(commitPointLabel);
+ String interfaceName = iConstruct.name;
+ String interfaceNum = Integer.toString(semantics.interface2Num
+ .get(interfaceName));
+ return interfaceNum;
+ }
+
+ /**
+ * <p>
+ * Commit point define check should be unique to each interface, meaning
+ * that they are not shared between different interfaces
+ * </p>
+ *
+ * @param semantics
+ * @param construct
+ * @return
+ */
public static ArrayList<String> generateCPDefineCheck(
SemanticsChecker semantics, CPDefineCheckConstruct construct) {
ArrayList<String> newCode = new ArrayList<String>();
addAtomicReturn(semantics, construct);
}
// Generate redundant header files
- newCode.add("\t" + COMMENT("Automatically generated code for commit point define check: "
- + construct.label));
+ newCode.add("\t"
+ + COMMENT("Automatically generated code for commit point define check: "
+ + construct.label));
newCode.add("");
// Add annotation
+
newCode.add("\t" + "if (" + construct.condition + ") {");
String structName = "cp_define_check", anno = "annotation_cp_define_check";
- newCode.add("\t\t" + 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));
+ String interfaceNum = getCPInterfaceNum(semantics, construct.label);
newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(structName, "label_name", "\""
+ + 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));
+ 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;
}
+ /**
+ * <p>
+ * Commit point define check should be unique to each interface, meaning
+ * that they are not shared between different interfaces
+ * </p>
+ *
+ * @param semantics
+ * @param construct
+ * @return
+ */
+ public static ArrayList<String> generateCPClear(SemanticsChecker semantics,
+ CPClearConstruct construct) {
+ ArrayList<String> newCode = new ArrayList<String>();
+ // Add atomic return variable if the predicate accesses to it
+ if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
+ addAtomicReturn(semantics, construct);
+ }
+ // Generate redundant header files
+ newCode.add("\t"
+ + COMMENT("Automatically generated code for commit point clear: "
+ + construct.label));
+ newCode.add("");
+ // Add annotation
+
+ newCode.add("\t" + "if (" + construct.condition + ") {");
+ String structName = "cp_clear", anno = "annotation_cp_clear";
+ newCode.add("\t\t"
+ + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_CLEAR, structName));
+ // String labelNum = Integer.toString(semantics.commitPointLabel2Num
+ // .get(construct.label));
+ // String interfaceNum = getCPInterfaceNum(semantics, construct.label);
+ // newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num",
+ // labelNum));
+ // newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num",
+ // interfaceNum));
+ newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_CLEAR));
+ newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName));
+ newCode.add("\t\t" + ANNOTATE(semantics, anno));
+ newCode.add("\t" + "}");
+ return newCode;
+ }
+
+ /**
+ * <p>
+ * Commit point define should be unique to each interface, meaning that they
+ * are not shared between different interfaces
+ * </p>
+ *
+ * @param semantics
+ * @param construct
+ * @return
+ */
public static ArrayList<String> generateCPDefine(
SemanticsChecker semantics, CPDefineConstruct construct) {
ArrayList<String> newCode = new ArrayList<String>();
// Generate redundant header files
- newCode.add("\t" + COMMENT("Automatically generated code for commit point define: "
- + construct.label));
+ newCode.add("\t"
+ + COMMENT("Automatically generated code for commit point define: "
+ + construct.label));
newCode.add("");
// Add annotation
newCode.add("\t" + "if (" + construct.condition + ") {");
String structName = "cp_define", anno = "annotation_cp_define";
- newCode.add("\t\t" + 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 interfaceNum = getCPInterfaceNum(semantics, construct.label);
String potentialLabelNum = Integer
.toString(semantics.commitPointLabel2Num
.get(construct.potentialCPLabel));
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("\t\t"
+ + ASSIGN_TO_PTR(structName, "label_name", "\""
+ + construct.label + "\""));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(structName, "potential_cp_label_num",
+ potentialLabelNum));
+ newCode.add("\t\t"
+ + ASSIGN_TO_PTR(structName, "potential_label_name", "\""
+ + 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));
+ 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" + "}");