-- File: DJExtAlloc.mesa
-- Allocation routines for the disjoint circuit extractor
-- Written by Martin Newell/Dan Fitzpatrick June 1981
-- Last edited: August 27, 1981 5:50 PM

DIRECTORY


DisjointAllocDefs: FROM "DisjointAllocDefs" USING [Alloc, Free, EnumerateSymbols],
DisjointPropDefs: FROM "DisjointPropDefs" USING [GetLongProp],
DisjointTypes: FROM "DisjointTypes" USING [Symbol],
DJExtDefs: FROM "DJExtDefs",
DJExtractDefs: FROM "DJExtractDefs" USING [GetSegmentID, GetParamID, GetNodeLocID, GetExtCapID, GetIntCapID, GetExtTransID, GetIntTransID],
DJExtAllocDefs: FROM "DJExtAllocDefs",
DJExtUtilsDefs: FROM "DJExtUtilsDefs" USING [WriteLongDecimal],
DJExtTypes: FROM "DJExtTypes" USING [Edge, EdgeRecord, Segment, SegmentRecord, Box, BoxRecord, NodeNumber, Position, Side, SideRecord, NodeLocation, NodeLocationRecord, NodeSegment, NodeSegmentRecord, ActualParameter, ActualParameterRecord, Node, NodeRecord, Diffusion, DiffusionRecord],
IODefs: FROM "IODefs" USING [WriteString, WriteLine];

DJExtAlloc: PROGRAM
IMPORTS DisjointAllocDefs, DisjointPropDefs, DJExtractDefs, DJExtUtilsDefs, IODefs
EXPORTS DJExtDefs, DJExtAllocDefs =
BEGIN
OPEN DisjointAllocDefs, DisjointPropDefs, DisjointTypes, DJExtractDefs, DJExtUtilsDefs, DJExtTypes, IODefs;

MakeHEdge
: PUBLIC PROCEDURE [h, left, right: REAL] RETURNS[e:Edge] =
BEGIN
e ← AllocateEdge[];
e.by ← e.ty ← h;
e.bx ← left;
e.tx ← right;
e.segment ← NIL;
e.count ← 0;
END;

MakeVEdge: PUBLIC PROCEDURE [v, bottom, top: REAL] RETURNS[e:Edge] =
BEGIN
e ← AllocateEdge[];
e.bx ← e.tx ← v;
e.by ← bottom;
e.ty ← top;
e.segment ← NIL;
e.count ← 0;
END;

AllocateEdge: PUBLIC PROCEDURE RETURNS[e:Edge] =
BEGIN
AllocatedEdges ← AllocatedEdges + 1;
e ← Alloc[SIZE[EdgeRecord]];
END;

FreeEdge: PUBLIC PROCEDURE[e:Edge] =
BEGIN
Free[e,SIZE[EdgeRecord]];
AllocatedEdges ← AllocatedEdges - 1;
END;

AllocateSegment: PUBLIC PROCEDURE RETURNS[e:Segment] =
BEGIN
AllocatedSegments ← AllocatedSegments + 1;
e ← Alloc[SIZE[SegmentRecord]];
END;

FreeSegment: PUBLIC PROCEDURE[e:Segment] =
BEGIN
Free[e,SIZE[SegmentRecord]];
AllocatedSegments ← AllocatedSegments - 1;
END;

AllocateBox: PUBLIC PROCEDURE RETURNS[e:Box] =
BEGIN
AllocatedBoxes ← AllocatedBoxes + 1;
e ← Alloc[SIZE[BoxRecord]];
END;

FreeBox: PUBLIC PROCEDURE[e:Box] =
BEGIN
Free[e,SIZE[BoxRecord]];
AllocatedBoxes ← AllocatedBoxes - 1;
END;

MakeSide: PUBLIC PROCEDURE [x, bottom, top: REAL, node: NodeNumber, pos:Position, layer:INTEGER]
RETURNS[s:Side] =
BEGIN
s ← AllocateSide[];
s↑ ← [
next: NIL,
layer: layer,
node: node,
pos: pos,
x: x,
b: bottom,
t: top
];
END;

AllocateSide: PUBLIC PROCEDURE RETURNS[s:Side] =
BEGIN
AllocatedSides ← AllocatedSides + 1;
s ← Alloc[SIZE[SideRecord]];
END;

FreeSide: PUBLIC PROCEDURE[s:Side] =
BEGIN
Free[s,SIZE[SideRecord]];
AllocatedSides ← AllocatedSides - 1;
END;

AllocateNodeSegment: PUBLIC PROCEDURE RETURNS[e:NodeSegment] =
BEGIN
AllocatedNodeSegments ← AllocatedNodeSegments + 1;
e ← Alloc[SIZE[NodeSegmentRecord]];
END;

FreeNodeSegment: PUBLIC PROCEDURE[e:NodeSegment] =
BEGIN
Free[e,SIZE[NodeSegmentRecord]];
AllocatedNodeSegments ← AllocatedNodeSegments - 1;
END;

AllocateActualParameter: PUBLIC PROCEDURE RETURNS[e:ActualParameter] =
BEGIN
AllocatedActualParameters ← AllocatedActualParameters + 1;
e ← Alloc[SIZE[ActualParameterRecord]];
END;

FreeActualParameter: PUBLIC PROCEDURE[e:ActualParameter] =
BEGIN
Free[e,SIZE[ActualParameterRecord]];
AllocatedActualParameters ← AllocatedActualParameters - 1;
END;

MakeNodeLocation: PUBLIC PROCEDURE[node:NodeNumber, x,y:REAL] RETURNS[e:NodeLocation] =
BEGIN
e ← AllocateNodeLocation[];
e↑ ← [
next: NIL,
node: node,
x: x,
y: y
];
END;

