OnionCore.mesa 
Copyright © 1985, 1986 by Xerox Corporation. All rights reversed.
Created by Bertrand Serlet, February 10, 1986 9:30:28 pm PST
Bertrand Serlet, February 10, 1987 4:44:11 pm PST
Onion is a smill and (relatively) efficient PadRing router implemented from a paper by Smith, Saxe, Newkirk and Mathews (Stanford; CH1813-5, 1982 IEEE). This method is called Loop Routing Scheme (LRS).
DIRECTORY
CD, CMosB, CoreGeometry, HashTable, Rope;
OnionCore: CEDAR DEFINITIONS IMPORTS CMosB =
BEGIN
Useful types
ROPE: TYPE = Rope.ROPE;
Object: TYPE = CD.Object;
Side: TYPE = CoreGeometry.Side;
Arcs
Arc: TYPE = REF ArcRec;
ArcRec: TYPE = RECORD [
rect: CD.Rect,     -- this is the bounding rect of all components. The arc, whatever its thickness, is included inside this bbox.
segs: LIST OF Seg -- the ring segments, non sorted
];
Seg: TYPE = REF SegRec;
SegRec: TYPE = RECORD [point1, point2: INT, side1, side2: Side]; -- always rotating in the direct direction (counterClockWise). By convention, point1 is included but point2 is not.
EmptyArc: PROC [rect: CD.Rect] RETURNS [arc: Arc];
Length: PROC [arc: Arc] RETURNS [length: INT ← 0];
ConnectSegBitToArc: PROC [min, max: INT, side: Side, arc: Arc] RETURNS [connection: Arc];
The 2 arcs can be of different sizes
NotOverlapping: PROC [arc1, arc2: Arc, minDist: INT] RETURNS [notOverlapping: BOOLTRUE];
The union is positionned to fit on the largest rect
It is assumed that arc1 and arc2 do not overlap.
Union: PROC [arc1, arc2: Arc] RETURNS [union: Arc];
EachSegBitProc: TYPE = PROC [min, max: INT, side: Side];
EnumerateSegBits: PROC [arc: Arc, eachSegBit: EachSegBitProc];
Nets
Net: TYPE = REF NetRec;
NetRec: TYPE = RECORD [
name: ROPE,          -- must be filled by the user
width: INT ← 0,         -- 0 default means minimum size
routeEveryOuterSeg: BOOLTRUE,   -- FALSE if there is redundancy in outer pins
facing: BOOLFALSE,       -- already facing
chosen: BOOLFALSE,       -- chosen for being routed
eval: INT ← 0,          -- evaluation function
arc: Arc ← NIL,         -- arc used by this net
innerSegs, outerSegs, newInnerSegs: LIST OF Seg ← NIL  -- pins of the net, position is relative to the [0, 0] of the interest rect of the outer. newInnerPins is used internally (pins for the next iteration)
];
Onion ringing
IncludeInOuter: PROC [outer: Object, nets: HashTable.Table, innerPos: CD.Position, innerSize, outerSize: CD.Position, radialLayer: CD.Layer ← CMosB.met, ringLayer: CD.Layer ← CMosB.met2] RETURNS [done: BOOL];
Nets is an association REF -> Net (REF can conveniently be a Core.Wire or a ROPE)
Just adds the onion rings in outer
The only fields that should be filled in nets are name, width, routeEveryOuterSeg, innerSegs and outerSegs. The nets table is modified in place, so watch out!
Center: PROC [inner, outer: Object] RETURNS [innerPos: CD.Position];
Returns the innerPos needed for centering the inner in the outer. Usually that is what users want before refining by hand.
END.