DIRECTORY 
CD USING [Design, Instance, Layer, Object, Position],
Core,
CoreClasses USING [CreateIdentity],
CoreCreate USING [PA],
PWPins USING [Side],
Sinix USING [Mode];

PWCore: CEDAR DEFINITIONS IMPORTS CoreClasses = BEGIN
CellType: TYPE = Core.CellType;
Object: TYPE = CD.Object;
Wire: TYPE = Core.Wire;
ROPE: TYPE = Core.ROPE;
Properties: TYPE = Core.Properties;

testLichen: BOOL;
checkAbuts: BOOL;
extractMode: Sinix.Mode;
maskSuffix: ROPE;
LayoutProc: TYPE = PROC [cellType: CellType] RETURNS [obj: Object];
DecorateProc: TYPE = PROC [cellType: CellType, obj: Object];
RegisterLayoutAtom: PROC [layoutAtom: ATOM, layoutProc: LayoutProc, decorateProc: DecorateProc] RETURNS [sameAtom: ATOM];

layoutAtomProp: ATOM; -- =$Layout.  Property on cellTypes to specifies layoutAtoms

SetLayout: PROC [cellType: CellType, layoutAtom: ATOM, userDataProp: ATOM _ NIL, userData: REF _ NIL];
Layout: PROC [cellType: CellType] RETURNS [obj: Object];

FromLayout: PROC [public: Wire, obj: CD.Object] RETURNS [cellType: CellType];
FromLayoutWithoutPublic: PROC [obj: CD.Object] RETURNS [cellType: CellType];

Get: LayoutProc;
GetAndFlatten: LayoutProc;
AbutX: LayoutProc;
AbutY: LayoutProc;
ReverseAbutX: LayoutProc;
ReverseAbutY: LayoutProc;
ArrayX: LayoutProc;
ArrayY: LayoutProc;
ReverseArrayX: LayoutProc;
ReverseArrayY: LayoutProc;
FlipX: LayoutProc;
FlipY: LayoutProc;
Rot90: LayoutProc;
Rot180: LayoutProc;
Rot270: LayoutProc;

DecorateGet: DecorateProc;
DecorateAbutX: DecorateProc;
DecorateAbutY: DecorateProc;
DecorateReverseAbutX: DecorateProc;
DecorateReverseAbutY: DecorateProc;
DecorateRotated: DecorateProc;
DecorateRecasted: DecorateProc;

OrderProc: TYPE = PROC [CD.Position, CD.Position] RETURNS [BOOL];
SortInX: OrderProc;
SortInY: OrderProc;
ReverseSortInX: OrderProc;
ReverseSortInY: OrderProc;

DecorateFlatten: PROC [cellType: CellType, obj: CD.Object, inOrder: OrderProc];
SortInstances: PROC [cellType: CellType, inOrder: OrderProc];
SetGet: PROC [cellType: CellType, source: CD.Design] = 
INLINE {SetLayout[cellType, $Get, $PWCoreSourceDesign, source]};
SetAbutX: PROC [cellType: CellType] = INLINE {SetLayout[cellType, $AbutX]};
SetAbutY: PROC [cellType: CellType] = INLINE {SetLayout[cellType, $AbutY]};

SetArrayX: PROC [cellType: CellType] = INLINE {SetLayout[cellType, $ArrayX]};
SetArrayY: PROC [cellType: CellType] = INLINE {SetLayout[cellType, $ArrayY]};

RotateCellType: PROC [cellType: CellType, orientation: ATOM] RETURNS [rotatedCellType: CellType] = INLINE {
rotatedCellType _ CoreClasses.CreateIdentity[cellType];
SetLayout[rotatedCellType, orientation];
};
AbutInstance: TYPE = RECORD [object: CD.Object, pas: LIST OF CoreCreate.PA _ NIL];
AbutCell: PROC [public: Wire, abutInstances: LIST OF AbutInstance, inX: BOOL, shared: BOOL _ FALSE, name: ROPE _ NIL, props: Properties _ NIL] RETURNS [recordCell: CellType];

Side: TYPE = PWPins.Side; -- {bottom, right, top, left, none}; none side should not be given nor received as argument for all the following functions. 
EnumerateWirePins: PROC [cellType: CellType, eachWirePin: EachWirePinProc] RETURNS [quit: BOOL];
EachWirePinProc: TYPE = PROC [wire: Wire, instance: CD.Instance, min, max: INT, side: Side, layer: CD.Layer] RETURNS [quit: BOOL _ FALSE];

EnumerateNonOverlappingWirePins: PROC [cellType: CellType, eachWirePin: EachWirePinProc] RETURNS [quit: BOOL];

EnumeratePins: PROC [cellType: CellType, wire: Wire, eachPin: EachPinProc] RETURNS [quit: BOOL];
EachPinProc: TYPE = PROC [instance: CD.Instance, min, max: INT, side: Side, layer: CD.Layer] RETURNS [quit: BOOL _ FALSE];

