From: Peizhao Ou Date: Tue, 18 Mar 2014 00:26:15 +0000 (-0700) Subject: more X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=commitdiff_plain;h=b870b2732f7a88f0804510bd5c88d0b5d6d4ddd3;hp=01b38b1079dea8b5d197bc246d7aced60496edff more --- diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java index af9bde4..1d78d6d 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java @@ -275,8 +275,10 @@ public class CodeGenerator { File[] srcLinuxRWLocks = { new File(homeDir + "/benchmark/linuxrwlocks/linuxrwlocks.c") }; - File[] srcHashtable = { new File(homeDir - + "/benchmark/cliffc-hashtable/simplified_cliffc_hashtable.h") }; + File[] srcHashtable = { + new File(homeDir + + "/benchmark/cliffc-hashtable/cliffc_hashtable.h"), + new File(homeDir + "/benchmark/cliffc-hashtable/main.cc") }; File[] srcMSQueue = { new File(homeDir + "/benchmark/ms-queue/my_queue.c"), @@ -304,10 +306,10 @@ public class CodeGenerator { new File(homeDir + "/benchmark/mpmc-queue/mpmc-queue.h"), new File(homeDir + "/benchmark/mpmc-queue/mpmc-queue.cc") }; -// File[][] sources = { srcLinuxRWLocks, srcHashtable, srcMSQueue, srcRCU, -// srcDeque, srcMCSLock, srcSPSCQueue, srcMPMCQueue }; + File[][] sources = { srcLinuxRWLocks, srcHashtable, srcMSQueue, srcRCU, + srcDeque, srcMCSLock, srcSPSCQueue, srcMPMCQueue }; - File[][] sources = { srcLinuxRWLocks }; +// File[][] sources = { srcDeque }; // Compile all the benchmarks for (int i = 0; i < sources.length; i++) { CodeGenerator gen = new CodeGenerator(sources[i]); diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java index 53f40bb..d0a935c 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java @@ -94,6 +94,10 @@ public class CodeVariables { return "/* " + comment + " */"; } + private static String SHORT_COMMENT(String comment) { + return " // " + comment; + } + private static String INCLUDE(String header) { return "#include " + header; } @@ -408,29 +412,36 @@ public class CodeVariables { newCode.add("inline static void __sequential_init() {"); // Init func_ptr_table newCode.add("\t" + COMMENT("Init func_ptr_table")); - newCode.add("\t" + ASSIGN("func_ptr_table", "(void**) malloc(sizeof(void*) * " - + semantics.interface2Num.size() + " * 2)")); + 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("\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("\t" + + ASSIGN("func_ptr_table[2 * " + interfaceNum + "]", + "(void*) &" + interfaceName + "_id")); + newCode.add("\t" + + 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("\t" + COMMENT("Pass init info, including function table info & HB rules")); + newCode.add("\t" + + COMMENT("Pass init info, including function table info & HB rules")); String structName = "anno_init", anno = "init"; newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INIT, structName)); - 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_init_table", "hb_init_table")); - newCode.add("\t" + ASSIGN_TO_PTR(structName, "hb_init_table_size", - "HB_INIT_TABLE_SIZE")); + 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_init_table", "hb_init_table")); + newCode.add("\t" + + ASSIGN_TO_PTR(structName, "hb_init_table_size", + "HB_INIT_TABLE_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)); @@ -443,7 +454,7 @@ public class CodeVariables { newCode.add("}"); newCode.add(COMMENT("End of Global construct generation in class")); - //printCode(newCode); + // printCode(newCode); return newCode; } @@ -504,61 +515,49 @@ public class CodeVariables { .get(right.hbConditionLabel)); newCode.add("\t" + COMMENT(left + " -> " + right)); - newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT, - structVarName)); - newCode.add("\t" + ASSIGN_TO_PTR(structVarName, - "interface_num_before", interfaceNumBefore)); - newCode.add("\t" + ASSIGN_TO_PTR(structVarName, - "hb_condition_num_before", hbLabelNumBefore)); - newCode.add("\t" + ASSIGN_TO_PTR(structVarName, "interface_num_after", - interfaceNumAfter)); - newCode.add("\t" + 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" + + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_INIT, 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_init_table newCode.add("\t" + COMMENT("Init hb_init_table")); - newCode.add("\t" + ASSIGN("hb_init_table", "(" + ANNO_HB_INIT - + "**) malloc(sizeof(" + ANNO_HB_INIT + "*) * " - + hbConditionInitIdx + ")")); + newCode.add("\t" + + ASSIGN("hb_init_table", "(" + ANNO_HB_INIT + + "**) malloc(sizeof(" + ANNO_HB_INIT + "*) * " + + hbConditionInitIdx + ")")); // Define HB_INIT_TABLE_SIZE - newCode.add("\t" + DEFINE("HB_INIT_TABLE_SIZE", - Integer.toString(hbConditionInitIdx))); + newCode.add("\t" + + DEFINE("HB_INIT_TABLE_SIZE", + Integer.toString(hbConditionInitIdx))); for (int i = 0; i < hbConditionInitIdx; i++) { - newCode.add("\t" + ASSIGN("hb_init_table[" + i + "]", "hbConditionInit" - + i)); + newCode.add("\t" + + ASSIGN("hb_init_table[" + i + "]", "hbConditionInit" + i)); } return newCode; } public static ArrayList generateEntryPointInitCall() { ArrayList newCode = new ArrayList(); - newCode.add("__sequential_init();"); + 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; - // } - public static ArrayList generateInterfaceWrapperDeclaration( SemanticsChecker semantics, InterfaceConstruct construct) { FunctionHeader header = getFunctionHeader(semantics, construct); @@ -584,21 +583,27 @@ public class CodeVariables { newCode.add("\t" + COMMENT("Interface begins")); // Interface begin String structName = "interface_begin"; - newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN, - "interface_begin")); - newCode.add("\t" + 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)); String anno = "annotation_interface_begin"; 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, "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("\t" + header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";"); + newCode.add("\t" + header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + + ";"); } else { - newCode.add("\t" + 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()) { @@ -607,13 +612,19 @@ public class CodeVariables { .get(label)); newCode.add("\t" + "if " + BRACE(condition) + " {"); structName = "hb_condition"; - newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName)); - newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); - - newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum)); + 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("\t\t" + + ASSIGN_TO_PTR(structName, "hb_condition_num", hbCondNum)); anno = "annotation_hb_condition"; - 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" + + 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" + "}"); @@ -623,12 +634,17 @@ public class CodeVariables { if (semantics.containsConditionalInterface(new ConditionalInterface( interfaceName, ""))) { structName = "hb_condition"; - newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_HB_CONDITION, structName)); - newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); - newCode.add("\t" + 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("\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, "type", SPEC_ANNO_TYPE_HB_CONDITION)); newCode.add("\t" + ASSIGN_TO_PTR(anno, "annotation", structName)); newCode.add("\t" + ANNOTATE(semantics, anno)); newCode.add(""); @@ -638,11 +654,13 @@ public class CodeVariables { if (!header.returnType.equals("void") || header.args.size() > 0) { infoStructType = interfaceName + "_info"; infoName = "info"; - newCode.add("\t" + 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("\t" + 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; @@ -653,11 +671,15 @@ public class CodeVariables { } structName = "interface_end"; anno = "annoation_interface_end"; - newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName)); - newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); + 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, "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 @@ -684,6 +706,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; @@ -693,12 +716,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, @@ -718,23 +744,26 @@ public class CodeVariables { addAtomicReturn(semantics, construct); } // Generate redundant header files - newCode.add(COMMENT("Automatically generated code for potential commit point: " - + construct.label)); + 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(semantics, anno)); - newCode.add("}"); + 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_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; } @@ -746,18 +775,21 @@ public class CodeVariables { addAtomicReturn(semantics, construct); } // Generate redundant header files - newCode.add("\t" + COMMENT("Automatically generated code for commit point define check: " - + construct.label)); + newCode.add("\t" + + COMMENT("Automatically generated code for commit point define check: " + + construct.label)); newCode.add(""); // Add annotation newCode.add("\t" + "if (" + construct.condition + ") {"); String structName = "cp_define_check", anno = "annotation_cp_define_check"; - newCode.add("\t\t" + 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("\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_DEFINE_CHECK)); + 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" + "}"); @@ -768,23 +800,27 @@ public class CodeVariables { SemanticsChecker semantics, CPDefineConstruct construct) { ArrayList newCode = new ArrayList(); // Generate redundant header files - newCode.add("\t" + COMMENT("Automatically generated code for commit point define: " - + construct.label)); + newCode.add("\t" + + COMMENT("Automatically generated code for commit point define: " + + construct.label)); newCode.add(""); // Add annotation newCode.add("\t" + "if (" + construct.condition + ") {"); String structName = "cp_define", anno = "annotation_cp_define"; - newCode.add("\t\t" + 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)); 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, "potential_cp_label_num", - potentialLabelNum)); + newCode.add("\t\t" + + ASSIGN_TO_PTR(structName, "potential_cp_label_num", + potentialLabelNum)); 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, "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" + "}"); diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/SemanticsChecker.java b/src/edu/uci/eecs/specCompiler/codeGenerator/SemanticsChecker.java index 74b48a2..cb5792a 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/SemanticsChecker.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/SemanticsChecker.java @@ -31,8 +31,11 @@ public class SemanticsChecker { public final HashMap> CPLabel2InterfaceConstruct; public final HashMap interface2Num; + public final HashMap num2Interface; public final HashMap hbLabel2Num; + public final HashMap num2HBLabel; public final HashMap commitPointLabel2Num; + public final HashMap num2CommitPointLabel; private HashMap options; private HashMap> hbConditions; @@ -40,7 +43,7 @@ public class SemanticsChecker { private ClassBeginConstruct classBeginConstruct; private ClassEndConstruct classEndConstruct; private GlobalConstruct globalConstruct; - + private String templateStr; private String templateFullStr; private String className; @@ -62,41 +65,45 @@ public class SemanticsChecker { this.classEndConstruct = null; this.interface2Num = new HashMap(); + this.num2Interface = new HashMap(); this.hbLabel2Num = new HashMap(); + this.num2HBLabel = new HashMap(); // Immediately init the true HB-condition to be 0 hbLabel2Num.put("", 0); + num2HBLabel.put(0, ""); this.commitPointLabel2Num = new HashMap(); + this.num2CommitPointLabel = new HashMap(); _interfaceNum = 0; _hbLabelNum = 0; _commitPointNum = 0; - + templateStr = null; templateFullStr = null; className = null; } - + public ClassBeginConstruct getClassBeginConstruct() { return this.classBeginConstruct; } - + public ClassEndConstruct getClassEndConstruct() { return this.classEndConstruct; } - + public String getTemplateFullStr() { return this.templateFullStr; } - + public String getTemplateStr() { return this.templateStr; } - + public String getClassName() { return this.className; } - + public GlobalConstruct getGlobalConstruct() { return this.globalConstruct; } @@ -104,13 +111,15 @@ public class SemanticsChecker { public HashMap> getHBConditions() { return this.hbConditions; } - + /** * Check if the conditional interface is in the HB checking list + * * @param condInterface * @return */ - public boolean containsConditionalInterface(ConditionalInterface condInterface) { + public boolean containsConditionalInterface( + ConditionalInterface condInterface) { if (hbConditions.containsKey(condInterface)) return true; for (ConditionalInterface key : hbConditions.keySet()) { @@ -142,6 +151,7 @@ public class SemanticsChecker { // Number the HB-condition label hbLabel2Num.put(label, _hbLabelNum++); + num2HBLabel.put(_hbLabelNum, label); } } @@ -194,6 +204,7 @@ public class SemanticsChecker { } // Number the interface label interface2Num.put(iConstruct.name, _interfaceNum++); + num2Interface.put(_interfaceNum, iConstruct.name); interfaceName2Construct.put(iConstruct.name, (InterfaceConstruct) constructs.get(i)); @@ -238,8 +249,9 @@ public class SemanticsChecker { PotentialCPDefineConstruct theConstruct = (PotentialCPDefineConstruct) construct; label = theConstruct.label; checkLabelDuplication(construct, label); - // Number the commit_point label + // Number the commit point potential commit point label commitPointLabel2Num.put(label, _commitPointNum++); + num2CommitPointLabel.put(_commitPointNum, label); potentialCPLabel2Construct.put(label, (PotentialCPDefineConstruct) construct); @@ -247,16 +259,18 @@ public class SemanticsChecker { CPDefineCheckConstruct theConstruct = (CPDefineCheckConstruct) construct; label = theConstruct.label; checkLabelDuplication(construct, label); - // Number the commit_point label + // Number the commit point define check label commitPointLabel2Num.put(label, _commitPointNum++); + num2CommitPointLabel.put(_commitPointNum, label); CPLabel2Construct.put(label, construct); } else if (construct instanceof CPDefineConstruct) { CPDefineConstruct theConstruct = (CPDefineConstruct) construct; label = theConstruct.label; checkLabelDuplication(construct, label); - // Number the commit_point label + // Number the commit point define label commitPointLabel2Num.put(label, _commitPointNum++); + num2CommitPointLabel.put(_commitPointNum, label); CPLabel2Construct.put(label, construct); } else if (construct instanceof EntryPointConstruct) { @@ -271,17 +285,20 @@ public class SemanticsChecker { interfaceName2DefineConstruct.put(name, theConstruct); } else if (construct instanceof ClassBeginConstruct) { classBeginConstruct = (ClassBeginConstruct) construct; - ArrayList content = srcFilesInfo.get(classBeginConstruct.file).content; - String firstLine = content.get(classBeginConstruct.beginLineNum), secondLine; + ArrayList content = srcFilesInfo + .get(classBeginConstruct.file).content; + String firstLine = content + .get(classBeginConstruct.beginLineNum + 1), secondLine; if (firstLine.startsWith("template")) { - secondLine = content.get(classBeginConstruct.beginLineNum + 1); + secondLine = content + .get(classBeginConstruct.beginLineNum + 1); templateFullStr = firstLine; templateStr = ParserUtils.getTemplateStr(firstLine); className = ParserUtils.getClassName(secondLine); } else { className = ParserUtils.getClassName(firstLine); } - + } else if (construct instanceof ClassEndConstruct) { classEndConstruct = (ClassEndConstruct) construct; className = getOption("CLASS"); diff --git a/src/edu/uci/eecs/specCompiler/specExtraction/ParserUtils.java b/src/edu/uci/eecs/specCompiler/specExtraction/ParserUtils.java index c80ce51..201bb8c 100644 --- a/src/edu/uci/eecs/specCompiler/specExtraction/ParserUtils.java +++ b/src/edu/uci/eecs/specCompiler/specExtraction/ParserUtils.java @@ -57,12 +57,14 @@ public class ParserUtils { } catch (ParseException e) { e.printStackTrace(); } - + return templateStr; } - + public static void write2File(File file, ArrayList content) { - String newFileName = Environment.GENERATED_FILE_DIR + "/" + file.getName(); + String newFileName = Environment.GENERATED_FILE_DIR + "/" + + file.getParentFile().getName() + "/" + file.getName(); + File newFile = new File(newFileName); newFile.getParentFile().mkdirs(); if (!newFile.exists()) {