AllocateNodeLocation: PUBLIC PROCEDURE RETURNS[e:NodeLocation] =
BEGIN
AllocatedNodeLocations ← AllocatedNodeLocations + 1;
e ← Alloc[SIZE[NodeLocationRecord]];
END;

FreeNodeLocation: PUBLIC PROCEDURE[e:NodeLocation] =
BEGIN
Free[e,SIZE[NodeLocationRecord]];
AllocatedNodeLocations ← AllocatedNodeLocations - 1;
END;

AllocateCap: PUBLIC PROCEDURE RETURNS[e:Node] =
BEGIN
AllocatedCapacitors ← AllocatedCapacitors + 1;
e ← Alloc[SIZE[cap NodeRecord]];
END;

FreeCap: PUBLIC PROCEDURE[e:Node] =
BEGIN
Free[e,SIZE[cap NodeRecord]];
AllocatedCapacitors ← AllocatedCapacitors - 1;
END;

AllocateTransistor: PUBLIC PROCEDURE RETURNS[e:Node] =
BEGIN
AllocatedTransistors ← AllocatedTransistors + 1;
e ← Alloc[SIZE[trans NodeRecord]];
END;

FreeTransistor: PUBLIC PROCEDURE[e:Node] =
BEGIN
Free[e,SIZE[trans NodeRecord]];
AllocatedTransistors ← AllocatedTransistors - 1;
END;

AllocateDiffusion: PUBLIC PROCEDURE RETURNS[e:Diffusion] =
BEGIN
AllocatedDiffusions ← AllocatedDiffusions + 1;
e ← Alloc[SIZE[DiffusionRecord]];
END;

FreeDiffusion: PUBLIC PROCEDURE[e:Diffusion] =
BEGIN
Free[e,SIZE[DiffusionRecord]];
AllocatedDiffusions ← AllocatedDiffusions - 1;
END;

PrintExtAlloc: PUBLIC PROCEDURE =
BEGIN
Print: PROC [str:STRING, alloc,used:LONG INTEGER] =
BEGIN
WriteString[""]; WriteString[str]; WriteString[": "];
WriteLongDecimal[alloc]; WriteString[" allocated, "];
WriteLongDecimal[used]; WriteLine[" used"];
END;

Check[];
Print["Edges",AllocatedEdges,0];
Print["Segments",AllocatedSegments,uSeg];
Print["Sides",AllocatedSides,0];
Print["Boxes",AllocatedBoxes,0];
Print["NodeSegments",AllocatedNodeSegments,0];
Print["ActualParameters",AllocatedActualParameters,uParam];
Print["NodeLocations",AllocatedNodeLocations,uLoc];
Print["Capacitors",AllocatedCapacitors,uCap];
Print["Transistors",AllocatedTransistors,uTrans];
Print["Diffusions",AllocatedDiffusions,uDiff];
END;

Check: PROCEDURE =
BEGIN

Count: PROC[s: Symbol] RETURNS [BOOLEAN] =
BEGIN
nSymbols ← nSymbols + 1;
FOR i: Segment ← GetLongProp[s.prop,GetSegmentID[]],i.next UNTIL i = NIL DO
uSeg ← uSeg + 1;
ENDLOOP;
FOR i: ActualParameter ← GetLongProp[s.prop,GetParamID[]],i.next UNTIL i = NIL DO
uParam ← uParam + 1;
ENDLOOP;
FOR i: NodeLocation ← GetLongProp[s.prop,GetNodeLocID[]],i.next UNTIL i = NIL DO
uLoc ← uLoc + 1;
ENDLOOP;
FOR i: Node ← GetLongProp[s.prop,GetExtCapID[]],i.next UNTIL i = NIL DO
uCap ← uCap + 1;
ENDLOOP;
FOR i: Node ← GetLongProp[s.prop,GetIntCapID[]],i.next UNTIL i = NIL DO
uCap ← uCap + 1;
ENDLOOP;
FOR i: Node ← GetLongProp[s.prop,GetExtTransID[]],i.next UNTIL i = NIL DO
uTrans ← uTrans + 1;
FOR d: Diffusion ← i.diff,d.next UNTIL d = NIL DO
uDiff ← uDiff + 1;
ENDLOOP;
ENDLOOP;
FOR i: Node ← GetLongProp[s.prop,GetIntTransID[]],i.next UNTIL i = NIL DO
uTrans ← uTrans + 1;
FOR d: Diffusion ← i.diff,d.next UNTIL d = NIL DO
uDiff ← uDiff + 1;
ENDLOOP;
ENDLOOP;
RETURN[FALSE];
END;

uSeg ← 0;
uParam ← 0;
uLoc ← 0;
uCap ← 0;
uTrans ← 0;
uDiff ← 0;
nSymbols ← 0;
[] ← EnumerateSymbols[Count];
WriteLongDecimal[nSymbols]; WriteLine[""];
END;

nSymbols:LONG INTEGER;
uSeg:LONG INTEGER;
uParam:LONG INTEGER;
uLoc:LONG INTEGER;
uCap:LONG INTEGER;
uTrans:LONG INTEGER;
uDiff:LONG INTEGER;


AllocatedEdges: LONG INTEGER ← 0;
AllocatedSegments: LONG INTEGER ← 0;
AllocatedBoxes: LONG INTEGER ← 0;
AllocatedSides: LONG INTEGER ← 0;
AllocatedNodeSegments: LONG INTEGER ← 0;
AllocatedActualParameters: LONG INTEGER ← 0;
AllocatedNodeLocations: LONG INTEGER ← 0;
AllocatedCapacitors: LONG INTEGER ← 0;
AllocatedTransistors: LONG INTEGER ← 0;
AllocatedDiffusions: LONG INTEGER ← 0;

END.