LichenOtherTransforms.Mesa
Last tweaked by Mike Spreitzer on February 2, 1988 11:54:15 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]};
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.