EnumerateSortedPins: PROC [cellType: CellType, side: Side, eachSortedPin: EachSortedPinProc] RETURNS [quit: BOOL];
EachSortedPinProc: TYPE = PROC [wire: Wire, instance: CD.Instance, min, max: INT, layer: CD.Layer] RETURNS [quit: BOOL _ FALSE];
HasLayout: PRIVATE PROC [cellType: CellType] RETURNS [BOOL];
CancelLayout: PRIVATE PROC [cellType: CellType];
Signal: PRIVATE SIGNAL;

END.
���ž��PWCore.mesa
Copyright c 1985 by Xerox Corporation.  All rights reversed.
Louis Monier February 14, 1986 11:00:35 am PST
Bertrand Serlet, June 9, 1986 11:45:12 am PDT
Theory
This interface defines how to generate layout attached to Core, using PatchWork (PW).  Layout generated without using PW can also be attached.  When layout is attached to Core, it is also specified how to check it and to decorate the original Core source with information derived from extraction.  
Basics
Global Variables
Some global variables are used for calling Sinix and Lichen.  Yes, they should be parameters for all PWCore functions, but for now that is fine enough.  Better rollback between changes, if you don't know what you are doing.  
Defaulted to FALSE.  TRUE means that graph isomorphism is attempted on Get.
Defaulted to FALSE.  TRUE means that graph isomorphism is attempted on Abuts.
Contains the mode that is to be passed to Sinix when doing extraction.  Its default is SinixCMos.extractBMode and it can be changed to SinixCMos.checkBMode.
Contains the rope that is to be concatenated to the name of a cellType to find the name of the corresponding layout cell.
Primitive operations
obj is the layout for cellType.  
Identical (REF equal) cellTypes must have the same (REF equal) layout, and the same layout must correspond to the same cellType.  To follow this restriction, the Layout function automatically insert one level of indirection (Indirect object).

Checks that obj is compatible with the source cellType, and decorates cellType with the geometric information derived from obj.

LayoutProcs are not directly accessible and must be associated with an atom.  This allows delayed generation, description of the Core structure without the geometry, and lazy evaluation of the geometry to improve efficiency.
Attaches the atom as a property (layoutAtomProp) of the cell type.  
If the user wants to supply some data, this data is stored under the property userDataProp on the cellType.
The implementation is the following:
CoreProperties.PutCellTypeProp[cellType, layoutAtomProp, layoutAtom];
IF userDataProp#NIL THEN CoreProperties.PutCellTypeProp[cellType, userDataProp, userData];

Retrieves the layout corresponding to a cell type by:
1) fetching the layoutAtom (property layoutAtomProp), 
2) finding the corresponding layoutProc and decorateProc, 
3) evaluating layoutProc, 
4) using the decorateProc to decorate the original cellType
5) returning an indirect object of obj with a special property to extract it as cellType.
The result is cached, so that means that called twice with the same (REF equal) cellType, Layout will produce the same (REF equal) obj.
To follow the restriction that the same layout can not correspond to two different cellTypes, Layout automatically inserts one level of indirection (Indirect object).
This PROC is used to bypass most checks and get the Core description directly from the Layout using Sinix.  Avoid using it!
This PROC is used to bypass all checks and get the Core description directly from the Layout using Sinix.  Really avoid using it!
Predefined layoutAtoms and their associated procs
$Get and $GetAndFlatten: expect a $PWCoreSourceDesign property [of type CD.Design] on the cellType.  The cellType must be a recordCell.  GetAndFlatten flattens the layout, so that corresponding transistors inter-cells are fused.
$AbutX, $AbutY, $ReverseAbutX, $ReverseAbutY: the cellType must be a recordCell.
$ArrayX, $ArrayY, $ReverseArrayX, $ReverseArrayY: the cellType must be a sequenceCell.
$FlipX, $FlipY, $Rot90, $Rot180, $Rot270: the cellType must be an identityCell.
$Recast: the cellType must have a Recast proc and the recasted cellType must have layout.  This is the default for identity cellTypes.
Assumes that sourceCT is an identityCellClass and extractedCT a recordCell with a single instance.
Only assumes that extractedCT and sourceCT have similar public.
Returns TRUE if the first position is "before" the second
Assumes that cellType is a record Cell.
Extracts obj, flattens the result of the extraction (stopping for the cellTypes which have an associated layout), sorts the instances using inOrder, and assumes they match the instances of cellType. 
This function modifies physically the instances of cellType, by permuting the ith and the jth instance when inOrder (called with the positions of the instances) returns FALSE (for i<j).
Short cuts for the designer
Fetches layout from a source design.

