X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fuci%2Feecs%2FspecCompiler%2FcodeGenerator%2FCodeVariables.java;h=aeace485b78e6c8453c9a7bfee3d1d9d3f07010f;hb=c9d0845c129ac0c7d8ced2e04677006c333b2c73;hp=af2ebcaf218008363756bfda7412ea2e78b81b4f;hpb=99de26ee130b9bbf2dd336c02ac63da7914296f3;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 af2ebca..aeace48 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; @@ -26,6 +27,7 @@ public class CodeVariables { public static final String HEADER_STDLIB = ""; 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 BOOLEAN = "bool"; @@ -33,15 +35,17 @@ public class CodeVariables { // Model checker code public static final String HEADER_CDSANNOTATE = ""; + 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 C_CDSAnnotate = "_Z11cdsannotatemPv"; + // public static final String CDSAnnotate = "cdsannotate"; public static final String CDSAnnotateType = "SPEC_ANALYSIS"; public static final String IDType = "call_id_t"; public static final String SPEC_ANNO_TYPE = "spec_anno_type"; - public static final String SPEC_ANNO_TYPE_FUNC_TABLE_INIT = "FUNC_TABLE_INIT"; + public static final String SPEC_ANNO_TYPE_INIT = "INIT"; public static final String SPEC_ANNO_TYPE_HB_INIT = "HB_INIT"; public static final String SPEC_ANNO_TYPE_INTERFACE_BEGIN = "INTERFACE_BEGIN"; public static final String SPEC_ANNO_TYPE_HB_CONDITION = "HB_CONDITION"; @@ -53,11 +57,11 @@ public class CodeVariables { public static final String SPEC_ANNOTATION_FIELD_TYPE = "type"; public static final String SPEC_ANNOTATION_FIELD_ANNO = "annotation"; - public static final String ANNO_FUNC_TABLE_INIT = "anno_func_table_init"; + public static final String ANNO_INIT = "anno_init"; 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"; @@ -77,11 +81,22 @@ public class CodeVariables { public static final String SPEC_TAG_CURRENT = "current"; public static final String SPEC_TAG_NEXT = "next"; + // 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++) { @@ -134,6 +149,16 @@ public class CodeVariables { return structName + "->" + field + " = " + val + ";"; } + private static String ASSIGN_PTR_TO_PTR(String structName, String field, + String val) { + return structName + "->" + field + " = &" + val + ";"; + } + + private static String STRUCT_NEW_DECLARE_DEFINE(String type, String name) { + return "struct " + type + " *" + name + " = (struct " + type + + "*) malloc(sizeof(struct " + type + "));"; + } + private static String DECLARE(String type, String name) { return type + " " + name + ";"; } @@ -147,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, @@ -168,7 +193,7 @@ public class CodeVariables { private static ArrayList DEFINE_ID_FUNC(String interfaceName, String idCode) { ArrayList code = new ArrayList(); - code.add("static " + IDType + " " + interfaceName + "_id() {"); + code.add("inline static " + IDType + " " + interfaceName + "_id() {"); if (!idCode.equals("")) { code.add(DECLARE_DEFINE(IDType, MACRO_ID, idCode)); } else { @@ -183,8 +208,9 @@ public class CodeVariables { InterfaceConstruct construct, FunctionHeader header) { String interfaceName = construct.name; ArrayList code = new ArrayList(); - code.add("static bool " + interfaceName + "_check_action(void *info, " - + IDType + " " + MACRO_ID + ") {"); + code.add("inline static bool " + interfaceName + + "_check_action(void *info, " + IDType + " " + MACRO_ID + + ") {"); code.add(DECLARE("bool", "check_passed")); // Read info struct if (!header.returnType.equals("void") || header.args.size() != 0) { @@ -232,18 +258,26 @@ 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; } private static void makeFunctionStatic(ArrayList funcDefine) { String headLine = funcDefine.get(0); - headLine = "static " + headLine; + headLine = "inline static " + headLine; funcDefine.set(0, headLine); } @@ -255,13 +289,20 @@ public class CodeVariables { private static FunctionHeader getFunctionHeader(SemanticsChecker semantics, Construct construct) { ArrayList content = semantics.srcFilesInfo.get(construct.file).content; - String headerLine = content.get(construct.beginLineNum); + String headerLine = content.get(construct.beginLineNum), templateLine = null; if (headerLine.startsWith("template")) { + templateLine = headerLine; headerLine = content.get(construct.beginLineNum + 1); } headerLine = headerLine.substring(0, headerLine.indexOf(')') + 1); try { - return SpecParser.parseFuncHeader(headerLine); + FunctionHeader header = SpecParser.parseFuncHeader(headerLine); + if (templateLine != null) { + ArrayList templateArgs = SpecParser + .getTemplateArg(templateLine); + header.setTemplateList(templateArgs); + } + return header; } catch (ParseException e) { e.printStackTrace(); } @@ -273,19 +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_STDINT)); - newCode.add(INCLUDE(HEADER_CDSANNOTATE)); - newCode.add(INCLUDE(HEADER_SPEC_LIB)); - newCode.add(INCLUDE(HEADER_SPECANNOTATION)); - newCode.add(""); SequentialDefineSubConstruct code = construct.code; // User-defined structs first @@ -347,14 +375,16 @@ public class CodeVariables { .toString(semantics.interfaceName2Construct.size()); newCode.add(DEFINE("INTERFACE_SIZE", interfaceSize)); newCode.add(DECLARE("void**", "func_ptr_table")); + // Happens-before initialization rules + newCode.add(DECLARE(ANNO_HB_INIT + "**", "hb_init_table")); newCode.add(""); newCode.add(COMMENT("Define function for sequential code initialization")); - newCode.add("static void __sequential_init() {"); + newCode.add("inline static void __sequential_init() {"); // Init func_ptr_table newCode.add(COMMENT("Init func_ptr_table")); - newCode.add(ASSIGN("func_ptr_table", - "(void**) malloc(sizeof(void*) * 2)")); + newCode.add(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)); @@ -363,22 +393,28 @@ public class CodeVariables { newCode.add(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(COMMENT("Pass init info, including function table info & HB rules")); + String structName = "anno_init", anno = "init"; + newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INIT, structName)); + newCode.add(ASSIGN_TO_PTR(structName, "func_table", "func_ptr_table")); + newCode.add(ASSIGN_TO_PTR(structName, "func_table_size", + "INTERFACE_SIZE")); + newCode.add(ASSIGN_TO_PTR(structName, "hb_init_table", "hb_init_table")); + newCode.add(ASSIGN_TO_PTR(structName, "hb_init_table_size", + "HB_INIT_TABLE_SIZE")); + 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(semantics, anno)); + newCode.add(""); // Init user-defined variables newCode.addAll(construct.code.initVar); - // Pass function table info - newCode.add(COMMENT("Pass function table info")); - String structName = "anno_func_table_init", anno = "func_init"; - newCode.add(DECLARE(ANNO_FUNC_TABLE_INIT, structName)); - newCode.add(ASSIGN(structName, "size", "INTERFACE_SIZE")); - newCode.add(ASSIGN(structName, "table", "func_ptr_table")); - newCode.add(DECLARE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_FUNC_TABLE_INIT)); - newCode.add(ASSIGN_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(anno)); - - // Pass Happens-before relationship - newCode.addAll(generateHBInitAnnotation(semantics)); + newCode.add("}"); newCode.add(COMMENT("End of Global construct generation in class")); @@ -402,6 +438,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")); 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)); @@ -409,6 +446,8 @@ public class CodeVariables { } else { newCode.add(templateDecl); newCode.add(DECLARE("void**", varPrefix + "func_ptr_table")); + newCode.add(templateDecl); + newCode.add(DECLARE("void**", varPrefix + "hb_init_table")); for (int i = 0; i < construct.code.declareVar.size(); i++) { VariableDeclaration varDecl = construct.code.declareVar.get(i); newCode.add(templateDecl); @@ -421,12 +460,13 @@ public class CodeVariables { private static ArrayList generateHBInitAnnotation( SemanticsChecker semantics) { ArrayList newCode = new ArrayList(); + int hbConditionInitIdx = 0; for (ConditionalInterface left : semantics.getHBConditions().keySet()) { for (ConditionalInterface right : semantics.getHBConditions().get( left)) { String structVarName = "hbConditionInit" + hbConditionInitIdx; - String annotationVarName = "hb_init" + hbConditionInitIdx; + // String annotationVarName = "hb_init" + hbConditionInitIdx; hbConditionInitIdx++; String interfaceNumBefore = Integer .toString(semantics.interface2Num @@ -439,76 +479,92 @@ public class CodeVariables { .get(right.hbConditionLabel)); newCode.add(COMMENT(left + " -> " + right)); - newCode.add(ANNO_HB_INIT + " " + structVarName + ";"); - newCode.add(ASSIGN(structVarName, "interface_num_before", - interfaceNumBefore)); - newCode.add(ASSIGN(structVarName, "hb_condition_num_before", - hbLabelNumBefore)); - newCode.add(ASSIGN(structVarName, "interface_num_after", + newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT, + structVarName)); + newCode.add(ASSIGN_TO_PTR(structVarName, + "interface_num_before", interfaceNumBefore)); + newCode.add(ASSIGN_TO_PTR(structVarName, + "hb_condition_num_before", hbLabelNumBefore)); + newCode.add(ASSIGN_TO_PTR(structVarName, "interface_num_after", interfaceNumAfter)); - newCode.add(ASSIGN(structVarName, "hb_condition_num_after", - hbLabelNumAfter)); - - newCode.add(DECLARE(SPEC_ANNOTATION, annotationVarName)); - newCode.add(ASSIGN(annotationVarName, - SPEC_ANNOTATION_FIELD_TYPE, SPEC_ANNO_TYPE_HB_INIT)); - newCode.add(ASSIGN_PTR(annotationVarName, - SPEC_ANNOTATION_FIELD_ANNO, structVarName)); - newCode.add(ANNOTATE(annotationVarName)); + newCode.add(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)); } } + // Init hb_init_table + newCode.add(COMMENT("Init hb_init_table")); + newCode.add(ASSIGN("hb_init_table", "(" + ANNO_HB_INIT + + "**) malloc(sizeof(" + ANNO_HB_INIT + "*) * " + + hbConditionInitIdx + ")")); + // Define HB_INIT_TABLE_SIZE + newCode.add(DEFINE("HB_INIT_TABLE_SIZE", + Integer.toString(hbConditionInitIdx))); + for (int i = 0; i < hbConditionInitIdx; i++) { + newCode.add(ASSIGN("hb_init_table[" + i + "]", "hbConditionInit" + + i)); + } return newCode; } public static ArrayList generateEntryPointInitCall() { - ArrayList newCode = new ArrayList(1); + ArrayList newCode = new ArrayList(); newCode.add("__sequential_init();"); return newCode; } - public static ArrayList generateInterfaceWrapper( + // 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) { + FunctionHeader header = getFunctionHeader(semantics, construct); + 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 + public static ArrayList generateInterfaceWrapperDefinition( 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_THREADS)); - 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 .get(construct.name)); - // Rename the interface - renameInterface(semantics, construct); - InterfaceDefineConstruct defineConstruct = semantics.interfaceName2DefineConstruct - .get(interfaceName); - if (defineConstruct != null) { - renameInterface(semantics, defineConstruct); - } - - // Generate wrapper header - // If it's not in a class, we should declare the wrapper function - if (semantics.getClassName() == null) { - FunctionHeader renamedHeader = header - .getRenamedHeader(SPEC_INTERFACE_WRAPPER); - newCode.add(COMMENT("Declaration of the wrapper")); - newCode.add(renamedHeader + ";"); - newCode.add(""); - } - newCode.add(header.toString() + " {"); + + newCode.add(header.getTemplateFullStr()); + newCode.add(header.getFuncStr() + " {"); // Wrapper function body newCode.add(COMMENT("Interface begins")); // Interface begin String structName = "interface_begin"; - newCode.add(DECLARE(ANNO_INTERFACE_BEGIN, "interface_begin")); - newCode.add(ASSIGN(structName, "interface_num", interfaceNum)); + 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(DECLARE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN)); - newCode.add(ASSIGN_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(anno)); + 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(semantics, anno)); // Call original renamed function if (header.returnType.equals("void")) { newCode.add(header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";"); @@ -523,18 +579,32 @@ public class CodeVariables { .get(label)); newCode.add("if " + BRACE(condition) + " {"); structName = "hb_condition"; - newCode.add(DECLARE(ANNO_HB_CONDITION, structName)); - newCode.add(ASSIGN(structName, "interface_num", interfaceNum)); + newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName)); + newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); - newCode.add(ASSIGN(structName, "hb_condition_num", hbCondNum)); + newCode.add(ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum)); anno = "annotation_hb_condition"; - newCode.add(DECLARE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION)); - newCode.add(ASSIGN_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(anno)); + 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(semantics, anno)); newCode.add("}"); newCode.add(""); } + // Also add the true condition if any + if (semantics.containsConditionalInterface(new ConditionalInterface( + interfaceName, ""))) { + structName = "hb_condition"; + newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName)); + newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); + newCode.add(ASSIGN_TO_PTR(structName, "hb_condition_num", "0")); + anno = "annotation_hb_condition"; + 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(semantics, anno)); + newCode.add(""); + } // Interface end String infoStructType = null, infoName = null; if (!header.returnType.equals("void") || header.args.size() > 0) { @@ -555,13 +625,13 @@ public class CodeVariables { } structName = "interface_end"; anno = "annoation_interface_end"; - newCode.add(DECLARE(ANNO_INTERFACE_END, structName)); - newCode.add(ASSIGN(structName, "interface_num", interfaceNum)); - newCode.add(ASSIGN(structName, "info", infoName)); - newCode.add(DECLARE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END)); - newCode.add(ASSIGN_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(anno)); + newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName)); + newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); + newCode.add(ASSIGN_TO_PTR(structName, "info", infoName)); + 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(semantics, anno)); // Return __RET__ if it's not void if (!header.returnType.equals("void")) { newCode.add("return " + MACRO_RETURN + ";"); @@ -573,6 +643,7 @@ public class CodeVariables { return newCode; } + // Rename the interface name for declaration or definition public static void renameInterface(SemanticsChecker semantics, Construct construct) { FunctionHeader header = getFunctionHeader(semantics, construct); @@ -584,7 +655,21 @@ public class CodeVariables { lineNum++; } String newLine = header.getRenamedHeader(SPEC_INTERFACE_WRAPPER) - .toString() + " {"; + .toString(); + + if (construct instanceof InterfaceConstruct) { + InterfaceConstruct iConstruct = (InterfaceConstruct) construct; + InterfaceDefineConstruct defineConstruct = semantics.interfaceName2DefineConstruct + .get(iConstruct.name); + if (defineConstruct != null) { // There is a defineConstruct + newLine = newLine + " ;"; + renameInterface(semantics, defineConstruct); + } else { // This is a declare & define construct + newLine = newLine + " {"; + } + } else { + newLine = newLine + " {"; + } content.set(lineNum, newLine); } @@ -607,21 +692,20 @@ 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(""); // Add annotation newCode.add("if (" + construct.condition + ") {"); String structName = "potential_cp_define", anno = "annotation_potential_cp_define"; - newCode.add(DECLARE(ANNO_POTENTIAL_CP_DEFINE, structName)); + newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_POTENTIAL_CP_DEFINE, + structName)); String labelNum = Integer.toString(semantics.commitPointLabel2Num .get(construct.label)); - newCode.add(ASSIGN(structName, "label_num", labelNum)); - newCode.add(DECLARE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE)); - newCode.add(ASSIGN_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(anno)); + 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("}"); return newCode; } @@ -636,21 +720,18 @@ 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 + ") {"); String structName = "cp_define_check", anno = "annotation_cp_define_check"; - newCode.add(DECLARE(ANNO_CP_DEFINE_CHECK, structName)); + newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName)); String labelNum = Integer.toString(semantics.commitPointLabel2Num .get(construct.label)); - newCode.add(ASSIGN(structName, "label_num", labelNum)); - newCode.add(DECLARE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK)); - newCode.add(ASSIGN_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(anno)); + 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_CP_DEFINE_CHECK)); + newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add(ANNOTATE(semantics, anno)); newCode.add("}"); return newCode; } @@ -665,14 +746,14 @@ public class CodeVariables { // Add annotation newCode.add("if (" + construct.condition + ") {"); String structName = "cp_define", anno = "annotation_cp_define"; - newCode.add(DECLARE(ANNO_CP_DEFINE, structName)); + newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName)); String labelNum = Integer.toString(semantics.commitPointLabel2Num .get(construct.label)); - newCode.add(ASSIGN(structName, "label_num", labelNum)); - newCode.add(DECLARE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE)); - newCode.add(ASSIGN_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(anno)); + 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_CP_DEFINE)); + newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add(ANNOTATE(semantics, anno)); newCode.add("}"); return newCode; }