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=7e4ab29c446c74db5683957664c197fe86600aa7;hp=0e4a712e4c75e23c9794f11baa5a9b5057d44c02;hb=8ac7b8682c102a5c2661e7798c9a0f11cfcec4e3;hpb=9715bde2a0d400f34e601b5f5d8589a73eb46010 diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java index 0e4a712..7e4ab29 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java @@ -1,33 +1,42 @@ package edu.uci.eecs.specCompiler.codeGenerator; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.io.File; -import edu.uci.eecs.specCompiler.grammerParser.ParseException; -import edu.uci.eecs.specCompiler.grammerParser.SpecParser; +import edu.uci.eecs.specCompiler.grammerParser.utilParser.UtilParser; +import edu.uci.eecs.specCompiler.grammerParser.utilParser.ParseException; +import edu.uci.eecs.specCompiler.specExtraction.CPClearConstruct; import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct; import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct; +import edu.uci.eecs.specCompiler.specExtraction.CommutativityRule; import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface; import edu.uci.eecs.specCompiler.specExtraction.Construct; import edu.uci.eecs.specCompiler.specExtraction.FunctionHeader; import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct; -import edu.uci.eecs.specCompiler.specExtraction.IDExtractor; import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct; import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct; -import edu.uci.eecs.specCompiler.specExtraction.ParserUtils; import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct; import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct; -import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor; 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 = ""; public static final String HEADER_THREADS = ""; public static final String HEADER_STDINT = ""; - public static final String ThreadIDType = "thrd_t"; - public static final String GET_THREAD_ID = "thrd_current"; + public static final String HEADER_MODELMEMORY = ""; + 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"; @@ -36,31 +45,34 @@ 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 = "cdsannotate"; - public static final String CDSAnnotate = "_Z11cdsannotatemPv"; 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_HB_INIT = "HB_INIT"; + public static final String SPEC_ANNO_TYPE_INIT = "INIT"; + public static final String SPEC_ANNO_TYPE_HB_RULE = "HB_RULE"; public static final String SPEC_ANNO_TYPE_INTERFACE_BEGIN = "INTERFACE_BEGIN"; public static final String SPEC_ANNO_TYPE_HB_CONDITION = "HB_CONDITION"; 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"; 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_HB_INIT = "anno_hb_init"; + public static final String ANNO_INIT = "anno_init"; + public static final String HB_RULE = "hb_rule"; + public static final String COMMUTATIVITY_RULE = "commutativity_rule"; 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_CP_CLEAR = "anno_cp_clear"; public static final String ANNO_HB_CONDITION = "anno_hb_condition"; // Specification variables @@ -83,6 +95,7 @@ public class CodeVariables { 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++) { @@ -94,6 +107,10 @@ public class CodeVariables { return "/* " + comment + " */"; } + private static String SHORT_COMMENT(String comment) { + return " // " + comment; + } + private static String INCLUDE(String header) { return "#include " + header; } @@ -158,7 +175,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 + ");"; } @@ -176,16 +193,39 @@ 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("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("\t" + infoStructType + "*", + infoStructName, BRACE(infoStructType + "*") + "info")); + if (!header.returnType.equals("void")) { + code.add((DECLARE_DEFINE("\t" + 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("\t" + + (DECLARE_DEFINE(type, var, + GET_FIELD_BY_PTR(infoStructName, var)))); + } + code.add(""); + } + if (!idCode.equals("")) { - code.add(DECLARE_DEFINE(IDType, MACRO_ID, idCode)); + code.add("\t" + DECLARE_DEFINE(IDType, MACRO_ID, idCode)); } else { - code.add(DECLARE_DEFINE(IDType, MACRO_ID, DEFAULT_ID)); + code.add("\t" + DECLARE_DEFINE(IDType, MACRO_ID, DEFAULT_ID)); } - code.add("return " + MACRO_ID + ";"); + code.add("\treturn " + MACRO_ID + ";"); code.add("}"); return code; } @@ -194,67 +234,91 @@ 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(DECLARE("bool", "check_passed")); + code.add("inline static bool " + interfaceName + + "_check_action(void *info, " + IDType + " " + MACRO_ID + ", " + + ThreadIDType + " " + MACRO_THREAD_ID + ") {"); + code.add("\t" + DECLARE("bool", "check_passed")); // 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")); + code.add("\t" + + 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)))); + code.add("\t" + + (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("\t" + + (DECLARE_DEFINE(type, var, + GET_FIELD_BY_PTR(infoStructName, var)))); } code.add(""); } // __COND_SAT if (!construct.condition.equals("")) { - code.add(DECLARE_DEFINE("bool", MACRO_COND, construct.condition)); + code.add("\t" + + DECLARE_DEFINE("bool", MACRO_COND, construct.condition)); } // Check if (!construct.check.equals("")) { - code.add(ASSIGN("check_passed", construct.check)); - code.add("if (!check_passed) return false;"); + code.add("\t" + ASSIGN("check_passed", construct.check)); + code.add("\tif (!check_passed)"); + code.add("\t\treturn false;"); + } // Action if (construct.action.size() > 0) { - code.addAll(construct.action); + addAllCodeWithIndent(code, construct.action, "\t"); } // Post_check if (!construct.postCheck.equals("")) { - code.add(ASSIGN("check_passed", construct.postCheck)); - code.add("if (!check_passed) return false;"); + code.add("\t" + ASSIGN("check_passed", construct.postCheck)); + code.add("\tif (!check_passed)"); + code.add("\t\treturn false;"); } // Post_action if (construct.postAction.size() > 0) { - code.addAll(construct.postAction); + addAllCodeWithIndent(code, construct.postAction, "\t"); } // Return true finally - code.add("return true;"); + code.add("\treturn true;"); code.add("}"); return code; } - private static HashSet getAllHeaders(SemanticsChecker semantics) { + private static void addAllCodeWithIndent(ArrayList allCode, + ArrayList target, String indent) { + for (int i = 0; i < target.size(); i++) { + allCode.add(indent + target.get(i)); + } + } + + 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_MODELTYPES); + headers.add(HEADER_SPEC_LIB); + headers.add(HEADER_STDINT); + headers.add(HEADER_CDSANNOTATE); + // headers.add(HEADER_COMMON); + 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); } @@ -266,16 +330,16 @@ 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), templateLine = null; + String headerLine = content.get(construct.beginLineNum + 1), templateLine = null; if (headerLine.startsWith("template")) { templateLine = headerLine; - headerLine = content.get(construct.beginLineNum + 1); + headerLine = content.get(construct.beginLineNum + 2); } headerLine = headerLine.substring(0, headerLine.indexOf(')') + 1); try { - FunctionHeader header = SpecParser.parseFuncHeader(headerLine); + FunctionHeader header = UtilParser.parseFuncHeader(headerLine); if (templateLine != null) { - ArrayList templateArgs = SpecParser + ArrayList templateArgs = UtilParser .getTemplateArg(templateLine); header.setTemplateList(templateArgs); } @@ -291,21 +355,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_COMMON)); - newCode.add(INCLUDE(HEADER_SPEC_LIB)); - newCode.add(INCLUDE(HEADER_SPECANNOTATION)); - newCode.add(""); - SequentialDefineSubConstruct code = construct.code; // User-defined structs first newCode.add(COMMENT("All other user-defined structs")); @@ -349,7 +398,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,43 +414,128 @@ 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 + // Should make it static + newCode.add("static " + DECLARE(HB_RULE + "**", "hb_rule_table")); + + // Declare the Commutativity Rule table + newCode.add("static " + + DECLARE(COMMUTATIVITY_RULE + "**", "commutativity_rule_table")); + // Define the Commutativity Rule condition functions + ArrayList rules = semantics.getGlobalConstruct().commutativityRules; + for (int i = 0; i < rules.size(); i++) { + CommutativityRule rule = rules.get(i); + String infoStructType1 = rule.method1 + "_info"; + String infoStructType2 = rule.method2 + "_info"; + String condition = rule.condition; + String conditionFuncName = "CommutativityCondition" + + Integer.toString(i); + + // Replace the "_M1." and "_M2." with the actual info struct + condition = condition.replaceAll("_Method1 \\.", "_info1->"); + condition = condition.replaceAll("_Method2 \\.", "_info2->"); + + // Declare the signature of the condition function + newCode.add("inline static bool " + conditionFuncName + + "(void *info1, void *info2) {"); + + // Cast the "void*" type to the actual info type + newCode.add("\t" + + DECLARE_DEFINE(infoStructType1, "*_info1", "(" + + infoStructType1 + "*) info1")); + newCode.add("\t" + + DECLARE_DEFINE(infoStructType2, "*_info2", "(" + + infoStructType2 + "*) info2")); + newCode.add("\treturn " + condition + ";"); + + // End of the condition function + newCode.add("}"); + } newCode.add(""); + + // Beginning initialization + // 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("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*) * " - + semantics.interface2Num.size() + " * 2)")); + newCode.add("\t" + COMMENT("Init func_ptr_table")); + newCode.add("\t" + + 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)); - newCode.add(ASSIGN("func_ptr_table[2 * " + interfaceNum + "]", - "(void*) &" + interfaceName + "_id")); - newCode.add(ASSIGN("func_ptr_table[2 * " + interfaceNum + " + 1]", - "(void*) &" + interfaceName + "_check_action")); + newCode.add("\t" + + ASSIGN("func_ptr_table[2 * " + interfaceNum + "]", + "(void*) &" + interfaceName + "_id")); + newCode.add("\t" + + ASSIGN("func_ptr_table[2 * " + interfaceNum + " + 1]", + "(void*) &" + interfaceName + "_check_action")); } - 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(STRUCT_NEW_DECLARE_DEFINE(ANNO_FUNC_TABLE_INIT, structName)); - newCode.add(ASSIGN_TO_PTR(structName, "size", "INTERFACE_SIZE")); - newCode.add(ASSIGN_TO_PTR(structName, "table", "func_ptr_table")); - newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_FUNC_TABLE_INIT)); - newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(anno)); - - // Pass Happens-before relationship + + // Init Happens-before rules table newCode.addAll(generateHBInitAnnotation(semantics)); + + // Init Commutativity rules table + newCode.addAll(generateCommutativityAnnotation(semantics)); + + // Pass init info, including function table info & HB rules + newCode.add("\t" + + COMMENT("Pass init info, including function table info & HB rules & Commutativity 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", + "(void_func_t*) __SPEC_INIT__")); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "cleanup_func", + "(void_func_t*) __SPEC_CLEANUP__")); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "func_table", "func_ptr_table")); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "func_table_size", "INTERFACE_SIZE")); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "hb_rule_table", "hb_rule_table")); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "hb_rule_table_size", + "HB_RULE_TABLE_SIZE")); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "commutativity_rule_table", + "commutativity_rule_table")); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "commutativity_rule_table_size", + Integer.toString(rules.size()))); + + newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); + newCode.add("\t" + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INIT)); + newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add("\t" + ANNOTATE(semantics, anno)); + + newCode.add(""); newCode.add("}"); + newCode.add(""); + newCode.add(COMMENT("End of Global construct generation in class")); - printCode(newCode); + // printCode(newCode); return newCode; } @@ -421,6 +555,7 @@ public class CodeVariables { String templateDecl = semantics.getTemplateFullStr(); if (templateList == null) { newCode.add(DECLARE("void**", varPrefix + "func_ptr_table")); + newCode.add(DECLARE("hb_rule**", varPrefix + "hb_rule_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)); @@ -428,6 +563,8 @@ public class CodeVariables { } else { newCode.add(templateDecl); newCode.add(DECLARE("void**", varPrefix + "func_ptr_table")); + newCode.add(templateDecl); + newCode.add(DECLARE("hb_rule**", varPrefix + "hb_rule_table")); for (int i = 0; i < construct.code.declareVar.size(); i++) { VariableDeclaration varDecl = construct.code.declareVar.get(i); newCode.add(templateDecl); @@ -440,12 +577,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_rule" + hbConditionInitIdx; hbConditionInitIdx++; String interfaceNumBefore = Integer .toString(semantics.interface2Num @@ -456,49 +594,111 @@ public class CodeVariables { .get(right.interfaceName)), hbLabelNumAfter = Integer .toString(semantics.hbLabel2Num .get(right.hbConditionLabel)); - newCode.add(COMMENT(left + " -> " + right)); - - 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_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)); + newCode.add("\t" + COMMENT(left + " -> " + right)); + + newCode.add("\t" + + STRUCT_NEW_DECLARE_DEFINE(HB_RULE, structVarName)); + newCode.add("\t" + + ASSIGN_TO_PTR(structVarName, "interface_num_before", + interfaceNumBefore) + + SHORT_COMMENT(left.interfaceName)); + newCode.add("\t" + + ASSIGN_TO_PTR(structVarName, + "hb_condition_num_before", hbLabelNumBefore) + + SHORT_COMMENT(left.hbConditionLabel)); + newCode.add("\t" + + ASSIGN_TO_PTR(structVarName, "interface_num_after", + interfaceNumAfter) + + SHORT_COMMENT(right.interfaceName)); + newCode.add("\t" + + ASSIGN_TO_PTR(structVarName, + "hb_condition_num_after", hbLabelNumAfter) + + SHORT_COMMENT(right.hbConditionLabel)); } } + // Init hb_rule_table + newCode.add("\t" + COMMENT("Init hb_rule_table")); + newCode.add("\t" + + ASSIGN("hb_rule_table", "(" + HB_RULE + + "**) malloc(sizeof(" + HB_RULE + "*) * " + + hbConditionInitIdx + ")")); + // Define HB_RULE_TABLE_SIZE + newCode.add("\t" + + DEFINE("HB_RULE_TABLE_SIZE", + Integer.toString(hbConditionInitIdx))); + for (int i = 0; i < hbConditionInitIdx; i++) { + newCode.add("\t" + + ASSIGN("hb_rule_table[" + i + "]", "hbConditionInit" + i)); + } + return newCode; + } + + private static ArrayList generateCommutativityAnnotation( + SemanticsChecker semantics) { + ArrayList newCode = new ArrayList(); + ArrayList rules = semantics.getGlobalConstruct().commutativityRules; + + // Init commutativity_rule_table + newCode.add("\t" + COMMENT("Init commutativity_rule_table")); + + // Users have not defined any commutativity rules + if (rules.size() == 0) + return newCode; + + newCode.add("\t" + + ASSIGN("commutativity_rule_table", "(" + COMMUTATIVITY_RULE + + "**) malloc(sizeof(" + COMMUTATIVITY_RULE + "*) * " + + rules.size() + ")")); + + // Declare a rule pointer + newCode.add("\t" + DECLARE("commutativity_rule*", "rule")); + + for (int i = 0; i < rules.size(); i++) { + CommutativityRule rule = rules.get(i); + String interfaceNumBefore = Integer + .toString(semantics.interface2Num.get(rule.method1)); + String interfaceNumAfter = Integer.toString(semantics.interface2Num + .get(rule.method2)); + String conditionFuncName = "CommutativityCondition" + i; + + // Construct a new rule + newCode.add("\t" + + ASSIGN("rule", + "(commutativity_rule*) malloc (sizeof(commutativity_rule))")); + newCode.add("\t" + + ASSIGN_TO_PTR("rule", "interface_num_before", + interfaceNumBefore)); + newCode.add("\t" + + ASSIGN_TO_PTR("rule", "interface_num_after", + interfaceNumAfter)); + newCode.add("\t" + + ASSIGN_TO_PTR("rule", "rule", + "\"" + rule.condition + "\"")); + + newCode.add("\t" + + ASSIGN_TO_PTR("rule", "condition", conditionFuncName)); + + // Assign the rule to the corresponding commutativity table slot + newCode.add("\t" + + ASSIGN("commutativity_rule_table[" + i + "]", "rule")); + } + return newCode; } public static ArrayList generateEntryPointInitCall() { - ArrayList newCode = new ArrayList(1); - newCode.add("__sequential_init();"); + ArrayList newCode = new ArrayList(); + newCode.add("\t" + "__sequential_init();"); return newCode; } - // 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; + 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 @@ -506,68 +706,84 @@ 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_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)); - + newCode.add(header.getTemplateFullStr()); newCode.add(header.getFuncStr() + " {"); // Wrapper function body - newCode.add(COMMENT("Interface begins")); + newCode.add("\t" + COMMENT("Interface begins")); // Interface begin String structName = "interface_begin"; - newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN, - "interface_begin")); - newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); + newCode.add("\t" + + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN, + "interface_begin")); + 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(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("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); + newCode.add("\t" + + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN)); + newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add("\t" + ANNOTATE(semantics, anno)); // Call original renamed function if (header.returnType.equals("void")) { - newCode.add(header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";"); + newCode.add("\t" + header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + + ";"); } else { - newCode.add(DECLARE_DEFINE(header.returnType, MACRO_RETURN, - header.getRenamedCall(SPEC_INTERFACE_WRAPPER))); + newCode.add("\t" + + DECLARE_DEFINE(header.returnType, MACRO_RETURN, + header.getRenamedCall(SPEC_INTERFACE_WRAPPER))); } // HB conditions for (String label : construct.hbConditions.keySet()) { String condition = construct.hbConditions.get(label); String hbCondNum = Integer.toString(semantics.hbLabel2Num .get(label)); - newCode.add("if " + BRACE(condition) + " {"); + newCode.add("\t" + "if " + BRACE(condition) + " {"); structName = "hb_condition"; - newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName)); - newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); + newCode.add("\t\t" + + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName)); + newCode.add("\t\t" + + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum) + + SHORT_COMMENT(construct.name)); - newCode.add(ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum)); + newCode.add("\t\t" + + ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum)); 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(anno)); - newCode.add("}"); + newCode.add("\t\t" + + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); + newCode.add("\t\t" + + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION)); + newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add("\t\t" + ANNOTATE(semantics, anno)); + newCode.add("\t" + "}"); 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")); + newCode.add("\t" + + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName)); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum) + + SHORT_COMMENT(construct.name)); + newCode.add("\t" + + 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(anno)); + newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); + newCode.add("\t" + + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION)); + newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add("\t" + ANNOTATE(semantics, anno)); newCode.add(""); } // Interface end @@ -575,31 +791,37 @@ public class CodeVariables { if (!header.returnType.equals("void") || header.args.size() > 0) { infoStructType = interfaceName + "_info"; infoName = "info"; - newCode.add(DECLARE_DEFINE(infoStructType + "*", infoName, - BRACE(infoStructType + "*") + " malloc(sizeof(" - + infoStructType + "))")); + newCode.add("\t" + + DECLARE_DEFINE(infoStructType + "*", infoName, + BRACE(infoStructType + "*") + " malloc(sizeof(" + + infoStructType + "))")); if (!header.returnType.equals("void")) { - newCode.add(ASSIGN_TO_PTR(infoName, MACRO_RETURN, MACRO_RETURN)); + newCode.add("\t" + + ASSIGN_TO_PTR(infoName, MACRO_RETURN, MACRO_RETURN)); } for (int i = 0; i < header.args.size(); i++) { String argName = header.args.get(i).name; - newCode.add(ASSIGN_TO_PTR(infoName, argName, argName)); + newCode.add("\t" + ASSIGN_TO_PTR(infoName, argName, argName)); } } else { infoName = "NULL"; } structName = "interface_end"; anno = "annoation_interface_end"; - 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(anno)); + newCode.add("\t" + + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName)); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum) + + SHORT_COMMENT(construct.name)); + newCode.add("\t" + ASSIGN_TO_PTR(structName, "info", infoName)); + newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); + newCode.add("\t" + + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END)); + newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add("\t" + ANNOTATE(semantics, anno)); // Return __RET__ if it's not void if (!header.returnType.equals("void")) { - newCode.add("return " + MACRO_RETURN + ";"); + newCode.add("\t" + "return " + MACRO_RETURN + ";"); } // End of the wrapper function newCode.add("}"); @@ -621,6 +843,7 @@ public class CodeVariables { } String newLine = header.getRenamedHeader(SPEC_INTERFACE_WRAPPER) .toString(); + String oldLine = content.get(lineNum + 1); if (construct instanceof InterfaceConstruct) { InterfaceConstruct iConstruct = (InterfaceConstruct) construct; @@ -630,12 +853,15 @@ public class CodeVariables { newLine = newLine + " ;"; renameInterface(semantics, defineConstruct); } else { // This is a declare & define construct - newLine = newLine + " {"; + if (oldLine.indexOf('{') != -1) + newLine = newLine + " {"; } } else { - newLine = newLine + " {"; + if (oldLine.indexOf('{') != -1) + newLine = newLine + " {"; } - content.set(lineNum, newLine); + + content.set(lineNum + 1, newLine); } public static void addAtomicReturn(SemanticsChecker semantics, @@ -655,30 +881,53 @@ public class CodeVariables { addAtomicReturn(semantics, construct); } // 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("\t" + + COMMENT("Automatically generated code for potential commit point: " + + construct.label)); newCode.add(""); // Add annotation - newCode.add("if (" + construct.condition + ") {"); + newCode.add("\t" + "if (" + construct.condition + ") {"); String structName = "potential_cp_define", anno = "annotation_potential_cp_define"; - newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_POTENTIAL_CP_DEFINE, - structName)); + newCode.add("\t\t" + + STRUCT_NEW_DECLARE_DEFINE(ANNO_POTENTIAL_CP_DEFINE, + structName)); String labelNum = Integer.toString(semantics.commitPointLabel2Num .get(construct.label)); - 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(anno)); - newCode.add("}"); + 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" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); + newCode.add("\t\t" + + ASSIGN_TO_PTR(anno, "type", + SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE)); + newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add("\t\t" + ANNOTATE(semantics, anno)); + newCode.add("\t" + "}"); return newCode; } + public static String getCPInterfaceNum(SemanticsChecker semantics, + String commitPointLabel) { + HashMap cp2Interface = semantics.CPLabel2InterfaceConstruct; + InterfaceConstruct iConstruct = cp2Interface.get(commitPointLabel); + String interfaceName = iConstruct.name; + String interfaceNum = Integer.toString(semantics.interface2Num + .get(interfaceName)); + return interfaceNum; + } + + /** + *

