X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=src%2Fedu%2Fuci%2Feecs%2FspecCompiler%2FcodeGenerator%2FCodeGenerator.java;h=4a1c2a79db852b1e29c2aa883f3932e3e896a6d1;hb=375b8b02ae398aceddb920e0e7e94287e33f231e;hp=7b9dc411aa82b593ff9d50438bac6036047938ca;hpb=4f1e1f913bc95499f9e5fff2a8e30938b7cf3f08;p=cdsspec-compiler.git diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java index 7b9dc41..4a1c2a7 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java @@ -11,6 +11,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import edu.uci.eecs.specCompiler.specExtraction.CPClearConstruct; import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct; import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct; import edu.uci.eecs.specCompiler.specExtraction.ClassEndConstruct; @@ -46,6 +47,7 @@ public class CodeGenerator { private HashMap srcFilesInfo; private HashMap> codeAdditions; + private String homeDir; public CodeGenerator(File[] srcFiles) { this.srcFiles = srcFiles; @@ -182,12 +184,11 @@ public class CodeGenerator { } codeAdditions.get(construct.file).add(addition); } - - /** - private void ClassEnd2Code(ClassEndConstruct construct) { + + private void CPClear2Code(CPClearConstruct construct) { int lineNum = construct.beginLineNum; - ArrayList newCode = CodeVariables.generateStaticVarDefine(_semantics, - _semantics.getGlobalConstruct()); + ArrayList newCode = CodeVariables.generateCPClear( + _semantics, construct); CodeAddition addition = new CodeAddition(lineNum, newCode); if (!codeAdditions.containsKey(construct.file)) { @@ -195,8 +196,20 @@ public class CodeGenerator { } codeAdditions.get(construct.file).add(addition); } - */ + + /** + * private void ClassEnd2Code(ClassEndConstruct construct) { int lineNum = + * construct.beginLineNum; ArrayList newCode = + * CodeVariables.generateStaticVarDefine(_semantics, + * _semantics.getGlobalConstruct()); + * + * CodeAddition addition = new CodeAddition(lineNum, newCode); if + * (!codeAdditions.containsKey(construct.file)) { + * codeAdditions.put(construct.file, new ArrayList()); } + * codeAdditions.get(construct.file).add(addition); } + */ + private void EntryPoint2Code(EntryPointConstruct construct) { int lineNum = construct.beginLineNum; ArrayList newCode = new ArrayList(); @@ -244,22 +257,19 @@ public class CodeGenerator { CPDefine2Code((CPDefineConstruct) construct); } else if (construct instanceof CPDefineCheckConstruct) { CPDefineCheck2Code((CPDefineCheckConstruct) construct); + } else if (construct instanceof CPClearConstruct) { + CPClear2Code((CPClearConstruct) construct); } else if (construct instanceof EntryPointConstruct) { EntryPoint2Code((EntryPointConstruct) construct); } } -// ClassEndConstruct endConstruct = _semantics.getClassEndConstruct(); -// if (endConstruct != null) { -// ClassEnd2Code(endConstruct); -// } + // ClassEndConstruct endConstruct = _semantics.getClassEndConstruct(); + // if (endConstruct != null) { + // ClassEnd2Code(endConstruct); + // } // Sort code additions - HashSet headers = CodeVariables.getAllHeaders(_semantics); - ArrayList headerCode = new ArrayList(); - for (String header : headers) { - headerCode.add("#include " + header); - } for (File file : codeAdditions.keySet()) { ArrayList additions = codeAdditions.get(file); @@ -270,46 +280,58 @@ public class CodeGenerator { // Insert generated annotation to the source files ArrayList newContent = insertAnnotation2Src(additions, content); - ArrayList finalContent = new ArrayList( - 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(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") }; - -// 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") }; - -// new File(homeDir + "/benchmark/mcs-lock/mcs-lock.cc"), -// new File(homeDir + "/benchmark/mcs-lock/mcs-lock.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/testcase.c"), + new File(homeDir + "/benchmark/ms-queue/testcase1.c"), + new File(homeDir + "/benchmark/ms-queue/main.c"), + new File(homeDir + "/benchmark/ms-queue/my_queue.h") }; + + 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") }; - - CodeGenerator gen = new CodeGenerator(srcFiles); - gen.generateCode(); + File[] srcMPMCQueue = { + new File(homeDir + "/benchmark/mpmc-queue/mpmc-queue.h"), + new File(homeDir + "/benchmark/mpmc-queue/mpmc-queue.cc") }; +// +// File[][] sources = { srcLinuxRWLocks, srcMSQueue, srcRCU, +// srcDeque, srcMCSLock, srcSPSCQueue, srcMPMCQueue, srcHashtable }; + + File[][] sources = {srcMSQueue, srcHashtable }; + // Compile all the benchmarks + for (int i = 0; i < sources.length; i++) { + CodeGenerator gen = new CodeGenerator(sources[i]); + gen.generateCode(); + } } }