From 86a369048fdc607fb908cf5ff88f8af20579cffa Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Mon, 17 Mar 2014 14:19:45 -0700 Subject: [PATCH] more fix --- .../codeGenerator/CodeGenerator.java | 11 +- .../codeGenerator/CodeVariables.java | 110 +++++++++--------- 2 files changed, 56 insertions(+), 65 deletions(-) diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java index 93dae99..af9bde4 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java @@ -254,11 +254,6 @@ public class CodeGenerator { // } // Sort code additions - HashSet headers = CodeVariables.getAllHeaders(_semantics); - ArrayList headerCode = new ArrayList(); - for (String header : headers) { - headerCode.add("#include " + header); - } for (File file : codeAdditions.keySet()) { ArrayList additions = codeAdditions.get(file); @@ -269,12 +264,8 @@ public class CodeGenerator { // Insert generated annotation to the source files ArrayList newContent = insertAnnotation2Src(additions, content); - ArrayList finalContent = new ArrayList( - headerCode.size() + newContent.size()); - finalContent.addAll(headerCode); - finalContent.addAll(newContent); // Write it back to file - ParserUtils.write2File(file, finalContent); + ParserUtils.write2File(file, newContent); } } diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java index 39ef342..53f40bb 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java @@ -581,23 +581,23 @@ public class CodeVariables { 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, + newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_BEGIN, "interface_begin")); - newCode.add(ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); + newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); String anno = "annotation_interface_begin"; - newCode.add(STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno)); - newCode.add(ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN)); - newCode.add(ASSIGN_TO_PTR(anno, "annotation", structName)); - newCode.add(ANNOTATE(semantics, 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, + newCode.add("\t" + DECLARE_DEFINE(header.returnType, MACRO_RETURN, header.getRenamedCall(SPEC_INTERFACE_WRAPPER))); } // HB conditions @@ -605,32 +605,32 @@ public class CodeVariables { 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)); - 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(semantics, 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)); + 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(semantics, 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 @@ -638,31 +638,31 @@ public class CodeVariables { if (!header.returnType.equals("void") || header.args.size() > 0) { infoStructType = interfaceName + "_info"; infoName = "info"; - newCode.add(DECLARE_DEFINE(infoStructType + "*", infoName, + 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(semantics, anno)); + newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INTERFACE_END, structName)); + newCode.add("\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)); + 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("}"); @@ -746,21 +746,21 @@ public class CodeVariables { addAtomicReturn(semantics, construct); } // Generate redundant header files - newCode.add(COMMENT("Automatically generated code for commit point define check: " + 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(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_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; } @@ -768,26 +768,26 @@ public class CodeVariables { SemanticsChecker semantics, CPDefineConstruct construct) { ArrayList newCode = new ArrayList(); // Generate redundant header files - newCode.add(COMMENT("Automatically generated code for commit point define check: " + 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)); String potentialLabelNum = Integer .toString(semantics.commitPointLabel2Num .get(construct.potentialCPLabel)); - newCode.add(ASSIGN_TO_PTR(structName, "label_num", labelNum)); - newCode.add(ASSIGN_TO_PTR(structName, "potential_cp_label_num", + 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(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("}"); + 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; } } -- 2.34.1