import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
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;
}
}
- // Mainly rename and wrap the interface
+ // Wrap the interface and then renaem it
private void interface2Code(InterfaceConstruct construct) {
- // First rename the interface
- CodeVariables.renameInterface(_semantics, construct);
-
// If there's no define construct for it, we generate the wrapper just
// in place without declaration
InterfaceDefineConstruct defineConstruct = _semantics.interfaceName2DefineConstruct
CodeAddition addition;
// Then generate the wrapper if necessary
if (defineConstruct != null) { // Need to have a wrapper declaration
- newCode = CodeVariables.generateInterfaceWrapperDeclaration(_semantics, construct);
+ newCode = CodeVariables.generateInterfaceWrapperDeclaration(
+ _semantics, construct);
lineNum = construct.beginLineNum;
// Add the wrapper declaration
addition = new CodeAddition(lineNum, newCode);
if (!codeAdditions.containsKey(construct.file)) {
- codeAdditions.put(construct.file, new ArrayList<CodeAddition>());
+ codeAdditions
+ .put(construct.file, new ArrayList<CodeAddition>());
}
codeAdditions.get(construct.file).add(addition);
-
+
// Add the wrapper definition
- newCode = CodeVariables.generateInterfaceWrapperDefinition(_semantics, construct);
+ newCode = CodeVariables.generateInterfaceWrapperDefinition(
+ _semantics, construct);
lineNum = defineConstruct.beginLineNum;
// Add the wrapper declaration
addition = new CodeAddition(lineNum, newCode);
if (!codeAdditions.containsKey(defineConstruct.file)) {
- codeAdditions.put(defineConstruct.file, new ArrayList<CodeAddition>());
+ codeAdditions.put(defineConstruct.file,
+ new ArrayList<CodeAddition>());
}
codeAdditions.get(defineConstruct.file).add(addition);
- } else { // No declaration needed
+ } else { // No declaration needed but should add forward declaration
// Last generate the definition
- newCode = CodeVariables.generateInterfaceWrapperDefinition(_semantics, construct);
+ newCode = new ArrayList<String>();
+ newCode.addAll(CodeVariables.generateInterfaceWrapperDeclaration(_semantics, construct));
+ newCode.addAll(CodeVariables.generateInterfaceWrapperDefinition(
+ _semantics, construct));
lineNum = construct.beginLineNum;
// Add the wrapper declaration
addition = new CodeAddition(lineNum, newCode);
if (!codeAdditions.containsKey(construct.file)) {
- codeAdditions.put(construct.file, new ArrayList<CodeAddition>());
+ codeAdditions
+ .put(construct.file, new ArrayList<CodeAddition>());
}
codeAdditions.get(construct.file).add(addition);
}
-
+
+ // Don't forget to rename the interface
+ CodeVariables.renameInterface(_semantics, construct);
}
private void potentialCPDefine2Code(PotentialCPDefineConstruct construct) {
}
}
// 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, already written
- // once
+
+ if (additions.size() == 0) // Simply do nothing
continue;
ArrayList<String> content = _semantics.srcFilesInfo.get(file).content;
Collections.sort(additions, CodeAddition.lineNumComparator);
// 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, newContent);
+ ParserUtils.write2File(file, finalContent);
}
}
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"), };
- // new File(homeDir + "/benchmark/ms-queue/my_queue.c"),
- // new File(homeDir + "/benchmark/ms-queue/my_queue.c") };
- // new File(homeDir + "/benchmark/test/test.c") };
+// new File(homeDir
+// + "/benchmark/linuxrwlocks/linuxrwlocks.c") };
+ // new File(homeDir
+ // +
+ // "/benchmark/cliffc-hashtable/simplified_cliffc_hashtable.h"),
+ // };
+// 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/read-copy-update/rcu.cc") };
CodeGenerator gen = new CodeGenerator(srcFiles);
gen.generateCode();
}