ScaldIOImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Barth, June 17, 1986 6:53:08 pm PDT
DIRECTORY FS, HashTable, IO, Rope, ScaldIO;
ScaldIOImpl: CEDAR PROGRAM
IMPORTS FS, HashTable, IO, Rope
EXPORTS ScaldIO
= BEGIN OPEN ScaldIO;
Handle: TYPE = REF HandleRec;
HandleRec: TYPE = RECORD[
stream: Core.STREAMNIL,
cellTypeIDTab: HashTable.Table ← NIL];
On write cellTypeIDTab maps REF to ROPE. On read cellTypeIDTab maps ROPE to REF.
SaveCellType: PUBLIC PROC [cellType: Core.CellType, fileName: ROPENIL] = {
h: Handle ← NEW[HandleRec];
IF fileName=NIL THEN fileName ← Rope.Cat[CoreOps.GetCellTypeName[cellType], ".scald"];
h.stream ← FS.StreamOpen[fileName, $create];
h.cellTypeIDTab ← HashTable.Create[];
WriteCellType[h, cellType];
IO.Close[h.stream];
};
RestoreCellType: PUBLIC PROC [cellName: ROPENIL, fileName: ROPENIL] RETURNS [cellType: Core.CellType] = {
h: Handle ← NEW[HandleRec];
IF fileName=NIL AND cellName=NIL THEN ERROR;
IF fileName=NIL THEN fileName ← Rope.Cat[cellName, ".scald"];
h.stream ← FS.StreamOpen[fileName];
h.cellTypeIDTab ← HashTable.Create[equal: HashTable.RopeEqual, hash: HashTable.HashRope];
h.ropeIDTab ← HashTable.Create[equal: HashTable.RopeEqual, hash: HashTable.HashRope];
h.atomIDTab ← HashTable.Create[equal: HashTable.RopeEqual, hash: HashTable.HashRope];
cellType ← ReadCellType[h];
IO.Close[h.stream];
};
WriteCellType: PUBLIC PROC [h: Handle, cellType: Core.CellType] = {
cellTypeID: ROPE;
cellType ← CoreOps.ToBasic[cellType];
IF cellType.class#CoreClasses.
cellTypeID ← NARROW[HashTable.Fetch[h.cellTypeIDTab, cellType].value];
IF cellTypeID=NIL THEN {
WritePublic: PROC [publicWire: Core.Wire, name: ROPE] = {
IF publicWire.size=0 THEN {
IF parameterCount=0 THEN IO.PutRope[h.stream, "PARAMETER = "]
ELSE IO.PutRope[h.stream, ", "];
IO.PutRope[name];
parameterCount ← parameterCount+1;
}
ELSE FOR i: NAT IN [0..publicWire.size) DO
subWire: Core.Wire ← publicWire[i];
subName: ROPE ← CoreOps.GetShortWireName[subWire];
WritePublic[subWire, Rope.Cat[name, "x", IF subName=NIL THEN ? ELSE subName]];
ENDLOOP;
};
wireIDTab: HashTable.Table ← HashTable.Create[];
parameterCount: NAT ← 0;
Recast into record cell type or transistor cell type.
IO.PutRope[h.stream, "\nMNAME = "];
cellTypeID ← CoreOps.GetCellTypeName[cellType];
IF NOT HashTable.Insert[h.cellTypeIDTab, cellType, cellTypeID] THEN {
};
IO.PutRope[h.stream, cellTypeID];
IO.PutRope[h.stream, ";\n"];
Write public wire, assume first levels are named, use x instead of . to seperate the wire levels, e.g. Data[0] becomes Datax0.
FOR i: NAT IN [0..cellType.public.size) DO
subWire: Core.Wire ← cellType.public[i];
WritePublic[subWire, CoreOps.GetShortWireName[subWire]];
ENDLOOP;
IF parameterCount>0 THEN IO.PutRope[h.stream, ";\n"];
Write instances
Write type name
Write public-actual binding
IF actual has no name THEN generate a name
};
};
END.