X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=src%2Fedu%2Fuci%2Feecs%2FspecCompiler%2FcodeGenerator%2FCodeVariables.java;h=47c2e9c3cfbffec404a443200a3f506e8a1d4927;hb=0332e0e5575b7d717bccad0b53f7a4b87c1ca969;hp=a97edc34e2aa968452e886ed83a0411b924721dd;hpb=e551d9733ed4e29fe2928713c34ad3e58e424e95;p=cdsspec-compiler.git diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java index a97edc3..47c2e9c 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java @@ -28,8 +28,8 @@ public class CodeVariables { public static final String HEADER_THREADS = ""; public static final String HEADER_STDINT = ""; public static final String HEADER_MODELMEMORY = ""; - public static final String ThreadIDType = "thrd_t"; - public static final String GET_THREAD_ID = "thrd_current"; + public static final String HEADER_MODELTYPES = ""; + public static final String ThreadIDType = "thread_id_t"; public static final String BOOLEAN = "bool"; public static final String UINT64 = "uint64_t"; @@ -38,8 +38,7 @@ 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 CDSAnnotate = "_Z11cdsannotatemPv"; + public static final String CDSAnnotate = "cdsannotate"; // public static final String CDSAnnotate = "cdsannotate"; public static final String CDSAnnotateType = "SPEC_ANALYSIS"; public static final String IDType = "call_id_t"; @@ -81,13 +80,12 @@ 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 final String MACRO_THREAD_ID = "__TID__"; public static void printCode(ArrayList code) { for (int i = 0; i < code.size(); i++) { @@ -163,7 +161,7 @@ public class CodeVariables { return type + " " + var + " = " + val + ";"; } - private static String ANNOTATE(String structName) { + private static String ANNOTATE(SemanticsChecker semantics, String structName) { return CDSAnnotate + "(" + CDSAnnotateType + ", " + structName + ");"; } @@ -181,10 +179,31 @@ public class CodeVariables { return code; } - private static ArrayList DEFINE_ID_FUNC(String interfaceName, - String idCode) { + private static ArrayList DEFINE_ID_FUNC( + InterfaceConstruct construct, FunctionHeader header) { + String interfaceName = construct.name; ArrayList code = new ArrayList(); - code.add("inline static " + IDType + " " + interfaceName + "_id() {"); + String idCode = construct.idCode; + code.add("inline static " + IDType + " " + interfaceName + "_id(" + + "void *info, " + ThreadIDType + " " + MACRO_THREAD_ID + ") {"); + + // Read info struct + if (!header.returnType.equals("void") || header.args.size() != 0) { + String infoStructType = interfaceName + "_info", infoStructName = "theInfo"; + code.add(DECLARE_DEFINE(infoStructType + "*", infoStructName, + BRACE(infoStructType + "*") + "info")); + if (!header.returnType.equals("void")) { + code.add((DECLARE_DEFINE(header.returnType, MACRO_RETURN, + GET_FIELD_BY_PTR(infoStructName, MACRO_RETURN)))); + } + for (int i = 0; i < header.args.size(); i++) { + String type = header.args.get(i).type, var = header.args.get(i).name; + code.add((DECLARE_DEFINE(type, var, + GET_FIELD_BY_PTR(infoStructName, var)))); + } + code.add(""); + } + if (!idCode.equals("")) { code.add(DECLARE_DEFINE(IDType, MACRO_ID, idCode)); } else { @@ -200,8 +219,8 @@ public class CodeVariables { String interfaceName = construct.name; ArrayList code = new ArrayList(); code.add("inline static bool " + interfaceName - + "_check_action(void *info, " + IDType + " " + MACRO_ID - + ") {"); + + "_check_action(void *info, " + IDType + " " + MACRO_ID + ", " + + ThreadIDType + " " + MACRO_THREAD_ID + ") {"); code.add(DECLARE("bool", "check_passed")); // Read info struct if (!header.returnType.equals("void") || header.args.size() != 0) { @@ -258,10 +277,11 @@ public class CodeVariables { headers.add(HEADER_STDLIB); headers.add(HEADER_STDINT); headers.add(HEADER_MODELMEMORY); + headers.add(HEADER_MODELTYPES); + headers.add(HEADER_SPEC_LIB); headers.add(HEADER_STDINT); headers.add(HEADER_CDSANNOTATE); - headers.add(HEADER_COMMON); - headers.add(HEADER_SPEC_LIB); + // headers.add(HEADER_COMMON); headers.add(HEADER_SPECANNOTATION); return headers; } @@ -305,7 +325,6 @@ public class CodeVariables { ArrayList newCode = new ArrayList(); HashSet allHeaders = getAllHeaders(semantics); - SequentialDefineSubConstruct code = construct.code; // User-defined structs first newCode.add(COMMENT("All other user-defined structs")); @@ -349,7 +368,7 @@ public class CodeVariables { // Define ID function newCode.add(COMMENT("ID function of interface: " + interfaceName)); - newCode.addAll(DEFINE_ID_FUNC(interfaceName, iConstruct.idCode)); + newCode.addAll(DEFINE_ID_FUNC(iConstruct, funcHeader)); newCode.add(COMMENT("End of ID function: " + interfaceName)); newCode.add(""); @@ -365,9 +384,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")); @@ -400,7 +421,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 @@ -429,7 +450,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)); @@ -438,7 +459,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); @@ -512,17 +533,26 @@ 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(); + // 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) { - 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; + 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 @@ -544,11 +574,12 @@ public class CodeVariables { newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN, "interface_begin")); newCode.add(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(anno)); + newCode.add(ANNOTATE(semantics, anno)); // Call original renamed function if (header.returnType.equals("void")) { newCode.add(header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";"); @@ -571,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("}"); newCode.add(""); } @@ -586,7 +617,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 +646,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 +720,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 +746,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 +768,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; }