Iterator ftk = fieldsToKeep.iterator(); while (ftk.hasNext()) { filter.addField((JFieldDeclaration)ftk.next()); }
	public static void doit(SIRFilter f) 	{	    filter = f;	    localVariables = new HashSet();	    	    JBlock rawMainBlock = RemoveGlobals.getRawMain(filter).getBody();	    JFieldDeclaration[] fields = filter.getFields();	    	    HashSet arrays = new HashSet();	    //move all globals var defs into the raw main function	    for (int i = 0; i < fields.length; i++) {		JVariableDefinition def = fields[i].getVariable();				//remember all the arrays so we can 		//zero them later		if (def.getType().isArrayType())		    arrays.add(def);		localVariables.add(def);				rawMainBlock.addStatementFirst		    (new JVariableDeclarationStatement		     (null, def, null));	    }	    	    //we need to initialize all array elements to zero	    //create a statement of the form	    //memset(var, 0, sizeof(var));	    Iterator arrayIt = arrays.iterator();	    while (arrayIt.hasNext()) {		JVariableDefinition def = (JVariableDefinition)arrayIt.next();		//use memset to zero the array, need to calculate size		JExpression[] args = new JExpression[3];				args[0] = new JLocalVariableExpression(null, def);				//set up the size of arg, just the array name...		JExpression[] sizeofArgs = new JExpression[1];		sizeofArgs[0] = new JLocalVariableExpression(null, def);				args[1] = new JIntLiteral(0);				args[2] = new JMethodCallExpression(null,						    new JThisExpression(null),						    "sizeof",						    sizeofArgs);		JExpressionStatement memset = 		    new JExpressionStatement(null,					     new JMethodCallExpression(null,								       new JThisExpression(null), 								       "memset",								       args),					     null);		JEqualityExpression isZero = 		    new JEqualityExpression(null, false,					    new JLocalVariableExpression(null, def),					    new JIntLiteral(0));		JIfStatement zeroArray = new JIfStatement(null, isZero, memset, 							  new JEmptyStatement(null, null),							  null);				//place the statement after the variable defs		rawMainBlock.addStatement(fields.length, zeroArray);	    }	    //remove the field defs from the filter	    filter.setFields(new JFieldDeclaration[0]);	    //convert all access of globals into locals	    RemoveGlobals.getRawMain(filter).accept(new ConvertGlobalsToLocals());	    //remove all the functions except the raw main and 	    //anything we could not inline	    filter.setMethods		((JMethodDeclaration[])		 RemoveGlobals.functionsToKeep.toArray(new JMethodDeclaration[0]));	    	    //set the init to a dummy init if we need an init 	    if (filter.needsInit()) {		filter.setInit(SIRStream.makeEmptyInit());	    }	    //set the work to a dummy work if we need a work	    if (filter.needsWork()) {		filter.setWork(new JMethodDeclaration(null, ACC_PUBLIC, 						      CStdType.Void, 						      "work",						      new JFormalParameter[0], 						      new CClassType[0],						      new JBlock(),						      null, null));	    }	    	}