fixed rcu
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / codeGenerator / CodeVariables.java
index a97edc34e2aa968452e886ed83a0411b924721dd..aeace485b78e6c8453c9a7bfee3d1d9d3f07010f 100644 (file)
@@ -38,8 +38,8 @@ public class CodeVariables {
        public static final String HEADER_COMMON = "<common.h>";
        public static final String HEADER_SPECANNOTATION = "<specannotation.h>";
        public static final String HEADER_CDSTRACE = "<cdstrace.h>";
-       // public static final String CDSAnnotate = "cdsannotate";
-       public static final String CDSAnnotate = "_Z11cdsannotatemPv";
+       public static final String CDSAnnotate = "cdsannotate";
+       public static final String C_CDSAnnotate = "_Z11cdsannotatemPv";
        // public static final String CDSAnnotate = "cdsannotate";
        public static final String CDSAnnotateType = "SPEC_ANALYSIS";
        public static final String IDType = "call_id_t";
@@ -81,13 +81,22 @@ public class CodeVariables {
        public static final String SPEC_TAG_CURRENT = "current";
        public static final String SPEC_TAG_NEXT = "next";
 
-       public static final String MODEL_MALLOC = "model_malloc";
 
        // Macro
        public static final String MACRO_ID = "__ID__";
        public static final String MACRO_COND = "__COND_SAT__";
        public static final String MACRO_RETURN = "__RET__";
        public static final String MACRO_ATOMIC_RETURN = "__ATOMIC_RET__";
+       
+       public static String CDSAnnotate(SemanticsChecker semantics) {
+               String LANG = semantics.getOption("LANG");
+               boolean isCPP = LANG == null || !LANG.equals("C");
+               if (isCPP) {
+                       return CDSAnnotate;
+               } else {
+                       return C_CDSAnnotate;
+               }
+       }
 
        public static void printCode(ArrayList<String> code) {
                for (int i = 0; i < code.size(); i++) {
@@ -163,8 +172,8 @@ public class CodeVariables {
                return type + " " + var + " = " + val + ";";
        }
 
-       private static String ANNOTATE(String structName) {
-               return CDSAnnotate + "(" + CDSAnnotateType + ", " + structName + ");";
+       private static String ANNOTATE(SemanticsChecker semantics, String structName) {
+               return CDSAnnotate(semantics) + "(" + CDSAnnotateType + ", " + structName + ");";
        }
 
        private static ArrayList<String> DEFINE_INFO_STRUCT(String interfaceName,
@@ -400,7 +409,7 @@ public class CodeVariables {
                newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
                newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INIT));
                newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName));
-               newCode.add(ANNOTATE(anno));
+               newCode.add(ANNOTATE(semantics, anno));
 
                newCode.add("");
                // Init user-defined variables
@@ -512,17 +521,24 @@ public class CodeVariables {
        }
 
        // 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>();
+//     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(COMMENT("Declaration of the wrapper"));
-               String templateStr = header.getTemplateFullStr();
-               newCode.add(templateStr);
-               newCode.add(header.getFuncStr() + ";");
-               newCode.add("");
-
-               return newCode;
+               ArrayList<String> declaration = new ArrayList<String>();
+               declaration.add(header.getRenamedHeader(SPEC_INTERFACE_WRAPPER).getDeclaration() + ";");
+               return declaration;
        }
 
        // Only generate the definition of the wrapper, don't do any renaming
@@ -548,7 +564,7 @@ public class CodeVariables {
                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));
+               newCode.add(ANNOTATE(semantics, anno));
                // Call original renamed function
                if (header.returnType.equals("void")) {
                        newCode.add(header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";");
@@ -571,7 +587,7 @@ public class CodeVariables {
                        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(ANNOTATE(semantics, anno));
                        newCode.add("}");
                        newCode.add("");
                }
@@ -586,7 +602,7 @@ public class CodeVariables {
                        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(ANNOTATE(semantics, anno));
                        newCode.add("");
                }
                // Interface end
@@ -615,7 +631,7 @@ public class CodeVariables {
                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));
+               newCode.add(ANNOTATE(semantics, anno));
                // Return __RET__ if it's not void
                if (!header.returnType.equals("void")) {
                        newCode.add("return " + MACRO_RETURN + ";");
@@ -689,7 +705,7 @@ public class CodeVariables {
                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(ANNOTATE(semantics, anno));
                newCode.add("}");
                return newCode;
        }
@@ -715,7 +731,7 @@ public class CodeVariables {
                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(ANNOTATE(semantics, anno));
                newCode.add("}");
                return newCode;
        }
@@ -737,7 +753,7 @@ public class CodeVariables {
                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(ANNOTATE(semantics, anno));
                newCode.add("}");
                return newCode;
        }