3 import java.io.FileOutputStream;
4 import java.io.PrintStream;
6 import java.io.BufferedReader;
7 import java.io.FileReader;
8 import java.io.FileInputStream;
9 import java.util.Hashtable;
10 import java.util.Iterator;
12 import java.util.Vector;
14 import IR.Tree.ParseNode;
15 import IR.Tree.BuildIR;
16 import IR.Tree.JavaBuilder;
17 import IR.Tree.SemanticCheck;
19 import IR.Flat.Inliner;
20 import IR.ClassDescriptor;
22 import IR.TaskDescriptor;
24 import Analysis.SSJava.SSJavaAnalysis;
25 import Analysis.Scheduling.MCImplSynthesis;
26 import Analysis.Scheduling.Schedule;
27 import Analysis.Scheduling.ScheduleAnalysis;
28 import Analysis.Scheduling.ScheduleSimulator;
29 import Analysis.TaskStateAnalysis.TaskAnalysis;
30 import Analysis.TaskStateAnalysis.TaskTagAnalysis;
31 import Analysis.TaskStateAnalysis.TaskGraph;
32 import Analysis.CallGraph.CallGraph;
33 import Analysis.CallGraph.BaseCallGraph;
34 import Analysis.CallGraph.JavaCallGraph;
35 import Analysis.TaskStateAnalysis.FEdge;
36 import Analysis.TaskStateAnalysis.FlagState;
37 import Analysis.TaskStateAnalysis.TagAnalysis;
38 import Analysis.TaskStateAnalysis.GarbageAnalysis;
39 import Analysis.TaskStateAnalysis.ExecutionGraph;
40 import Analysis.TaskStateAnalysis.SafetyAnalysis;
41 import Analysis.Locality.LocalityAnalysis;
42 import Analysis.Locality.GenerateConversions;
43 import Analysis.Prefetch.PrefetchAnalysis;
44 import Analysis.FlatIRGraph.FlatIRGraph;
45 import Analysis.OwnershipAnalysis.OwnershipAnalysis;
46 import Analysis.Disjoint.DisjointAnalysis;
47 import Analysis.OoOJava.OoOJavaAnalysis;
48 import Analysis.Loops.*;
49 import Analysis.Liveness;
50 import Analysis.ArrayReferencees;
51 import Analysis.Pointer.Pointer;
52 import Analysis.Disjoint.HeapAnalysis;
53 import IR.MethodDescriptor;
54 import IR.Flat.FlatMethod;
56 import Util.GraphNode;
57 import Util.GraphNode.DFS;
58 import Util.GraphNode.SCC;
62 /** Main method for the compiler. */
64 public static void main(String args[]) throws Exception {
65 String ClassLibraryPrefix="./ClassLibrary/";
66 State state=new State();
67 Vector<String> sourcefiles=new Vector<String>();
69 state.classpath.add(".");
71 String outputdir = null;
72 boolean isDistributeInfo = false;
73 boolean isDisAll = false;
77 for(int i=0; i<args.length; i++) {
78 String option=args[i];
79 if (option.equals("-precise"))
80 IR.Flat.BuildCode.GENERATEPRECISEGC=true;
81 else if (option.equals("-jni"))
83 else if (option.equals("-capture-null-dereferences"))
84 state.CAPTURE_NULL_DEREFERENCES=true;
85 else if (option.equals("-prefetch"))
87 else if (option.equals("-dir"))
88 IR.Flat.BuildCode.PREFIX=args[++i]+"/";
89 else if (option.equals("-fastcheck"))
91 else if (option.equals("-selfloop"))
92 state.selfloops.add(args[++i]);
93 else if (option.equals("-outputdir"))
94 state.outputdir = args[++i];
95 else if (option.equals("-excprefetch"))
96 state.excprefetch.add(args[++i]);
97 else if (option.equals("-classlibrary"))
98 state.classpath.add(args[++i]);
99 else if (option.equals("-inlineatomic")) {
100 state.INLINEATOMIC=true;
101 state.inlineatomicdepth=Integer.parseInt(args[++i]);
102 } else if(option.equals("-numcore")) {
104 state.CORENUM = Integer.parseInt(args[i]);
105 } else if(option.equals("-numcore4gc")) {
107 state.CORENUM4GC = Integer.parseInt(args[i]);
108 } else if (option.equals("-mainclass"))
109 state.main=args[++i];
110 else if (option.equals("-trueprob")) {
111 state.TRUEPROB=Double.parseDouble(args[++i]);
112 } else if (option.equals("-printflat"))
113 State.PRINTFLAT=true;
114 else if (option.equals("-printscheduling"))
115 State.PRINTSCHEDULING=true;
116 else if (option.equals("-minimize"))
118 else if (option.equals("-printschedulesim"))
119 State.PRINTSCHEDULESIM=true;
120 else if (option.equals("-printcriticalpath"))
121 State.PRINTCRITICALPATH=true;
122 else if (option.equals("-struct"))
123 state.structfile=args[++i];
124 else if (option.equals("-conscheck"))
125 state.CONSCHECK=true;
126 else if (option.equals("-task"))
128 else if (option.equals("-abortreaders"))
129 state.ABORTREADERS=true;
130 else if (option.equals("-sandbox"))
132 else if (option.equals("-taskstate"))
133 state.TASKSTATE=true;
134 else if (option.equals("-tagstate"))
136 else if (option.equals("-stmarray"))
138 else if (option.equals("-eventmonitor"))
139 state.EVENTMONITOR=true;
140 else if (option.equals("-dualview"))
142 else if (option.equals("-hybrid"))
144 else if (option.equals("-flatirtasks")) {
145 state.FLATIRGRAPH=true;
146 state.FLATIRGRAPHTASKS=true;
147 } else if (option.equals("-flatirusermethods")) {
148 state.FLATIRGRAPH=true;
149 state.FLATIRGRAPHUSERMETHODS=true;
150 } else if (option.equals("-flatirlibmethods")) {
151 state.FLATIRGRAPH=true;
152 state.FLATIRGRAPHLIBMETHODS=true;
153 } else if (option.equals("-bamboocompiletime")) {
154 state.BAMBOOCOMPILETIME = true;
155 } else if (option.equals("-multicore"))
156 state.MULTICORE=true;
157 else if (option.equals("-multicoregc"))
158 state.MULTICOREGC=true;
159 else if (option.equals("-mgc")) {
161 } else if (option.equals("-objectlockdebug")) {
162 state.OBJECTLOCKDEBUG = true;
163 } else if (option.equals("-ownership"))
164 state.OWNERSHIP=true;
165 else if (option.equals("-ownallocdepth")) {
166 state.OWNERSHIPALLOCDEPTH=Integer.parseInt(args[++i]);
167 } else if (option.equals("-ownwritedots")) {
168 state.OWNERSHIPWRITEDOTS=true;
169 if (args[++i].equals("all")) {
170 state.OWNERSHIPWRITEALL=true;
172 } else if (option.equals("-ownaliasfile")) {
173 state.OWNERSHIPALIASFILE=args[++i];
174 } else if (option.equals("-ownaliasfiletab")) {
175 state.OWNERSHIPALIASFILE=args[++i];
176 state.OWNERSHIPALIASTAB=true;
177 } else if (option.equals("-owndebugcallee")) {
178 state.OWNERSHIPDEBUGCALLEE=args[++i];
179 } else if (option.equals("-owndebugcaller")) {
180 state.OWNERSHIPDEBUGCALLER=args[++i];
181 } else if (option.equals("-owndebugcallcount")) {
182 state.OWNERSHIPDEBUGCALLCOUNT=Integer.parseInt(args[++i]);
183 } else if (option.equals("-pointer")) {
185 } else if (option.equals("-disjoint"))
187 else if (option.equals("-disjoint-k")) {
188 state.DISJOINTALLOCDEPTH=Integer.parseInt(args[++i]);
190 } else if (option.equals("-disjoint-write-dots")) {
191 state.DISJOINTWRITEDOTS = true;
192 String arg = args[++i];
193 if( arg.equals("all") ) {
194 state.DISJOINTWRITEALL = true;
195 } else if( arg.equals("final") ) {
196 state.DISJOINTWRITEALL = false;
198 throw new Error("disjoint-write-dots requires argument <all/final>");
201 } else if (option.equals("-disjoint-write-initial-contexts")) {
202 state.DISJOINTWRITEINITCONTEXTS = true;
204 } else if (option.equals("-disjoint-write-ihms")) {
205 state.DISJOINTWRITEIHMS = true;
207 } else if (option.equals("-disjoint-alias-file")) {
208 state.DISJOINTALIASFILE = args[++i];
209 String arg = args[++i];
210 if( arg.equals("normal") ) {
211 state.DISJOINTALIASTAB = false;
212 } else if( arg.equals("tabbed") ) {
213 state.DISJOINTALIASTAB = true;
215 throw new Error("disjoint-alias-file requires arguments: <filename> <normal/tabbed>");
218 } else if (option.equals("-disjoint-debug-callsite")) {
219 state.DISJOINTDEBUGCALLEE=args[++i];
220 state.DISJOINTDEBUGCALLER=args[++i];
221 state.DISJOINTDEBUGCALLVISITTOSTART=Integer.parseInt(args[++i]);
222 state.DISJOINTDEBUGCALLNUMVISITS=Integer.parseInt(args[++i]);
223 String arg = args[++i];
224 if( arg.equals("true") ) {
225 state.DISJOINTDEBUGCALLSTOPAFTER = true;
226 } else if( arg.equals("false") ) {
227 state.DISJOINTDEBUGCALLSTOPAFTER = false;
229 throw new Error("disjoint-debug-callsite requires arguments:\n"+
230 " <callee symbol> <caller symbol> <# visit to start> <# visits to capture> <T/F stop after>");
232 System.out.println( "Disjoint analysis is debugging when "+
233 state.DISJOINTDEBUGCALLER+" calls "+
234 state.DISJOINTDEBUGCALLEE+" starting after "+
235 state.DISJOINTDEBUGCALLVISITTOSTART+" visits and running for "+
236 state.DISJOINTDEBUGCALLNUMVISITS+ " visits." );
238 } else if (option.equals("-disjoint-debug-snap-method")) {
239 state.DISJOINTSNAPSYMBOL=args[++i];
240 state.DISJOINTSNAPVISITTOSTART=Integer.parseInt(args[++i]);
241 state.DISJOINTSNAPNUMVISITS=Integer.parseInt(args[++i]);
242 String arg = args[++i];
243 if( arg.equals("true") ) {
244 state.DISJOINTSNAPSTOPAFTER = true;
245 } else if( arg.equals("false") ) {
246 state.DISJOINTSNAPSTOPAFTER = false;
248 throw new Error("disjoint-debug-snap-method requires arguments:\n"+
249 " <method symbol> <# visit to start> <# visits to snap> <T/F stop after>");
252 } else if( option.equals("-disjoint-release-mode") ) {
253 state.DISJOINTRELEASEMODE = true;
255 } else if( option.equals("-disjoint-dvisit-stack") ) {
256 state.DISJOINTDVISITSTACK = true;
257 state.DISJOINTDVISITPQUE = false;
258 state.DISJOINTDVISITSTACKEESONTOP = false;
260 } else if( option.equals("-disjoint-dvisit-pqueue") ) {
261 state.DISJOINTDVISITPQUE = true;
262 state.DISJOINTDVISITSTACK = false;
263 state.DISJOINTDVISITSTACKEESONTOP = false;
265 } else if( option.equals("-disjoint-dvisit-stack-callees-on-top") ) {
266 state.DISJOINTDVISITSTACKEESONTOP = true;
267 state.DISJOINTDVISITPQUE = false;
268 state.DISJOINTDVISITSTACK = false;
270 } else if( option.equals("-disjoint-desire-determinism") ) {
271 state.DISJOINTDETERMINISM = true;
273 // when asking analysis for a deterministic result, force
274 // a stack-based visiting scheme, because the priority queue
275 // requires a non-deterministic topological sort
276 state.DISJOINTDVISITSTACKEESONTOP = true;
277 state.DISJOINTDVISITPQUE = false;
278 state.DISJOINTDVISITSTACK = false;
281 } else if( option.equals("-disjoint-debug-scheduling") ) {
282 state.DISJOINTDEBUGSCHEDULING = true;
285 } else if( option.equals("-pointsto-check-v-runtime") ) {
286 state.POINTSTO_CHECK_V_RUNTIME = true;
289 } else if (option.equals("-optional"))
291 else if (option.equals("-optimize"))
293 else if (option.equals("-noloop"))
295 else if (option.equals("-dcopts"))
297 else if (option.equals("-arraypad"))
299 else if (option.equals("-delaycomp"))
300 state.DELAYCOMP=true;
301 else if (option.equals("-raw"))
303 else if (option.equals("-scheduling"))
304 state.SCHEDULING=true;
305 else if (option.equals("-distributioninfo"))
306 isDistributeInfo=true;
307 else if (option.equals("-disall"))
309 else if (option.equals("-disstart"))
310 startnum = Integer.parseInt(args[++i]);
311 else if (option.equals("-useprofile")) {
312 state.USEPROFILE=true;
313 state.profilename = args[++i];
314 } else if (option.equals("-thread"))
316 else if (option.equals("-dsm"))
318 else if (option.equals("-recoverystats"))
319 state.DSMRECOVERYSTATS=true;
320 else if (option.equals("-dsmtask"))
322 else if (option.equals("-singleTM"))
324 else if (option.equals("-readset"))
326 else if (option.equals("-webinterface"))
327 state.WEBINTERFACE=true;
328 else if (option.equals("-instructionfailures"))
329 state.INSTRUCTIONFAILURE=true;
330 else if (option.equals("-abcclose"))
331 state.ARRAYBOUNDARYCHECK=false;
333 else if (option.equals("-methodeffects")) {
334 state.METHODEFFECTS=true;
336 } else if (option.equals("-coreprof")) {
339 } else if (option.equals("-ooojava")) {
340 state.OOOJAVA = true;
341 state.DISJOINT = true;
342 state.OOO_NUMCORES = Integer.parseInt(args[++i]);
343 state.OOO_MAXSESEAGE = Integer.parseInt(args[++i]);
345 } else if (option.equals("-ooodebug") ) {
346 state.OOODEBUG = true;
347 } else if (option.equals("-rcr")) {
349 state.KEEP_RG_FOR_ALL_PROGRAM_POINTS=true;
350 } else if (option.equals("-rcr_debug")) {
351 state.RCR_DEBUG = true;
352 state.KEEP_RG_FOR_ALL_PROGRAM_POINTS=true;
353 } else if (option.equals("-rcr_debug_verbose")) {
354 state.RCR_DEBUG_VERBOSE = true;
355 state.KEEP_RG_FOR_ALL_PROGRAM_POINTS=true;
356 } else if (option.equals("-nostalltr")) {
357 state.NOSTALLTR = true;
358 } else if (option.equals("-ssjava")) {
360 } else if (option.equals("-printlinenum")) {
362 } else if (option.equals("-help")) {
363 System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
364 System.out.println("-selfloop task -- this task doesn't self loop its parameters forever");
365 System.out.println("-dir outputdirectory -- output code in outputdirectory");
366 System.out.println("-struct structfile -- output structure declarations for repair tool");
367 System.out.println("-mainclass -- main function to call");
368 System.out.println("-dsm -- distributed shared memory support");
369 System.out.println("-singleTM -- single machine committing transactions");
370 System.out.println("-abortreaders -- abort readers");
371 System.out.println("-precise -- use precise garbage collection");
372 System.out.println("-conscheck -- turn on consistency checking");
373 System.out.println("-task -- compiler for tasks");
374 System.out.println("-fastcheck -- fastcheckpointing for Bristlecone");
375 System.out.println("-thread -- threads");
376 System.out.println("-trueprob <d> -- probability of true branch");
377 System.out.println("-printflat -- print out flat representation");
378 System.out.println("-instructionfailures -- insert code for instruction level failures");
379 System.out.println("-taskstate -- do task state analysis");
380 System.out.println("-flatirtasks -- create dot files for flat IR graphs of tasks");
381 System.out.println("-flatirusermethods -- create dot files for flat IR graphs of user methods");
382 System.out.println("-flatirlibmethods -- create dot files for flat IR graphs of library class methods");
383 System.out.println(" note: -flatirusermethods or -flatirlibmethods currently generate all class method flat IR graphs");
384 System.out.println("-ownership -- do ownership analysis");
385 System.out.println("-ownallocdepth <d> -- set allocation depth for ownership analysis");
386 System.out.println("-ownwritedots <all/final> -- write ownership graphs; can be all results or just final results");
387 System.out.println("-ownaliasfile <filename> -- write a text file showing all detected aliases in program tasks");
388 System.out.println("-optimize -- enable optimizations");
389 System.out.println("-noloop -- disable loop optimizations");
390 System.out.println("-optional -- enable optional arguments");
391 System.out.println("-abcclose close the array boundary check");
392 System.out.println("-scheduling do task scheduling");
393 System.out.println("-mlp <num cores> <max sese age> build mlp code");
394 System.out.println("-mlpdebug if mlp, report progress and interim results");
395 System.out.println("-multicore generate multi-core version binary");
396 System.out.println("-numcore set the number of cores (should be used together with -multicore), defaultly set as 1");
397 System.out.println("-interrupt generate raw version binary with interruption (should be used togethere with -raw)");
398 System.out.println("-rawconfig config raw simulator as 4xn (should be used together with -raw)");
399 System.out.println("-rawpath print out execute path information for raw version (should be used together with -raw)");
400 System.out.println("-useprofile use profiling data for scheduling (should be used together with -raw)");
401 System.out.println("-threadsimulate generate multi-thread simulate version binary");
402 System.out.println("-rawuseio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version");
403 System.out.println("-printscheduling -- print out scheduling graphs");
404 System.out.println("-printschedulesim -- print out scheduling simulation result graphs");
405 System.out.println("-webinterface -- enable web interface");
406 System.out.println("-linenum print out line numbers in generated C codes");
407 System.out.println("-help -- print out help");
410 sourcefiles.add(args[i]);
414 //add default classpath
415 if (state.classpath.size()==1)
416 state.classpath.add(ClassLibraryPrefix);
418 State.logEvent("Done Parsing Commands");
419 System.out.println("Classpath: "+state.classpath);
421 SSJavaAnalysis ssjava=new SSJavaAnalysis(state);
428 BuildIR bir=new BuildIR(state);
429 tu=new TypeUtil(state, bir);
430 SemanticCheck sc=new SemanticCheck(state,tu);
432 for(int i=0; i<sourcefiles.size(); i++)
433 loadClass(state, bir, sourcefiles.get(i));
435 //Stuff the runtime wants to see
438 sc.getClass(null, "TagDescriptor");
442 State.logEvent("Done Semantic Checking");
444 tu.createFullTable();
445 State.logEvent("Done Creating TypeUtil");
447 bf=new BuildFlat(state,tu);
449 State.logEvent("Done Building Flat");
451 jb=new JavaBuilder(state);
454 bf=jb.getBuildFlat();
457 SafetyAnalysis sa=null;
458 PrefetchAnalysis pa=null;
459 OoOJavaAnalysis oooa=null;
460 HeapAnalysis heapAnalysis=null;
462 if (state.INLINEATOMIC) {
463 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
464 while(classit.hasNext()) {
465 ClassDescriptor cn=(ClassDescriptor)classit.next();
466 Iterator methodit=cn.getMethods();
467 while(methodit.hasNext()) {
469 MethodDescriptor md=(MethodDescriptor)methodit.next();
470 FlatMethod fm=state.getMethodFlat(md);
471 Inliner.inlineAtomic(state, tu, fm, state.inlineatomicdepth);
476 CallGraph callgraph=jb!=null?jb:(state.TASK?new BaseCallGraph(state, tu):new JavaCallGraph(state, tu));
481 State.logEvent("Done SSJava Checking");
484 if (state.OPTIMIZE) {
485 CopyPropagation cp=new CopyPropagation();
486 DeadCode dc=new DeadCode();
487 GlobalFieldType gft=new GlobalFieldType(callgraph, state, tu.getMain());
488 CSE cse=new CSE(gft, tu);
489 localCSE lcse=new localCSE(gft, tu);
490 LoopOptimize lo=null;
492 lo=new LoopOptimize(gft, tu);
493 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
494 while(classit.hasNext()) {
495 ClassDescriptor cn=(ClassDescriptor)classit.next();
496 Iterator methodit=cn.getMethods();
497 while(methodit.hasNext()) {
498 /* Classify parameters */
499 MethodDescriptor md=(MethodDescriptor)methodit.next();
500 FlatMethod fm=state.getMethodFlat(md);
517 State.logEvent("Done Optimizing");
520 if (state.FLATIRGRAPH) {
521 FlatIRGraph firg = new FlatIRGraph(state,
522 state.FLATIRGRAPHTASKS,
523 state.FLATIRGRAPHUSERMETHODS,
524 state.FLATIRGRAPHLIBMETHODS);
527 if (state.OWNERSHIP) {
528 Liveness liveness = new Liveness();
529 ArrayReferencees ar = new ArrayReferencees(state, tu, callgraph);
530 OwnershipAnalysis oa = new OwnershipAnalysis(state,
535 state.OWNERSHIPALLOCDEPTH,
536 state.OWNERSHIPWRITEDOTS,
537 state.OWNERSHIPWRITEALL,
538 state.OWNERSHIPALIASFILE,
539 state.METHODEFFECTS);
542 if (state.DISJOINT && !state.OOOJAVA) {
543 Liveness l = new Liveness();
544 ArrayReferencees ar = new ArrayReferencees(state, tu, callgraph);
545 DisjointAnalysis da = new DisjointAnalysis(state, tu, callgraph, l, ar, null, null);
550 Liveness l = new Liveness();
551 ArrayReferencees ar = new ArrayReferencees(state, tu, callgraph);
552 oooa = new OoOJavaAnalysis(state, tu, callgraph, l, ar);
553 heapAnalysis = oooa.getHeapAnalysis();
557 if (state.TAGSTATE) {
558 TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
559 TaskTagAnalysis tta=new TaskTagAnalysis(state, taganalysis, tu);
562 if (state.TASKSTATE) {
563 TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
564 TaskAnalysis ta=new TaskAnalysis(state, taganalysis, tu);
566 TaskGraph tg=new TaskGraph(state, ta);
569 if (state.OPTIONAL) {
570 ExecutionGraph et=new ExecutionGraph(state, ta);
571 et.createExecutionGraph();
572 sa = new SafetyAnalysis(et.getExecutionGraph(), state, ta);
574 state.storeAnalysisResult(sa.getResult());
575 state.storeOptionalTaskDescriptors(sa.getOptionalTaskDescriptors());
578 if (state.WEBINTERFACE) {
579 GarbageAnalysis ga=new GarbageAnalysis(state, ta);
580 WebInterface wi=new WebInterface(state, ta, tg, ga, taganalysis);
581 JhttpServer serve=new JhttpServer(8000,wi);
585 if (state.SCHEDULING) {
586 // Use ownership analysis to get alias information
587 Liveness liveness = new Liveness();
588 ArrayReferencees ar = new ArrayReferencees(state, tu, callgraph);
589 OwnershipAnalysis oa = null; /*new OwnershipAnalysis(state,
594 state.OWNERSHIPALLOCDEPTH,
595 state.OWNERSHIPWRITEDOTS,
596 state.OWNERSHIPWRITEALL,
597 state.OWNERSHIPALIASFILE);*/
599 // synthesis a layout according to target multicore processor
600 MCImplSynthesis mcImplSynthesis = new MCImplSynthesis(state,
603 if(isDistributeInfo) {
604 mcImplSynthesis.distribution(isDisAll, startnum);
606 double timeStartAnalysis = (double) System.nanoTime();
607 mcImplSynthesis.setScheduleThreshold(20);
608 mcImplSynthesis.setProbThreshold(0);
609 mcImplSynthesis.setGenerateThreshold(30);
610 Vector<Schedule> scheduling = mcImplSynthesis.synthesis();
612 double timeEndAnalysis = (double) System.nanoTime();
613 if(state.BAMBOOCOMPILETIME) {
614 double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow(10.0, 9.0) );
615 System.err.println("The analysis took" + dt + "sec.");
619 // generate multicore codes
620 if(state.MULTICORE) {
621 BuildCodeMultiCore bcm=new BuildCodeMultiCore(state,
626 mcImplSynthesis.getCoreNum(),
627 state.CORENUM4GC, callgraph);
628 bcm.setOwnershipAnalysis(oa);
638 // generate multicore codes
639 if(state.MULTICORE) {
640 BuildCodeMGC bcmgc=new BuildCodeMGC(state,
646 state.CORENUM4GC, callgraph);
651 if(!state.MULTICORE) {
654 if (state.DSM||state.SINGLETM) {
655 if (state.PREFETCH) {
656 //speed up prefetch generation using locality analysis results
657 LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
658 pa=new PrefetchAnalysis(state, callgraph, tu, la);
660 LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
661 GenerateConversions gc=new GenerateConversions(la, state);
662 bc=new BuildCodeTran(state, bf.getMap(), tu, la, pa, callgraph);
664 if( state.OOOJAVA ) {
665 bc=new BuildOoOJavaCode(state, bf.getMap(), tu, sa, oooa, callgraph);
667 bc=new BuildCode(state, bf.getMap(), tu, sa, callgraph, jb);
671 if( (state.OOOJAVA || state.POINTSTO_CHECK_V_RUNTIME) &&
672 heapAnalysis != null ) {
673 // use this extension to generate the allocsite field of Object and
674 // ArrayObject for whatever other extensions and systems need it
675 BCXallocsiteObjectField bcx = new BCXallocsiteObjectField( bc, heapAnalysis );
676 bc.registerExtension( bcx );
679 if( state.POINTSTO_CHECK_V_RUNTIME &&
680 heapAnalysis != null ) {
681 BCXPointsToCheckVRuntime bcx = new BCXPointsToCheckVRuntime( bc, heapAnalysis );
682 bc.registerExtension( bcx );
686 State.logEvent("Done With BuildCode");
690 System.out.println("Lines="+state.lines);
694 public static void loadClass(State state, BuildIR bir, String sourcefile) {
696 ParseNode pn=readSourceFile(state, sourcefile);
697 bir.buildtree(pn, null,sourcefile);
698 } catch (Exception e) {
699 System.out.println("Error in sourcefile:"+sourcefile);
703 System.out.println("Error in sourcefile:"+sourcefile);
709 /** Reads in a source file and adds the parse tree to the state object. */
711 public static ParseNode readSourceFile(State state, String sourcefile) {
713 Reader fr= new BufferedReader(new FileReader(sourcefile));
714 Lex.Lexer l = new Lex.Lexer(fr, state.TASK);
715 java_cup.runtime.lr_parser g;
716 g = new Parse.Parser(l);
719 p=(ParseNode) g./*debug_*/ parse().value;
720 } catch (Exception e) {
721 System.err.println("Error parsing file:"+sourcefile);
725 state.addParseNode(p);
726 if (l.numErrors()!=0) {
727 System.out.println("Error parsing "+sourcefile);
728 System.exit(l.numErrors());
730 state.lines+=l.line_num;
733 } catch (Exception e) {