<> <> DIRECTORY AbSets, Asserting, BiRelBasics, BiRels, IntStuff, IO, LichenDataOps, LichenDataStructure, LichenTransforms, LichenTransformsPrivate, TextReplace; LichenOtherTransforms: CEDAR PROGRAM IMPORTS AbSets, Asserting, BiRelBasics, BiRels, IntStuff, IO, LichenDataOps, LichenDataStructure, LichenTransforms, TextReplace EXPORTS LichenTransforms = BEGIN OPEN LichenDataStructure, LichenTransforms, LichenDataOps, LichenTransformsPrivate, Sets:AbSets; CellTypeList: TYPE ~ LIST OF CellType; GroupUnorganized: PUBLIC PROC [ design: Design, mapper: ConstFunction--any RETURNS [newType: CellType, pairs: BiRels.ConstOneToOne--domain of mapper gcs: Seq--role ComputeName: PROC [] RETURNS [r: ROPE] ~ { pair: BiRels.Pair ~ mapper.First[].P; r _ IO.PutFR["#gen%g", [integer[nGen _ nGen+1]]]; RETURN}; newTypeName: ROPE ~ ComputeName[]; pairsV: BiRels.OneToOne ~ BiRels.CreateHashOTO[]; Seed: PROC [left, right: REF ANY] ~ { <<>> seq: Seq--role ci0: CellInstance ~ NARROW[seq.ApplyI[0].MA]; ti: CellInstance ~ FullyInstantiate[newType, ci0.containingCT]; pairsV.AddNewAA[left, ti]; RETURN}; newType _ CreateCellType[design, newTypeName, NIL, TRUE, TRUE, NIL, NIL]; mapper.EnumAA[Seed]; pairs _ pairsV.Freeze; gcs _ LowerChildren[design, newType, pairs.Invert.Compose[mapper].AsConst]; RETURN}; nGen: NATURAL _ 0; SimpleGrouper: PROC [design: Design, cellTypes: Set--of CellType--] RETURNS [grouper: ConstFunction--any instance of array* of cellTypes[role])--] ~ { roles: NATURAL ~ cellTypes.Size[].EN; ctSeq: Seq--role grouperV: BiRels.OneToOne ~ BiRels.CreateHashOTO[]; PerCellType: PROC [ra: Sets.Value] ~ { ct: CellType ~ NARROW[ra.VA]; IF ct.asUnorganized#NIL THEN { sibs: Seq--role PerInstance: PROC [ra: Sets.Value] ~ { ci: CellInstance ~ NARROW[ra.VA]; cit: CellType _ ci.type; DO mr: Sets.MaybeValue ~ ctSeq.ApplyA[cit, rightToLeft]; IF mr.found THEN { role: NAT ~ mr.it.VI; sibs.AddNewIA[role, ci]; RETURN}; IF cit.asArray=NIL THEN EXIT; cit _ cit.asArray.eltType; ENDLOOP; RETURN}; ct.asUnorganized.containedInstances.Enumerate[PerInstance]; SELECT sibs.Size[].EN FROM 0 => NULL; roles => grouperV.AddNewAA[ct, sibs.Freeze.Refify]; ENDCASE => ERROR; }; RETURN}; design.cellTypes.Enumerate[PerCellType]; grouper _ grouperV.Freeze; RETURN}; CellTypeListLength: PROC [cellTypes: CellTypeList] RETURNS [length: NATURAL] ~ { length _ 0; FOR cellTypes _ cellTypes, cellTypes.rest WHILE cellTypes # NIL DO length _ length + 1 ENDLOOP; RETURN}; BaseStar: PROC [ct: CellType] RETURNS [CellType] ~ { WHILE ct.asArray#NIL DO ct _ ct.asArray.eltType ENDLOOP; RETURN [ct]}; SteppyNameChange: TYPE ~ RECORD [old, new: SteppyName]; SNCList: TYPE ~ LIST OF SteppyNameChange; RopeChange: TYPE ~ RECORD [old, new: ROPE]; RCList: TYPE ~ LIST OF RopeChange; RenameSteps: PUBLIC PROC [design: Design, classFilter: EntityClassFilter, map: RopeMap] RETURNS [nChanged: ARRAY EntityClass OF CARD _ ALL[0]] ~ { FixPort: PROC [port: Port] ~ { names: Set--of SteppyName-- ~ port.PortNames[]; changes: SNCList ~ FindChanges[names, map]; IF changes#NIL THEN nChanged[Port] _ nChanged[Port]+1; FOR cl: SNCList _ changes, cl.rest WHILE cl#NIL DO IF NOT ForgetPortName[port, cl.first.old] THEN ERROR; [] _ KnowPortName[port, cl.first.new]; design _ design; ENDLOOP; RETURN}; FixVertex: PROC [v: Vertex, class: EntityClass] ~ { changes: SNCList ~ FindChanges[v.VertexNames[], map]; IF changes#NIL THEN nChanged[class] _ nChanged[class]+1; FOR cl: SNCList _ changes, cl.rest WHILE cl#NIL DO ForgetVertexName[v, cl.first.old]; KnowVertexName[v, cl.first.new]; design _ design; ENDLOOP; RETURN}; FixWire: PROC [wire: Wire] RETURNS [doKids, moreSibs: BOOL _ TRUE] ~ {FixVertex[wire, Wire]}; FixInstance: PROC [ra: REF ANY] ~ {FixVertex[NARROW[ra], CellInstance]}; PerCellType: PROC [ra: REF ANY] ~ { ct: CellType ~ NARROW[ra]; IF classFilter[CellType] THEN { changes: RCList _ NIL; CheckName: PROC [assertion: Assertion] ~ { old: ROPE ~ NARROW[Asserting.TermOf[assertion]]; new: ROPE ~ map.Apply[old]; IF new#old THEN changes _ CONS[[old, new], changes]; RETURN}; Asserting.EnumerateAssertionsAbout[nameReln, ct.otherPublic, CheckName]; IF changes#NIL THEN nChanged[CellType] _ nChanged[CellType]+1; FOR cl: RCList _ changes, cl.rest WHILE cl#NIL DO ct.otherPublic _ Asserting.Remove1[nameReln, cl.first.old, ct.otherPublic, TRUE]; ct.otherPublic _ Asserting.Assert1[nameReln, cl.first.new, ct.otherPublic]; ENDLOOP; }; IF classFilter[Port] THEN ct.EnumeratePorts[FixPort]; IF ct.asUnorganized#NIL THEN { IF classFilter[Wire] THEN [] _ ct.asUnorganized.internalWire.EnumerateWire[FixWire]; IF classFilter[Wire] THEN ct.asUnorganized.containedInstances.EnumA[FixInstance]; }; RETURN}; design.cellTypes.EnumA[PerCellType]; RETURN}; FindChanges: PROC [names: Set--of SteppyName--, map: RopeMap] RETURNS [changes: SNCList _ NIL] ~ { FindChange: PROC [val: Sets.Value] ~ { oldName: SteppyName ~ VSn[val]; oldSteps: NameStepList ~ oldName.steps; cur: NameStepList _ oldSteps; copied: BOOL _ FALSE; WHILE cur#NIL DO WITH cur.first SELECT FROM x: REF INT => NULL; x: ROPE => {y: ROPE ~ map.Apply[x]; IF x#y THEN { IF copied THEN cur.first _ y ELSE { moded: TList ~ CopyTil[[cur.rest]].Prepend[y]; new: NameStepList ~ CopyTil[[oldSteps, cur]].Cat[moded].head; cur _ moded.head; changes _ CONS[[oldName, LSn[new]], changes]; copied _ TRUE}}}; ENDCASE => ERROR; cur _ cur.rest; ENDLOOP; RETURN}; names.Enumerate[FindChange]; RETURN}; END.