#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 {
/* ID functions of interface */
static id_t Put_id() {
- id_t id = PUT_ID;
+ id_t id = PUT_ID; // Default ID == 0;
return 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__) {
}
/* 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;
/* Define function for sequential code initialization */
void __sequential_init() {
+ /* Init func_ptr_table */
+
/* Init user-defined variables */
lock_acquired = false;
reader_lock_cnt = 0;
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;
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";
// 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>";
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 + ";";
}
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()) {
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>();
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;