X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=src%2Fedu%2Fuci%2Feecs%2FspecCompiler%2FcodeGenerator%2FCodeVariables.java;h=999221bce28b81e3b703969a8debc45e2d049556;hp=fb1b520202f77d755c22a73f2d6936e009468842;hb=60246219b510f28980a6f93f615458e41262a23f;hpb=161d269d279b9c77640e8658d794d503db8ad8a2
diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java
index fb1b520..999221b 100644
--- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java
+++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java
@@ -20,6 +20,14 @@ import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
+/**
+ *
+ * Defines a list of commonly used constant strings.
+ *
+ *
+ * @author peizhaoo
+ *
+ */
public class CodeVariables {
// C++ code or library
public static final String HEADER_STDLIB = "";
@@ -49,6 +57,7 @@ public class CodeVariables {
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";
@@ -410,6 +419,22 @@ public class CodeVariables {
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
@@ -435,6 +460,10 @@ public class CodeVariables {
+ 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, "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"
@@ -450,10 +479,9 @@ public class CodeVariables {
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);
@@ -591,6 +619,9 @@ public class CodeVariables {
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));
@@ -759,6 +790,16 @@ public class CodeVariables {
String labelNum = Integer.toString(semantics.commitPointLabel2Num
.get(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 + "\""));
+ 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",
@@ -768,8 +809,9 @@ public class CodeVariables {
newCode.add("\t" + "}");
return newCode;
}
-
- public static String getCPInterfaceNum(SemanticsChecker semantics, String commitPointLabel) {
+
+ public static String getCPInterfaceNum(SemanticsChecker semantics,
+ String commitPointLabel) {
HashMap cp2Interface = semantics.CPLabel2InterfaceConstruct;
InterfaceConstruct iConstruct = cp2Interface.get(commitPointLabel);
String interfaceName = iConstruct.name;
@@ -780,8 +822,8 @@ public class CodeVariables {
/**
*
- * Commit point define check should be unique to each interface, meaning that they
- * are not shared between different interfaces
+ * Commit point define check should be unique to each interface, meaning
+ * that they are not shared between different interfaces
*
*
* @param semantics
@@ -801,7 +843,7 @@ public class CodeVariables {
+ 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"
@@ -810,7 +852,18 @@ public class CodeVariables {
.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"
+ + 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));
@@ -819,19 +872,19 @@ public class CodeVariables {
newCode.add("\t" + "}");
return newCode;
}
-
+
/**
*
- * Commit point define check should be unique to each interface, meaning that they
- * are not shared between different interfaces
+ * Commit point define check should be unique to each interface, meaning
+ * that they are not shared between different interfaces
*
*
* @param semantics
* @param construct
* @return
*/
- public static ArrayList generateCPClear(
- SemanticsChecker semantics, CPClearConstruct construct) {
+ public static ArrayList generateCPClear(SemanticsChecker semantics,
+ CPClearConstruct construct) {
ArrayList newCode = new ArrayList();
// Add atomic return variable if the predicate accesses to it
if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
@@ -843,19 +896,21 @@ public class CodeVariables {
+ 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));
+ // 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_DEFINE_CHECK));
+ + 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" + "}");
@@ -892,10 +947,24 @@ public class CodeVariables {
.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, "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, "interface_num", interfaceNum));
+ 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));