+ * 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 generateCPDefineCheck( SemanticsChecker semantics, CPDefineCheckConstruct construct) { ArrayList newCode = new ArrayList(); @@ -687,46 +936,128 @@ public class CodeVariables { addAtomicReturn(semantics, construct); } // 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("\t" + + COMMENT("Automatically generated code for commit point define check: " + + construct.label)); newCode.add(""); // Add annotation - newCode.add("if (" + construct.condition + ") {"); + + newCode.add("\t" + "if (" + construct.condition + ") {"); String structName = "cp_define_check", anno = "annotation_cp_define_check"; - newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName)); + newCode.add("\t\t" + + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE_CHECK, structName)); String labelNum = Integer.toString(semantics.commitPointLabel2Num .get(construct.label)); - 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(anno)); - newCode.add("}"); + 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, "label_name", "\"" + + construct.label + "\"")); + 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)); + newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add("\t\t" + ANNOTATE(semantics, anno)); + newCode.add("\t" + "}"); + return newCode; + } + + /** + *

+ * 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) { + ArrayList newCode = new ArrayList(); + // Add atomic return variable if the predicate accesses to it + if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) { + addAtomicReturn(semantics, construct); + } + // Generate redundant header files + newCode.add("\t" + + COMMENT("Automatically generated code for commit point clear: " + + 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 labelName = construct.label; + newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_name", + "\"" + labelName + "\"")); + newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", + labelNum)); + + newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); + newCode.add("\t\t" + + 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" + "}"); return newCode; } + /** + *

+ * Commit point define should be unique to each interface, meaning that they + * are not shared between different interfaces + *

+ * + * @param semantics + * @param construct + * @return + */ public static ArrayList generateCPDefine( SemanticsChecker semantics, CPDefineConstruct construct) { ArrayList newCode = new ArrayList(); // Generate redundant header files - newCode.add(COMMENT("Automatically generated code for commit point define check: " - + construct.label)); + newCode.add("\t" + + COMMENT("Automatically generated code for commit point define: " + + construct.label)); newCode.add(""); // Add annotation - newCode.add("if (" + construct.condition + ") {"); + newCode.add("\t" + "if (" + construct.condition + ") {"); String structName = "cp_define", anno = "annotation_cp_define"; - newCode.add(STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName)); + newCode.add("\t\t" + + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_DEFINE, structName)); String labelNum = Integer.toString(semantics.commitPointLabel2Num .get(construct.label)); - 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(anno)); - newCode.add("}"); + String interfaceNum = getCPInterfaceNum(semantics, construct.label); + String potentialLabelNum = Integer + .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, "potential_label_name", "\"" + + construct.potentialCPLabel + "\"")); + 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)); + newCode.add("\t\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); + newCode.add("\t\t" + ANNOTATE(semantics, anno)); + newCode.add("\t" + "}"); return newCode; } }