LichenFromExtImpl2.Mesa
Last tweaked by Mike Spreitzer on May 6, 1988 10:18:14 am PDT
DIRECTORY AbSets, BasicTime, BiRels, Histograms, IntStuff, IO, LichenDataOps, LichenDataStructure, LichenFromExtPrivate, LichenIntBasics, RefText, Rope, SetBasics;
LichenFromExtImpl2: CEDAR MONITOR
LOCKS dr USING dr: DesignReading
IMPORTS AbSets, BasicTime, BiRels, Histograms, IntStuff, IO, LichenDataOps, LichenDataStructure, LichenFromExtPrivate, LichenIntBasics, RefText, Rope, SetBasics
EXPORTS LichenFromExtPrivate
=
BEGIN OPEN IB:LichenIntBasics, IB, LichenDataStructure, LichenDataOps, LichenFromExtPrivate, Sets:AbSets;
PrintImpossibles: PROC [to: IO.STREAM, dr: DesignReading] = {
FOR ims: ImpossibleMergeList ← dr.impossibleMerges, ims.rest WHILE ims # NIL DO
im: ImpossibleMerge = ims.first;
to.PutF["%g: %g & %g\n", [rope[Describe[dr.d, im.arrayInstance]]], [rope[FmtPath[im.path1]]], [rope[FmtPath[im.path2]]]];
ENDLOOP;
};
FinishWaitingMerges: PUBLIC PROC [cr: CellReading] = {
DO
progress: BOOLFALSE;
wml: PathPairList ← cr.waitingMerges;
cr.waitingMerges ← NIL;
FOR wml ← wml, wml.rest WHILE wml # NIL DO
progress ← MergeWork[cr, wml.first.p1, wml.first.p2] OR progress;
ENDLOOP;
IF NOT progress THEN EXIT;
ENDLOOP;
IF cr.waitingMerges # NIL THEN ERROR;
};
GetSteppyName: PROC [s: Source] RETURNS [name: SteppyName] ~ {
raw: ROPE ~ GetName[s];
name ← ParseSteppyName[raw];
RETURN};
GetName: PROC [s: Source] RETURNS [name: ROPE] = {
from: IO.STREAM = s.stream;
[] ← from.SkipWhitespace[];
SELECT from.PeekChar[] FROM
'" => name ← from.GetRopeLiteral[];
ENDCASE => name ← from.GetTokenRope[TokenBreak].token;
};
TokenBreak: PUBLIC PROC [char: CHAR] RETURNS [cc: IO.CharClass] =
{cc ← SELECT char FROM
'\n => break,
IN [0C .. ' ] => sepr,
ENDCASE => other};
EndLine: PROC [from: IO.STREAM, buffer: REFTEXT] = {
IF NOT from.EndOf[] THEN [] ← from.GetLine[buffer];
};
ReadTech: PROC [s: Source, reader: Reader, cr: CellReading] = {
ct: CellType = cr.ct;
from: IO.STREAM = s.stream;
techname: ROPE ← GetName[s];
EndLine[from, cr.dr.buffer];
RETURN};
ReadTimestamp: PROC [s: Source, reader: Reader, cr: CellReading] = {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
unixTime: INT ~ from.GetInt[];
time: BasicTime.GMT ~ BasicTime.Update[unixOrigin, unixTime];
EndLine[from, cr.dr.buffer];
RETURN};
unixOrigin: BasicTime.GMT ← BasicTime.Pack[[
year: 1970,
month: January,
day: 1,
hour: 0,
minute: 0,
second: 0,
zone: 0--GMT, I hope--,
dst: no]];
ReadVersion: PROC [s: Source, reader: Reader, cr: CellReading] ~ {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
version: ROPE ~ GetName[s];
deriver: ROPE ~ "UCB's Magic .extractor";
EndLine[from, cr.dr.buffer];
RETURN};
ReadScale: PROC [s: Source, reader: Reader, cr: CellReading] ~ {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
rscale: INT ~ from.GetInt[];
cscale: INT ~ from.GetInt[];
lscale: INT ~ from.GetInt[];
meters: ROPE ~ "meters";
IF cr.scalingDefined THEN Warn[s, "More than one scale statment"];
cr.scalingDefined ← TRUE;
cr.rScale ← rscale * cr.rScale;
cr.cScale ← cscale * cr.cScale;
cr.lUnits ← lscale * cr.lUnits;
EndLine[from, cr.dr.buffer];
RETURN};
ReadResistClasses: PROC [s: Source, reader: Reader, cr: CellReading] ~ {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
n: INT ← 0;
IF cr.resistClasses # undefinedINT THEN Warn[s, "More than one resistclasses statment"];
DO
token: ROPE = from.GetTokenRope[TokenBreak].token;
IF token.Equal["\n"] THEN EXIT;
n ← n + 1;
ENDLOOP;
cr.resistClasses ← n;
RETURN};
keepCruft: BOOLFALSE;
ReadNode: PROC [s: Source, reader: Reader, cr: CellReading] ~ {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
fullName: SteppyName ~ GetSteppyName[s];
R: INT ~ from.GetInt[];
C: INT ~ from.GetInt[];
x: INT ~ from.GetInt[];
y: INT ~ from.GetInt[];
ok: BOOL ~ SkipNTokens[from, cr.resistClasses*2, cr.dr.buffer];
attrs: LORA ~ ReadAttrs[s];
nv: Wire ← FetchWire[ct, fullName];
IF fullName.steps.rest#NIL THEN ERROR;
IF nv = NIL THEN nv ← CreateWire[ct, OneSteppy[fullName], TRUE, TRUE ];
EndLine[from, cr.dr.buffer];
RETURN};
ReadAttrs: PROC [s: Source, zeroNIL: BOOLFALSE] RETURNS [allTogetherNow: LORANIL] = {
from: IO.STREAM = s.stream;
toke: ROPENIL;
IF zeroNIL THEN {
[] ← from.SkipWhitespace[];
IF from.PeekChar[] = '0 THEN {
IF from.GetChar[] # '0 THEN ERROR;
RETURN};
};
{DO
attr: ROPENIL;
toke ← from.GetTokenRope[AttrBreak !IO.EndOfStream => EXIT].token;
IF toke.Equal[","] THEN {Warn[s, "Extra comma"]; LOOP};
IF NOT toke.Equal["\""] THEN GOTO Return;
from.Backup['"];
attr ← from.GetRopeLiteral[ !IO.Error, IO.EndOfStream => {Warn[s, "not a rope literal"]; CONTINUE}];
IF attr # NIL THEN allTogetherNow ← CONS[attr, allTogetherNow];
toke ← from.GetTokenRope[AttrBreak !IO.EndOfStream => EXIT].token;
IF NOT toke.Equal[","] THEN GOTO Return;
ENDLOOP;
EXITS
Return => {
FOR i: INT DECREASING IN [0 .. toke.Length[]) DO
s.stream.Backup[toke.Fetch[i]];
ENDLOOP;
};
}};
AttrBreak: PROC [char: CHAR] RETURNS [cc: IO.CharClass] =
{cc ← SELECT char FROM ',, '\n, '" => break, ENDCASE => sepr};
ReadEquiv: PROC [s: Source, reader: Reader, cr: CellReading] ~ {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
name1: SteppyName ~ GetSteppyName[s];
name2: SteppyName ~ GetSteppyName[s];
v1: Wire ~ FetchWire[ct, name1];
v2: Wire ~ FetchWire[ct, name2];
IF name1.steps.rest#NIL OR name2.steps.rest#NIL THEN ERROR;
SELECT TRUE FROM
v1=v2 => IF v1=NIL THEN ERROR;
v1=NIL => KnowVertexName[cr.dr.d, v2, name1];
v2=NIL => KnowVertexName[cr.dr.d, v1, name2];
ENDCASE => ERROR;
EndLine[from, cr.dr.buffer];
RETURN};
ReadFet: PROC [s: Source, reader: Reader, cr: CellReading] ~ {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
type: ROPE ~ GetName[s];
xl: INT ~ from.GetInt[];
yl: INT ~ from.GetInt[];
xh: INT ~ from.GetInt[];
yh: INT ~ from.GetInt[];
area: INT ~ from.GetInt[];
perim: INT ~ from.GetInt[];
sub: SteppyName ~ GetSteppyName[s];
GATE: FetTerminal ~ GetFetTerminal[s];
T1: FetTerminal ~ GetFetTerminal[s];
T2: FetTerminal ~ GetFetTerminal[s];
sct: CellType;
tv: CellInstance;
DoTerm: PROC [portName: ROPE, ft: FetTerminal] ~ {
w: Wire ~ GetNet[s, cr.dr, ct, ft.name];
p: Port ~ FetchPort[sct, LSn[LIST[portName]]];
Connect[cr.dr.d, w, p, tv];
RETURN};
sct ← GetFetType[cr.dr, type, [xl, yl, xh, yh], area, perim, T1.length+T2.length];
tv ← Instantiate[sct, ct, FALSE, OneLSn[IO.PutFR["Q%g#", IO.int[cr.fetCount ← cr.fetCount + 1]]]];
DoTerm["gate", GATE];
DoTerm["ch1", T1];
DoTerm["ch2", T2];
EndLine[from, cr.dr.buffer];
RETURN};
GetFetTerminal: PROC [s: Source] RETURNS [ft: FetTerminal] ~ {
from: IO.STREAM ~ s.stream;
ft.name ← GetSteppyName[s];
ft.length ← from.GetInt[];
{attrs: LORA ← ReadAttrs[s, TRUE];
RETURN}};
GetFetType: PROC [dr: DesignReading, className: ROPE, innerGate: IntBox, area, perim, sumChannelLengths: INT] RETURNS [ct: CellType] ~ {
d: Design ~ dr.d;
ft: FetType ~ NEW [FetTypeRep ← [className, area, perim, sumChannelLengths]];
rft: FetType;
rft ← NARROW[dr.fetTypes.ApplyA[ft].MDA];
IF rft = NIL THEN {
cellTypeName: ROPE ~ IO.PutFR["%g[%g,%g,%g]", IO.rope[ft.className], IO.int[ft.area], IO.int[ft.perim], IO.int[ft.twiceLength]];
rft ← ft;
ft.ct ← CreateCellType[d, leaf, OneRope[cellTypeName]];
ft.ct.asTrans ← NEW [TransistorPrivate ← [
type: className,
area: area,
perimeter: perim]];
[] ← CreatePort[ft.ct, OneLSn[R["gate"]], TRUE, TRUE, TRUE, TRUE, TRUE];
[] ← CreatePort[ft.ct, OneLSn[R["ch1"]], TRUE, TRUE, TRUE, TRUE, TRUE];
[] ← CreatePort[ft.ct, OneLSn[R["ch2"]], TRUE, TRUE, TRUE, TRUE, TRUE];
dr.fetTypes.AddNewAA[ft, rft];
};
ct ← rft.ct;
RETURN};
ReadUse: PROC [s: Source, reader: Reader, cr: CellReading] ~ {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
typeName: ROPE ~ GetName[s];
useId: ROPE ~ GetName[s];
ok: BOOL ~ SkipNTokens[from, 6, cr.dr.buffer];
u: Use ~ ParseUseDef[useId];
type: CellType ~ EnsureType[cr, typeName, u.as, ct, u.childName];
ci: CellInstance ~ Instantiate[type, ct, TRUE, OneLSn[u.childName]];
EndLine[from, cr.dr.buffer]};
ParseUseDef: PROC [useId: ROPE] RETURNS [u: Use] ~ {
in: IO.STREAM ~ IO.RIS[useId];
u.childName ← in.GetTokenRope[UseNameBreak].token;
IF in.EndOf[] THEN {
in.Close[];
RETURN [[u.childName, [scalar[]]]]
}
ELSE {
as: ArraySpec.array ← [array[range: ALL[[0, 0]], sep: [0, 0]]];
Get: PROC [d: Dim2] ~ {
IF in.GetChar[] # '[ THEN ERROR;
as.range[d].min ← in.GetInt[];
IF in.GetChar[] # ': THEN ERROR;
as.range[d].maxPlusOne ← in.GetInt[]+1;
IF in.GetChar[] # ': THEN ERROR;
as.sep[d] ← in.GetInt[];
IF in.GetChar[] # '] THEN ERROR;
};
Get[X];
Get[Y];
IF NOT in.EndOf[] THEN ERROR;
in.Close[];
RETURN [[u.childName, as]];
};
};
UseNameBreak: PROC [char: CHAR] RETURNS [cc: IO.CharClass] --IO.BreakProc-- = {
cc ← SELECT char FROM
'[, '], ': => break,
ENDCASE => other;
};
EnsureType: PROC [cr: CellReading, typeName: ROPE, as: ArraySpec, parent: CellType, childName: ROPE] RETURNS [ct: CellType] ~ {
dr: DesignReading ~ cr.dr;
d: Design ~ dr.d;
WITH as SELECT FROM
x: ArraySpec.scalar => {
ct ← NARROW[d.ctName.ApplyA[typeName, rightToLeft].MDA];
IF ct=NIL THEN ct ← ReadCellType[d, typeName, dr];
};
x: ArraySpec.array => {
ec: ROPE ~ typeName.Cat[FmtAS[as]];
cellTypeName: ROPE ~ IO.PutFR["%g(%g.%g)", IO.rope[ec], IO.rope[NARROW[d.ctName.ApplyA[parent].MA]], IO.rope[childName]];
eltType: CellType ~ EnsureType[cr, typeName, [scalar[]], NIL, NIL];
size: Int2 ~ RangeShape[x.range];
ct ← CreateArray[d, eltType, size, [1, 1], OneRope[cellTypeName]];
cr.dr.arraySpecs.AddNewAA[ct, NEW [ArraySpec.array ← x]];
IF NOT cr.newArrays.AddA[ct] THEN ERROR;
};
ENDCASE => ERROR;
};
NameElt: PROC [i: INT] RETURNS [eltName: NameStep] ~
{eltName ← NewInt[i]};
FmtAS: PROC [as: ArraySpec] RETURNS [r: ROPE] = {
r ← WITH as SELECT FROM
scalar => "scalar",
array => IO.PutFLR["[%g:%g:%g][%g:%g:%g]", LIST[
IO.int[range[X].min],
IO.int[range[X].maxPlusOne-1],
IO.int[sep[X]],
IO.int[range[Y].min],
IO.int[range[Y].maxPlusOne-1],
IO.int[sep[Y]]]],
ENDCASE => ERROR;
};
FmtShape: PROC [shape: Int2] RETURNS [r: ROPE] = {
r ← IO.PutFR["[X: %g, Y: %g]", IO.int[shape[X]], IO.int[shape[Y]]];
RETURN};
FmtPath: PROC [path: Path] RETURNS [r: ROPE] = {
r ← NIL;
FOR path ← path, path.rest WHILE path # NIL DO
step: ROPEWITH path.first SELECT FROM
x: ROPE => x,
x: REF Range2 => IO.PutFR["[%g:%g,%g:%g]", [integer[x[X].min]], [integer[x[X].maxPlusOne-1]], [integer[x[Y].min]], [integer[x[Y].maxPlusOne-1]]],
ENDCASE => ERROR;
r ← (IF r # NIL THEN r.Concat["/"] ELSE r).Concat[step];
ENDLOOP;
RETURN};
ReadMerge: PROC [s: Source, reader: Reader, cr: CellReading] ~ {
ct: CellType ~ cr.ct;
from: IO.STREAM ~ s.stream;
IF cr.firstMerge THEN {cr.firstMerge ← FALSE; TryArrayFile[cr]};
{name1: ROPE ~ GetName[s];
name2: ROPE ~ GetName[s];
path1: Path ~ ParsePath[s, cr.dr, ct, name1];
path2: Path ~ ParsePath[s, cr.dr, ct, name2];
IF ComparePaths[path1, cr.dr.mostRecentPathToMerge]#equal THEN {
DoMerges[s, cr];
AddMerge[cr.dr, path1];
};
AddMerge[cr.dr, path2];
cr.dr.mostRecentPathToMerge ← path2;
EndLine[from, cr.dr.buffer];
RETURN}};
AddMerge: PROC [dr: DesignReading, path: Path] ~ {
arrayPrefix: Path ~ IF path#NIL AND path.rest#NIL AND path.rest.rest#NIL
THEN WITH path.first SELECT FROM
x: ROPE => WITH path.rest.first SELECT FROM
r: REF Range2 => LIST[x, r],
ENDCASE => NIL,
ENDCASE => NIL
ELSE NIL;
rs: REF Set--of Path--NARROW[dr.toMerge.ApplyA[arrayPrefix].MDA];
IF rs=NIL THEN dr.toMerge.AddNewAA[arrayPrefix, rs ← Sets.CreateHashSet[].Refify];
IF NOT rs^.AddA[path] THEN ERROR;
RETURN};
nsh: Histograms.Histogram ~ Histograms.Create1D[];
DoMerges: PUBLIC PROC [s: Source, cr: CellReading] = {
from: CellType = cr.ct;
dr: DesignReading = cr.dr;
nSets: INT ~ dr.toMerge.Size[].EN;
i: INT ← 0;
lastPath: Path ← NIL;
firstSet: REF Set--of Path--NIL;
DoAMerge: PROC [ra: Sets.Value] ~ {
path: Path ~ NARROW[ra.VA];
IF lastPath # NIL THEN [] ← MergeWork[cr, lastPath, path];
IF nSets=1 THEN lastPath ← path;
RETURN};
DoASet: PROC [pair: BiRels.Pair] ~ {
rs: REF Set--of Path-- ~ NARROW[pair[right].VA];
IF i=0 THEN firstSet ← rs;
IF nSets=1 AND pair[left].VA#NIL THEN ERROR;
IF nSets=1 OR i>0 THEN rs^.Enumerate[DoAMerge];
lastPath ← NARROW[rs^.First[].MA];
IF i=1 THEN firstSet^.Enumerate[DoAMerge];
i ← i + 1;
RETURN};
nsh.Increment[nSets];
dr.toMerge.Enumerate[DoASet];
IF i # nSets THEN ERROR;
dr.toMerge.Erase[];
IF NOT dr.toMerge.Empty[] THEN ERROR;
dr.mostRecentPathToMerge ← NIL};
MergeWork: PROC [cr: CellReading, path1, path2: Path] RETURNS [success: BOOL] = {
ct: CellType = cr.ct;
IF ct.asArray # NIL THEN ERROR;
IF path1.rest # NIL AND path2.rest # NIL THEN WITH path1.first SELECT FROM
x: ROPE => WITH path2.first SELECT FROM
y: ROPE => IF x.Equal[y] THEN {
ci: CellInstance = FetchSubcell[ct, OSn[x]];
it: CellType ~ cr.dr.d.CiT[ci];
IF it.asArray # NIL THEN {
CheckArrayUsage[cr.dr.d, it];
success ← ArrayMerge[cr, ci, x, path1.rest, path2.rest, cr.dr.curArray];
IF cr.dr.curArray AND NOT success THEN cr.waitingMerges ← CONS[NEW [PathPairPrivate ← [path1, path2]], cr.waitingMerges];
IF cr.dr.curArray OR success THEN RETURN;
};
};
y: REF Range2 => ERROR;
ENDCASE => ERROR;
x: REF Range2 => ERROR;
ENDCASE => ERROR;
MergeFinal[cr.dr, ct, path1, path2];
success ← TRUE;
};
ArrayMerge: PROC [cr: CellReading, arrayInstance: CellInstance, instanceName: ROPE, path1, path2: Path, may: BOOL] RETURNS [merged: BOOL] = {
dr: DesignReading ~ cr.dr;
d: Design ~ dr.d;
act: CellType = d.CiT[arrayInstance];
a: Array = act.asArray;
et: CellType = act.EltType[];
rr1: REF Range2 = NARROW[path1.first];
rr2: REF Range2 = NARROW[path2.first];
r1: Range2 = rr1^;
r2: Range2 = rr2^;
size: Int2 = RangeShape[r2];
mai1: Int2 = Range2Min[r1];
mai2: Int2 = Range2Min[r2];
D: Int2 = IB.Sub[mai2, mai1];
p1: Port = PortGet[dr, et, path1.rest, may];
p2: Port = PortGet[dr, et, path2.rest, may];
IF RangeShape[r1] # size THEN ERROR;
IF p1=NIL OR p2=NIL THEN {IF may THEN ERROR ELSE RETURN [FALSE]};
IF may THEN {
IF ABS[D[X]]>1 OR ABS[D[Y]]>1 THEN ERROR;
MakeArrayNewConnection[act, r1, D, p1, p2];
RETURN [TRUE]}
ELSE {
IF size # [1, 1] THEN ERROR;
merged ← ArrayEltPortsConnected[act, mai1, mai2, p1, p2];
RETURN};
};
MergeFinal: PROC [dr: DesignReading, ct: CellType, path1, path2: Path] = {
w1, w2, nw: Wire;
w1 ← PathGet[dr, ct, path1, TRUE];
w2 ← PathGet[dr, ct, path2, TRUE];
IF w1#w2 THEN nw ← MergeNets[dr.d, w1, w2].merged;
RETURN};
ParsePath: PROC [s: Source, dr: DesignReading, from: CellType, asRope: ROPE] RETURNS [Path] = {
in: IO.STREAM = IO.RIS[asRope];
path: TList ← [];
GetRange: PROC RETURNS [x: Range] = {
x.maxPlusOne ← (x.min ← in.GetInt[]) + 1;
SELECT in.PeekChar[] FROM
': => {
IF in.GetChar[] # ': THEN ERROR;
x.maxPlusOne ← in.GetInt[] + 1;
};
',, '] => NULL;
ENDCASE => ERROR;
};
WHILE NOT in.EndOf[] DO
toke: ROPE ← in.GetTokenRope[PathNameBreak].token;
ras: REF ArraySpec.array = NARROW[dr.arraySpecs.ApplyA[from].MDA];
SELECT TRUE FROM
toke.Equal["/"] => LOOP;
toke.Equal["["] => {
food: BOOL = ras.range[X].min # ras.range[X].maxPlusOne-1;
bard: BOOL = ras.range[Y].min # ras.range[Y].maxPlusOne-1;
r2: Range2 ← ras.range;
twoD: BOOLFALSE;
IF NOT (food OR bard) THEN ERROR;
IF bard THEN r2[Y] ← GetRange[] ELSE r2[X] ← GetRange[];
toke ← in.GetTokenRope[PathNameBreak].token;
SELECT TRUE FROM
toke.Equal["]"] => NULL;
toke.Equal[","] => {
twoD ← TRUE;
r2[X] ← GetRange[];
toke ← in.GetTokenRope[PathNameBreak].token;
IF NOT toke.Equal["]"] THEN ERROR;
};
ENDCASE => ERROR;
IF twoD # (food AND bard) THEN ERROR;
path ← path.Append[NEW [Range2 ← r2]];
from ← from.EltType[];
};
toke.Equal["]"] => ERROR;
toke.Equal[":"] => ERROR;
toke.Equal[","] => ERROR;
ENDCASE => {
path ← path.Append[toke];
IF in.EndOf[]
THEN {IF from.FetchWire[OSn[toke]]=NIL THEN ERROR; from ← NIL}
ELSE {from ← dr.d.CiT[from.FetchSubcell[OSn[toke]]]};
};
ENDLOOP;
in.Close[];
RETURN [path.head]};
PathNameBreak: PROC [char: CHAR] RETURNS [cc: IO.CharClass] --IO.BreakProc-- = {
cc ← SELECT char FROM
'[, '], ':, '/, ', => break,
ENDCASE => other;
};
PathGet: PROC [dr: DesignReading, from: CellType, path: Path, mayAdd: BOOL] RETURNS [w: Wire] = {
d: Design ~ dr.d;
WITH path.first SELECT FROM
r: ROPE => IF path.rest=NIL
THEN w ← from.FetchWire[OSn[r]]
ELSE {
ci: CellInstance ~ from.FetchSubcell[OSn[r]];
childPort: Port ~ PortGet[dr, d.CiT[ci], path.rest, mayAdd];
IF childPort # NIL THEN {
w ← ConndWire[ci, childPort];
IF w=NIL THEN ERROR;
};
};
x: REF Range2 => ERROR;
ENDCASE => ERROR;
};
PortGet: PROC [dr: DesignReading, from: CellType, path: Path, mayAdd: BOOL] RETURNS [port: Port] = {
d: Design ~ dr.d;
WITH path.first SELECT FROM
x: REF Range2 => {
ras: REF ArraySpec.array = NARROW[dr.arraySpecs.ApplyA[from].MDA];
a: Array = from.asArray;
eltPort: Port = PortGet[dr, from.EltType[], path.rest, mayAdd];
IF eltPort=NIL THEN port ← NIL ELSE {
index: Int2 = IB.Sub[Range2Min[x^], Range2Min[ras.range]];
IF NOT Range2IsSingleton[x^] THEN ERROR;
port ← GetArrayPortForPort[from, index, eltPort, mayAdd];
};
};
x: ROPE => IF path.rest=NIL
THEN {
w: Wire ~ from.FetchWire[OSn[x]];
port ← PortForWire[from, w, mayAdd]}
ELSE {
ci: CellInstance ~ from.FetchSubcell[OSn[x]];
childPort: Port ~ PortGet[dr, d.CiT[ci], path.rest, mayAdd];
IF childPort = NIL THEN port ← NIL ELSE {
w: Wire ~ ConndWire[ci, childPort];
IF w=NIL THEN ERROR;
port ← PortForWire[from, w, mayAdd];
};
};
ENDCASE => ERROR;
port ← port;
};
GetNet: PROC [s: Source, dr: DesignReading, from: CellType, name: SteppyName] RETURNS [w: Wire] = {
path: Path ~ Pathify[s, dr, from, name.steps];
w ← PathGet[dr, from, path, TRUE];
};
Pathify: PROC [s: Source, dr: DesignReading, from: CellType, steps: NameStepList] RETURNS [Path] ~ {
d: Design ~ dr.d;
path: TList ← [];
WHILE steps#NIL DO
ras: REF ArraySpec.array = NARROW[dr.arraySpecs.ApplyA[from].MDA];
WITH steps.first SELECT FROM
x: REF INT => {
food: BOOL ~ ras.range[X].min # ras.range[X].maxPlusOne-1;
bard: BOOL ~ ras.range[Y].min # ras.range[Y].maxPlusOne-1;
r2: Range2 ← ras.range;
IF food=bard THEN ERROR;
r2[IF food THEN X ELSE Y] ← [min: x^, maxPlusOne: x^+1];
path ← path.Append[NEW [Range2 ← r2]];
from ← from.EltType[];
steps ← steps.rest};
x: ROPE => {
path ← path.Append[x];
IF steps.rest=NIL
THEN {IF from.FetchWire[OSn[x]]=NIL THEN ERROR; from ← NIL}
ELSE from ← d.CiT[from.FetchSubcell[OSn[x]]];
steps ← steps.rest};
ENDCASE => ERROR;
ENDLOOP;
RETURN [path.head]};
ReadCap: PROC [s: Source, reader: Reader, cr: CellReading] = {
ct: CellType = cr.ct;
from: IO.STREAM = s.stream;
EndLine[from, cr.dr.buffer];
};
SkipNTokens: PROC [from: IO.STREAM, n: INT, buffer: REFTEXT] RETURNS [ok: BOOL] = {
WHILE n > 0 DO
token: REFTEXT = from.GetToken[TokenBreak, buffer].token;
IF RefText.Equal[token, "\n"] THEN RETURN [FALSE];
n ← n - 1;
ENDLOOP;
ok ← TRUE;
};
Warn: PROC [s: Source, msg: ROPE, v1, v2, v3, v4, v5: IO.Value ← [null[]]] = {
IF s.name # NIL THEN msg ← IO.PutFR["At %g[%g]: %g", [rope[s.name]], [integer[s.stream.GetIndex[]]], [rope[msg]]];
SIGNAL Warning[IO.PutFR[msg, v1, v2, v3, v4, v5]];
RETURN};
Start: PROC = {
Register["tech", ReadTech];
Register["timestamp", ReadTimestamp];
Register["version", ReadVersion];
Register["scale", ReadScale];
Register["resistclasses", ReadResistClasses];
Register["node", ReadNode];
Register["equiv", ReadEquiv];
Register["fet", ReadFet];
Register["use", ReadUse];
Register["merge", ReadMerge];
Register["adjust", ReadAdjust];
Register["cap", ReadCap];
[] ← nsh.Show[viewerInit: [name: "LichenFromExt2Impl.DoMerges.nSets"], updatePeriod: 5];
RETURN};
Start[];
END.