DIRECTORY CD, CDBasics, CDCells, CDCellsInteractions, CDCommandOps, CDCurves, CDDirectory, CDImports, CDInstances, CDIO, CDOps, CDProperties, CDPropertyTools, CDSatellites, CDSequencer, CDTexts, CDVArrow, CStitching, FS, IO, List USING [Append], Rope, TerminalIO; BrandyCIFter: CEDAR PROGRAM IMPORTS CD, CDBasics, CDCells, CDCellsInteractions, CDCurves, CDCommandOps, CDDirectory, CDImports, CDInstances, CDIO, CDOps, CDProperties, CDPropertyTools, CDSatellites, CDSequencer, CDTexts, CDVArrow, CStitching, FS, IO, List, Rope, TerminalIO = BEGIN CIFUnits: TYPE = CD.Number; CIFPos: TYPE = CD.Position -- in CIFUnits -- ; CIFRect: TYPE = CD.Rect -- in CIFUnits -- ; Rational: TYPE = RECORD [num, denom: INT _ 1]; CIFDest: TYPE = REF CIFDestRec _ NIL; CIFDestRec: TYPE = RECORD [ cifDest: Rope.ROPE, deltaRadius: INT -- nanometers, + means cif is bigger ]; CIFDirective: TYPE = REF CIFDirectiveRec _ NIL; CIFDirectiveRec: TYPE = RECORD [ cdSource: CD.Layer, cifDest: Rope.ROPE, deltaRadius: INT -- nanometers, + means cif is bigger ]; MaskStateRef: TYPE = REF MaskState; MaskState: TYPE = RECORD [ areas, unbloated: CStitching.Tesselation _ NIL, partClip: CIFRect _ [0,0,0,0] ]; cellIDKey: REF ATOM = NEW[ATOM _ $CellIDNo]; --not accessible debugging: BOOL _ FALSE; -- used for printing out debugging messages satellitesSignals: BOOL _ TRUE; -- whether satellites should contribute signal names design: CD.Design; stopFlag: REF BOOL; topLayerOb: CD.Object _ NEW[CD.ObjectRep]; clearIDsRec: CD.DrawRef; cifMeasureR: CD.DrawRef; cifDrawRec: CD.DrawRef; --for CIFOrArea contextFilter: REF CD.ContextFilter _ NEW[CD.ContextFilter_ALL[FALSE]]; --used in cifDrawRec infinity: CD.Number _ LAST[CD.Number]; --used to initialize sizes and positions cellCount: INTEGER _ 0; -- used to assign consecutive CIF ID numbers cifLayerAnnounced: BOOL _ FALSE; lambda: INT _ 0; cifPerLambda: INT _ 100; -- CIF units per lambda nmPerCIF: INT = 10; -- nanometers per CIF unit, given 0.01 microns per CIF unit cifScaling: Rational; cifFile: IO.STREAM; -- file where output will be stored comment, base, name, lastCellName: Rope.ROPE; mainRect: CD.Rect _ [x1: infinity, y1: infinity, x2: -infinity, y2: -infinity]; cifDirectives: LIST OF REF ANY -- CIFDirective -- _ NIL; currentDirective: CIFDirective; partWidth: CIFUnits _ 800000; -- window for flat CIF partHeight: CIFUnits _ 800000; FreeStorage: PROC [] = { cifMeasureR _ clearIDsRec _ cifDrawRec _ NIL; --help the garbage collector design _ NIL; cifFile _ NIL; }; SimpleRect: PROC [ob: CD.Object] RETURNS [yes: BOOL] = INLINE { yes _ ob.class.wireTyped AND ob.class.objectType=$Rect }; flattenAtomics: BOOL _ FALSE; MakeCall: PROC [ob: CD.Object] RETURNS [yes: BOOL] = { IF SimpleRect[ob] THEN RETURN [FALSE]; IF ob.class.symbolic THEN RETURN [FALSE]; IF flattenAtomics THEN { IF ob.class.wireTyped THEN RETURN [FALSE]; IF ob.class.technology#NIL THEN RETURN [FALSE]; }; IF CDTexts.IsText[ob] THEN { FOR dir: LIST OF REF ANY _ cifDirectives, dir.rest WHILE dir#NIL DO directive: CIFDirective _ NARROW[dir.first]; IF directive.cdSource=ob.layer THEN RETURN [TRUE]; ENDLOOP; RETURN [FALSE]; }; RETURN [TRUE]; }; specialProperties: CDProperties.PropRef _ CDProperties.InitPropRef[]; SetUpSpecialClasses: PROC [] = { x: REF _ CDProperties.GetProp[$CDxCIFRegistrations, $CDxCIFTechnology]; IF design.technology.key#x AND design.technology#x THEN { IF x=NIL THEN TerminalIO.PutRope["CIF commandfile not set up\n"] ELSE TerminalIO.PutRope["CIF commandfile set up for different technology\n"]; ERROR ABORTED }; WITH CDProperties.GetProp[$CDxCIFRegistrations, $CDxCIFSpecials] SELECT FROM pRef: CDProperties.PropRef => specialProperties _ pRef; ENDCASE => specialProperties _ CDProperties.InitPropRef[]; flattenAtomics _ CDProperties.GetProp[$CDxCIFRegistrations, $CDxFlattenAtomic]=$TRUE; }; IsSpecialCase: PROC [ob: CD.Object] RETURNS [yes: BOOL_FALSE] = { yes _ CDProperties.GetListProp[specialProperties^, ob.class.objectType]#NIL }; HandleSpecialCase: PROC [ob: CD.Object] = { WITH CDProperties.GetListProp[specialProperties^, ob.class.objectType] SELECT FROM rp: REF PROC [ob: CD.Object] RETURNS [Rope.ROPE] => { r: Rope.ROPE _ rp^[ob]; IO.PutRope[cifFile, r]; }; r: Rope.ROPE => { IO.PutRope[cifFile, r]; }; rt: REF TEXT => { IO.PutText[cifFile, rt]; }; ENDCASE => { TerminalIO.PutRope["object class handled specialy is inconsistent\n"]; ERROR }; }; ClearCellIDs: CD.DrawProc = { CDProperties.PutObjectProp[onto: inst.ob, prop: cellIDKey, val: NIL]; IF inst.ob.class.inDirectory THEN inst.ob.class.drawMe[inst: inst, trans: inst.trans, pr: clearIDsRec]; }; SymHeader: PROC [obj: CD.Object] = { cellID: REF INT _ NEW[INT _ (cellCount _ cellCount + 1)]; cifFile.PutF["DS %d %d %d;\n", IO.int[cellCount], IO.int[cifScaling.num], IO.int[cifScaling.denom]]; CDProperties.PutObjectProp[obj, cellIDKey, cellID]; }; UnfinishedSymHeader: PROC [obj: CD.Object] = { cellID: REF INT _ NEW[INT _ (cellCount _ cellCount + 1)]; cifFile.PutF["DS %d ", IO.int[cellCount]]; CDProperties.PutObjectProp[obj, cellIDKey, cellID]; }; SymTrailer: PROC = { cifFile.PutRope["DF;\n"]; }; CallChildren: CD.DrawProc = { IF MakeCall[inst.ob] THEN CIFSymbolCall[inst.ob, trans.orient, CDPosToCIF[trans.off]]; }; DrawRectChilds: CD.DrawProc = { IF ~MakeCall[inst.ob] THEN inst.ob.class.drawMe[inst: inst, trans: trans, pr: pr]; }; GenerateCompositeOb: PROC [obj: CD.Object] = { cf: REF CD.ContextFilter _ NEW[CD.ContextFilter_ALL[FALSE]]; pr: CD.DrawRef _ CD.CreateDrawRef[[ stopFlag: stopFlag, design: design ]]; dummyInst: CD.Instance = NEW[CD.InstanceRep]; dummyInst^.ob _ obj; SymHeader[obj]; CIFDrawCellName[CDDirectory.Name[obj]]; pr.contextFilter _ NIL; pr.drawChild _ CallChildren; pr.drawRect _ IgnoreRect; obj.class.drawMe[dummyInst, [], pr]; pr.drawChild _ DrawRectChilds; pr.contextFilter _ cf; pr.drawRect _ CIFOrArea; FOR directives: LIST OF REF ANY _ cifDirectives, directives.rest WHILE directives#NIL DO currentDirective _ NARROW[directives.first]; cifLayerAnnounced _ FALSE; cf[currentDirective.cdSource] _ TRUE; obj.class.drawMe[dummyInst, [], pr]; cf[currentDirective.cdSource] _ FALSE; ENDLOOP; SymTrailer[]; }; GenerateGeometricOb: PROC [obj: CD.Object] = { dummyInst: CD.Instance = NEW[CD.InstanceRep]; dummyInst^.ob _ obj; IF IsSpecialCase[obj] THEN { UnfinishedSymHeader[obj]; HandleSpecialCase[obj] } ELSE { SymHeader[obj]; FOR directives: LIST OF REF ANY _ cifDirectives, directives.rest WHILE directives#NIL DO currentDirective _ NARROW[directives.first]; cifLayerAnnounced _ FALSE; cifDrawRec.contextFilter _ contextFilter; contextFilter[currentDirective.cdSource] _ TRUE; obj.class.drawMe[inst: dummyInst, trans: [], pr: cifDrawRec]; contextFilter[currentDirective.cdSource] _ FALSE; ENDLOOP; }; SymTrailer[]; }; MustCompensate: PROC [layer: CD.Layer] RETURNS [BOOL] = { FOR dList: LIST OF REF ANY _ cifDirectives, dList.rest WHILE dList#NIL DO cdir: CIFDirective _ NARROW[dList.first]; IF cdir.cdSource=layer AND cdir.deltaRadius#0 THEN RETURN [TRUE]; ENDLOOP; RETURN [FALSE]; }; GeneratePolygon: PROC [obj: CD.Object] = { CifPolygonOut: PROC [points: LIST OF CD.Position] = { IF NOT cifLayerAnnounced THEN { cifFile.PutF["L %g;\n", IO.rope[currentDirective.cifDest]]; cifLayerAnnounced _ TRUE; }; cifFile.PutRope["P"]; FOR p: LIST OF CD.Position _ points, p.rest WHILE p#NIL DO cifPos: CD.Position = CDPosToCIF[p.first]; cifFile.PutRope[" "]; CIFOutPoint[cifPos.x, cifPos.y]; ENDLOOP; cifFile.PutRope[";\n"]; }; polygon: CDCurves.CurveSpecific = NARROW[obj.specific]; bad: BOOL _ FALSE; SymHeader[obj]; FOR directives: LIST OF REF ANY _ cifDirectives, directives.rest WHILE directives#NIL DO currentDirective _ NARROW[directives.first]; cifLayerAnnounced _ FALSE; IF currentDirective.cdSource=obj.layer THEN { IF currentDirective.deltaRadius#0 THEN bad _ TRUE; CifPolygonOut[polygon.points]; } ENDLOOP; IF bad THEN { TerminalIO.PutRope["**polygon shrink or bloat failed\n"]; cifFile.PutRope["( polygon has incorrect sizing );\n"]; }; SymTrailer[]; }; CIFDefineObject: PROC [obj: CD.Object] = { CheckChildren: CDDirectory.EnumerateObjectsProc = { IF MakeCall[me] THEN CIFDefineObject[me] }; IF debugging THEN TerminalIO.PutRope["Entering CIFDefineObject\n"]; IF CDProperties.GetObjectProp[obj, cellIDKey]#NIL THEN RETURN; IF obj.class.inDirectory THEN { [] _ CDDirectory.EnumerateChildObjects[obj, CheckChildren, NIL]; }; WITH obj.specific SELECT FROM rp: CDImports.ImportSpecific => { IF rp.boundInstance=NIL THEN ERROR; CIFDefineObject[rp.boundInstance.ob]; SymHeader[obj]; CIFDrawCellName[Rope.Cat[rp.designName, ".", rp.objectName]]; CIFSymbolCall[rp.boundInstance.ob]; SymTrailer[]; }; cp: CD.CellSpecific => { IF satellitesSignals THEN [] _ CDSatellites.GetSatellites[obj]; SymHeader[obj]; CIFDrawCellName[CDDirectory.Name[obj]]; BEGIN EachInst: CDCells.InstEnumerator = { IF MakeCall[inst.ob] THEN CIFSymbolCall[inst.ob, inst.trans.orient, CDPosToCIF[inst.trans.off]]; }; [] _ CDCells.EnumerateInstances[obj, EachInst]; END; FOR dir: LIST OF REF ANY _ cifDirectives, dir.rest WHILE dir#NIL DO currentDirective _ NARROW[dir.first]; cifLayerAnnounced _ FALSE; BEGIN EachInst: CDCells.InstEnumerator = { IF ~MakeCall[inst.ob] THEN inst.ob.class.drawMe[inst: inst, trans: inst.trans, pr: cifDrawRec]; }; [] _ CDCells.EnumerateInstances[obj, EachInst]; END; ENDLOOP; BEGIN EachInst: CDCells.InstEnumerator = { IF ~MakeCall[inst.ob] THEN { WITH CDProperties.GetInstanceProp[inst, $SignalName] SELECT FROM r: Rope.ROPE => CIFLabelTerminal[inst, r, inst.ob.layer]; ENDCASE => NULL; IF satellitesSignals THEN { FOR list: LIST OF Rope.ROPE _ CDSatellites.GetSatelliteRopes[inst], list.rest WHILE list#NIL DO CIFLabelTerminal[inst, list.first, inst.ob.layer]; ENDLOOP; }; } }; [] _ CDCells.EnumerateInstances[obj, EachInst]; END; SymTrailer[]; }; -- of cell ENDCASE => -- crazy or transistors or geometry or rects IF obj.class.inDirectory THEN GenerateCompositeOb[obj] ELSE IF MakeCall[obj] THEN { IF CDCurves.IsPolygon[obj] AND ~MustCompensate[obj.layer] THEN GeneratePolygon[obj] ELSE GenerateGeometricOb[obj]; }; IF debugging THEN TerminalIO.PutRope["Leaving CIFDefineObject\n"]; }; CIFSymbolCall: PROC[ob: CD.Object, orient: CD.Orientation_original, pos: CD.Position_ [0,0]] = { WITH CDProperties.GetObjectProp[ob, cellIDKey] SELECT FROM iDNo: REF INT => { cifFile.PutF["C %d", IO.int[iDNo^]]; IF orient#original THEN { xrotation: CD.Orientation _ CDBasics.ConcentrateOnRotate90[orient]; IF xrotation#original THEN { cifFile.PutRope[" R "]; cifFile.PutRope[SELECT xrotation FROM rotate90 => "0,1" , rotate180=> "-1,0", rotate270=> "0,-1", ENDCASE=> "1,0" -- never use this one ]; }; IF CDBasics.IncludesMirrorX[orient] THEN cifFile.PutRope[" M X "]; }; IF pos#[0, 0] THEN { cifFile.PutRope[" T "]; CIFOutPoint[pos.x, pos.y]; }; cifFile.PutRope[";\n"]; }; ENDCASE => ERROR; }; CIFMeasureArea: CD.DrawRectProc = { r _ CDBasics.ReInterpreteRect[r]; IF CDBasics.NonEmpty[r] THEN mainRect _ CDBasics.Surround[mainRect, r]; }; IgnoreRect: CD.DrawRectProc = { }; CIFOrArea: CD.DrawRectProc = { IF l=currentDirective.cdSource AND CDBasics.NonEmpty[r] THEN { rd: CIFRect _ CDBasics.Extend[CDRectToCIF[CDBasics.ReInterpreteRect[r]], currentDirective.deltaRadius/nmPerCIF]; IF CDBasics.NonEmpty[rd] THEN CIFRectOut[rd]; } }; CIFRectOut: PROC [r: CIFRect] = { IF NOT CDBasics.NonEmpty[r] THEN RETURN; IF NOT cifLayerAnnounced THEN { cifFile.PutF["L %g;\n", IO.rope[currentDirective.cifDest]]; cifLayerAnnounced _ TRUE; }; cifFile.PutF["B %d %d %d %d;\n",-- BOX command, in prescaled CIF units IO.int[PrescaleCIF[[r.x2-r.x1, 1]]] -- length -- , IO.int[PrescaleCIF[[r.y2-r.y1, 1]]] -- width -- , IO.int[PrescaleCIF[[r.x1+r.x2, 2]]] -- center x-coord -- , IO.int[PrescaleCIF[[r.y1+r.y2, 2]]] -- center y-coord -- ]; }; CIFOutPoint: PROC[x, y: CIFUnits] = { cifFile.PutF["%d,%d", IO.int[PrescaleCIF[[x,1]]], IO.int[PrescaleCIF[[y,1]]]] }; CIFLabelTerminal: PROC [ap: CD.Instance, s: Rope.ROPE, lev: CD.Layer] = { pt: CD.Position _ CDBasics.Center[CDRectToCIF[CDInstances.InstRectO[ap]]]; cifFile.PutF["94 %s ", IO.rope[s]]; CIFOutPoint[pt.x, pt.y]; cifFile.PutChar[' ]; FOR directives: LIST OF REF ANY _ cifDirectives, directives.rest WHILE directives#NIL DO d: CIFDirective = NARROW[directives.first]; IF d.cdSource = lev THEN {cifFile.PutRope[d.cifDest]; EXIT}; ENDLOOP; cifFile.PutRope[";\n"]; }; CIFDrawCellName: PROC[s: Rope.ROPE] = { lastCellName _ s; IF ~Rope.IsEmpty[s] THEN cifFile.PutF["9 %s;\n", IO.rope[s]]; }; CantRepresentExactly: SIGNAL = CODE; SetCIFScaling: PROC = { cifScaling _ ReduceTerms[[num: cifPerLambda, denom: 2*lambda]]; -- the "2" allows for box centers FOR directives: LIST OF REF ANY _ cifDirectives, directives.rest WHILE directives#NIL DO d: CIFDirective = NARROW[directives.first]; cif: CIFUnits; IF ABS[d.deltaRadius] MOD nmPerCIF # 0 THEN ERROR CantRepresentExactly; cif _ ABS[d.deltaRadius]/nmPerCIF; cifScaling _ ReduceTerms[[ num: cifScaling.num, denom: (cifScaling.num*cifScaling.denom)/GCD[cif*cifScaling.denom, cifScaling.num]]]; ENDLOOP; }; CollectDirectives: PROC = { GetDirectives: PROC [p: REF, lev: CD.Layer] RETURNS [l: LIST OF REF ANY _ NIL] = { IF p#NIL THEN { WITH p SELECT FROM d: CIFDest => l _ LIST[NEW[CIFDirectiveRec _ [lev, d.cifDest, d.deltaRadius]]]; list: LIST OF REF ANY => l _ List.Append[GetDirectives[list.first, lev], GetDirectives[list.rest, lev]]; ENDCASE => l _ LIST[NEW[CIFDirectiveRec _ [lev, CDOps.ToRope[p, $Interactive], 0]]]; }; }; cifDirectives _ NIL; FOR layers: LIST OF CD.Layer _ design.technology.usedLayers, layers.rest WHILE layers#NIL DO cifDirectives _ List.Append[GetDirectives[CDProperties.GetLayerProp[layers.first, $CDxCIFRegistrations], layers.first ], cifDirectives]; ENDLOOP; }; GetCifPerLambda: PROC [] = { WITH CDProperties.GetProp[$CDxCIFRegistrations, $CDxCIFUnitsPerLambda] SELECT FROM ri: REF INT => cifPerLambda _ ri^; ENDCASE => cifPerLambda _ 0; TerminalIO.PutF["using %g cif units per lambda; (1 CIF unit = 0.01 microns)\n", IO.int[cifPerLambda]] ; IF cifPerLambda<2 THEN { TerminalIO.PutRope["cif units per lambda not reasonable\n"]; ERROR ABORTED }; }; WriteCIF: PROC[ comm: CDSequencer.Command] = { ENABLE { ABORTED => {TerminalIO.PutRope[" CIF generation aborted\n"]; GOTO Exit}; UNWIND => NULL; }; --enable mainOb: CD.Object; mainInst: CD.Instance; cifKey: Rope.ROPE; stopFlag _ NEW[BOOL_FALSE]; design _ comm.design; lambda _ design.technology.lambda; CDSequencer.UseAbortFlag[design, stopFlag]; SetUpSpecialClasses[]; cifKey _ CDOps.ToRope[CDProperties.GetProp[$CDxCIFRegistrations, $CDxCIFName], $Interactive]; IF Rope.IsEmpty[cifKey] THEN { TerminalIO.PutRope["The CIF layers for this technology are not yet defined\n"]; RETURN }; TerminalIO.PutRopes["Use CIF layer definitions [", cifKey, "]\n"]; mainInst _ CDCellsInteractions.MakeTopInstance[design]; IF mainInst=NIL THEN { TerminalIO.PutRope["no top level object found\n"]; RETURN }; mainOb _ mainInst.ob; cellCount _ 0; stopFlag^ _ FALSE; cifMeasureR _ CD.CreateDrawRef[[ interestClip: CDBasics.universe, drawRect: CIFMeasureArea, stopFlag: stopFlag, design: design ]]; clearIDsRec _ CD.CreateDrawRef[[ interestClip: CDBasics.universe, drawChild: ClearCellIDs, stopFlag: stopFlag, design: design ]]; cifDrawRec _ CD.CreateDrawRef[[ interestClip: CDBasics.universe, drawRect: CIFOrArea, stopFlag: stopFlag, design: design ]]; CDOps.DrawDesign[design, cifMeasureR]; GetCifPerLambda[]; TerminalIO.PutRopes["Input name of CIF file (", CDIO.GetWorkingDirectory[design], ") "]; base _ TerminalIO.RequestRope["> "]; IF Rope.IsEmpty[base] THEN base _ design.name; IF Rope.IsEmpty[base] THEN base _ "foo"; name _ CDIO.MakeName[base: base, ext: ".cif", wDir: CDIO.GetWorkingDirectory[design]]; cifFile _ FS.StreamOpen[name, create ! FS.Error => IF error.group#bug THEN { TerminalIO.PutRope[error.explanation]; GOTO FileIOOpenFailed; } ]; cifFile.PutF["( %s );\n", IO.rope[design.name]]; cifFile.PutF["( generated %g by Xerox PARC ChipNDale and BrandyCIFter);\n", IO.time[]]; cifFile.PutF["( with lambda = %d CIF units );\n", IO.int[cifPerLambda]]; cifFile.PutF["( origin = [x: 0, y: 0], size = [x: %d, y: %d] CIF units );\n", IO.int[CDCIFUp[mainRect.x2-mainRect.x1]], IO.int[CDCIFUp[mainRect.y2-mainRect.y1]]]; cifFile.PutF["( CIF KEY: %s );\n", IO.rope[cifKey]]; TerminalIO.PutRope["Comment line: \n"]; comment _ TerminalIO.RequestRope["(parens are changed, CR for no comment)\n> "]; WHILE NOT Rope.IsEmpty[comment] DO comment _ EliminateParens[comment]; cifFile.PutF["( %s );\n", IO.rope[comment]]; comment _ NIL; TerminalIO.PutRope["Another comment line:\n"]; comment _ TerminalIO.RequestRope["(parens are changed, CR for no further comments)\n> "]; ENDLOOP; IO.PutChar[cifFile, IO.CR]; CollectDirectives[]; SetCIFScaling[]; ClearCellIDs[design.actual.first.dummyCell, [], NIL]; CIFDefineObject[mainOb]; SymHeader[topLayerOb]; CIFSymbolCall[mainOb]; FOR directives: LIST OF REF ANY _ cifDirectives, directives.rest WHILE directives#NIL DO currentDirective _ NARROW[directives.first]; IF currentDirective.deltaRadius<0 THEN { cifLayerAnnounced _ FALSE; MakeFlatCIF[rectProc: CIFRectOut]; }; ENDLOOP; SymTrailer[]; CIFSymbolCall[topLayerOb, original, [x: -cifPerLambda*mainRect.x1/lambda, y: -cifPerLambda*mainRect.y2/lambda]]; cifFile.PutRope[";\nEnd ... \n"]; cifFile.Close[]; TerminalIO.PutF["\nCIF file on %g\n", IO.rope[name]]; FreeStorage[] EXITS Exit => FreeStorage[]; FileIOOpenFailed => { TerminalIO.PutRope["Open Failed\n"]; FreeStorage[] }; }; -- of WriteCIF MakeFlatCIF: PROC [rectProc: PROC[rect: CIFRect]] = { AnalyzeTesselation: PROC [ms: MaskStateRef] = { active: CD.Rect = ms.areas.BBox[]; IF CDBasics.NonEmpty[active] THEN { IF currentDirective.deltaRadius#0 THEN { t: CStitching.Tesselation = ms.unbloated; ms.unbloated _ ms.areas; ms.areas _ t; CStitching.ChangeRect[plane: ms.areas, rect: CDBasics.universe, new: NIL]; IF currentDirective.deltaRadius>0 THEN CStitching.EnumerateArea[plane: ms.unbloated, rect: CDBasics.universe, eachTile: BloatTile, data: ms] ELSE { CStitching.ChangeRect[plane: ms.areas, rect: active, new: $covered]; CStitching.EnumerateArea[plane: ms.unbloated, rect: CDBasics.universe, eachTile: BloatTile, data: ms, skip: $covered]; }; }; CStitching.EnumerateArea[plane: ms.areas, rect: CDBasics.universe, eachTile: OutputTile, data: ms]; TerminalIO.PutRope["."]; }; }; OutputTile: PROCEDURE [tile: CStitching.Tile, data: REF ANY] = { -- CStitching.PerTileProc -- only called on tiles with non-NIL values ms: MaskStateRef = NARROW[data]; cr: CIFRect = CDBasics.Intersection[tile.Area, ms.partClip]; rectProc[cr]; }; designClip: CD.Rect; cifClip: CD.Rect; nRows, nCols: NAT; ms: MaskStateRef = NEW[MaskState _ [ areas: CStitching.NewTesselation[], unbloated: CStitching.NewTesselation[] ]]; dr: CD.DrawRef _ CD.CreateDrawRef[[ drawRect: NoteBoundingBox, devicePrivate: NEW[CD.Rect _ CDBasics.empty], interestClip: CDBasics.universe, stopFlag: stopFlag, design: design ]]; CDOps.DrawDesign[design, dr]; -- measure design designClip _ NARROW[dr.devicePrivate, REF CD.Rect]^; cifClip _ Bloat[CDRectToCIF[designClip], ABS[currentDirective.deltaRadius]/nmPerCIF]; nRows _ Ceiling[num: cifClip.y2-cifClip.y1, denom: partHeight]; nCols _ Ceiling[num: cifClip.x2-cifClip.x1, denom: partWidth]; TerminalIO.PutF[".. in %d rows and %d columns..", IO.int[nRows], IO.int[nCols]]; dr.drawRect _ NoteRectangle; dr.devicePrivate _ ms; TerminalIO.PutF["%s -> %s", IO.rope[CDOps.ToRope[CD.LayerKey[currentDirective.cdSource], $Interactive]], IO.rope[currentDirective.cifDest]]; FOR col: NAT IN [0..nCols) DO FOR row: NAT IN [0..nRows) DO ms.areas.ChangeRect[rect: CDBasics.universe, new: NIL]; ms.partClip _ [ -- in cif space x1: cifClip.x1+col*partWidth, y1: cifClip.y1+row*partHeight, x2: cifClip.x1+col*partWidth+MIN[partWidth, cifClip.x2-cifClip.x1-partWidth*col], y2: cifClip.y1+row*partHeight+MIN[partHeight, cifClip.y2-cifClip.y1-partHeight*row] ]; dr.interestClip _ CIFRectToCD[CDBasics.Extend[ms.partClip, 1+ABS[currentDirective.deltaRadius]/nmPerCIF]]; CDVArrow.ShowArrow[design: design, pos: [x: (dr.interestClip.x1+dr.interestClip.x2)/2, y: (dr.interestClip.y1+dr.interestClip.y2)/2]]; -- keep user happy CDOps.DrawDesign[design, dr]; -- build tesselation of the relevant design rectangle AnalyzeTesselation[ms]; -- sends the current part to s ENDLOOP; ENDLOOP; TerminalIO.PutRope["+"]; CDVArrow.RemoveArrow[design: design]; dr _ NIL; }; NoteBoundingBox: CD.DrawRectProc = { bb: REF CD.Rect = NARROW[pr.devicePrivate]; bb^ _ CDBasics.Surround[bb^, r]; }; NoteRectangle: CD.DrawRectProc = { ms: MaskStateRef = NARROW[pr.devicePrivate]; IF l=currentDirective.cdSource AND CDBasics.NonEmpty[r] THEN ms.areas.ChangeRect[rect: CDRectToCIF[r], new: $covered]; }; BloatTile: PROCEDURE [tile: CStitching.Tile, data: REF ANY] = { -- CStitching.PerTileProc -- ms: MaskStateRef = NARROW[data]; cr: CD.Rect = CDBasics.Intersection[CDBasics.universe, Bloat[tile.Area, ABS[currentDirective.deltaRadius/nmPerCIF]]]; IF CDBasics.NonEmpty[cr] THEN ms.areas.ChangeRect[rect: cr, new: tile.value]; }; Bloat: PROC [r: CD.Rect, delta: CD.Number] RETURNS [br: CD.Rect] = INLINE { br _ [x1: MAX[FIRST[CD.Number]+delta, r.x1]-delta, y1: MAX[FIRST[CD.Number]+delta, r.y1]-delta, x2: MIN[LAST[CD.Number]-delta, r.x2]+delta, y2: MIN[LAST[CD.Number]-delta, r.y2]+delta] }; CDRectToCIF: PROC [ cdr: CD.Rect ] RETURNS [ cifr: CIFRect ] = { cifr _ CDBasics.ReInterpreteRect[[ x1: cifPerLambda*cdr.x1/lambda, y1: cifPerLambda*cdr.y1/lambda, x2: cifPerLambda*cdr.x2/lambda, y2: cifPerLambda*cdr.y2/lambda ]] }; CDPosToCIF: PROC [ cdp: CD.Position ] RETURNS [ cifp: CIFPos ] = { cifp _ [x: cifPerLambda*cdp.x/lambda, y: cifPerLambda*cdp.y/lambda] }; CDCIFUp: PROC [ n: CD.Number ] RETURNS [ cif: CIFUnits ] = { cif _ (cifPerLambda*n+lambda-1)/lambda }; CIFRectToCD: PROC [ cifr: CIFRect ] RETURNS [ cdr: CD.Rect ] = BEGIN cdr _ CDBasics.ReInterpreteRect[[ x1: lambda*cifr.x1/cifPerLambda, y1: lambda*cifr.y1/cifPerLambda, x2: (lambda*cifr.x2+cifPerLambda-1)/cifPerLambda, y2: (lambda*cifr.y2+cifPerLambda-1)/cifPerLambda ]] END; errOnCantRepresentExactly: BOOL _ TRUE; PrescaleCIF: PROC [ cif: Rational ] RETURNS [ INT ] = { n: INT = cif.num*cifScaling.denom; d: INT = cif.denom*cifScaling.num; IF ABS[n] MOD ABS[d] # 0 THEN { TerminalIO.PutRope["feature cant be represented exactly\n"]; IF errOnCantRepresentExactly THEN SIGNAL CantRepresentExactly; }; RETURN[n/d]; }; Ceiling: PROC [num, denom: CD.Number] RETURNS [ c: INT ] = { c _ (num+denom-1)/denom }; ReduceTerms: PROC [ r: Rational ] RETURNS [ Rational ] = { gcd: INT = GCD[r.num, r.denom]; RETURN[[num: r.num/gcd, denom: r.denom/gcd]]; }; GCD: PROC [ m, n: INT ] RETURNS [ INT ] = { r: INT; SELECT m FROM <0 => m _ -m; ENDCASE => NULL; SELECT n FROM <0 => n _ -n; >0 => NULL; ENDCASE => RETURN[m]; r _ m MOD n; WHILE r>0 DO m _ n; n _ r; r _ m MOD n; ENDLOOP; RETURN[n]; }; WriteCIFComm: PROC [comm: CDSequencer.Command] = { TerminalIO.PutRope["Hierarchical CIF output\n"]; TerminalIO.PutRope["Version of December 6, 1985 11:17:55 am PST\n"]; TerminalIO.PutRope["better read back the cif file and look at it\n"]; TerminalIO.PutRope["**WARNING not tested in release 2.4\n"]; IF CDCells.IsPushedIn[comm.design] THEN { TerminalIO.PutRope["**Design is pushed in\n"]; RETURN }; IF CDImports.HasUnloadedImports[comm.design] THEN { TerminalIO.PutRope["**Design has non bound imports\n"]; RETURN }; [] _ CDCommandOps.DoWithResource[WriteCIF, comm, $CIF]; }; EliminateParens: PROC [r: Rope.ROPE] RETURNS [Rope.ROPE] = { Translator: Rope.TranslatorType = { RETURN [SELECT old FROM '( => '[, ') => '], ENDCASE => old ] }; RETURN [Rope.Translate[base: r, translator: Translator]] }; CDPropertyTools.Associate[$CDxCIFRegistrations, $CDxCIFName]; CDPropertyTools.Associate[$CDxCIFRegistrations, $CDxCIFTechnology]; CDPropertyTools.Associate[$CDxCIFRegistrations, $CDxCIFSpecials]; CDPropertyTools.Associate[$CDxCIFRegistrations, $CDxCIFUnitsPerLambda]; CDPropertyTools.Associate[$CDxCIFRegistrations, $CDxFlattenAtomic]; CDSequencer.ImplementCommand[key: $WriteCif, proc: WriteCIFComm, queue: doQueue]; CDCommandOps.RegisterWithMenu[menu: $ProgramMenu, entry: "Hierarchical CIF", key: $WriteCif, proc: WriteCIFComm]; END. ¦BrandyCIFter.mesa A package to output CIF files from ChipNDale Copyright c 1984, 1987 by Xerox Corporation. All rights reserved. Last Edited by: Kimr, October 15, 1984 5:15:13 pm PDT Last Edited by: Christian Jacobi, October 30, 1984 12:10:38 pm PST Last Edited by: Christian Jacobi, January 6, 1987 3:47:13 pm PST Last Edited by McCreight, October 17, 1984 7:02:18 pm PDT --Global Variables --layer assumed to be unchanged until the next layer is announced cifPerCD: INT; -- cifPerLambda/l, since l is defined in CD units per lambda --..output numbers*cifScaling = CIFUnits --..CIFUnits/cifScaling = output numbers --set to design size in CIFMeasureArea, used to switch between ChipNDale and CIF coordinate systems --%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --used to set all CellIDNo's to NIL at the start --start outputting a new cell and assign its cellID --start outputting a new cell and assign its cellID --but don't output the scaling --finish off cell description --logically local to GenerateCompositeOb --logically local to GenerateCompositeOb --output composite objects --the children must be already defined --match the type of drawMe parameter --call the children --draw the rectangles --IF currentDirective.deltaRadius>=0 THEN redundant but easier to understand --output CIF for structures only identified as geometries --match the type of drawMe parameter --IF currentDirective.deltaRadius>=0 THEN redundant but easier to understand --output CIF for structures for polygons --points are in design coords, not yet CIF coords --Print out CIF pertaining to object starting with the furthest object from the top; After leaving procedure, object will have been assigned a CIF ID # in its properties field --non-NIL value indicates that object has already been assigned an ID # and is therefore already defined --We should also make a test here to decide whether any hierarchical geometry results from this object, and assign a special value to this object's attribute $CellIDNo if not. --For each member of the instance list, determine whether obj is a cell. If so, determine transformations --for each layer, pick out the rectangles belonging to that layer --and output them --IF currentDirective.deltaRadius>=0 THEN removed for simplicity --generate all signal names --we don't deal with signal names on p-diffusion; --sorry, but I have more important things to do right now --pos in CIFUnits --indicate which cell is called using its ID number --OUTPUT PROCEDURES -- Sets mainRect to be a large as is necessary to contain design. --.. adds the condition that cif/cifScaling is guaranteed to be an integer, so cif*cifScaling.denom MOD cifScaling.num = 0 --assign world variable from sequencer --initialize main object, layer names, resolution, cellCount, and draw records --Search world data structure: normalize coordinates, --set mainRect to design size, mark used layers --get file name cifPerCD _ cifPerLambda/lambda; need not be integer.. --output header --ask for comment lines --define hybrid top layer object --Flat CIF code --the tesselation is in cif coordinates --Be careful not to exceed the limits of a CD.Number, even temporarily --rounds to rect beeing bigger Κ!;˜codešœ@™@Kšœ Οmœ7™BKšœ5™5KšœB™BK™@K™9—K˜šΟk ˜ Kšžœ˜Kšœ ˜ Kšœ˜Kšœ˜Kšœ ˜ Kšœ ˜ Kšœ ˜ Kšœ ˜ Kšœ ˜ Kšžœ˜Kšœ˜Kšœ ˜ Kšœ˜Kšœ ˜ Kšœ ˜ Kšœ˜Kšœ ˜ Kšœ ˜ Kšžœ˜Kšžœ˜Kšœžœ ˜Kšœ˜Kšœ ˜ —Kšœ˜šΟb œžœž˜Kš žœžœMžœ~žœžœ˜χ—Kšž˜˜Kšœ žœžœ˜Kšœžœžœ Οcœ˜.Kšœ žœžœ œ˜+Kšœ žœžœžœ˜.Kšœ žœžœžœ˜%šœ žœžœ˜Kšœžœ˜Kšœ žœ $˜5Kšœ˜—Kšœžœžœžœ˜/šœžœžœ˜ Kšœ žœ˜Kšœžœ˜Kšœ žœ $˜5K˜—Kšœžœžœ ˜#šœ žœžœ˜Kšœ+žœ˜0Kšœ˜Kšœ˜K˜——K™KšŸ™˜Kš œ žœžœžœžœ ˜=K˜Kšœ žœžœ +˜EKšœžœžœ 4˜UK˜Kšœžœ ˜Kšœ žœžœ˜Kšœ žœ žœžœ ˜*Kšœ žœ ˜Kšœ žœ ˜šœ žœ  ˜(Kšœžœžœžœžœžœžœ ˜\K˜—K˜Kšœ žœ žœžœ  (˜PKšœ˜Kšœ žœ ,˜FK˜šœžœžœ˜ KšœA™A—K˜Kšœžœ˜Kšœžœ  ˜1Kšœ žœ ;˜OKšœ žœ Πcg ‘ "™LK˜šœ˜Kšœ(™(Kšœ(™(—K˜Kšœ žœžœ $˜8Kšœ(žœ˜-K˜šœO˜OKšœc™c—K™Kš œžœžœžœž œžœ˜9Kšœ˜K˜Kšœ ˜4Kšœ˜K˜—šœ˜šΟn œžœ˜Kšœ)žœ ˜JKšœ žœ˜ Kšœ žœ˜Kšœ˜—K˜š ’ œžœžœ žœžœžœ˜@Kšœžœ˜6Kšœ˜——˜Kšœžœžœ˜K˜š ’œžœžœ žœžœ˜6Kšžœžœžœžœ˜&Jšžœžœžœžœ˜)šžœžœ˜Jšžœžœžœžœ˜*Jš žœžœžœžœžœ˜/J˜—šžœžœ˜šžœžœžœžœžœžœžœž˜CKšœžœ ˜,Kšžœžœžœžœ˜2Kšžœ˜—Jšžœžœ˜J˜—Jšžœžœ˜K˜—K™Kšœ ™ K˜KšœE˜EK˜š’œžœ˜ KšœžœA˜Gšžœžœžœ˜9Kšžœžœžœ3˜@KšžœI˜MKšžœž˜ K˜—šžœ=žœž˜LKšœ7˜7Kšžœ3˜:—KšœU˜UKšœ˜—K˜š ’ œžœžœ žœžœžœ˜AKšœHž˜KKšœ˜—K˜š’œžœžœ ˜+šžœCžœž˜Rš œžœžœžœ žœžœ˜5Kšœžœ ˜Kšžœ˜K˜—šœžœ˜Kšžœ˜K˜—šœžœžœ˜Kšžœ˜K˜—šžœ˜ KšœF˜FKšž˜K˜——Kšœ˜—K™K™Kšœ ™ K˜š’ œžœ ˜Kšœ0™0Kšœ@žœ˜Ešžœž˜!KšœF˜F—Kšœ˜—K˜š’ œžœžœ ˜$Kšœ3™3Kš œžœžœžœžœ ˜9šœ˜Kšžœžœžœ˜E—Kšœ3˜3Kšœ˜K˜—š’œžœžœ ˜.Kšœ3™3Kšœ™Kš œžœžœžœžœ ˜9Kšœžœ˜*Kšœ3˜3Kšœ˜K˜—š’ œžœ˜Kšœ™Kšœ˜Kšœ˜K˜—Kšœ(™(šŸ œžœ ˜šžœžœ˜Kšœ<˜<—Kšœ˜—K˜Kšœ(™(šŸœžœ ˜šžœž˜Kšœ7˜7—Kšœ˜—K˜š’œžœžœ ˜.Kšœ™Kšœ&™&Kš œžœžœžœžœžœžœ˜<šœžœ žœ˜#Kšœ˜Kšœ˜Kšœ˜—šœ žœ žœžœ˜.Kšœ$™$—Kšœ˜Kšœ˜Kšœ'˜'Kšœ™Kšœžœ˜Kšœ˜Kšœ˜Kšœ$˜$Kšœ™Kšœ˜Kšœ˜Kšœ˜šžœ žœžœžœžœ"žœ žœž˜XKšœžœ˜,šœžœ˜Kšžœ!žœ"™L—Kšœ žœ˜%Kšœ$˜$Kšœ žœ˜&Kšžœ˜—Kšœ ˜ Kšœ˜—K˜š’œžœžœ ˜.Kšœ9™9šœ žœ žœžœ˜.Kšœ$™$—Kšœ˜šžœžœ˜Kšœ˜Kšœ˜K˜—šžœ˜Kšœ˜šžœ žœžœžœžœ"žœ žœž˜XKšœžœ˜,šœžœ˜KšœL™L—Kšœ)˜)Kšœ+žœ˜0Kšœ=˜=Kšœ+žœ˜1Kšžœ˜—K˜—Kšœ ˜ Kšœ˜—K˜š ’œžœ žœžœžœ˜9šžœžœžœžœžœžœžœž˜IKšœžœ˜)Kš žœžœžœžœžœ˜AKšžœ˜—Kšžœžœ˜Kšœ˜—K˜š’œžœžœ ˜*Kšœ(™(K˜š ’ œžœ žœžœžœ˜5Kšœ1™1šžœžœž˜Kšœžœ!˜;Kšœžœ˜Kšžœ˜—Kšœ˜š žœžœžœžœžœžœž˜:Kšœžœ ˜*Kšœ˜Kšœ ˜ Kšžœ˜—Kšœ˜Kšœ˜—K˜Kšœ"žœ˜7Kšœžœžœ˜Kšœ˜šžœ žœžœžœžœ"žœ žœž˜XKšœžœ˜,Kšœžœ˜šžœ%ž˜-Kšžœ žœž˜2Kšœ˜K˜—Kšžœ˜—šžœžœ˜ Kšœ9˜9Kšœ7˜7K˜—Kšœ ˜ Kšœ˜—K˜š’œžœžœ ˜*Kšœ°™°K˜šΠbn œ&˜3Kšžœžœ˜(Kšœ˜K˜—Kšžœ žœ2˜CKšœ˜šžœ,žœžœžœ˜AKšœh™h—Kšœ˜Kšœ―™―K˜šžœžœ˜Kšœ;žœ˜@K˜—šžœžœž˜šœ!˜!Kšžœžœžœžœ˜#Kšœ%˜%Kšœ˜Kšœ=˜=Kšœ#˜#Kšœ ˜ Kšœ˜—šœžœ˜Kšžœžœ&˜?Kšœ˜Kšœ'˜'K˜Kšœi™išž˜š’œ˜$šžœžœ˜KšœF˜F—K˜—Kšœ/˜/Kšžœ˜—K˜KšœB™BKšœ™šžœžœžœžœžœžœžœž˜CKšœžœ ˜%šœžœ˜Kš @™@—šž˜š’œ˜$šžœžœ˜KšœD˜D—K˜—Kšœ/˜/Kšžœ˜—Kšžœ˜—K˜Kšœ™šž˜š’œ˜$Kšœ1™1Kšœ9™9šžœžœ˜šžœ1žœž˜@Kšœžœ-˜9Kšžœžœ˜—šžœžœ˜š žœžœžœžœ3žœžœž˜_Kšœ2˜2Kšžœ˜—K˜—K˜—K˜—Kšœ/˜/Kšžœ˜—Kšœ˜Kšœ ˜ Kšžœ  ˜ —šžœ ,˜7Kšžœžœ˜6šžœžœžœ˜Kšžœžœžœ˜SKšžœ˜K˜———Kšžœ žœ1˜BKšœ˜—K˜K˜š ’ œžœžœžœžœ˜`Kšœ™Kšœ3™3šžœ+žœž˜:šœžœžœ˜Kšœžœ ˜$šžœžœ˜Kšœ žœ6˜Cšžœžœ˜Kšœ˜šœžœ ž˜%Kšœ˜Kšœ˜Kšœ˜Kšžœ  ˜%Kšœ˜—Kšœ˜—Kšžœ"žœ˜BKšœ˜—šžœ žœ˜Kšœ˜Kšœ˜Kšœ˜—Kšœ˜Kšœ˜—Kšžœžœ˜—Kšœ˜—Kšœ˜KšŸ™K˜Kšœ˜š£œ˜#KšœA™AKšœ!˜!Kšžœžœ+˜GKšœ˜—Kšœ˜š£ œ˜Kšœ˜—K˜š£ œ˜šžœžœžœ˜>Kšœp˜pKšžœžœ˜-Kšœ˜—Kšœ˜—Kšœ˜š’ œžœ˜!Kšžœžœžœžœ˜(šžœžœž˜Kšœžœ!˜;Kšœžœ˜Kšžœ˜—šœ  &˜FKšžœ"  œ˜2Kšžœ"  œ˜1Kšžœ" œ˜:Kšžœ" œ˜;—Kšœ˜K˜—š’ œžœ˜%Kšœžœžœ˜MKšœ˜K˜—š ’œžœžœžœžœ ˜IKšœJ˜JKšœžœ ˜#Kšœ˜Kšœ˜šžœ žœžœžœžœ"žœ žœž˜XKšœžœ˜+Kšžœžœžœ˜K˜Kšœ2žœ žœ ˜PK™Kšœ˜K˜K˜Kšœžœžœ6žœ!˜Œšžœžœžœ ž˜šžœžœžœ ž˜Kšœ2žœ˜7šœ ˜Kšœ˜Kšœ˜Kšœžœ1˜QKšœžœ2˜SKšœ˜—Kšœ=žœ*˜jšœ"˜"Kšœd ˜v—Kšœ 5˜SKšœ ˜6Kšžœ˜—Kšžœ˜—Kšœ˜Kšœ%˜%Kšœžœ˜ Kšœ˜K˜—š’œ˜$Kšœžœžœžœ˜+Kšœ ˜ Kšœ˜K˜—š’ œ˜"Kšœžœ˜,šžœžœž˜Kšœ™šž˜šœ!˜!Kšœ ˜ Kšœ ˜ Kšœ1˜1Kšœ0˜0Kšœ˜——Kšžœ˜—K˜Kšœžœžœ˜'K˜š’ œžœžœžœ˜7Kšœžœ˜"Kšœžœ˜"š žœžœžœžœžœ˜Kšœ<˜K˜—Kšžœ˜ šœ˜K˜——š ’œžœžœ žœžœ˜