--File: IPTypeTabImpl.mesa
Last Edited by: CSChow, January 27, 1985 0:03:53 am PST
DIRECTORY
Rope,
IO,
SymTab,
IP,
IPParams,
IPToolBox,
IPBasicOps,
IPChipRose,
IPTypeTab;
IPTypeTabImpl: CEDAR PROGRAM
IMPORTS IO, Rope, SymTab, IP, IPParams, IPChipRose, IPToolBox, IPBasicOps
EXPORTS IPTypeTab = BEGIN OPEN BO: IPBasicOps, TB: IPToolBox, CR: IPChipRose, IPTypeTab;
Create: PUBLIC PROC[chipRose: CR.Ref] RETURNS [Ref] = {
tab: SymTab.Ref ← SymTab.Create[];
eachTypeProc: CR.EachTypeAction ={
[] ← tab.Store[type, ToCoType[type, val]];
}; --eachTypeProc
chipRose.Types[eachTypeProc];
RETURN [NEW[Rep ← [tab]]];
}; --Create
FetchCoType: PUBLIC PROC[typeTab: Ref, name: Rope.ROPE, raiseError: BOOL] RETURNS [CoType] ={
found: BOOL;
val: REF;
[found, val] ← typeTab.tab.Fetch[name];
IF found
THEN RETURN [NARROW[val]];
IF raiseError
THEN ERROR IP.Error[missingRegistration, Rope.Cat[name, " is not a type name"]]
ELSE RETURN [NIL];
}; --FetchCoType
CoTypes: PUBLIC PROC[typeTab: Ref, action: EachCoTypeAction] ={
p: SymTab.EachPairAction = {RETURN[action[NARROW[val]]]};--p
[] ← typeTab.tab.Pairs[p];
}; --CoTypes
CheckSelf: PUBLIC PROC[typeTab: Ref] ={NULL}; --CheckSelf
DescribeSelf: PUBLIC PROC[typeTab: Ref, stream: IO.STREAM, debug: BOOL] ={
pShapeInfo: PROC[shapeInfo: IP.ShapeInfoRec] ={
shape: REF IP.ShapeRep ← shapeInfo.shape;
--(1) print shape
stream.PutF["shape: "];
TB.PutShape[stream, shape];
--(2) print shapeFn
stream.PutF[" shapeFn: {"];
SHOULD PRINT pShapeInfo.shapeFn HERE
stream.PutF["} "];
--(3) print restriction
stream.PutF["restriction: {"];
--SHOULD PRINT pShapeInfo.restriction HERE
stream.PutF["} "];
}; --pShapeInfo
pPin: PROC[pin: Pin] ={
stream.PutF["%g: {", IO.rope[pin.name]];
stream.PutF["physicalPins: "];
TB.PutPhysicalPins[stream, pin.physicalPins];
stream.PutF[" auxInfo: {"];
--SHOULD PRINT pin.auxInfo HERE
stream.PutF["} "];
stream.PutF["}\n\t "];
}; --pPin
pCoType: EachCoTypeAction ={
stream.PutF["%g: {\n\t" , IO.rope[coType.name]];
--(1) print shapeInfo
stream.PutF["shapeInfo: {"];
pShapeInfo[coType.shapeInfo];
stream.PutF["}\n\t"];
--(2) print pins
stream.PutF["pins: {\n\t "];
FOR pins: LIST OF Pin ← coType.pins, pins.rest UNTIL pins = NIL DO
pPin[pins.first];
ENDLOOP;
stream.PutF["}\n\t"];
--(3) print instances
IF debug THEN {
stream.PutF["instances: ("];
FOR l: LIST OF REF IP.ComponentRep ← coType.instances, l.rest UNTIL l = NIL DO
stream.PutF[" %g", IO.rope[l.first.name]];
ENDLOOP;
stream.PutF[")\n\t"];
};
stream.PutF["}\n"];
}; --pCoType
stream.PutF["\nBeginTypeTab"];
stream.PutF["\n%g \t--Number of CoTypes\n", IO.int[typeTab.tab.GetSize[]]];
CoTypes[typeTab, pCoType];
stream.PutF["EndTypeTab\n"];
}; --DescribeSelf
ReconstructSelf: PUBLIC PROC[stream: IO.STREAM] RETURNS [Ref] ={
tab: SymTab.Ref ← SymTab.Create[];
THROUGH [0..stream.GetInt) DO
name: Rope.ROPE;
coType: CoType;
[name, coType] ← GetCoType[stream];
[] ← tab.Store[name, coType];
ENDLOOP;
IF stream.GetAtom[] # $EndTypeTab THEN ERROR IP.Error;
RETURN [NEW[Rep ← [tab]]];
}; --ReconstructSelf
ToCoType: PROC[name: Rope.ROPE, crType: REF CR.TypeRec] RETURNS [ct: CoType] ={
pins: LIST OF Pin ← TB.MakeIPPins[crType.pins, crType.origin, crType.shape, IPParams.PinMaxDistFromEdge];
shapeInfo: IP.ShapeInfoRec ← [BO.Copy2Shape[crType.shape], crType.shapeFn, crType. restriction];
RETURN [NEW[CoTypeRep ← [name, NIL, pins, shapeInfo]]]
}; --ToCoType
GetCoType: PROC[stream: IO.STREAM] RETURNS [Rope.ROPE, CoType] ={
name: Rope.ROPETB.GetIdRope[stream];
pins: LIST OF Pin;
shapeInfo: IP.ShapeInfoRec;
TB.EnterBlock[stream];
UNTIL TB.ExitBlock[stream] DO
token: ATOMTB.GetIdAtom[stream];
SELECT token FROM
$instances => [] ← stream.GetRefAny[]; --Get instances. NOT used; for show
$shapeInfo => shapeInfo ← GetShapeInfo[stream]; -- Get shapeInfo
$pins => pins ← GetPins[stream]; -- Get pins
ENDCASE => ERROR;
ENDLOOP;
RETURN[name, NEW[CoTypeRep ← [name, NIL, pins, shapeInfo]]];
}; --GetCoType
GetPins: PROC [stream: IO.STREAM] RETURNS [pins: LIST OF REF IP.PinRep ← NIL] = {
getPin: PROC RETURNS [pin: Pin] = {
getAuxInfo: PROC RETURNS [REFNIL] = {
TB.EnterBlock[stream];
[] ← TB.ExitBlock[stream]
}; --getAuxInfo
pin ← NEW[PinRep ← [name: TB.GetIdRope[stream]]];
TB.EnterBlock[stream];
UNTIL TB.ExitBlock[stream] DO
SELECT TB.GetIdAtom[stream] FROM
$auxInfo => pin.auxInfo ← getAuxInfo[];
$physicalPins => pin.physicalPins ← TB.GetPhysicalPins[stream];
ENDCASE => ERROR;
ENDLOOP;
}; --getPin
TB.EnterBlock[stream];
UNTIL TB.ExitBlock[stream] DO
pins ← CONS[getPin[], pins];
ENDLOOP;
}; --GetPins
GetShapeInfo: PROC [stream: IO.STREAM] RETURNS [IP.ShapeInfoRec] ={
shape: REF IP.ShapeRep ← NIL;
shapeFn: REFNIL;
restriction: REFNIL;
TB.EnterBlock[stream];
UNTIL TB.ExitBlock[stream] DO
SELECT TB.GetIdAtom[stream] FROM
$shape => shape ← TB.GetShape[stream];
$shapeFn, $restriction => { 
TB.EnterBlock[stream];
--GET INFO HERE LATER
[] ← TB.ExitBlock[stream];};
ENDCASE => ERROR;
ENDLOOP;
RETURN [IP.ShapeInfoRec[shape, shapeFn, restriction]]
}; --GetShapeInfo
--Operation on individual CoType
GetPin: PUBLIC PROC [coType: CoType, pinName: Rope.ROPE] RETURNS [pin: Pin] ={
FOR l: LIST OF Pin ← coType.pins, l.rest UNTIL l = NIL DO
IF Rope.Equal[l.first.name, pinName] THEN {pin ← l.first; EXIT}
REPEAT
FINISHED => ERROR IP.Error[missingRegistration, Rope.Cat[pinName, " is not a pin in type ", coType.name]];
ENDLOOP;
}; --GetPin
RemInstance: PUBLIC PROC[coType: CoType, instance: REF IP.ComponentRep] ={
lHd, lTl: LIST OF REF IP.ComponentRep;
lHd ← lTl ← CONS[NIL, NIL];
FOR l: LIST OF REF IP.ComponentRep ← coType.instances, l.rest UNTIL l = NIL DO
IF l.first = instance
THEN {lTl.rest ← l.rest; EXIT}
ELSE {lTl.rest ← LIST[l.first]; lTl ← lTl.rest};
REPEAT
FINISHED => ERROR IP.Error[callingError, Rope.Cat[instance.name, " is not an instance of type", coType.name]];
ENDLOOP;
coType.instances ← lHd.rest;
}; --RemInstance
MakePhysicalPins: PUBLIC PROC[coType: CoType, pin: Pin, orient: IP.Orientation] RETURNS [phyPins: LIST OF PhysicalPin ← NIL] ={
FOR l: LIST OF PhysicalPin ← pin.physicalPins, l.rest UNTIL l = NIL DO
pPin: PhysicalPin ← l.first;
phyPins ← CONS[NEW[PhysicalPinRep ← [pPin.coord, pPin.side, pPin.active]], phyPins]
ENDLOOP;
IF coType.shapeInfo.shape = NIL
THEN ERROR IP.Error[callingError, "Not implemented yet"] -- haven't figure out how to handle soft types yet
ELSE TB.OrientPhysicalPins[phyPins, coType.shapeInfo.shape.dim^, orient]
}; --MakePhysicalPins
END.