/** * This static method creates the main function as described in the class comment. It first checks * that the filter has no inputs/outputs and does not declare any I/O rates Then it creates the * function and attaches it to the filter. * * @param top The single flatnode that contains the single filter of the app. * @param executionCounts The schedule for the stream graph as calculated by the scheduler. */ public static void doit(FlatNode top, HashMap[] executionCounts) { assert top.contents instanceof SIRFilter : "Error top of graph is not filter"; assert top.inputs == 0 && top.ways == 0 : "Error: Fused filter contains neighbors"; SIRFilter filter = (SIRFilter) top.contents; assert filter.getPushInt() == 0 && filter.getPopInt() == 0 && filter.getPeekInt() == 0 : "Error: fused filter declares non-zero I/O rate(s)"; // make sure there are no push, pops or peeks... assert CheckForCommunication.check(filter) == false : "Error: Communication expression found in filter"; // assert !(filter instanceof SIRTwoStageFilter) : // "Error: Fused filter is a two stage"; ExecutionCode exeCode = new ExecutionCode(); // check to see if the schedule is valid and // set the number of times the filter fires in the init // stage (weird) exeCode.checkSchedule(executionCounts, filter); // create the main function of the C code that will call // the filter JBlock block = exeCode.mainFunction(filter); // create the method and add it to the filter JMethodDeclaration mainFunct = new JMethodDeclaration( null, at.dms.kjc.Constants.ACC_PUBLIC, CStdType.Void, Names.main, JFormalParameter.EMPTY, CClassType.EMPTY, block, null, null); // make the main the new work function filter.setWork(mainFunct); }