DIRECTORY
Imager USING [Context, PathProc, SetGray, SetXY, ShowRope, MaskBox, MaskStroke],
IO,
IP,
IPConstants,
IPToolBox,
IPChipRose,
IPNetTab,
IPPortTab,
Rope,
SymTab,
RTStructure;
IPPortTabImpl:
CEDAR
PROGRAM
IMPORTS IO, Imager, SymTab, Rope, IP, IPChipRose, IPNetTab, IPToolBox, RTStructure
EXPORTS IPPortTab = BEGIN OPEN TB: IPToolBox, CR: IPChipRose, IPPortTab;
Create:
PUBLIC
PROC[chipRose:
CR.Ref, netTab: IPNetTab.Ref]
RETURNS [Ref] = {
ports: SymTab.Ref ← SymTab.Create[];
eachPort:
CR.EachPortAction ={
[] ← ports.Store[port, NEW[PortRep ← [name: port, eqClass: val.eqClass, net: IPNetTab.FetchNet[netTab, val.net]]]];
}; --eachPort
chipRose.Ports[eachPort];
RETURN [NEW[Rep ← [ports]]];
}; --Create
CreateFromStructure:
PUBLIC
PROC[structure: RTStructure.Structure, netTab: IPNetTab.Ref]
RETURNS [Ref] = {
EachPort: RTStructure.EachInstancePinAction ={
[] ← SymTab.Store[ports, iPin.oPin.name, NEW[PortRep ← [name: iPin.oPin.name, eqClass: iPin.oPin.name, net: IPNetTab.FetchNet[netTab, iPin.net.name]]]];
}; --eachPort
ports: SymTab.Ref ← SymTab.Create[];
IF structure.outerInstance #
NIL
THEN
[] ← RTStructure.EnumerateInstancePins[structure.outerInstance, EachPort];
RETURN [NEW[Rep ← [ports]]];
}; --CreateFromStructure
FetchPort:
PUBLIC
PROC[portTab: Ref, name: Rope.
ROPE]
RETURNS [Port] ={
found: BOOL;
val: REF;
[found, val] ← portTab.ports.Fetch[name];
IF found
THEN RETURN [NARROW[val]]
ELSE ERROR IP.Error[missingRegistration, Rope.Cat[name, " is not a port name"]];
}; --FetchPort
Ports:
PUBLIC
PROC[portTab: Ref, action: EachPortAction] ={
p: SymTab.EachPairAction = {RETURN[action[NARROW[val]]]};--p
[] ← portTab.ports.Pairs[p];
}; --Ports
CheckSelf: PUBLIC PROC[portTab: Ref] ={NULL}; --CheckSelf
DescribeSelf:
PUBLIC
PROC[portTab: Ref, stream:
IO.
STREAM] ={
eachPortAction: EachPortAction ={
--(1) Print <portName>: <eqClass> <net>
stream.PutF["%g:\t%g %g ", IO.rope[port.name], IO.refAny[port.eqClass], IO.refAny[IPNetTab.NetName[port.net]]];
--(2) Print port positon
IF port.position =
NIL
THEN stream.PutF["()\n"]
ELSE stream.PutF["(%g %g)\n", IO.int[port.position.x], IO.int[port.position.y]];
};--eachPortAction
stream.PutF["\nBeginPortTab\n"];
stream.PutF["\n%g \t--Number of Ports\n", IO.int[portTab.ports.GetSize[]]];
Ports[portTab, eachPortAction];
stream.PutF["EndPortTab\n"];
}; --DescribeSelf
ReconstructSelf:
PUBLIC
PROC[stream:
IO.
STREAM, netTab: IPNetTab.Ref]
RETURNS [Ref] ={
ports: SymTab.Ref ← SymTab.Create[];
THROUGH [0..stream.GetInt)
DO
name: Rope.ROPE;
port: REF IP.PortRep;
[name, port] ← GetPort[stream, netTab];
[] ← ports.Store[name, port];
ENDLOOP;
IF stream.GetAtom[] # $EndPortTab THEN ERROR;
RETURN [NEW[Rep ← [ports]]];
}; --ReconstructSelf
PaintPort:
PUBLIC
PROC [port: Port, context: Imager.Context, xOffset, yOffset, scaleFactor:
REAL, stipple:
CARDINAL, size:
NAT, showPortName:
BOOL] ={
IF port.position #
NIL
THEN {
--Cant paint port that is not active
halfDim: REAL ← (scaleFactor * size) /2.0;
coordX, coordY: REAL;
[coordX, coordY] ← port.position^;
coordX ← xOffset + (coordX * scaleFactor);
coordY ← yOffset + (coordY * scaleFactor);
IF stipple = IPConstants.White
THEN {
path: Imager.PathProc ~ {
moveTo[[coordX - halfDim, coordY - halfDim]];
lineTo[[coordX + halfDim, coordY - halfDim]];
lineTo[[coordX + halfDim, coordY + halfDim]];
lineTo[[coordX - halfDim, coordY + halfDim]];
lineTo[[coordX - halfDim, coordY - halfDim]];};
Imager.MaskStroke[context, path];}
ELSE {
Imager.SetGray[context, stipple];
Imager.MaskBox[context, [coordX - halfDim, coordY - halfDim, coordX + halfDim, coordY + halfDim]];};
IF showPortName
THEN {
Imager.SetXY[context, [coordX, coordY + (1.25 * halfDim)]];
Imager.ShowRope[context, port.name]};
};
};--PaintPort
GetPort:
PROC[stream:
IO.
STREAM, netTab: IPNetTab.Ref]
RETURNS [Rope.
ROPE,
REF
IP.PortRep] ={
name: Rope.ROPE ← TB.GetIdRope[stream]; -- First get the name
eqClass: Rope.ROPE ← NARROW[IO.GetRefAny[stream]];
net: REF IP.NetRep ← IPNetTab.FetchNet[netTab, NARROW[IO.GetRefAny[stream]]];
position: REF IP.IntVector ← TB.GetIntVector[stream];
RETURN[name, NEW[IP.PortRep ← [name, eqClass, net, position]]];
}; --GetPort
END.