X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FMain%2FMain.java;h=748c0027fa06bdfcf33a21ecfae53e671574d0e8;hb=e33201f8be840c89d9e1994a2e742bf01ca8ff0c;hp=a46cca8253f35ac80d147011014c73325ee38ee4;hpb=7fbe9cf2767b8be5994064d18ba53c7c7c20ed57;p=IRC.git diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index a46cca82..748c0027 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -1,13 +1,14 @@ package Main; import java.io.FileOutputStream; -import java.io.InputStream; import java.io.PrintStream; import java.io.Reader; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileInputStream; +import java.util.Hashtable; import java.util.Iterator; +import java.util.Set; import java.util.Vector; import IR.Tree.ParseNode; @@ -16,14 +17,14 @@ import IR.Tree.SemanticCheck; import IR.Flat.BuildCodeMultiCore; import IR.Flat.BuildFlat; import IR.Flat.BuildCode; +import IR.Flat.Inliner; import IR.ClassDescriptor; import IR.State; import IR.TaskDescriptor; import IR.TypeUtil; +import Analysis.Scheduling.MCImplSynthesis; import Analysis.Scheduling.Schedule; import Analysis.Scheduling.ScheduleAnalysis; -import Analysis.Scheduling.ScheduleEdge; -import Analysis.Scheduling.ScheduleNode; import Analysis.Scheduling.ScheduleSimulator; import Analysis.TaskStateAnalysis.TaskAnalysis; import Analysis.TaskStateAnalysis.TaskTagAnalysis; @@ -40,436 +41,540 @@ import Analysis.Locality.GenerateConversions; import Analysis.Prefetch.PrefetchAnalysis; import Analysis.FlatIRGraph.FlatIRGraph; import Analysis.OwnershipAnalysis.OwnershipAnalysis; +import Analysis.Disjoint.DisjointAnalysis; +import Analysis.MLP.MLPAnalysis; +import Analysis.Loops.*; +import Analysis.Liveness; +import Analysis.ArrayReferencees; +import IR.MethodDescriptor; +import IR.Flat.FlatMethod; import Interface.*; +import Util.GraphNode; +import Util.GraphNode.DFS; +import Util.GraphNode.SCC; public class Main { - /** Main method for the compiler. */ + /** Main method for the compiler. */ public static void main(String args[]) throws Exception { - String ClassLibraryPrefix="./ClassLibrary/"; - State state=new State(); - - for(int i=0;i -- probability of true branch"); - System.out.println("-printflat -- print out flat representation"); - System.out.println("-instructionfailures -- insert code for instruction level failures"); - System.out.println("-taskstate -- do task state analysis"); - System.out.println("-flatirtasks -- create dot files for flat IR graphs of tasks"); - System.out.println("-flatirusermethods -- create dot files for flat IR graphs of user methods"); - System.out.println("-flatirlibmethods -- create dot files for flat IR graphs of library class methods"); - System.out.println(" note: -flatirusermethods or -flatirlibmethods currently generate all class method flat IR graphs"); - System.out.println("-ownership -- do ownership analysis"); - System.out.println("-optional -- enable optional arguments"); - System.out.println("-webinterface -- enable web interface"); - System.out.println("-help -- print out help"); - System.exit(0); - } else { - readSourceFile(state, args[i]); - } + String ClassLibraryPrefix="./ClassLibrary/"; + State state=new State(); + Vector sourcefiles=new Vector(); + state.classpath.add("."); + + String outputdir = null; + boolean isDistributeInfo = false; + boolean isDisAll = false; + int startnum = 0; + + for(int i=0; i"); + } + } else if (option.equals("-disjoint-alias-file")) { + state.DISJOINTALIASFILE = args[++i]; + String arg = args[++i]; + if( arg.equals("normal") ) { + state.DISJOINTALIASTAB = false; + } else if( arg.equals("tabbed") ) { + state.DISJOINTALIASTAB = true; + } else { + throw new Error("disjoint-alias-file requires arguments "); + } + } else if (option.equals("-disjoint-debug-callsite")) { + state.DISJOINTDEBUGCALLEE=args[++i]; + state.DISJOINTDEBUGCALLER=args[++i]; + state.DISJOINTDEBUGCALLCOUNT=Integer.parseInt(args[++i]); } + else if (option.equals("-optional")) + state.OPTIONAL=true; + else if (option.equals("-optimize")) + state.OPTIMIZE=true; + else if (option.equals("-dcopts")) + state.DCOPTS=true; + else if (option.equals("-arraypad")) + state.ARRAYPAD=true; + else if (option.equals("-delaycomp")) + state.DELAYCOMP=true; + else if (option.equals("-raw")) + state.RAW=true; + else if (option.equals("-scheduling")) + state.SCHEDULING=true; + else if (option.equals("-distributioninfo")) + isDistributeInfo=true; + else if (option.equals("-disall")) + isDisAll=true; + else if (option.equals("-disstart")) + startnum = Integer.parseInt(args[++i]); + else if (option.equals("-useprofile")) { + state.USEPROFILE=true; + state.profilename = args[++i]; + } + else if (option.equals("-thread")) + state.THREAD=true; + else if (option.equals("-dsm")) + state.DSM=true; + else if (option.equals("-recoverystats")) + state.DSMRECOVERYSTATS=true; + else if (option.equals("-dsmtask")) + state.DSMTASK=true; + else if (option.equals("-singleTM")) + state.SINGLETM=true; + else if (option.equals("-readset")) + state.READSET=true; + else if (option.equals("-webinterface")) + state.WEBINTERFACE=true; + else if (option.equals("-instructionfailures")) + state.INSTRUCTIONFAILURE=true; + else if (option.equals("-abcclose")) + state.ARRAYBOUNDARYCHECK=false; + + else if (option.equals("-mlp")) { + state.MLP = true; + state.OWNERSHIP = true; + state.MLP_NUMCORES = Integer.parseInt( args[++i] ); + state.MLP_MAXSESEAGE = Integer.parseInt( args[++i] ); + + } else if (option.equals("-mlpdebug")) { + state.MLPDEBUG=true; - if (state.TASK) { - readSourceFile(state, ClassLibraryPrefix+"StartupObject.java"); - readSourceFile(state, ClassLibraryPrefix+"Socket.java"); - readSourceFile(state, ClassLibraryPrefix+"ServerSocket.java"); + } else if (option.equals("-methodeffects")) { + state.METHODEFFECTS=true; + }else if (option.equals("-help")) { + System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located"); + System.out.println("-selfloop task -- this task doesn't self loop its parameters forever"); + System.out.println("-dir outputdirectory -- output code in outputdirectory"); + System.out.println("-struct structfile -- output structure declarations for repair tool"); + System.out.println("-mainclass -- main function to call"); + System.out.println("-dsm -- distributed shared memory support"); + System.out.println("-singleTM -- single machine committing transactions"); + System.out.println("-abortreaders -- abort readers"); + System.out.println("-precise -- use precise garbage collection"); + System.out.println("-conscheck -- turn on consistency checking"); + System.out.println("-task -- compiler for tasks"); + System.out.println("-fastcheck -- fastcheckpointing for Bristlecone"); + System.out.println("-thread -- threads"); + System.out.println("-trueprob -- probability of true branch"); + System.out.println("-printflat -- print out flat representation"); + System.out.println("-instructionfailures -- insert code for instruction level failures"); + System.out.println("-taskstate -- do task state analysis"); + System.out.println("-flatirtasks -- create dot files for flat IR graphs of tasks"); + System.out.println("-flatirusermethods -- create dot files for flat IR graphs of user methods"); + System.out.println("-flatirlibmethods -- create dot files for flat IR graphs of library class methods"); + System.out.println(" note: -flatirusermethods or -flatirlibmethods currently generate all class method flat IR graphs"); + System.out.println("-ownership -- do ownership analysis"); + System.out.println("-ownallocdepth -- set allocation depth for ownership analysis"); + System.out.println("-ownwritedots -- write ownership graphs; can be all results or just final results"); + System.out.println("-ownaliasfile -- write a text file showing all detected aliases in program tasks"); + System.out.println("-optimize -- enable optimizations"); + System.out.println("-optional -- enable optional arguments"); + System.out.println("-abcclose close the array boundary check"); + System.out.println("-scheduling do task scheduling"); + System.out.println("-mlp build mlp code"); + System.out.println("-mlpdebug if mlp, report progress and interim results"); + System.out.println("-multicore generate multi-core version binary"); + System.out.println("-numcore set the number of cores (should be used together with -multicore), defaultly set as 1"); + System.out.println("-interrupt generate raw version binary with interruption (should be used togethere with -raw)"); + System.out.println("-rawconfig config raw simulator as 4xn (should be used together with -raw)"); + System.out.println("-rawpath print out execute path information for raw version (should be used together with -raw)"); + System.out.println("-useprofile use profiling data for scheduling (should be used together with -raw)"); + System.out.println("-threadsimulate generate multi-thread simulate version binary"); + 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"); + System.out.println("-printscheduling -- print out scheduling graphs"); + System.out.println("-printschedulesim -- print out scheduling simulation result graphs"); + System.out.println("-webinterface -- enable web interface"); + System.out.println("-help -- print out help"); + System.exit(0); } else { - readSourceFile(state, ClassLibraryPrefix+"SocketJava.java"); - readSourceFile(state, ClassLibraryPrefix+"ServerSocketJava.java"); + sourcefiles.add(args[i]); } + } + + //add default classpath + if (state.classpath.size()==1) + state.classpath.add(ClassLibraryPrefix); - BuildIR bir=new BuildIR(state); - bir.buildtree(); - - TypeUtil tu=new TypeUtil(state); - - SemanticCheck sc=new SemanticCheck(state,tu); - sc.semanticCheck(); - tu.createFullTable(); - - BuildFlat bf=new BuildFlat(state,tu); - bf.buildFlat(); - SafetyAnalysis sa=null; - - if (state.TAGSTATE) { - CallGraph callgraph=new CallGraph(state); - TagAnalysis taganalysis=new TagAnalysis(state, callgraph); - TaskTagAnalysis tta=new TaskTagAnalysis(state, taganalysis); - } + BuildIR bir=new BuildIR(state); + TypeUtil tu=new TypeUtil(state, bir); + + + SemanticCheck sc=new SemanticCheck(state,tu); + + for(int i=0;i fev = (Vector)ta.getFEdgesFromTD(td); - int numEdges = fev.size(); - int total = 100; - for(int j = 0; j < numEdges; j++) { - FEdge pfe = fev.elementAt(j); - if(numEdges - j == 1) { - pfe.setProbability(total); - } else { - if((total != 0) && (total != 1)){ - do { - tint = r.nextInt()%total; - } while(tint <= 0); - } - pfe.setProbability(tint); - total -= tint; - } - /*do { - tint = r.nextInt()%10; - } while(tint <= 0);*/ - //int newRate = tint; - //int newRate = (j+1)%2+1; - int newRate = 1; - /*do { - tint = r.nextInt()%100; - } while(tint <= 0); - int probability = tint;*/ - int probability = 100; - pfe.addNewObjInfo(cd, newRate, probability); - } - } - } - } - - Iterator it_flags = ta.getFlagStates(cd).iterator(); - while(it_flags.hasNext()) { - FlagState fs = (FlagState)it_flags.next(); - Iterator it_edges = fs.edges(); - while(it_edges.hasNext()) { - /*do { - tint = r.nextInt()%10; - } while(tint <= 0);*/ - tint = 1; - ((FEdge)it_edges.next()).setExeTime(tint); - } - } - } - } - - // generate multiple schedulings - ScheduleAnalysis scheduleAnalysis = new ScheduleAnalysis(state, ta); - scheduleAnalysis.preSchedule(); - scheduleAnalysis.scheduleAnalysis(); - //scheduleAnalysis.setCoreNum(scheduleAnalysis.getSEdges4Test().size()); - scheduleAnalysis.setCoreNum(state.CORENUM); - scheduleAnalysis.schedule(); - - //simulate these schedulings - ScheduleSimulator scheduleSimulator = new ScheduleSimulator(scheduleAnalysis.getCoreNum(), state, ta); - Iterator it_scheduling = scheduleAnalysis.getSchedulingsIter(); - int index = 0; - Vector selectedScheduling = new Vector(); - int processTime = Integer.MAX_VALUE; - while(it_scheduling.hasNext()) { - Vector scheduling = (Vector)it_scheduling.next(); - scheduleSimulator.setScheduling(scheduling); - int tmpTime = scheduleSimulator.process(); - if(tmpTime < processTime) { - selectedScheduling.clear(); - selectedScheduling.add(index); - processTime = tmpTime; - } else if(tmpTime == processTime) { - selectedScheduling.add(index); - } - index++; - } - System.out.print("Selected schedulings with least exectution time " + processTime + ": \n\t"); - for(int i = 0; i < selectedScheduling.size(); i++) { - System.out.print(selectedScheduling.elementAt(i) + ", "); - } - System.out.println(); - - /*ScheduleSimulator scheduleSimulator = new ScheduleSimulator(4, state, ta); - Vector scheduling = new Vector(); - for(int i = 0; i < 4; i++) { - Schedule schedule = new Schedule(i); - scheduling.add(schedule); - } - Iterator it_tasks = state.getTaskSymbolTable().getAllDescriptorsIterator(); - while(it_tasks.hasNext()) { - TaskDescriptor td = (TaskDescriptor)it_tasks.next(); - if(td.getSymbol().equals("t10")) { - scheduling.elementAt(1).addTask(td); - } else { - scheduling.elementAt(0).addTask(td); - } - } - ClassDescriptor cd = (ClassDescriptor)state.getClassSymbolTable().get("E"); - scheduling.elementAt(0).addTargetCore(cd, 1); - scheduleSimulator.setScheduling(scheduling); - scheduleSimulator.process(); - - Vector scheduling1 = new Vector(); - for(int i = 0; i < 4; i++) { - Schedule schedule = new Schedule(i); - scheduling1.add(schedule); - } - Iterator it_tasks1 = state.getTaskSymbolTable().getAllDescriptorsIterator(); - while(it_tasks1.hasNext()) { - TaskDescriptor td = (TaskDescriptor)it_tasks1.next(); - scheduling1.elementAt(0).addTask(td); - } - scheduleSimulator.setScheduling(scheduling1); - scheduleSimulator.process();*/ - - // Close the streams. - try { - stdout.close (); - System.setOut(origOut); - } catch (Exception e) { - origOut.println ("Redirect: Unable to close files!"); - } - - if(state.MULTICORE) { - it_scheduling = scheduleAnalysis.getSchedulingsIter(); - Vector scheduling = (Vector)it_scheduling.next(); - BuildCodeMultiCore bcm=new BuildCodeMultiCore(state, bf.getMap(), tu, sa, scheduling, scheduleAnalysis.getCoreNum()); - bcm.buildCode(); - } - } - + //Stuff the runtime wants to see + sc.getClass("String"); + sc.getClass("Math"); + sc.getClass("File"); + sc.getClass("Socket"); + sc.getClass("ServerSocket"); + sc.getClass("FileInputStream"); + sc.getClass("FileOutputStream"); + if (state.TASK) { + sc.getClass("TagDescriptor"); + } + if (state.THREAD||state.DSM||state.SINGLETM) { + sc.getClass("Thread"); + } + + sc.semanticCheck(); + + tu.createFullTable(); + + BuildFlat bf=new BuildFlat(state,tu); + bf.buildFlat(); + SafetyAnalysis sa=null; + PrefetchAnalysis pa=null; + MLPAnalysis mlpa=null; + if (state.INLINEATOMIC) { + Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); + while(classit.hasNext()) { + ClassDescriptor cn=(ClassDescriptor)classit.next(); + Iterator methodit=cn.getMethods(); + while(methodit.hasNext()) { + // do inlining + MethodDescriptor md=(MethodDescriptor)methodit.next(); + FlatMethod fm=state.getMethodFlat(md); + Inliner.inlineAtomic(state, tu, fm, state.inlineatomicdepth); + } } + } - if(!state.MULTICORE) { - if (state.DSM) { - CallGraph callgraph=new CallGraph(state); - if (state.PREFETCH) { - //speed up prefetch generation using locality analysis results - LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); - PrefetchAnalysis pa=new PrefetchAnalysis(state, callgraph, tu, la); - } - - LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); - GenerateConversions gc=new GenerateConversions(la, state); - BuildCode bc=new BuildCode(state, bf.getMap(), tu, la); - bc.buildCode(); - } else { - BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa); - bc.buildCode(); - } + + if (state.OPTIMIZE) { + CallGraph callgraph=new CallGraph(state); + CopyPropagation cp=new CopyPropagation(); + DeadCode dc=new DeadCode(); + GlobalFieldType gft=new GlobalFieldType(callgraph, state, tu.getMain()); + CSE cse=new CSE(gft, tu); + localCSE lcse=new localCSE(gft, tu); + LoopOptimize lo=new LoopOptimize(gft, tu); + Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); + while(classit.hasNext()) { + ClassDescriptor cn=(ClassDescriptor)classit.next(); + Iterator methodit=cn.getMethods(); + while(methodit.hasNext()) { + /* Classify parameters */ + MethodDescriptor md=(MethodDescriptor)methodit.next(); + FlatMethod fm=state.getMethodFlat(md); + cp.optimize(fm); + dc.optimize(fm); + lo.optimize(fm); + cp.optimize(fm); + dc.optimize(fm); + lcse.doAnalysis(fm); + cse.doAnalysis(fm); + cp.optimize(fm); + dc.optimize(fm); + cp.optimize(fm); + dc.optimize(fm); + } } + } + + if (state.FLATIRGRAPH) { + FlatIRGraph firg = new FlatIRGraph(state, + state.FLATIRGRAPHTASKS, + state.FLATIRGRAPHUSERMETHODS, + state.FLATIRGRAPHLIBMETHODS); + } + + if (state.OWNERSHIP && !state.MLP) { + CallGraph callGraph = new CallGraph(state); + Liveness liveness = new Liveness(); + ArrayReferencees ar = new ArrayReferencees(state); + OwnershipAnalysis oa = new OwnershipAnalysis(state, + tu, + callGraph, + liveness, + ar, + state.OWNERSHIPALLOCDEPTH, + state.OWNERSHIPWRITEDOTS, + state.OWNERSHIPWRITEALL, + state.OWNERSHIPALIASFILE, + state.METHODEFFECTS); + } - if (state.FLATIRGRAPH) { - FlatIRGraph firg = new FlatIRGraph(state, - state.FLATIRGRAPHTASKS, - state.FLATIRGRAPHUSERMETHODS, - state.FLATIRGRAPHLIBMETHODS); + if (state.MLP) { + CallGraph callGraph = new CallGraph(state); + Liveness liveness = new Liveness(); + ArrayReferencees ar = new ArrayReferencees(state); + OwnershipAnalysis oa = new OwnershipAnalysis(state, + tu, + callGraph, + liveness, + ar, + state.OWNERSHIPALLOCDEPTH, + state.OWNERSHIPWRITEDOTS, + state.OWNERSHIPWRITEALL, + state.OWNERSHIPALIASFILE, + state.METHODEFFECTS); + mlpa = new MLPAnalysis(state, + tu, + callGraph, + oa); + } + + if (state.DISJOINT) { + CallGraph cg = new CallGraph(state); + Liveness l = new Liveness(); + ArrayReferencees ar = new ArrayReferencees(state); + DisjointAnalysis oa = new DisjointAnalysis(state, tu, cg, l, ar); + } + + if (state.TAGSTATE) { + CallGraph callgraph=new CallGraph(state); + TagAnalysis taganalysis=new TagAnalysis(state, callgraph); + TaskTagAnalysis tta=new TaskTagAnalysis(state, taganalysis, tu); + } + + if (state.TASKSTATE) { + CallGraph callgraph=new CallGraph(state); + TagAnalysis taganalysis=new TagAnalysis(state, callgraph); + TaskAnalysis ta=new TaskAnalysis(state, taganalysis, tu); + ta.taskAnalysis(); + TaskGraph tg=new TaskGraph(state, ta); + tg.createDOTfiles(); + + if (state.OPTIONAL) { + ExecutionGraph et=new ExecutionGraph(state, ta); + et.createExecutionGraph(); + sa = new SafetyAnalysis(et.getExecutionGraph(), state, ta); + sa.doAnalysis(); + state.storeAnalysisResult(sa.getResult()); + state.storeOptionalTaskDescriptors(sa.getOptionalTaskDescriptors()); } - if (state.OWNERSHIP) { - CallGraph callGraph = new CallGraph( state ); - int allocationDepth = 3; - OwnershipAnalysis oa = - new OwnershipAnalysis( state, callGraph, allocationDepth ); - //This was breaking the compile - // oa.writeAllAliases( "identifiedAliases.txt" ); + if (state.WEBINTERFACE) { + GarbageAnalysis ga=new GarbageAnalysis(state, ta); + WebInterface wi=new WebInterface(state, ta, tg, ga, taganalysis); + JhttpServer serve=new JhttpServer(8000,wi); + serve.run(); } - System.exit(0); - } - - /** Reads in a source file and adds the parse tree to the state object. */ - - private static void readSourceFile(State state, String sourcefile) throws Exception { - Reader fr = new BufferedReader(new FileReader(sourcefile)); - Lex.Lexer l = new Lex.Lexer(fr); - java_cup.runtime.lr_parser g; - g = new Parse.Parser(l); - ParseNode p=null; - try { - p=(ParseNode) g./*debug_*/parse().value; - } catch (Exception e) { - System.err.println("Error parsing file:"+sourcefile); - e.printStackTrace(); - System.exit(-1); + if (state.SCHEDULING) { + // Use ownership analysis to get alias information + CallGraph callGraph = new CallGraph(state); + Liveness liveness = new Liveness(); + ArrayReferencees ar = new ArrayReferencees(state); + OwnershipAnalysis oa = new OwnershipAnalysis(state, + tu, + callGraph, + liveness, + ar, + state.OWNERSHIPALLOCDEPTH, + state.OWNERSHIPWRITEDOTS, + state.OWNERSHIPWRITEALL, + state.OWNERSHIPALIASFILE); + + // synthesis a layout according to target multicore processor + MCImplSynthesis mcImplSynthesis = new MCImplSynthesis(state, + ta, + oa); + if(isDistributeInfo) { + mcImplSynthesis.distribution(isDisAll, startnum); + } else { + //double timeStartAnalysis = (double) System.nanoTime(); + mcImplSynthesis.setScheduleThreshold(20); + mcImplSynthesis.setProbThreshold(0); + mcImplSynthesis.setGenerateThreshold(30); + Vector scheduling = mcImplSynthesis.synthesis(); + + //double timeEndAnalysis = (double) System.nanoTime(); + //double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) ); + //System.err.println("The analysis took" + dt + "sec."); + //System.exit(0); + + // generate multicore codes + if(state.MULTICORE) { + BuildCodeMultiCore bcm=new BuildCodeMultiCore(state, + bf.getMap(), + tu, + sa, + scheduling, + mcImplSynthesis.getCoreNum(), + state.CORENUM4GC, + pa); + bcm.setOwnershipAnalysis(oa); + bcm.buildCode(); + } + scheduling.clear(); + scheduling = null; } - state.addParseNode(p); - if (l.numErrors()!=0) { - System.out.println("Error parsing "+sourcefile); - System.exit(l.numErrors()); + } + } + if(!state.MULTICORE) { + if (state.DSM||state.SINGLETM) { + CallGraph callgraph=new CallGraph(state); + if (state.PREFETCH) { + //speed up prefetch generation using locality analysis results + LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); + pa=new PrefetchAnalysis(state, callgraph, tu, la); } + LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); + GenerateConversions gc=new GenerateConversions(la, state); + BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa, mlpa); + bc.buildCode(); + } else { + BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa, pa, mlpa); + bc.buildCode(); + } } + + System.out.println("Lines="+state.lines); + System.exit(0); + } + + public static void loadClass(State state, BuildIR bir, String sourcefile) { + try { + ParseNode pn=readSourceFile(state, sourcefile); + bir.buildtree(pn, null); + } catch (Exception e) { + System.out.println("Error in sourcefile:"+sourcefile); + e.printStackTrace(); + System.exit(-1); + } catch (Error e) { + System.out.println("Error in sourcefile:"+sourcefile); + e.printStackTrace(); + System.exit(-1); + } + } + + /** Reads in a source file and adds the parse tree to the state object. */ + + public static ParseNode readSourceFile(State state, String sourcefile) { + try { + Reader fr= new BufferedReader(new FileReader(sourcefile)); + Lex.Lexer l = new Lex.Lexer(fr); + java_cup.runtime.lr_parser g; + g = new Parse.Parser(l); + ParseNode p=null; + try { + p=(ParseNode) g./*debug_*/parse().value; + } catch (Exception e) { + System.err.println("Error parsing file:"+sourcefile); + e.printStackTrace(); + System.exit(-1); + } + state.addParseNode(p); + if (l.numErrors()!=0) { + System.out.println("Error parsing "+sourcefile); + System.exit(l.numErrors()); + } + state.lines+=l.line_num; + return p; + + } catch (Exception e) { + throw new Error(e); + } + } }