add more
authorPeizhao Ou <peizhaoo@uci.edu>
Tue, 29 Oct 2013 03:52:05 +0000 (20:52 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Tue, 29 Oct 2013 03:52:05 +0000 (20:52 -0700)
notes/generated_code_examples.txt
src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java
src/edu/uci/eecs/specCompiler/specExtraction/ParserUtils.java

index 95e649a..1658001 100644 (file)
@@ -12,7 +12,7 @@ Global Variable Declaration
 #include <spec_lib.h>
 
 /* All other user-defined functions */
-ALL_USER_DEFINED_FUNCTIONS
+ALL_USER_DEFINED_FUNCTIONS  // Make them static 
 
 /* Definition of interface info struct (per interface) */
 typedef struct Put_info {
@@ -29,7 +29,7 @@ typedef struct Get_info {
 
 /* ID functions of interface */
 static id_t Put_id() {
-       id_t id = PUT_ID;
+       id_t id = PUT_ID;  // Default ID == 0;
        return id;
 }
 
@@ -39,10 +39,7 @@ static id_t Get_id() {
 }
 /* End of ID functions */
 
-/* Initialization of interface<->function_ptr table */
-#define INTERFACE_SIZE 2
-void* func_ptr_table[INTERFACE_SIZE * 2] = {
-       CLASS
+
 
 /* Check_action function of interfaces */
 bool Put_check_action(void *info, id_t __ID__) {
@@ -78,6 +75,9 @@ bool Get_check_action(void *info, id_t __ID__) {
 }
 /* End of check_action function definitions */ 
 
+/* Initialization of interface<->function_ptr table */
+#define INTERFACE_SIZE 2
+void* func_ptr_table[INTERFACE_SIZE * 2];
 
 /* Beginning of other user-defined variables */
 bool lock_acquired;
@@ -87,6 +87,8 @@ int reader_lock_cnt;
 
 /* Define function for sequential code initialization */
 void __sequential_init() {
+       /* Init func_ptr_table */
+
        /* Init user-defined variables */
        lock_acquired = false;
        reader_lock_cnt = 0;
index e2ae18b..2900601 100644 (file)
@@ -4,10 +4,14 @@ import java.util.ArrayList;
 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.specExtraction.ConditionalInterface;
+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.ParserUtils;
 import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor;
@@ -28,6 +32,7 @@ public class CodeVariables {
        public static final String HEADER_CDSTRACE = "<cdstrace.h>";
        public static final String CDSAnnotate = "cdsannotate";
        public static final String CDSAnnotateType = "SPEC_ANALYSIS";
+       public static final String IDType = "id_t";
 
        public static final String SPEC_ANNO_TYPE = "spec_anno_type";
        public static final String SPEC_ANNO_TYPE_HB_INIT = "HB_INIT";
@@ -50,6 +55,7 @@ public class CodeVariables {
 
        // Specification variables
        public static final String SPEC_INTERFACE_WRAPPER = "__wrapper_";
+       public static final String DEFAULT_ID = "0";
 
        // Specification library
        public static final String HEADER_SPEC_LIB = "<spec_lib.h>";
@@ -106,6 +112,11 @@ public class CodeVariables {
                return type + " " + name + ";";
        }
 
+       private static String DECLARE(VariableDeclaration varDecl) {
+               String type = varDecl.type, name = varDecl.name;
+               return type + " " + name + ";";
+       }
+
        private static String DECLARE_DEFINE(String type, String var, String val) {
                return type + " " + var + " = " + val + ";";
        }
@@ -114,6 +125,32 @@ public class CodeVariables {
                return CDSAnnotate + "(" + CDSAnnotateType + ", &" + structName + ");";
        }
 
+       private static ArrayList<String> DEFINE_INFO_STRUCT(String interfaceName,
+                       FunctionHeader funcDecl) {
+               ArrayList<String> code = new ArrayList<String>();
+               code.add("typedef struct " + interfaceName + "_info {");
+               code.add(DECLARE(funcDecl.returnType, MACRO_RETURN));
+               for (int i = 0; i < funcDecl.args.size(); i++) {
+                       code.add(DECLARE(funcDecl.args.get(i)));
+               }
+               code.add("} " + interfaceName + "_info {");
+               return code;
+       }
+
+       private static ArrayList<String> DEFINE_ID_FUNC(String interfaceName,
+                       String idCode) {
+               ArrayList<String> code = new ArrayList<String>();
+               code.add("static " + IDType + " " + interfaceName + "_id() {");
+               if (idCode != null) {
+                       code.add(DECLARE_DEFINE(IDType, MACRO_ID, idCode));
+               } else {
+                       code.add(DECLARE_DEFINE(IDType, MACRO_ID, DEFAULT_ID));
+               }
+               code.add("return " + MACRO_ID + ";");
+               code.add("}");
+               return code;
+       }
+
        private static HashSet<String> getAllHeaders(SemanticsChecker semantics) {
                HashSet<String> headers = new HashSet<String>();
                for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
@@ -123,6 +160,32 @@ public class CodeVariables {
                return headers;
        }
 
+       private static void makeFunctionStatic(ArrayList<String> funcDefine) {
+               String headLine = funcDefine.get(0);
+               headLine = "static " + headLine;
+               funcDefine.set(0, headLine);
+       }
+
+       private static void makeVariablesStatic(ArrayList<String> varDecls) {
+               for (int i = 0; i < varDecls.size(); i++) {
+                       String varDecl = varDecls.get(i);
+                       varDecl = "static " + varDecl;
+                       varDecls.set(i, varDecl);
+               }
+       }
+
+       private static FunctionHeader getFunctionHeader(SemanticsChecker semantics,
+                       InterfaceConstruct construct) {
+               ArrayList<String> content = semantics.srcFilesInfo.get(construct.file).content;
+               String headerLine = content.get(construct.beginLineNum);
+               try {
+                       return SpecParser.parseFuncHeader(headerLine);
+               } catch (ParseException e) {
+                       e.printStackTrace();
+               }
+               return null;
+       }
+
        public static ArrayList<String> generateGlobalVarDeclaration(
                        SemanticsChecker semantics, GlobalConstruct construct) {
                ArrayList<String> newCode = new ArrayList<String>();
@@ -145,13 +208,35 @@ public class CodeVariables {
                newCode.add(COMMENT("All other user-defined functions"));
                ArrayList<ArrayList<String>> defineFuncs = code.defineFuncs;
                for (int i = 0; i < defineFuncs.size(); i++) {
-                       newCode.addAll(defineFuncs.get(i));
+                       ArrayList<String> defineFunc = defineFuncs.get(i);
+                       makeFunctionStatic(defineFunc);
+                       newCode.addAll(defineFunc);
                        newCode.add("");
                }
 
-               // Define necessary info structure
-               newCode.add(COMMENT("Definition of interface info struct (per interface)"));
-               
+               for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
+                       InterfaceConstruct iConstruct = semantics.interfaceName2Construct
+                                       .get(interfaceName);
+                       FunctionHeader funcHeader = getFunctionHeader(semantics, iConstruct);
+                       // Define necessary info structure
+                       newCode.add(COMMENT("Definition of interface info struct: "
+                                       + interfaceName));
+                       newCode.addAll(DEFINE_INFO_STRUCT(interfaceName, funcHeader));
+                       newCode.add(COMMENT("End of info struct definition: "
+                                       + interfaceName));
+                       newCode.add("");
+
+                       // Define ID function
+                       newCode.add(COMMENT("ID functions of interface: " + interfaceName));
+                       newCode.addAll(DEFINE_ID_FUNC(interfaceName, iConstruct.idCode));
+                       newCode.add("");
+                       newCode.add(COMMENT("End of ID function: + " + interfaceName));
+                       newCode.add("");
+                       
+                       // Define check_action function
+                       
+
+               }
 
                // User-defined variables
                ArrayList<VariableDeclaration> varDecls = code.declareVar;
index c70aa94..0ce5332 100644 (file)
@@ -2,6 +2,9 @@ package edu.uci.eecs.specCompiler.specExtraction;
 
 import java.util.ArrayList;
 
+import edu.uci.eecs.specCompiler.grammerParser.ParseException;
+import edu.uci.eecs.specCompiler.grammerParser.SpecParser;
+
 public class ParserUtils {
        public static String trimSpace(String line) {
                int i, j;