introduces new flag for runtime conflict resolver.
[IRC.git] / Robust / src / Main / Main.java
1 package Main;
2
3 import java.io.FileOutputStream;
4 import java.io.PrintStream;
5 import java.io.Reader;
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;
11 import java.util.Set;
12 import java.util.Vector;
13
14 import IR.Tree.ParseNode;
15 import IR.Tree.BuildIR;
16 import IR.Tree.SemanticCheck;
17 import IR.Flat.BuildCodeMultiCore;
18 import IR.Flat.BuildFlat;
19 import IR.Flat.BuildCode;
20 import IR.Flat.Inliner;
21 import IR.ClassDescriptor;
22 import IR.State;
23 import IR.TaskDescriptor;
24 import IR.TypeUtil;
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.TaskStateAnalysis.FEdge;
34 import Analysis.TaskStateAnalysis.FlagState;
35 import Analysis.TaskStateAnalysis.TagAnalysis;
36 import Analysis.TaskStateAnalysis.GarbageAnalysis;
37 import Analysis.TaskStateAnalysis.ExecutionGraph;
38 import Analysis.TaskStateAnalysis.SafetyAnalysis;
39 import Analysis.Locality.LocalityAnalysis;
40 import Analysis.Locality.GenerateConversions;
41 import Analysis.Prefetch.PrefetchAnalysis;
42 import Analysis.FlatIRGraph.FlatIRGraph;
43 import Analysis.OwnershipAnalysis.OwnershipAnalysis;
44 import Analysis.MLP.MLPAnalysis;
45 import Analysis.Disjoint.DisjointAnalysis;
46 import Analysis.OoOJava.OoOJavaAnalysis;
47 import Analysis.Loops.*;
48 import Analysis.Liveness;
49 import Analysis.ArrayReferencees;
50 import IR.MethodDescriptor;
51 import IR.Flat.FlatMethod;
52 import Interface.*;
53 import Util.GraphNode;
54 import Util.GraphNode.DFS;
55 import Util.GraphNode.SCC;
56
57 public class Main {
58
59   /** Main method for the compiler.  */
60
61   public static void main(String args[]) throws Exception {
62     String ClassLibraryPrefix="./ClassLibrary/";
63     State state=new State();
64     Vector sourcefiles=new Vector();
65     state.classpath.add(".");
66
67     String outputdir = null;
68     boolean isDistributeInfo = false;
69     boolean isDisAll = false;
70     int startnum = 0;
71
72     for(int i=0; i<args.length; i++) {
73       String option=args[i];
74       if (option.equals("-precise"))
75         IR.Flat.BuildCode.GENERATEPRECISEGC=true;
76       else if (option.equals("-prefetch"))
77         state.PREFETCH=true;
78       else if (option.equals("-dir"))
79         IR.Flat.BuildCode.PREFIX=args[++i]+"/";
80       else if (option.equals("-fastcheck"))
81         state.FASTCHECK=true;
82       else if (option.equals("-selfloop"))
83         state.selfloops.add(args[++i]);
84           else if (option.equals("-outputdir"))
85         state.outputdir = args[++i];
86       else if (option.equals("-excprefetch"))
87         state.excprefetch.add(args[++i]);
88       else if (option.equals("-classlibrary"))
89         state.classpath.add(args[++i]);
90       else if (option.equals("-inlineatomic")) {
91         state.INLINEATOMIC=true;
92         state.inlineatomicdepth=Integer.parseInt(args[++i]);
93       } else if(option.equals("-numcore")) {
94         ++i;
95         state.CORENUM = Integer.parseInt(args[i]);
96       } else if(option.equals("-numcore4gc")) {
97         ++i;
98         state.CORENUM4GC = Integer.parseInt(args[i]);
99       } else if (option.equals("-mainclass"))
100         state.main=args[++i];
101       else if (option.equals("-trueprob")) {
102         state.TRUEPROB=Double.parseDouble(args[++i]);
103       } else if (option.equals("-printflat"))
104         State.PRINTFLAT=true;
105       else if (option.equals("-printscheduling"))
106         State.PRINTSCHEDULING=true;
107       else if (option.equals("-minimize"))
108         state.MINIMIZE=true;
109       else if (option.equals("-printschedulesim"))
110         State.PRINTSCHEDULESIM=true;
111       else if (option.equals("-printcriticalpath"))
112           State.PRINTCRITICALPATH=true;
113       else if (option.equals("-struct"))
114         state.structfile=args[++i];
115       else if (option.equals("-conscheck"))
116         state.CONSCHECK=true;
117       else if (option.equals("-task"))
118         state.TASK=true;
119       else if (option.equals("-abortreaders"))
120         state.ABORTREADERS=true;
121       else if (option.equals("-sandbox"))
122         state.SANDBOX=true;
123       else if (option.equals("-taskstate"))
124         state.TASKSTATE=true;
125       else if (option.equals("-tagstate"))
126         state.TAGSTATE=true;
127       else if (option.equals("-stmarray"))
128         state.STMARRAY=true;
129       else if (option.equals("-eventmonitor"))
130         state.EVENTMONITOR=true;
131       else if (option.equals("-dualview"))
132         state.DUALVIEW=true;
133       else if (option.equals("-hybrid"))
134         state.HYBRID=true;
135       else if (option.equals("-flatirtasks")) {
136         state.FLATIRGRAPH=true;
137         state.FLATIRGRAPHTASKS=true;
138       } else if (option.equals("-flatirusermethods")) {
139         state.FLATIRGRAPH=true;
140         state.FLATIRGRAPHUSERMETHODS=true;
141       } else if (option.equals("-flatirlibmethods")) {
142         state.FLATIRGRAPH=true;
143         state.FLATIRGRAPHLIBMETHODS=true;
144       } else if (option.equals("-bamboocompiletime")) {
145         state.BAMBOOCOMPILETIME = true;
146       } else if (option.equals("-multicore"))
147         state.MULTICORE=true;
148       else if (option.equals("-multicoregc"))
149         state.MULTICOREGC=true;
150       else if (option.equals("-ownership"))
151         state.OWNERSHIP=true;
152       else if (option.equals("-ownallocdepth")) {
153         state.OWNERSHIPALLOCDEPTH=Integer.parseInt(args[++i]);
154       } else if (option.equals("-ownwritedots")) {
155         state.OWNERSHIPWRITEDOTS=true;
156         if (args[++i].equals("all")) {
157           state.OWNERSHIPWRITEALL=true;
158         }
159       } else if (option.equals("-ownaliasfile")) {
160         state.OWNERSHIPALIASFILE=args[++i];
161       } else if (option.equals("-ownaliasfiletab")) {
162         state.OWNERSHIPALIASFILE=args[++i];
163         state.OWNERSHIPALIASTAB=true;      
164       } else if (option.equals("-owndebugcallee")) {
165         state.OWNERSHIPDEBUGCALLEE=args[++i];
166       } else if (option.equals("-owndebugcaller")) {
167         state.OWNERSHIPDEBUGCALLER=args[++i];
168       } else if (option.equals("-owndebugcallcount")) {
169         state.OWNERSHIPDEBUGCALLCOUNT=Integer.parseInt(args[++i]);
170       }
171
172       else if (option.equals("-disjoint"))
173         state.DISJOINT=true;
174
175       else if (option.equals("-disjoint-k")) {
176         state.DISJOINTALLOCDEPTH=Integer.parseInt(args[++i]);
177
178       } else if (option.equals("-disjoint-write-dots")) {
179         state.DISJOINTWRITEDOTS = true;
180         String arg = args[++i];
181         if( arg.equals("all") ) {
182           state.DISJOINTWRITEALL = true;
183         } else if( arg.equals("final") ) {
184           state.DISJOINTWRITEALL = false;
185         } else {
186           throw new Error("disjoint-write-dots requires argument <all/final>");
187         }
188
189       } else if (option.equals("-disjoint-write-initial-contexts")) {
190         state.DISJOINTWRITEINITCONTEXTS = true;
191
192       } else if (option.equals("-disjoint-write-ihms")) {
193         state.DISJOINTWRITEIHMS = true;
194
195       } else if (option.equals("-disjoint-alias-file")) {
196         state.DISJOINTALIASFILE = args[++i];
197         String arg = args[++i];
198         if( arg.equals("normal") ) {
199           state.DISJOINTALIASTAB = false;
200         } else if( arg.equals("tabbed") ) {
201           state.DISJOINTALIASTAB = true;
202         } else {
203           throw new Error("disjoint-alias-file requires arguments: <filename> <normal/tabbed>");
204         }
205
206       } else if (option.equals("-disjoint-debug-callsite")) {
207         state.DISJOINTDEBUGCALLEE=args[++i];
208         state.DISJOINTDEBUGCALLER=args[++i];
209         state.DISJOINTDEBUGCALLVISITTOSTART=Integer.parseInt(args[++i]);
210         state.DISJOINTDEBUGCALLNUMVISITS=Integer.parseInt(args[++i]);
211         String arg = args[++i];
212         if( arg.equals("true") ) {
213           state.DISJOINTDEBUGCALLSTOPAFTER = true;
214         } else if( arg.equals("false") ) {
215           state.DISJOINTDEBUGCALLSTOPAFTER = false;
216         } else {
217           throw new Error("disjoint-debug-callsite requires arguments:\n"+
218                           "  <callee symbol> <caller symbol> <# visit to start> <# visits to capture> <T/F stop after>");
219         }
220       
221       } else if (option.equals("-disjoint-debug-snap-method")) {
222         state.DISJOINTSNAPSYMBOL=args[++i];
223         state.DISJOINTSNAPVISITTOSTART=Integer.parseInt(args[++i]);
224         state.DISJOINTSNAPNUMVISITS=Integer.parseInt(args[++i]);
225         String arg = args[++i];
226         if( arg.equals("true") ) {
227           state.DISJOINTSNAPSTOPAFTER = true;
228         } else if( arg.equals("false") ) {
229           state.DISJOINTSNAPSTOPAFTER = false;
230         } else {
231           throw new Error("disjoint-debug-snap-method requires arguments:\n"+
232                           "  <method symbol> <# visit to start> <# visits to snap> <T/F stop after>");
233         }
234
235       } else if( option.equals( "-disjoint-release-mode" ) ) {
236         state.DISJOINTRELEASEMODE = true;        
237
238       } else if( option.equals( "-disjoint-dvisit-stack" ) ) {
239         state.DISJOINTDVISITSTACK         = true;      
240         state.DISJOINTDVISITPQUE          = false;
241         state.DISJOINTDVISITSTACKEESONTOP = false;
242
243       } else if( option.equals( "-disjoint-dvisit-pqueue" ) ) {
244         state.DISJOINTDVISITPQUE          = true;
245         state.DISJOINTDVISITSTACK         = false;
246         state.DISJOINTDVISITSTACKEESONTOP = false;
247
248       } else if( option.equals( "-disjoint-dvisit-stack-callees-on-top" ) ) {
249         state.DISJOINTDVISITSTACKEESONTOP = true;
250         state.DISJOINTDVISITPQUE          = false;
251         state.DISJOINTDVISITSTACK         = false;      
252
253       } else if( option.equals( "-disjoint-desire-determinism" ) ) {
254         state.DISJOINTDETERMINISM = true;
255
256         // when asking analysis for a deterministic result, force
257         // a stack-based visiting scheme, because the priority queue
258         // requires a non-deterministic topological sort
259         state.DISJOINTDVISITSTACKEESONTOP = true;
260         state.DISJOINTDVISITPQUE          = false;
261         state.DISJOINTDVISITSTACK         = false;
262
263
264       } else if( option.equals( "-disjoint-debug-scheduling" ) ) {
265         state.DISJOINTDEBUGSCHEDULING = true;
266       }
267       
268
269       else if (option.equals("-optional"))
270         state.OPTIONAL=true;
271       else if (option.equals("-optimize"))
272         state.OPTIMIZE=true;
273       else if (option.equals("-noloop"))
274         state.NOLOOP=true;
275       else if (option.equals("-dcopts"))
276         state.DCOPTS=true;
277       else if (option.equals("-arraypad"))
278         state.ARRAYPAD=true;
279       else if (option.equals("-delaycomp"))
280         state.DELAYCOMP=true;
281       else if (option.equals("-raw"))
282         state.RAW=true;
283       else if (option.equals("-scheduling"))
284         state.SCHEDULING=true;
285       else if (option.equals("-distributioninfo"))
286         isDistributeInfo=true;
287       else if (option.equals("-disall"))
288         isDisAll=true;
289       else if (option.equals("-disstart"))
290         startnum = Integer.parseInt(args[++i]);
291       else if (option.equals("-useprofile")) {
292         state.USEPROFILE=true;
293     state.profilename = args[++i];
294       }
295       else if (option.equals("-thread"))
296         state.THREAD=true;
297       else if (option.equals("-dsm"))
298         state.DSM=true;
299       else if (option.equals("-recoverystats"))
300   state.DSMRECOVERYSTATS=true;
301       else if (option.equals("-dsmtask"))
302   state.DSMTASK=true;
303       else if (option.equals("-singleTM"))
304         state.SINGLETM=true;
305       else if (option.equals("-readset"))
306         state.READSET=true;
307       else if (option.equals("-webinterface"))
308         state.WEBINTERFACE=true;
309       else if (option.equals("-instructionfailures"))
310         state.INSTRUCTIONFAILURE=true;
311       else if (option.equals("-abcclose"))
312         state.ARRAYBOUNDARYCHECK=false;
313
314       else if (option.equals("-mlp")) {
315         state.MLP            = true;
316         state.OWNERSHIP      = true;
317         state.MLP_NUMCORES   = Integer.parseInt( args[++i] );
318         state.MLP_MAXSESEAGE = Integer.parseInt( args[++i] );
319
320       } else if (option.equals("-mlpdebug")) {
321         state.MLPDEBUG=true;
322
323       } else if (option.equals("-methodeffects")) {
324         state.METHODEFFECTS=true;
325         
326       } else if (option.equals("-coreprof")) {
327         state.COREPROF=true;
328
329       } else if (option.equals("-ooojava")) {
330         state.OOOJAVA  = true;
331         state.DISJOINT = true;
332         state.MLP_NUMCORES   = Integer.parseInt( args[++i] );
333         state.MLP_MAXSESEAGE = Integer.parseInt( args[++i] );
334
335       } else if (option.equals("-ooodebug") ){ 
336   state.OOODEBUG  = true;
337       } else if (option.equals("-rcr")){
338    state.RCR = true;
339       } else if (option.equals("-help")) {
340         System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
341         System.out.println("-selfloop task -- this task doesn't self loop its parameters forever");
342         System.out.println("-dir outputdirectory -- output code in outputdirectory");
343         System.out.println("-struct structfile -- output structure declarations for repair tool");
344         System.out.println("-mainclass -- main function to call");
345         System.out.println("-dsm -- distributed shared memory support");
346         System.out.println("-singleTM -- single machine committing transactions");
347         System.out.println("-abortreaders -- abort readers");
348         System.out.println("-precise -- use precise garbage collection");
349         System.out.println("-conscheck -- turn on consistency checking");
350         System.out.println("-task -- compiler for tasks");
351         System.out.println("-fastcheck -- fastcheckpointing for Bristlecone");
352         System.out.println("-thread -- threads");
353         System.out.println("-trueprob <d> -- probability of true branch");
354         System.out.println("-printflat -- print out flat representation");
355         System.out.println("-instructionfailures -- insert code for instruction level failures");
356         System.out.println("-taskstate -- do task state analysis");
357         System.out.println("-flatirtasks -- create dot files for flat IR graphs of tasks");
358         System.out.println("-flatirusermethods -- create dot files for flat IR graphs of user methods");
359         System.out.println("-flatirlibmethods -- create dot files for flat IR graphs of library class methods");
360         System.out.println("  note: -flatirusermethods or -flatirlibmethods currently generate all class method flat IR graphs");
361         System.out.println("-ownership -- do ownership analysis");
362         System.out.println("-ownallocdepth <d> -- set allocation depth for ownership analysis");
363         System.out.println("-ownwritedots <all/final> -- write ownership graphs; can be all results or just final results");
364         System.out.println("-ownaliasfile <filename> -- write a text file showing all detected aliases in program tasks");
365         System.out.println("-optimize -- enable optimizations");
366         System.out.println("-noloop -- disable loop optimizations");
367         System.out.println("-optional -- enable optional arguments");
368         System.out.println("-abcclose close the array boundary check");
369         System.out.println("-scheduling do task scheduling");
370         System.out.println("-mlp <num cores> <max sese age> build mlp code");
371         System.out.println("-mlpdebug if mlp, report progress and interim results");
372         System.out.println("-multicore generate multi-core version binary");
373         System.out.println("-numcore set the number of cores (should be used together with -multicore), defaultly set as 1");
374         System.out.println("-interrupt generate raw version binary with interruption (should be used togethere with -raw)");
375         System.out.println("-rawconfig config raw simulator as 4xn (should be used together with -raw)");
376         System.out.println("-rawpath print out execute path information for raw version (should be used together with -raw)");
377         System.out.println("-useprofile use profiling data for scheduling (should be used together with -raw)");
378         System.out.println("-threadsimulate generate multi-thread simulate version binary");
379         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");
380         System.out.println("-printscheduling -- print out scheduling graphs");
381         System.out.println("-printschedulesim -- print out scheduling simulation result graphs");
382         System.out.println("-webinterface -- enable web interface");
383         System.out.println("-help -- print out help");
384         System.exit(0);
385       } else {
386         sourcefiles.add(args[i]);
387       }
388     }
389     
390     //add default classpath
391     if (state.classpath.size()==1)
392       state.classpath.add(ClassLibraryPrefix);
393
394     BuildIR bir=new BuildIR(state);
395     TypeUtil tu=new TypeUtil(state, bir);
396     
397
398     SemanticCheck sc=new SemanticCheck(state,tu);
399
400     for(int i=0;i<sourcefiles.size();i++)
401       loadClass(state, bir,(String)sourcefiles.get(i));
402
403
404     //Stuff the runtime wants to see
405     sc.getClass("String");
406     sc.getClass("Math");
407     sc.getClass("File");
408     sc.getClass("Socket");
409     sc.getClass("ServerSocket");
410     sc.getClass("FileInputStream");
411     sc.getClass("FileOutputStream");
412     if (state.TASK) {
413       sc.getClass("TagDescriptor");
414     }
415     if (state.THREAD||state.DSM||state.SINGLETM) {
416       sc.getClass("Thread");
417     }
418
419
420     sc.semanticCheck();
421
422     tu.createFullTable();
423
424     BuildFlat bf=new BuildFlat(state,tu);
425     bf.buildFlat();
426     SafetyAnalysis sa=null;
427     PrefetchAnalysis pa=null;
428     MLPAnalysis mlpa=null;
429     OoOJavaAnalysis  oooa=null;
430     if (state.INLINEATOMIC) {
431       Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
432       while(classit.hasNext()) {
433         ClassDescriptor cn=(ClassDescriptor)classit.next();
434         Iterator methodit=cn.getMethods();
435         while(methodit.hasNext()) {
436           // do inlining
437           MethodDescriptor md=(MethodDescriptor)methodit.next();
438           FlatMethod fm=state.getMethodFlat(md);
439           Inliner.inlineAtomic(state, tu, fm, state.inlineatomicdepth);
440         }
441       }
442     }
443
444
445     if (state.OPTIMIZE) {
446       CallGraph callgraph=new CallGraph(state);
447       CopyPropagation cp=new CopyPropagation();
448       DeadCode dc=new DeadCode();
449       GlobalFieldType gft=new GlobalFieldType(callgraph, state, tu.getMain());
450       CSE cse=new CSE(gft, tu);
451       localCSE lcse=new localCSE(gft, tu);
452       LoopOptimize lo=null;
453       if (!state.NOLOOP)
454           lo=new LoopOptimize(gft, tu);
455       Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
456       while(classit.hasNext()) {
457         ClassDescriptor cn=(ClassDescriptor)classit.next();
458         Iterator methodit=cn.getMethods();
459         while(methodit.hasNext()) {
460           /* Classify parameters */
461           MethodDescriptor md=(MethodDescriptor)methodit.next();
462           FlatMethod fm=state.getMethodFlat(md);
463           cp.optimize(fm);
464           dc.optimize(fm);
465           if (!state.NOLOOP)
466               lo.optimize(fm);
467           cp.optimize(fm);
468           dc.optimize(fm);
469           lcse.doAnalysis(fm);
470           cse.doAnalysis(fm);
471           cp.optimize(fm);
472           dc.optimize(fm);
473           cp.optimize(fm);
474           dc.optimize(fm);
475         }
476       }
477     }
478
479     if (state.FLATIRGRAPH) {
480       FlatIRGraph firg = new FlatIRGraph(state,
481                                          state.FLATIRGRAPHTASKS,
482                                          state.FLATIRGRAPHUSERMETHODS,
483                                          state.FLATIRGRAPHLIBMETHODS);
484     }
485     
486     if (state.OWNERSHIP && !state.MLP) {
487       CallGraph callGraph = new CallGraph(state);
488       Liveness liveness = new Liveness();
489       ArrayReferencees ar = new ArrayReferencees(state);
490       OwnershipAnalysis oa = new OwnershipAnalysis(state,
491                                                    tu,
492                                                    callGraph,
493                                                    liveness,
494                                                    ar,
495                                                    state.OWNERSHIPALLOCDEPTH,
496                                                    state.OWNERSHIPWRITEDOTS,
497                                                    state.OWNERSHIPWRITEALL,
498                                                    state.OWNERSHIPALIASFILE,
499                                                    state.METHODEFFECTS);
500     }
501
502     if (state.MLP) {
503       CallGraph callGraph = new CallGraph(state);
504       Liveness liveness = new Liveness();
505       ArrayReferencees ar = new ArrayReferencees(state);
506       OwnershipAnalysis oa = new OwnershipAnalysis(state,
507                                                    tu,
508                                                    callGraph,
509                                                    liveness,
510                                                    ar,
511                                                    state.OWNERSHIPALLOCDEPTH,
512                                                    state.OWNERSHIPWRITEDOTS,
513                                                    state.OWNERSHIPWRITEALL,
514                                                    state.OWNERSHIPALIASFILE,
515                                                    state.METHODEFFECTS);
516       mlpa = new MLPAnalysis(state,
517                              tu,
518                              callGraph,
519                              oa);
520     }    
521
522     if (state.DISJOINT && !state.OOOJAVA) {
523       CallGraph        cg = new CallGraph(state);
524       Liveness         l  = new Liveness();
525       ArrayReferencees ar = new ArrayReferencees(state);
526       DisjointAnalysis da = new DisjointAnalysis(state, tu, cg, l, ar, null, null, null);
527     }
528
529     if (state.OOOJAVA) {
530       CallGraph        cg  = new CallGraph(state);
531       Liveness         l   = new Liveness();
532       ArrayReferencees ar  = new ArrayReferencees(state);
533       oooa  = new OoOJavaAnalysis(state, tu, cg, l, ar);
534     }
535
536
537     if (state.TAGSTATE) {
538       CallGraph callgraph=new CallGraph(state);
539       TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
540       TaskTagAnalysis tta=new TaskTagAnalysis(state, taganalysis, tu);
541     }
542
543     if (state.TASKSTATE) {
544       CallGraph callgraph=new CallGraph(state);
545       TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
546       TaskAnalysis ta=new TaskAnalysis(state, taganalysis, tu);
547       ta.taskAnalysis();
548       TaskGraph tg=new TaskGraph(state, ta);
549       tg.createDOTfiles();
550
551       if (state.OPTIONAL) {
552         ExecutionGraph et=new ExecutionGraph(state, ta);
553         et.createExecutionGraph();
554         sa = new SafetyAnalysis(et.getExecutionGraph(), state, ta);
555         sa.doAnalysis();
556         state.storeAnalysisResult(sa.getResult());
557         state.storeOptionalTaskDescriptors(sa.getOptionalTaskDescriptors());
558       }
559
560       if (state.WEBINTERFACE) {
561         GarbageAnalysis ga=new GarbageAnalysis(state, ta);
562         WebInterface wi=new WebInterface(state, ta, tg, ga, taganalysis);
563         JhttpServer serve=new JhttpServer(8000,wi);
564         serve.run();
565       }
566
567       if (state.SCHEDULING) {
568         // Use ownership analysis to get alias information
569         CallGraph callGraph = new CallGraph(state);
570         Liveness liveness = new Liveness();
571         ArrayReferencees ar = new ArrayReferencees(state);
572         OwnershipAnalysis oa = null; /*new OwnershipAnalysis(state,
573                                                      tu,
574                                                      callGraph,
575                                                      liveness,
576                                                      ar,
577                                                      state.OWNERSHIPALLOCDEPTH,
578                                                      state.OWNERSHIPWRITEDOTS,
579                                                      state.OWNERSHIPWRITEALL,
580                                                      state.OWNERSHIPALIASFILE);*/
581         
582         // synthesis a layout according to target multicore processor
583         MCImplSynthesis mcImplSynthesis = new MCImplSynthesis(state,
584                                                               ta,
585                                                               oa);
586         if(isDistributeInfo) {
587             mcImplSynthesis.distribution(isDisAll, startnum);
588         } else {
589             double timeStartAnalysis = (double) System.nanoTime();
590             mcImplSynthesis.setScheduleThreshold(20);
591             mcImplSynthesis.setProbThreshold(0);
592             mcImplSynthesis.setGenerateThreshold(30);
593             Vector<Schedule> scheduling = mcImplSynthesis.synthesis();
594             
595             double timeEndAnalysis = (double) System.nanoTime();
596         if(state.BAMBOOCOMPILETIME) {
597           double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) );
598           System.err.println("The analysis took" + dt +  "sec.");
599           System.exit(0);
600         }
601
602             // generate multicore codes
603             if(state.MULTICORE) {
604                 BuildCodeMultiCore bcm=new BuildCodeMultiCore(state,
605                                                               bf.getMap(),
606                                                               tu,
607                                                               sa,
608                                                               scheduling,
609                                                               mcImplSynthesis.getCoreNum(),
610                                                   state.CORENUM4GC,
611                                                               pa);
612                 bcm.setOwnershipAnalysis(oa);
613                 bcm.buildCode();
614             }
615             scheduling.clear();
616             scheduling = null;
617         }
618       }
619     }
620     if(!state.MULTICORE) {
621       if (state.DSM||state.SINGLETM) {
622         CallGraph callgraph=new CallGraph(state);
623         if (state.PREFETCH) {
624           //speed up prefetch generation using locality analysis results
625           LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
626           pa=new PrefetchAnalysis(state, callgraph, tu, la);
627         }
628         LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
629         GenerateConversions gc=new GenerateConversions(la, state);
630         BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa, mlpa,oooa);
631         bc.buildCode();
632       } else {
633         BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa, pa, mlpa,oooa);
634         bc.buildCode();
635       }
636     }
637
638     System.out.println("Lines="+state.lines);
639     System.exit(0);
640   }
641
642   public static void loadClass(State state, BuildIR bir, String sourcefile) {
643     try {
644       ParseNode pn=readSourceFile(state, sourcefile);
645       bir.buildtree(pn, null);
646     } catch (Exception e) {
647       System.out.println("Error in sourcefile:"+sourcefile);
648       e.printStackTrace();
649       System.exit(-1);
650     } catch (Error e) {
651       System.out.println("Error in sourcefile:"+sourcefile);
652       e.printStackTrace();
653       System.exit(-1);
654     }
655   }
656
657   /** Reads in a source file and adds the parse tree to the state object. */
658
659   public static ParseNode readSourceFile(State state, String sourcefile) {
660     try {
661       Reader fr= new BufferedReader(new FileReader(sourcefile));
662       Lex.Lexer l = new Lex.Lexer(fr);
663       java_cup.runtime.lr_parser g;
664       g = new Parse.Parser(l);
665       ParseNode p=null;
666       try {
667         p=(ParseNode) g./*debug_*/parse().value;
668       } catch (Exception e) {
669         System.err.println("Error parsing file:"+sourcefile);
670         e.printStackTrace();
671         System.exit(-1);
672       }
673       state.addParseNode(p);
674       if (l.numErrors()!=0) {
675         System.out.println("Error parsing "+sourcefile);
676         System.exit(l.numErrors());
677       }
678       state.lines+=l.line_num;
679       return p;
680
681     } catch (Exception e) {
682       throw new Error(e);
683     }
684   }
685 }