import edu.uci.eecs.specExtraction.Code;
import edu.uci.eecs.specExtraction.CommutativityRule;
+import edu.uci.eecs.specExtraction.DefineConstruct;
import edu.uci.eecs.specExtraction.EntryConstruct;
import edu.uci.eecs.specExtraction.FunctionHeader;
import edu.uci.eecs.specExtraction.GlobalConstruct;
'_') + "_H");
code.addLine("");
+ // FIXME: We have included ad-hoc header files here
// System included headers
code.addLine(ShortComment("System included headers go here"));
- for (String header : SpecNaming.includedHeadersList) {
- code.addLine(IncludeHeader(header));
- }
+ code.addLine(IncludeHeader(SpecNaming.SPECANNOTATION_API));
+ code.addLine(IncludeHeader(SpecNaming.STDLIB));
+
code.addLine("");
// Users included headers
}
code.addLine("");
- code.addLine("using namespace std;");
- code.addLine("");
+ // Decalre extern "C" --- begin
+ code.addLine("#ifdef __cplusplus");
+ code.addLine("extern \"C\" {");
+ code.addLine("#endif");
code.addLine("");
code.addLine(ShortComment("Declaration of some c-strings (CSTR)"));
}
}
- // Declare customized StateStruct
- code.addLine(ShortComment("Declare customized StateStruct"));
- code.addLine("typedef struct " + SpecNaming.StateStruct + " {");
- for (VariableDeclaration decl : globalConstruct.declState) {
- code.addLine(TabbedLine(Declare(decl)));
- }
- code.addLine("");
- code.addLine(TabbedLine("SNAPSHOTALLOC"));
- code.addLine("} " + SpecNaming.StateStruct + ";");
- code.addLine("");
-
// Declare customized value struct
for (File file : interfaceListMap.keySet()) {
ArrayList<InterfaceConstruct> list = interfaceListMap.get(file);
code.addLine(ShortComment("Declare INIT annotation instrumentation function"));
code.addLine("void _createInitAnnotation();");
code.addLine("");
+
+ // Decalre extern "C" --- begin
+ code.addLine("#ifdef __cplusplus");
+ code.addLine("};");
+ code.addLine("#endif");
+ code.addLine("");
+
+ // Declare #endif
code.addLine("#endif");
return code;
code.addLine("");
code.addLine("#include " + SpecNaming.CDSSpecGeneratedHeader);
+ code.addLine("#include " + SpecNaming.CDSANNOTATE);
+ code.addLine("#include " + SpecNaming.SPEC_COMMON);
+ code.addLine("#include " + SpecNaming.METHODCALL);
+ code.addLine("#include " + SpecNaming.CDSSPEC);
+ code.addLine("#include " + SpecNaming.SPECANNOTATION);
+ code.addLine("");
+ code.addLine("");
+
+ // Declare customized StateStruct
+ code.addLine(ShortComment("Declare customized StateStruct"));
+ code.addLine("typedef struct " + SpecNaming.StateStruct + " {");
+ for (VariableDeclaration decl : globalConstruct.declState) {
+ code.addLine(TabbedLine(Declare(decl)));
+ }
+ code.addLine("");
+ code.addLine(TabbedLine("SNAPSHOTALLOC"));
+ code.addLine("} " + SpecNaming.StateStruct + ";");
code.addLine("");
code.addLine("");
code.addLine(TabbedLine("#define " + decl.name + " "
+ SpecNaming.StateInst + "->" + decl.name));
}
- code.addLine(TabbedLine(ShortComment("User-defined intial state code")));
+ if (!globalConstruct.autoGenInitial)
+ code.addLine(TabbedLine(ShortComment("User-defined state intialization code")));
+ else
+ // Auto-generated the initialization function
+ code.addLine(TabbedLine(ShortComment("Auto-generated state intialization code")));
// Align the code with one tab
globalConstruct.initState.align(1);
code.addLines(globalConstruct.initState);
fieldsInit.align(1);
code.addLines(fieldsInit);
code.addLine("");
- code.addLine(TabbedLine(ShortComment("Execute the print-out")));
+ if (!globalConstruct.autoGenPrint)
+ code.addLine(TabbedLine(ShortComment("Execute user-defined state printing code")));
+ else
+ // Auto-generated the copy function
+ code.addLine(TabbedLine(ShortComment("Execute auto-generated state printing code")));
+
// Align the code with one tab
globalConstruct.printState.align(1);
code.addLines(globalConstruct.printState);
code.addLines(fieldsInit);
construct.print.align(1);
- code.addLine(TabbedLine(ShortComment("Execute Print")));
+ if (!construct.autoGenPrint)
+ code.addLine(TabbedLine(ShortComment("Execute user-defined value printing code")));
+ else
+ // Auto-generated the value printing function
+ code.addLine(TabbedLine(ShortComment("Execute auto-generated value printing code")));
code.addLines(construct.print);
code.addLine("}");
+ SpecNaming.CopyState.toUpperCase() + ", " + "(void*) _"
+ SpecNaming.CopyState.toLowerCase() + "),", 2));
// new NamedFunction(_Print_str, PRINT_STATE, (void*) _print),
- code.addLine(TabbedLine("new " + SpecNaming.NamedFunction + "("
+ line = "new " + SpecNaming.NamedFunction + "("
+ SpecNaming.AppendStr(SpecNaming.PrintState) + ", "
- + SpecNaming.PrintStateType + ", " + "(void*) _"
- + SpecNaming.PrintState.toLowerCase() + "),", 2));
+ + SpecNaming.PrintStateType + ", " + "(void*)";
+ if (globalConstruct.printState.isEmpty()) {
+ line = line + SpecNaming.NullFunc + "),";
+ } else {
+ line = line + "_" + SpecNaming.PrintState.toLowerCase() + "),";
+ }
+ code.addLine(TabbedLine(line, 2));
// commuteRules, CommuteRuleSize);
code.addLine(TabbedLine(SpecNaming.CommutativityRuleInst + ", "
+ SpecNaming.CommutativityRuleSizeInst + ");", 2));
+ SpecNaming.PrintValue) + ", "
+ SpecNaming.PrintValueType + ", (void*) ";
if (construct.print.isEmpty()) {
- line = line + SpecNaming.NullFunc + "),";
+ line = line + SpecNaming.NullFunc + ")";
} else {
line = line + "_" + name + "_" + SpecNaming.PrintValue
+ ")";
return res;
}
+ /**
+ * <p>
+ * This function generates the code to be inserted right after the "@Define"
+ * construct (instrumentation code)
+ * </p>
+ *
+ * @param construct
+ * The corresponding entry construct
+ * @return
+ */
+ public static Code Generate4Define(DefineConstruct construct) {
+ Code code = new Code();
+ code.addLine("");
+ code.addLine("/********** User-defined code in annotation (BEGIN) **********/");
+ code.addLines(construct.code);
+ code.addLine("/********** User-defined code in annotation (END) **********/");
+ return code;
+ }
+
/**
* <p>
* This function generates the new interface wrapper code to be inserted
} else {
code.addLine(beginLine);
}
- // Instrument with the INTERFACE_BEGIN annotation
+ // Instrument with the INTERFACE_BEGIN annotations
code.addLine(prefixTabs
+ "\t"
+ ShortComment("Instrument with the INTERFACE_BEGIN annotation"));
- // AnnoInterfaceInfo *info = _createInterfaceBeginAnnotation(_DEQ_str);
+ // CAnnoInterfaceInfo info = _createInterfaceBeginAnnotation(_DEQ_str);
code.addLine(prefixTabs
+ "\t"
+ DeclareDefine(SpecNaming.AnnoInterfaceInfo, "*"
+ ShortComment("Initialize the value struct"));
// The very first assignment "
code.addLine(prefixTabs + "\t"
- + DeclareDefine(name, "*value", "new " + name));
+ + DeclareDefine(name, "*value", SpecNaming.New + Brace(name)));
// Don't leave out the RET field
if (!construct.getFunctionHeader().isReturnVoid())
code.addLine(prefixTabs + "\t"
code.addLine("");
// Store the value info into the current MethodCall
+ // _setInterfaceBeginAnnotationValue(info, value);
code.addLine(prefixTabs
+ "\t"
+ ShortComment("Store the value info into the current MethodCall"));
- code.addLine(prefixTabs
- + "\t"
- + AssignToPtr(SpecNaming.AnnoInterfaceInfoInst, "value",
- "value"));
+ code.addLine(prefixTabs + "\t"
+ + SpecNaming.SetInterfaceBeginAnnoValueFunc
+ + Brace(SpecNaming.AnnoInterfaceInfoInst + ", value") + ";");
code.addLine("");
// Return if necessary