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