/// <summary> /// Compiles entry code and body of a sheet-defined function /// </summary> /// <param name="info">The SdfInfo object describing the function</param> /// <returns></returns> private static Delegate CompileSdf(SdfInfo info) { // Build dependency graph containing all cells needed by the output cell DependencyGraph dpGraph = new DependencyGraph(info.outputCell, info.inputCells, delegate(FullCellAddr fca) { return(fca.sheet[fca.ca]); }); // Topologically sort the graph in calculation order; leave out constants IList <FullCellAddr> cellList = dpGraph.PrecedentOrder(); info.SetVolatility(cellList); // Convert each Expr into a CGExpr while preserving order. Inline single-use expressions cellToFunctionMapper.AddFunction(info, dpGraph.GetAllNodes()); return(ProgramLines.CreateSdfDelegate(info, dpGraph, cellList)); }
private ProgramLines PruneZeroUseCells() { // This is slightly more general than necessary, since we know that the // new order of FullCellAddrs could be embedded in the old one. So it would suffice // to simply count the number of uses of each FullCellAddr rather than do this sort. DependencyGraph dpGraph = new DependencyGraph(outputCell, inputCells, GetComputeCell); IList <FullCellAddr> prunedList = dpGraph.PrecedentOrder(); ProgramLines prunedProgram = new ProgramLines(outputCell, inputCells); foreach (FullCellAddr cellAddr in prunedList) { prunedProgram.AddComputeCell(cellAddr, GetComputeCell(cellAddr)); } return(prunedProgram); }
/// CodeGenerate.Initialize(ilg) must be called first. public void EvalCondReorderCompile() { ComputeEvalConds(); // Re-sort the expressions to reflect new dependencies // introduced by evaluation conditions DependencyGraph augmentedGraph = new DependencyGraph(outputCell, inputCells, GetComputeCell); IList <FullCellAddr> augmentedList = augmentedGraph.PrecedentOrder(); ProgramLines finalProgram = new ProgramLines(outputCell, inputCells); foreach (FullCellAddr cellAddr in augmentedList) { finalProgram.AddComputeCell(cellAddr, GetComputeCell(cellAddr)); } // This relies on all pathconds having been generated at this point: EmitCacheInitializations(); finalProgram.CreateUnwrappedNumberCells(); finalProgram.Compile(); }
/// CodeGenerate.Initialize(ilg) must be called first. public void EvalCondReorderCompile() { ComputeEvalConds(); // Re-sort the expressions to reflect new dependencies // introduced by evaluation conditions DependencyGraph augmentedGraph = new DependencyGraph(outputCell, inputCells, GetComputeCell); IList<FullCellAddr> augmentedList = augmentedGraph.PrecedentOrder(); ProgramLines finalProgram = new ProgramLines(outputCell, inputCells); foreach (FullCellAddr cellAddr in augmentedList) { finalProgram.AddComputeCell(cellAddr, GetComputeCell(cellAddr)); } // This relies on all pathconds having been generated at this point: EmitCacheInitializations(); finalProgram.CreateUnwrappedNumberCells(); finalProgram.Compile(); }
private ProgramLines PruneZeroUseCells() { // This is slightly more general than necessary, since we know that the // new order of FullCellAddrs could be embedded in the old one. So it would suffice // to simply count the number of uses of each FullCellAddr rather than do this sort. DependencyGraph dpGraph = new DependencyGraph(outputCell, inputCells, GetComputeCell); IList<FullCellAddr> prunedList = dpGraph.PrecedentOrder(); ProgramLines prunedProgram = new ProgramLines(outputCell, inputCells); foreach (FullCellAddr cellAddr in prunedList) { prunedProgram.AddComputeCell(cellAddr, GetComputeCell(cellAddr)); } return prunedProgram; }
/// <summary> /// Compiles entry code and body of a sheet-defined function /// </summary> /// <param name="info">The SdfInfo object describing the function</param> /// <returns></returns> private static Delegate CompileSdf(SdfInfo info) { // Build dependency graph containing all cells needed by the output cell DependencyGraph dpGraph = new DependencyGraph(info.outputCell, info.inputCells, delegate(FullCellAddr fca) { return fca.sheet[fca.ca]; }); // Topologically sort the graph in calculation order; leave out constants IList<FullCellAddr> cellList = dpGraph.PrecedentOrder(); info.SetVolatility(cellList); // Convert each Expr into a CGExpr while preserving order. Inline single-use expressions cellToFunctionMapper.AddFunction(info, dpGraph.GetAllNodes()); return ProgramLines.CreateSdfDelegate(info, dpGraph, cellList); }