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=ea1cb66dcdf3c9799d32261cb46b029d18a70eb7;hp=b79d38b962202a170664a65a696e99bd579325b9;hb=b779fde36fd5836709293c63945964d8c42cee1f;hpb=f7d72aaac976fe732a65c775855ee2e588ba847f diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java index b79d38b..ea1cb66 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java @@ -1,6 +1,7 @@ package edu.uci.eecs.specCompiler.codeGenerator; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.io.File; @@ -37,8 +38,9 @@ public class CodeVariables { public static final String HEADER_COMMON = ""; public static final String HEADER_SPECANNOTATION = ""; public static final String HEADER_CDSTRACE = ""; + public static final String CDSAnnotate = "cdsannotate"; + public static final String C_CDSAnnotate = "_Z11cdsannotatemPv"; // public static final String CDSAnnotate = "cdsannotate"; - public static final String CDSAnnotate = "_Z11cdsannotatemPv"; public static final String CDSAnnotateType = "SPEC_ANALYSIS"; public static final String IDType = "call_id_t"; @@ -59,7 +61,7 @@ public class CodeVariables { public static final String ANNO_HB_INIT = "anno_hb_init"; public static final String ANNO_INTERFACE_BEGIN = "anno_interface_begin"; public static final String ANNO_INTERFACE_END = "anno_interface_end"; - public static final String ANNO_POTENTIAL_CP_DEFINE = "anno_potentail_cp_define"; + 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_HB_CONDITION = "anno_hb_condition"; @@ -78,14 +80,23 @@ public class CodeVariables { public static final String SPEC_TAG = "spec_tag"; 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 code) { for (int i = 0; i < code.size(); i++) { @@ -161,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 DEFINE_INFO_STRUCT(String interfaceName, @@ -247,12 +258,20 @@ public class CodeVariables { return code; } - private static HashSet getAllHeaders(SemanticsChecker semantics) { + public static HashSet getAllHeaders(SemanticsChecker semantics) { HashSet headers = new HashSet(); for (String interfaceName : semantics.interfaceName2Construct.keySet()) { File f = semantics.interfaceName2Construct.get(interfaceName).file; headers.addAll(semantics.srcFilesInfo.get(f).headers); } + headers.add(HEADER_STDLIB); + headers.add(HEADER_STDINT); + headers.add(HEADER_MODELMEMORY); + headers.add(HEADER_STDINT); + headers.add(HEADER_CDSANNOTATE); +// headers.add(HEADER_COMMON); + headers.add(HEADER_SPEC_LIB); + headers.add(HEADER_SPECANNOTATION); return headers; } @@ -295,21 +314,6 @@ public class CodeVariables { ArrayList newCode = new ArrayList(); HashSet allHeaders = getAllHeaders(semantics); - // All headers needed by the interface decalration - newCode.add(COMMENT("Include all the header files that contains the interface declaration")); - for (String header : allHeaders) { - newCode.add(INCLUDE(header)); - } - newCode.add(""); - // Other necessary headers - newCode.add(INCLUDE(HEADER_STDLIB)); - newCode.add(INCLUDE(HEADER_MODELMEMORY)); - newCode.add(INCLUDE(HEADER_STDINT)); - newCode.add(INCLUDE(HEADER_CDSANNOTATE)); - newCode.add(INCLUDE(HEADER_COMMON)); - newCode.add(INCLUDE(HEADER_SPEC_LIB)); - newCode.add(INCLUDE(HEADER_SPECANNOTATION)); - newCode.add(""); SequentialDefineSubConstruct code = construct.code; // User-defined structs first @@ -370,9 +374,11 @@ public class CodeVariables { String interfaceSize = Integer .toString(semantics.interfaceName2Construct.size()); newCode.add(DEFINE("INTERFACE_SIZE", interfaceSize)); - newCode.add(DECLARE("void**", "func_ptr_table")); + // Make it static + newCode.add("static " + DECLARE("void**", "func_ptr_table")); // Happens-before initialization rules - newCode.add(DECLARE(ANNO_HB_INIT + "**", "hb_init_table")); + // Should make it static + newCode.add("static " + DECLARE(ANNO_HB_INIT + "**", "hb_init_table")); newCode.add(""); newCode.add(COMMENT("Define function for sequential code initialization")); @@ -405,7 +411,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 @@ -434,7 +440,7 @@ public class CodeVariables { String templateDecl = semantics.getTemplateFullStr(); if (templateList == null) { newCode.add(DECLARE("void**", varPrefix + "func_ptr_table")); - newCode.add(DECLARE("void**", varPrefix + "hb_init_table")); + newCode.add(DECLARE("anno_hb_init**", varPrefix + "hb_init_table")); for (int i = 0; i < construct.code.declareVar.size(); i++) { VariableDeclaration varDecl = construct.code.declareVar.get(i); newCode.add(DECLARE(varDecl.type, varPrefix + varDecl.name)); @@ -443,7 +449,7 @@ public class CodeVariables { newCode.add(templateDecl); newCode.add(DECLARE("void**", varPrefix + "func_ptr_table")); newCode.add(templateDecl); - newCode.add(DECLARE("void**", varPrefix + "hb_init_table")); + newCode.add(DECLARE("anno_hb_init**", varPrefix + "hb_init_table")); for (int i = 0; i < construct.code.declareVar.size(); i++) { VariableDeclaration varDecl = construct.code.declareVar.get(i); newCode.add(templateDecl); @@ -517,17 +523,24 @@ public class CodeVariables { } // Only generate the declaration of the wrapper, don't do any renaming - public static ArrayList generateInterfaceWrapperDeclaration( - SemanticsChecker semantics, InterfaceConstruct construct) { - ArrayList newCode = new ArrayList(); +// public static ArrayList generateInterfaceWrapperDeclaration( +// SemanticsChecker semantics, InterfaceConstruct construct) { +// ArrayList newCode = new ArrayList(); +// 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 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 declaration = new ArrayList(); + declaration.add(header.getRenamedHeader(SPEC_INTERFACE_WRAPPER).getDeclaration() + ";"); + return declaration; } // Only generate the definition of the wrapper, don't do any renaming @@ -535,12 +548,6 @@ public class CodeVariables { SemanticsChecker semantics, InterfaceConstruct construct) { ArrayList newCode = new ArrayList(); String interfaceName = construct.name; - // Generate necessary header file (might be redundant but never mind) - newCode.add(INCLUDE(HEADER_STDLIB)); - newCode.add(INCLUDE(HEADER_MODELMEMORY)); - newCode.add(INCLUDE(HEADER_CDSANNOTATE)); - newCode.add(INCLUDE(HEADER_SPECANNOTATION)); - newCode.add(INCLUDE(HEADER_SPEC_LIB)); FunctionHeader header = getFunctionHeader(semantics, construct); String interfaceNum = Integer.toString(semantics.interface2Num @@ -559,7 +566,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) + ";"); @@ -582,7 +589,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(""); } @@ -597,7 +604,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 @@ -626,7 +633,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 + ";"); @@ -687,10 +694,6 @@ public class CodeVariables { // Generate redundant header files newCode.add(COMMENT("Automatically generated code for potential commit point: " + construct.label)); - newCode.add(COMMENT("Include redundant headers")); - newCode.add(INCLUDE(HEADER_STDINT)); - newCode.add(INCLUDE(HEADER_CDSANNOTATE)); - newCode.add(INCLUDE(HEADER_SPECANNOTATION)); newCode.add(""); // Add annotation newCode.add("if (" + construct.condition + ") {"); @@ -704,7 +707,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; } @@ -719,9 +722,6 @@ public class CodeVariables { // Generate redundant header files newCode.add(COMMENT("Automatically generated code for commit point define check: " + construct.label)); - newCode.add(COMMENT("Include redundant headers")); - newCode.add(INCLUDE(HEADER_STDINT)); - newCode.add(INCLUDE(HEADER_CDSANNOTATE)); newCode.add(""); // Add annotation newCode.add("if (" + construct.condition + ") {"); @@ -733,7 +733,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; } @@ -755,7 +755,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; }