IPTypeTabImpl:
CEDAR
PROGRAM
IMPORTS CD, IO, IP, IPParams, IPChipRose, IPToolBox, IPBasicOps, Rope, SymTab, RTStructure
EXPORTS IPTypeTab =
BEGIN
OPEN IPToolBox, IPTypeTab;
Create:
PUBLIC
PROC[chipRose: IPChipRose.Ref]
RETURNS [Ref] = {
tab: SymTab.Ref ← SymTab.Create[];
eachTypeProc: IPChipRose.EachTypeAction ={
[] ← tab.Store[type, ToCoType[type, val]];
}; --eachTypeProc
chipRose.Types[eachTypeProc];
RETURN [NEW[Rep ← [tab]]];
}; --Create
CreateFromStructure:
PUBLIC
PROC[structure: RTStructure.Structure]
RETURNS [Ref] = {
EachTypeProc: RTStructure.EachObjectAction ={
IF object.heirarchyLevel = this
THEN
[] ← SymTab.Store[tab, object.name, ToCoTypeFromStructure[object]];
}; --EachTypeProc
tab: SymTab.Ref ← SymTab.Create[];
[] ← RTStructure.EnumerateObjects[structure, EachTypeProc];
RETURN [NEW[Rep ← [tab]]];
}; --CreateFromStructure
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: "];
IPToolBox.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: "];
IPToolBox.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 IPChipRose.TypeRec]
RETURNS [ct: CoType] ={
pins: LIST OF Pin ← IPToolBox.MakeIPPins[crType.pins, crType.origin, crType.shape, IPParams.PinMaxDistFromEdge];
shapeInfo: IP.ShapeInfoRec ← [IPBasicOps.Copy2Shape[crType.shape], crType.shapeFn, crType. restriction];
RETURN [NEW[CoTypeRep ← [name, NIL, pins, shapeInfo]]]
}; --ToCoType
ToCoTypeFromStructure:
PROC[object: RTStructure.Object]
RETURNS [ct: CoType] ={
size: IP.IntVector ← CD.InterestSize[object.cdObject];
shapeRec: REF IP.ShapeRep ← NEW[IP.ShapeRep ← [dim: IPBasicOps.NuNatVector[size.x, size.y]]];
shapeInfo: IP.ShapeInfoRec ← [shapeRec, NIL, NIL];
pins: LIST OF Pin ← IPToolBox.MakeIPPinsFromStructure[object, [0, 0], shapeRec, IPParams.PinMaxDistFromEdge];
RETURN [NEW[CoTypeRep ← [object.name, NIL, pins, shapeInfo]]]
}; --ToCoTypeFromStructure
GetCoType:
PROC[stream:
IO.
STREAM]
RETURNS [Rope.
ROPE, CoType] ={
name: Rope.ROPE ← IPToolBox.GetIdRope[stream];
pins: LIST OF Pin;
shapeInfo: IP.ShapeInfoRec;
IPToolBox.EnterBlock[stream];
UNTIL IPToolBox.ExitBlock[stream]
DO
token: ATOM ← IPToolBox.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 [
REF ←
NIL] = {
IPToolBox.EnterBlock[stream];
[] ← IPToolBox.ExitBlock[stream]
}; --getAuxInfo
pin ← NEW[PinRep ← [name: IPToolBox.GetIdRope[stream]]];
IPToolBox.EnterBlock[stream];
UNTIL IPToolBox.ExitBlock[stream]
DO
SELECT IPToolBox.GetIdAtom[stream]
FROM
$auxInfo => pin.auxInfo ← getAuxInfo[];
$physicalPins => pin.physicalPins ← IPToolBox.GetPhysicalPins[stream];
ENDCASE => ERROR;
ENDLOOP;
}; --getPin
IPToolBox.EnterBlock[stream];
UNTIL IPToolBox.ExitBlock[stream]
DO
pins ← CONS[getPin[], pins];
ENDLOOP;
}; --GetPins
GetShapeInfo:
PROC [stream:
IO.
STREAM]
RETURNS [
IP.ShapeInfoRec] ={
shape: REF IP.ShapeRep ← NIL;
shapeFn: REF ← NIL;
restriction: REF ← NIL;
IPToolBox.EnterBlock[stream];
UNTIL IPToolBox.ExitBlock[stream]
DO
SELECT IPToolBox.GetIdAtom[stream]
FROM
$shape => shape ← IPToolBox.GetShape[stream];
$shapeFn, $restriction => {
IPToolBox.EnterBlock[stream];
GET INFO HERE LATER
[] ← IPToolBox.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 IPToolBox.OrientPhysicalPins[phyPins, coType.shapeInfo.shape.dim^, orient]
}; --MakePhysicalPins
END.