import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
import edu.uci.eecs.specCompiler.specExtraction.Construct;
import edu.uci.eecs.specCompiler.specExtraction.EntryPointConstruct;
+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;
private HashMap<File, SourceFileInfo> srcFilesInfo;
private HashMap<File, ArrayList<CodeAddition>> codeAdditions;
+ private String homeDir;
public CodeGenerator(File[] srcFiles) {
this.srcFiles = srcFiles;
new ArrayList<CodeAddition>());
}
codeAdditions.get(defineConstruct.file).add(addition);
- } else { // No declaration needed
+ } else { // No declaration needed but should add forward declaration in
+ // Class
// Last generate the definition
- newCode = CodeVariables.generateInterfaceWrapperDefinition(
- _semantics, construct);
+ newCode = new ArrayList<String>();
+ if (_semantics.getOption("CLASS") == null) {
+ newCode.addAll(CodeVariables
+ .generateInterfaceWrapperDeclaration(_semantics,
+ construct));
+ }
+ newCode.addAll(CodeVariables.generateInterfaceWrapperDefinition(
+ _semantics, construct));
lineNum = construct.beginLineNum;
// Add the wrapper declaration
addition = new CodeAddition(lineNum, newCode);
codeAdditions.get(construct.file).add(addition);
}
+ /**
+ * private void ClassEnd2Code(ClassEndConstruct construct) { int lineNum =
+ * construct.beginLineNum; ArrayList<String> newCode =
+ * CodeVariables.generateStaticVarDefine(_semantics,
+ * _semantics.getGlobalConstruct());
+ *
+ * CodeAddition addition = new CodeAddition(lineNum, newCode); if
+ * (!codeAdditions.containsKey(construct.file)) {
+ * codeAdditions.put(construct.file, new ArrayList<CodeAddition>()); }
+ * codeAdditions.get(construct.file).add(addition); }
+ */
+
private void EntryPoint2Code(EntryPointConstruct construct) {
int lineNum = construct.beginLineNum;
ArrayList<String> newCode = new ArrayList<String>();
EntryPoint2Code((EntryPointConstruct) construct);
}
}
+
+ // ClassEndConstruct endConstruct = _semantics.getClassEndConstruct();
+ // if (endConstruct != null) {
+ // ClassEnd2Code(endConstruct);
+ // }
+
// Sort code additions
- HashSet<String> headers = CodeVariables.getAllHeaders(_semantics);
- ArrayList<String> headerCode = new ArrayList<String>(headers.size());
- for (String header : headers) {
- headerCode.add("#include " + header + ";");
- }
for (File file : codeAdditions.keySet()) {
ArrayList<CodeAddition> additions = codeAdditions.get(file);
-
+
if (additions.size() == 0) // Simply do nothing
continue;
ArrayList<String> content = _semantics.srcFilesInfo.get(file).content;
// Insert generated annotation to the source files
ArrayList<String> newContent = insertAnnotation2Src(additions,
content);
- ArrayList<String> finalContent = new ArrayList<String>(headerCode.size() + newContent.size());
- finalContent.addAll(headerCode);
- finalContent.addAll(newContent);
// Write it back to file
- ParserUtils.write2File(file, finalContent);
+ ParserUtils.write2File(file, newContent);
}
-
}
public static void main(String[] argvs) {
String homeDir = Environment.HOME_DIRECTORY;
- File[] srcFiles = {
- // new File(Environment.MODEL_CHECKER_TEST_DIR +
- // "/backup_linuxrwlocks.c") };
-// new File(homeDir + "/benchmark/linuxrwlocks/linuxrwlocks.c")
-// };
- // new File(homeDir
- // +
- // "/benchmark/cliffc-hashtable/simplified_cliffc_hashtable.h"),
- // };
+
+ File[] srcLinuxRWLocks = { new File(homeDir
+ + "/benchmark/linuxrwlocks/linuxrwlocks.c") };
+
+ 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"),
new File(homeDir + "/benchmark/ms-queue/main.c"),
new File(homeDir + "/benchmark/ms-queue/my_queue.h") };
- // new File(homeDir + "/benchmark/test/test.c") };
- CodeGenerator gen = new CodeGenerator(srcFiles);
- gen.generateCode();
+
+ File[] srcRCU = { new File(homeDir
+ + "/benchmark/read-copy-update/rcu.cc") };
+
+ File[] srcDeque = {
+ new File(homeDir + "/benchmark/chase-lev-deque-bugfix/deque.c"),
+ new File(homeDir + "/benchmark/chase-lev-deque-bugfix/main.c"),
+ new File(homeDir + "/benchmark/chase-lev-deque-bugfix/deque.h") };
+
+ File[] srcMCSLock = {
+ new File(homeDir + "/benchmark/mcs-lock/mcs-lock.cc"),
+ new File(homeDir + "/benchmark/mcs-lock/mcs-lock.h") };
+
+ File[] srcSPSCQueue = {
+ new File(homeDir + "/benchmark/spsc-bugfix/spsc-queue.cc"),
+ new File(homeDir + "/benchmark/spsc-bugfix/eventcount.h"),
+ new File(homeDir + "/benchmark/spsc-bugfix/queue.h") };
+
+ File[] srcMPMCQueue = {
+ 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 = { srcDeque };
+ // Compile all the benchmarks
+ for (int i = 0; i < sources.length; i++) {
+ CodeGenerator gen = new CodeGenerator(sources[i]);
+ gen.generateCode();
+ }
}
}