Creates an Identity cellType which layout is the same as the original, but rotated by orientation.  Code is the following.
Tentative help for regular structures
Object must be a layout cell with only atomic wires.  There is no need to describe object by other means (it defines the truth!).
ATTENTION: pas should contain all bindings (no default binding when public and sub-publics have same name is happening)
Abuts (in X or in Y depending on inX) the layout of the given abutInstances.  Extracts the result using extractMode, and uses the pas (given in abutInstances) to deduce the correspondance between extracted wires and public wires.  
The truth for this generated cellType comes soforth from the layout.
Boolean shared specifies which of PW.AbutList and PW.SharedAbutList should be used.
Help for writing routers
Pin should be understand, for the following functions, in the more general sense of segment of interface geometry.  Min and Max refer to the interesting projection in X or Y (depending on the side of the pin), relatively to the InterestRect of the layout of the object.  Note that the coordinate system is different from the one used in Sinix (which is the Outer coordinate system). 
Enumerates all the interface geometry for the given cellType
Enumerates all the interface geometry for the given cellType, but enumerates once only segments that overlap.
Enumerates all the interface geometry for the given wire
Enumerates all the interface geometry for the given cellType.  Segments are given in increasing min order.
Private functions for LayoutCheckpoint
Êä��˜�–
"Cedar" stylešœ™Jšœ
Ïmœ1™<Icode™.K™-—J˜�šÏk	œ˜
Jšžœžœ-˜5Jšœ˜Jšœžœ˜#Jšœžœžœ˜Jšœžœ˜Jšœžœ˜—J˜�Jš	Ðbnœžœžœžœž˜5head™KšœQžœ#žœ²™ª—™Kšœ
žœ˜Kšœžœžœ˜Kšœžœ
˜Kšžœžœžœ˜Kšœžœ˜#—™Kšœ™ÏcH™áK˜�šœžœ˜J™K—šœžœ˜J™M—šœ˜Kš œ™œ—šœžœ˜Kš y™y——™šœžœžœžœ˜CKšœ!™!Kšœò™òK™�—šœžœžœ#˜<Kšœ™K™�—š
Ïnœžœžœ6žœžœ˜yK™àK˜�—šœžœ <˜RK˜�—š¡	œžœ"žœžœžœžœžœ˜fKšœD™DKšœk™k™$KšœE™EKšžœžœžœB™Z—K™�—š¡œžœžœ˜8šœ5™5Kšœ6™6Kšœ:™:Kšœ™Kšœ;™;KšœY™Y—Kšœ‡™‡Kšœ¦™¦K˜�—š¡
œžœžœ	žœ˜MKšœžœr™{—š¡œžœžœ	žœ˜LKšœžœx™——šœ1™1KšœHžœš™äKšœP™PKšœV™VKšœO™OKšœ†™†K˜�Kš¡œ
˜Kš¡
œ
˜Kš¡œ
˜Kš¡œ
˜Kš¡œ
˜Kš¡œ
˜Kš¡œ
˜Kš¡œ
˜Kš¡
œ
˜Kš¡
œ
˜Kš¡œ
˜Kš¡œ
˜Kš¡œ
˜Kš¡œ
˜Kš¡œ
˜K˜�Kš¡œ˜Kš¡
œ˜Kš¡
œ˜Kš¡œ˜#Kš¡œ˜#š¡œ˜Kšœb™b—š¡œ˜Kšœ?™?—K˜�š
œžœžœžœžœžœžœ˜AK™9—Kš¡œ˜Kš¡œ˜Kš¡œ˜Kš¡œ˜K˜�š¡œžœžœ˜OKšœ'™'KšœÇ™Ç—š¡
œžœ*˜=Kšœ¹™¹——™š¡œžœžœ˜7Kšžœ:˜@K™$K™�—Kš¡œžœžœ˜Kš¡œžœžœ˜KK˜�—Kš¡	œžœžœ ˜MKš¡	œžœžœ ˜MK˜�Kšœz™zš
¡œžœ#žœžœžœ˜kKšœ7˜7Kšœ(˜(K˜——™%šœžœžœ
žœžœžœžœžœ˜RKšœ™Kšž	œn™w—š¡œžœžœžœžœ
žœžœžœžœžœžœ˜®Kšœç™çK™DK™S——™KšÏbœQ¢œs¢œu¢œ™ÿK˜�Kšœžœ }˜—š¡œžœ4žœžœ˜`Kšœ<™<Kšœžœžœžœžœžœžœžœžœ˜ŠK˜�—š¡œžœ4žœžœ˜nKšœm™mK˜�—š¡
œžœ8žœžœ˜`Kšœ8™8Kšœ
žœžœžœžœžœžœžœžœ˜zK˜�—š¡œžœDžœžœ˜rKšœj™jKšœžœžœžœžœ	žœžœžœžœ˜€——™&Kš
¡	œžœžœžœžœ˜<Kš¡œžœžœ˜0Jš¡œžœžœ˜—J˜�Jšžœ˜—�…—����v��-ø��