<<>> <> <> <> <<>> DIRECTORY Histograms, HistogramsViewing, RefTab, RefTabImpl, SoftHdwCompiler; Hack: CEDAR PROGRAM IMPORTS RefTab, Histograms, HistogramsViewing SHARES RefTabImpl = BEGIN CountChain: PROC [table: RefTabImpl.Impl, index: CARDINAL] RETURNS [count: INT _ 0] = { FOR node: RefTabImpl.Node _ table.data[index], node.next UNTIL node=NIL DO count _ count + 1; ENDLOOP; }; CountPrimitives: PROC [sinks: SoftHdwCompiler.Primitives] RETURNS [count: INT _ 0] = { FOR sl: SoftHdwCompiler.Primitives _ sinks, sl.rest UNTIL sl=NIL DO count _ count+1; ENDLOOP; }; HistogramRefTab: PROC [table: RefTabImpl.Impl] = { h: Histograms.Histogram _ Histograms.Create1D[]; FOR index: CARDINAL IN [0..table.data.max) DO size: INT _ CountChain[table, index]; Histograms.Change[h, index, size]; ENDLOOP; [] _ HistogramsViewing.Show[h]; }; HistogramConnectionCount: PROC [wireMap: RefTab.Ref] = { DoAWire: RefTab.EachPairAction = { p: SoftHdwCompiler.Primitive _ NARROW[val]; sinks: INT _ CountPrimitives[p.sinks]; Histograms.Change[h, sinks, 1]; }; h: Histograms.Histogram _ Histograms.Create1D[]; [] _ RefTab.Pairs[wireMap, DoAWire]; [] _ HistogramsViewing.Show[h]; }; <> <> <> <> <> <> <> <> <<};>> <> <> <> <> <> <> <> <> <<};>> <> <<[] _ HistogramsViewing.Show[h];>> <<};>> <<>> HistogramGroupSize: PROC [flatCell: SoftHdwCompiler.FlatCell] = { DoAWire: RefTab.EachPairAction = { p: SoftHdwCompiler.Primitive _ NARROW[val]; IF p.sinks#NIL AND p.sinks.rest=NIL THEN { IF RootPrimitive[primitiveMap, p.sinks.first]#p THEN { IF NOT RefTab.Insert[primitiveMap, p, p.sinks.first] THEN ERROR; }; }; }; CountGroup: RefTab.EachPairAction = { p: SoftHdwCompiler.Primitive _ NARROW[val]; root: SoftHdwCompiler.Primitive _ RootPrimitive[primitiveMap, p]; count: REF INT _ NIL; IF root=NIL THEN root _ p; count _ NARROW[RefTab.Fetch[primitiveCount, root].val]; IF count=NIL THEN { count _ NEW[INT]; count^ _ 0; IF NOT RefTab.Insert[primitiveCount, root, count] THEN ERROR; }; count^ _ count^ + 1; }; HistogramGroup: RefTab.EachPairAction = { count: REF INT _ NARROW[val]; Histograms.Change[h, count^, count^]; }; h: Histograms.Histogram _ Histograms.Create1D[]; primitiveMap: RefTab.Ref _ RefTab.Create[]; primitiveCount: RefTab.Ref _ RefTab.Create[]; [] _ RefTab.Pairs[flatCell.wires, DoAWire]; [] _ RefTab.Pairs[flatCell.wires, CountGroup]; [] _ RefTab.Pairs[primitiveCount, HistogramGroup]; [] _ HistogramsViewing.Show[h]; }; HistogramGroupSizeMultiple: PROC [flatCell: SoftHdwCompiler.FlatCell] = { DoAWire: RefTab.EachPairAction = { p: SoftHdwCompiler.Primitive _ NARROW[val]; sinks: INT _ CountPrimitives[p.sinks]; IF sinks>1 AND sinks<5 THEN { outputRoot: SoftHdwCompiler.Primitive _ RootPrimitive[primitiveMap, p]; FOR pl: SoftHdwCompiler.Primitives _ p.sinks, pl.rest UNTIL pl=NIL DO inputRoot: SoftHdwCompiler.Primitive _ RootPrimitive[primitiveMap, pl.first]; IF outputRoot#inputRoot THEN { IF NOT RefTab.Insert[primitiveMap, outputRoot, inputRoot] THEN ERROR; outputRoot _ inputRoot; }; ENDLOOP; }; }; CountGroup: RefTab.EachPairAction = { p: SoftHdwCompiler.Primitive _ NARROW[val]; root: SoftHdwCompiler.Primitive _ RootPrimitive[primitiveMap, p]; count: REF INT _ NIL; IF root=NIL THEN root _ p; count _ NARROW[RefTab.Fetch[primitiveCount, root].val]; IF count=NIL THEN { count _ NEW[INT]; count^ _ 0; IF NOT RefTab.Insert[primitiveCount, root, count] THEN ERROR; }; count^ _ count^ + 1; }; HistogramGroup: RefTab.EachPairAction = { count: REF INT _ NARROW[val]; Histograms.Change[h, count^, count^]; }; h: Histograms.Histogram _ Histograms.Create1D[]; primitiveMap: RefTab.Ref _ RefTab.Create[]; primitiveCount: RefTab.Ref _ RefTab.Create[]; [] _ RefTab.Pairs[flatCell.wires, DoAWire]; [] _ RefTab.Pairs[flatCell.wires, CountGroup]; [] _ RefTab.Pairs[primitiveCount, HistogramGroup]; [] _ HistogramsViewing.Show[h]; }; RootPrimitive: PROC [primitiveMap: RefTab.Ref, primitive: SoftHdwCompiler.Primitive] RETURNS [rootPrimitive: SoftHdwCompiler.Primitive] = { rootPrimitive _ NARROW [RefTab.Fetch[primitiveMap, primitive].val]; IF rootPrimitive=NIL THEN RETURN [primitive]; rootPrimitive _ RootPrimitive[primitiveMap, rootPrimitive]; [] _ RefTab.Replace[primitiveMap, primitive, rootPrimitive]; }; Orientation: TYPE = REF OrientationType; OrientationType: TYPE = {vertical, horizontal, ambiguous}; CountEvenOdd: PROC [flatCell: SoftHdwCompiler.FlatCell] RETURNS [vertical, horizontal, ambiguous, ambiguousMultipleSinks: INT _ 0] = { Inverse: PROC [curr: OrientationType] RETURNS [inverse: OrientationType] = { inverse _ SELECT curr FROM vertical => horizontal, horizontal => vertical, ambiguous => current, ENDCASE => ERROR; }; SetOrientation: PROC [p: SoftHdwCompiler.Primitive, c: OrientationType] RETURNS[new: BOOL _ FALSE] = { o: Orientation _ NARROW[RefTab.Fetch[primitiveOrientation, p].val]; IF o=NIL THEN { o _ NEW[OrientationType]; o^ _ c; IF NOT RefTab.Insert[primitiveOrientation, p, o] THEN ERROR; new _ TRUE; } ELSE IF o^#c THEN o^ _ ambiguous; }; DoAWire: RefTab.EachPairAction = { p: SoftHdwCompiler.Primitive _ NARROW[val]; IF NOT RefTab.Fetch[primitiveOrientation, p].found THEN { toVisit: SoftHdwCompiler.Primitives _ LIST[p]; IF NOT SetOrientation[p, current] THEN ERROR; current _ Inverse[current]; UNTIL toVisit=NIL DO SetPrim: PROC [prim: SoftHdwCompiler.Primitive] = { IF prim#NIL THEN IF SetOrientation[prim, c] THEN toVisit _ CONS[prim, toVisit]; }; prim: SoftHdwCompiler.Primitive _ toVisit.first; c: OrientationType _ Inverse[NARROW[RefTab.Fetch[primitiveOrientation, prim].val, Orientation]^]; toVisit _ toVisit.rest; FOR i: NAT IN [0..prim.size) DO SetPrim[prim[i].source]; ENDLOOP; FOR sinks: SoftHdwCompiler.Primitives _ prim.sinks, sinks.rest UNTIL sinks=NIL DO SetPrim[sinks.first]; ENDLOOP; ENDLOOP; }; }; CountOrientations: RefTab.EachPairAction = { p: SoftHdwCompiler.Primitive _ NARROW[key]; o: Orientation _ NARROW[val]; SELECT o^ FROM vertical => vertical _ vertical + 1; horizontal => horizontal _ horizontal + 1; ambiguous => { ambiguous _ ambiguous + 1; IF p.sinks#NIL AND p.sinks.rest#NIL THEN ambiguousMultipleSinks _ ambiguousMultipleSinks + 1; }; ENDCASE => ERROR; }; primitiveOrientation: RefTab.Ref _ RefTab.Create[]; current: OrientationType _ vertical; [] _ RefTab.Pairs[flatCell.wires, DoAWire]; [] _ RefTab.Pairs[primitiveOrientation, CountOrientations]; }; END.