SIRPrinter printer0 = new SIRPrinter("SIR_EnteringRawBackend.out"); IterFactory.createFactory().createIter(str).accept(printer0); printer0.close();
    public static void run(SIRStream str,			   JInterfaceDeclaration[] 			   interfaces,			   SIRInterfaceTable[]			   interfaceTables,			   SIRStructure[]			   structs) {	System.out.println("Entry to RAW Backend");	structures = structs;	if (KjcOptions.standalone)	    KjcOptions.ratematch = false;		// set number of columns/rows	RawBackend.rawRows = KjcOptions.raw;	if(KjcOptions.rawcol>-1)	    RawBackend.rawColumns = KjcOptions.rawcol;	else	    RawBackend.rawColumns = KjcOptions.raw;	//use the work based simulator to layout the communication instructions	if (KjcOptions.wbs)	    simulator = new WorkBasedSimulator();	else 	    simulator = new FineGrainSimulator();	//this must be run now, FlatIRToC relies on it!!!	RenameAll.renameAllFilters(str);		// propagate constants and unroll loop	System.out.println("Running Constant Prop and Unroll...");	ConstantProp.propagateAndUnroll(str);	System.out.println("Done Constant Prop and Unroll...");        // add initPath functions        EnqueueToInitPath.doInitPath(str);	// construct stream hierarchy from SIRInitStatements	ConstructSIRTree.doit(str);	if (Flattener.hasDynamicRates(str)) {	    System.err.println("Failure: Dynamic rates are not yet supported in the Raw backend.");	    System.exit(1);	}	//SIRPrinter printer1 = new SIRPrinter();	//str.accept(printer1);	//printer1.close();	//VarDecl Raise to move array assignments up	new VarDeclRaiser().raiseVars(str);	// loop to decrease unroll factor until everything fits in IMEM	SIRStream strOrig = null;	// only need to make copy if there is some unrolling, since	// otherwise we won't roll back	boolean scaleUnrollFactor = KjcOptions.unroll>1 && !KjcOptions.forceunroll && !KjcOptions.standalone;	if (scaleUnrollFactor) {	    strOrig = (SIRStream)ObjectDeepCloner.deepCopy(str);	}	boolean fitsInIMEM;	GraphFlattener graphFlattener;	do {	    // do constant propagation on fields	    if (KjcOptions.nofieldprop) {	    } else {		System.out.println("Running Constant Field Propagation...");		FieldProp.doPropagate(str);		System.out.println("Done Constant Field Propagation...");		//System.out.println("Analyzing Branches..");		//new BlockFlattener().flattenBlocks(str);		//new BranchAnalyzer().analyzeBranches(str);	    }	    	    // expand array initializers loaded from a file	    ArrayInitExpander.doit(str);	    Lifter.liftAggressiveSync(str);	    NumberDot.printGraph(str, "numbered.dot");	    StreamItDot.printGraph(str, "before-partition.dot");	    	    // gather application-characterization statistics	    if (KjcOptions.stats) {		StatisticsGathering.doit(str);	    }	    str = Flattener.doLinearAnalysis(str);	    str = Flattener.doStateSpaceAnalysis(str);	    if (KjcOptions.fusion) {		System.out.println("Running FuseAll...");		str = FuseAll.fuse(str);		Lifter.lift(str);		System.out.println("Done FuseAll...");	    }	    if (KjcOptions.fission>1) {		System.out.println("Running Vertical Fission...");		FissionReplacer.doit(str, KjcOptions.fission);		Lifter.lift(str);		System.out.println("Done Vertical Fission...");	    }	    // turn on partitioning if there aren't enough tiles for all	    // the filters	    int count = new GraphFlattener(str).getNumTiles();	    int numTiles = RawBackend.rawRows * RawBackend.rawColumns;	    boolean manual = KjcOptions.manual != null;	    boolean partitioning = ((KjcOptions.standalone || !manual) // still fuse graph if both manual and standalone enabled				    && (KjcOptions.partition_dp || KjcOptions.partition_greedy || KjcOptions.partition_greedier || KjcOptions.partition_ilp));	    // want to turn on partitioning for standalone; in this	    // case, manual is for manual optimizations, not manual	    // partitioning	    if (count>numTiles && !partitioning && !manual) { //		System.out.println("Need " + count + " tiles, so turning on partitioning...");		KjcOptions.partition_dp = true;		partitioning = true;	    }	    if (manual) {		System.err.println("Running Manual Partitioning...");		str = ManualPartition.doit(str);		System.err.println("Done Manual Partitioning...");	    }	    if (partitioning) {		System.err.println("Running Partitioning...");		str = Partitioner.doit(str, count, numTiles, true, false);		System.err.println("Done Partitioning...");	    }	    if (KjcOptions.sjtopipe) {		SJToPipe.doit(str);	    }	    StreamItDot.printGraph(str, "after-partition.dot");	    //VarDecl Raise to move array assignments up	    new VarDeclRaiser().raiseVars(str);		    //VarDecl Raise to move peek index up so	    //constant prop propagates the peek buffer index	    new VarDeclRaiser().raiseVars(str);	    // optionally print a version of the source code that we're	    // sending to the scheduler	    if (KjcOptions.print_partitioned_source) {		new streamit.scheduler2.print.PrintProgram().printProgram(IterFactory.createFactory().createIter(str));	    }	    //SIRPrinter printer1 = new SIRPrinter();	    //IterFactory.createFactory().createIter(str).accept(printer1);	    //printer1.close();	    System.out.println("Flattener Begin...");	    executionCounts = SIRScheduler.getExecutionCounts(str);	    PartitionDot.printScheduleGraph(str, "schedule.dot", executionCounts);	    graphFlattener = new GraphFlattener(str);	    System.out.println("Flattener End.");	    //create the execution counts for other passes	    createExecutionCounts(str, graphFlattener);	    //dump the flatgraph of the application, must be called after createExecutionCounts	    (new DumpGraph()).dumpGraph(graphFlattener.top, "flatgraph.dot", 					initExecutionCounts, steadyExecutionCounts);	    //Generate number gathering simulator code	    if (KjcOptions.numbers > 0) {		// do this on demand from NumberGathering		//SinkUnroller.doit(graphFlattener.top);		if (!NumberGathering.doit(graphFlattener.top)) {		    System.err.println("Could not generate number gathering code.  Exiting...");		    System.exit(1);		}	    }		    // see if we are going to overflow IMEM	    if (scaleUnrollFactor) {		System.out.println("Trying unroll factor " + KjcOptions.unroll);		fitsInIMEM = IMEMEstimation.testMe(graphFlattener.top);		if (fitsInIMEM) {		    // if we fit, clear backup copy of stream graph		    strOrig = null;		    System.gc();		} else if (KjcOptions.unroll<=1) {		    // if we have reached bottom of unrolling, print warning		    System.out.println("WARNING:  A filter overflows IMEM even though there is no unrolling.");		    // so that we exit the loop		    fitsInIMEM=true;		} else {		    // otherwise, cut unrolling in half and recurse		    System.out.println("Cutting unroll factor from " + KjcOptions.unroll + " to " + (KjcOptions.unroll/2) + " to try to fit in IMEM...");		    KjcOptions.unroll = KjcOptions.unroll / 2;		    str = (SIRStream)ObjectDeepCloner.deepCopy(strOrig);		}	    } else {		// it might not fit in IMEM, but we can't decrease the		// unrolling any, so just go ahead		fitsInIMEM = true;	    }	    	} while (!fitsInIMEM);	//see if we can remove any joiners	//JoinerRemoval.run(graphFlattener.top);	// layout the components (assign filters to tiles)		Layout.simAnnealAssign(graphFlattener.top);	//Layout.handAssign(graphFlattener.top);		//Layout.handAssign(graphFlattener.top);	System.out.println("Assign End.");	//if rate matching is requested, check if we can do it	//if we can, then keep KjcOptions.rateMatch as true, 	//otherwise set it to false	if (KjcOptions.ratematch) {	    if (RateMatch.doit(graphFlattener.top))		System.out.println("Rate Matching Test Successful.");	    else {		KjcOptions.ratematch = false;		System.out.println("Cannot perform Rate Matching.");	    }	}			if (KjcOptions.magic_net) {	    MagicNetworkSchedule.generateSchedules(graphFlattener.top);	}	else {	    System.out.println("Switch Code Begin...");	    SwitchCode.generate(graphFlattener.top);	    System.out.println("Switch Code End.");	}	//remove print statements in the original app	//if we are running with decoupled	if (KjcOptions.decoupled)	    RemovePrintStatements.doIt(graphFlattener.top);		//Generate the tile code	RawExecutionCode.doit(graphFlattener.top);	if (KjcOptions.removeglobals) {	    RemoveGlobals.doit(graphFlattener.top);	}		//VarDecl Raise to move array assignments down?	new VarDeclRaiser().raiseVars(str);	StructureIncludeFile.doit(structures, graphFlattener.top);	System.out.println("Tile Code begin...");	TileCode.generateCode(graphFlattener.top);	System.out.println("Tile Code End.");	//generate the makefiles	System.out.println("Creating Makefile.");	MakefileGenerator.createMakefile();	System.out.println("Exiting");	System.exit(0);    }