X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=src%2Fedu%2Fuci%2Feecs%2FspecCompiler%2FcodeGenerator%2FCodeGenerator.java;h=492263f2f85801d39287d48de0820747f181f34e;hp=b8f163e65387843b85743e6a43d1bcd1b265cba6;hb=7919b41aeee6c8d5f572299f80f2e91d389ae164;hpb=0a040a5b619952d29338f73db8f685d7367178fc diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java index b8f163e..492263f 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java @@ -8,14 +8,17 @@ import java.io.IOException; 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.CPClearConstruct; import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct; import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct; import edu.uci.eecs.specCompiler.specExtraction.ClassEndConstruct; 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; @@ -44,6 +47,7 @@ public class CodeGenerator { private HashMap srcFilesInfo; private HashMap> codeAdditions; + private String homeDir; public CodeGenerator(File[] srcFiles) { this.srcFiles = srcFiles; @@ -120,10 +124,17 @@ public class CodeGenerator { new ArrayList()); } 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(); + 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); @@ -173,6 +184,31 @@ public class CodeGenerator { } codeAdditions.get(construct.file).add(addition); } + + private void CPClear2Code(CPClearConstruct construct) { + int lineNum = construct.beginLineNum; + ArrayList newCode = CodeVariables.generateCPClear( + _semantics, construct); + + 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 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; @@ -221,13 +257,22 @@ 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); + // } + // Sort code additions for (File file : codeAdditions.keySet()) { ArrayList additions = codeAdditions.get(file); + if (additions.size() == 0) // Simply do nothing continue; ArrayList content = _semantics.srcFilesInfo.get(file).content; @@ -238,25 +283,70 @@ public class CodeGenerator { // Write it back to file 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"), - // }; -// 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[] srcLinuxRWLock1 = { + new File(homeDir + + "/benchmark/linuxrwlocks/linuxrwlocks.c") }; + File[] srcLinuxRWLock2 = { + new File(homeDir + + "/benchmark/linuxrwlocks/testcase1.c") }; + File[] srcLinuxRWLock3 = { + new File(homeDir + + "/benchmark/linuxrwlocks/testcase2.c") }; +// + File[] srcHashtable = { + new File(homeDir + + "/benchmark/concurrent-hashmap/hashmap.h"), + new File(homeDir + "/benchmark/concurrent-hashmap/testcase1.cc"), + new File(homeDir + "/benchmark/concurrent-hashmap/main.cc")}; + + File[] srcMSQueue = { + new File(homeDir + "/benchmark/ms-queue/my_queue.c"), + new File(homeDir + "/benchmark/ms-queue/testcase1.c"), + new File(homeDir + "/benchmark/ms-queue/testcase2.c"), + new File(homeDir + "/benchmark/ms-queue/testcase3.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[] srcTrylock = { new File(homeDir + + "/benchmark/trylock/trylock.c") }; + + 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/testcase1.c"), + new File(homeDir + "/benchmark/chase-lev-deque-bugfix/testcase2.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 = {srcLinuxRWLock1 , srcMSQueue, srcRCU, +// srcDeque, srcMCSLock, srcSPSCQueue, srcMPMCQueue, srcHashtable }; + +// File[][] sources = {srcDeque, srcLinuxRWLock1, srcLinuxRWLock2, srcLinuxRWLock3, srcMCSLock, srcHashtable, srcRCU}; + File[][] sources = {srcMPMCQueue}; + // Compile all the benchmarks + for (int i = 0; i < sources.length; i++) { + CodeGenerator gen = new CodeGenerator(sources[i]); + gen.generateCode(); + } } }