LichenOtherTransforms.Mesa
Last tweaked by Mike Spreitzer on February 1, 1988 11:15:41 am PST
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 b Seq (role é sibling: instance of array* of type of newType's roleth child)--]
RETURNS [newType: CellType,
pairs: BiRels.ConstOneToOne--domain of mapper é instance of array* of newType--,
gcs: Seq--role é instance in newType--] ~ {
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] ~ {
l <dom, seq> {ti ← Instantiate[newType, seq[0].parent]; pairs ← pairs + <dom, ti>}
seq: Seq--role é sibling: instance of array* of type of newType's roleth child-- ~ BiRels.DeRef[right];
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 b Seq (role é sibling: instance of array* of cellTypes[role])--] ~ {
roles: NATURAL ~ cellTypes.Size[].EN;
ctSeq: Seq--role é CellType-- ~ BiRels.EnumSeqOfSet[cellTypes];
grouperV: BiRels.OneToOne ~ BiRels.CreateHashOTO[];
PerCellType: PROC [ra: Sets.Value] ~ {
ct: CellType ~ NARROW[ra.VA];
IF ct.asUnorganized#NIL THEN {
sibs: Seq--role é sibling: instance of array* of cellTypes[role]-- ~ CreateSeq[len: roles, oneToOne: TRUE];
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]};
NameChange: TYPE ~ RECORD [old, new: REF ANY];
NCList: TYPE ~ LIST OF NameChange;
RenameSteps: PUBLIC PROC [design: Design, classFilter: EntityClassFilter, map: RopeMap] RETURNS [nChanged: ARRAY EntityClass OF CARDALL[0]] ~ {
FixPort: PROC [port: Port] ~ {
names: Set--of SteppyName-- ~ port.PortNames[];
changes: NCList ~ FindChanges[names, map];
IF changes#NIL THEN nChanged[Port] ← nChanged[Port]+1;
FOR cl: NCList ← changes, cl.rest WHILE cl#NIL DO
IF NOT ForgetPortName[port, NARROW[cl.first.old]] THEN ERROR;
[] ← KnowPortName[port, NARROW[cl.first.new]];
design ← design; ENDLOOP;
RETURN};
FixVertex: PROC [v: Vertex, class: EntityClass] ~ {
changes: NCList ~ FindChanges[v.VertexNames[], map];
IF changes#NIL THEN nChanged[class] ← nChanged[class]+1;
FOR cl: NCList ← changes, cl.rest WHILE cl#NIL DO
ForgetVertexName[v, NARROW[cl.first.old]];
KnowVertexName[v, NARROW[cl.first.new]];
design ← design; ENDLOOP;
RETURN};
FixWire: PROC [wire: Wire] RETURNS [doKids, moreSibs: BOOLTRUE] ~ {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: NCList ← 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: NCList ← 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: NCList ← NIL] ~ {
FindChange: PROC [ra: REF ANY] ~ {
old: SteppyName ~ NARROW[ra];
copied: BOOLFALSE;
cur: SteppyName ← old;
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: SteppyName ~ CopyTil[[old, cur]].Cat[moded].head;
cur ← moded.head;
changes ← CONS[[old, new], changes];
copied ← TRUE}}};
ENDCASE => ERROR;
cur ← cur.rest;
ENDLOOP;
RETURN};
names.EnumA[FindChange];
RETURN};
END.