SisyphImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Created by Pradeep Sindhu and Bertrand Serlet, December 3, 1985 0:03:15 am PST
Pradeep Sindhu February 4, 1986 4:06:39 pm PST
Barth, January 13, 1986 3:35:49 pm PST
DIRECTORY
AMTypes USING [TV, TVEqual],
AMBridge USING [SomeRefFromTV, TVForFrame, TVForReferent],
AMModel USING [Context],
AMModelBridge USING [ContextForFrame],
CD, CDCells, CDDirectory, CDInstances, CDLayers, CDPinObjects, CDProperties, CDRects, CDSatellites, CDSymbolicObjects, CDTexts,
CMosB,
Core, CoreClasses, CoreOps, CoreProperties,
IO,
Interpreter USING [Evaluate],
List,
PrincOpsUtils,
PW,
PWPins,
Rope,
Sinix,
Sisyph,
SymTab,
TerminalIO;
SisyphImpl: CEDAR PROGRAM    
IMPORTS AMBridge, AMModelBridge, AMTypes, CDCells, CDDirectory, CDInstances, CDLayers, CDPinObjects, CDProperties, CDRects, CDSatellites, CDTexts, CMosB, CoreClasses, CoreOps, CoreProperties, Interpreter, IO, List, PrincOpsUtils, PW, PWPins, Rope, Sinix, SymTab, TerminalIO
EXPORTS Sisyph
SHARES CDCells, CDPinObjects, CDRects, CDTexts =
BEGIN
OPEN Sisyph;
Design
A CD instance is represented by the tuple <obj, propList>, where obj is the object corresponding to the instance, and propList is the property list of the instance. An instance may have arguments that control the result of the extraction. These arguments may appear in any one of three places: (1) as "satellites" (or text objects) attatched to the instance, (2) as text inside the instance property $SisyphArguments, or (3) as text inside the object property $SisyphArguments.
Extraction begins at the top-level procedure ExtractSchematic. Extract schematic first evaluates the arguments of the object passed to it, and then calls Sinix.Extract, ExtractIcon, or ExtractWireIcon, depending on the Sisyph type of the object passed to it. Evaluation proceeds in an environment consisiting of a Sisyph context and an interpreter context. The Sisyph context is simply a SymTab containing <name> <value> pairs, while the interpreter context is the local frame of the caller of Eval. The evaluation always looks first at the Sisyph context and then at the interpreter context. Note that the interpreter context includes in it a definition of all variables that are visible (statically) from within Eval, and all global frames and interface records currently loaded in the Cedar world.
During extraction certain global names are treated specially. When a wire with its full name equal to one of the global names is encountered, the wire is promoted to be a public of the cellType in which it lies. When this cellType, say A, is used within another cellType, say B, the same global name also gets promoted to be a public of B. This promotion continues till a cellType is encountered in which a piece of geometry with the global name as its name touches the interest rect of the object corresponding to the cellType. The global names are kept as a list of rope in the Sisyph variable globalNames. Global wires are restricted to be atomic.
The following two invariants are checked when constructing a CellType C for an Iconic Cell IC.
(1) For each symbolic object (pin) inside IC there must be a wire in C.public one of whose full names is the same as the symbolic object's name.
(2) C.public must satisfy the property P(w): the wire w has a symbolic object (pin) in IC whose name is the same as one of w's full names, or each of w's sons satisfies P.
The following two invariants are checked when constructing a wire W for an Iconic Wire IW.
(1) For each symbolic object (pin) inside IW there must be a wire in W one of whose full names is the same as the symbolic object's name.
(2) W must satisfy the property P(w): the wire w has a symbolic object (pin) in IC whose name is the same as one of w's full names, or each of w's sons satisfies P.
Extraction
expressionsProp: PUBLIC ATOM ← $SisyphExpressions;
designRope: PUBLIC ROPE ← "design";
iconCoreRope: PUBLIC ROPE ← "iconCore";
wireCoreRope: PUBLIC ROPE ← "wireCore";
nameRope: PUBLIC ROPE ← "name";
globalNamesRope: PUBLIC ROPE ← "globalNames";
corePropsRope: PUBLIC ROPE ← "coreProps";
iconicProp: PUBLIC ATOMPW.RegisterProp[$SisyphIcon, TRUE];
iconicCell: PUBLIC ATOM ← $SisyphIconicCell;
iconicWire: PUBLIC ATOM ← $SisyphIconicWire;
extractProcProp: PUBLIC ATOMPW.RegisterProp[$SisyphExtractProcProp, TRUE];
ignoreMeProp: PUBLIC ATOM ← $SisyphIgnoreMe;
cachedResultProp: PUBLIC ATOMPW.RegisterProp[$SisyphCachedResult, FALSE, TRUE];
defaultGlobalNames: PUBLIC LIST OF ROPELIST["Vdd", "Gnd"];
Cache: TYPE = REF CacheRec;
CacheRec: TYPE = RECORD [
cx: Context ← NIL,
cellType: CellType ← NIL,
wire: Wire ← NIL,
category: ATOM ← $Device
];
This is the top-level extract proc. It evaluates the arguments to the schematic and then calls either ExtractIcon or Sinix.ExtractCell to do its job.
ExtractSchematic: PUBLIC Sinix.ExtractProc = BEGIN
inheritedContext: Context ← NARROW [userData];
iconType: ATOMNARROW [CDProperties.GetPropFromObject[obj, iconicProp]];
cachedResult: Cache ← NARROW [CDProperties.GetPropFromObject[obj, cachedResultProp]];
cx: Context ← Copy[inheritedContext];
props: Core.Properties;
InitLocalVariables[cx];
EvaluateExpressions[cx, obj, properties];
props ← GetCoreProps[cx];
IF cachedResult#NIL AND Equal[cx, cachedResult.cx] THEN {
cellType ← cachedResult.cellType;
wire ← cachedResult.wire;
category ← cachedResult.category;
TerminalIO.WriteF["Using cached result for cell %g\n", IO.rope[CDDirectory.Name[obj]]];
RETURN
};
SELECT TRUE FROM
iconType=NIL => {
globalWires: Wires ← GlobalWires[cx];
[cellType, wire, category] ← Sinix.ExtractCell[obj, extractProcProp, properties, cx];
ProcessGlobalWires[cellType, globalWires];
IF props#NIL THEN cellType.properties ← PutCoreProps[cellType.properties, props]
};
iconType=iconicCell => {
cellType ← ExtractIcon[obj, cx]; wire ← NIL; category ← $Device;
IF props#NIL THEN cellType.properties ← PutCoreProps[cellType.properties, props]
};
iconType=iconicWire => {
cellType ← NIL; wire ← ExtractWireIcon[obj, cx]; category ← $Wire;
IF props#NIL THEN wire.properties ← PutCoreProps[wire.properties, props]
};
ENDCASE => ERROR;
cachedResult ← NEW[CacheRec ← [cx: cx, cellType: cellType, wire: wire, category: category]];
CDProperties.PutPropOnObject[obj, cachedResultProp, cachedResult];
END;
ExtractWire: PUBLIC Sinix.ExtractProc = BEGIN
inheritedContext: Context ← NARROW [userData];
cx: Context ← Copy[inheritedContext];
name: ROPE;
props: Core.Properties;
IF obj.class#CDRects.bareRectClass THEN ERROR;
IF obj.layer#CMosB.comment THEN ERROR;
InitLocalVariables[cx];
EvaluateExpressions[cx, obj, properties];
wire ← GetWireCore[cx];
name ← GetName[cx];
props ← GetCoreProps[cx];
IF wire=NIL THEN wire ← CoreOps.CreateWire[name: name];
Sinix.AddPinsProp[wire, PWPins.NewInstance[obj]];
IF props#NIL THEN wire.properties ← PutCoreProps[wire.properties, props];
category ← $Wire;
END;
ExtractSchematicByName: PUBLIC PROC [name: ROPE, cx: Context] RETURNS [CellType] = BEGIN
design: CD.Design ← GetDesign[cx];
RETURN [
ExtractSchematic[
obj: CDDirectory.Fetch[design, name].object,
extractProcProp: extractProcProp,
userData: cx
].cellType
];
END;
IsResultExpression: PUBLIC PROC [expr: ROPE] RETURNS [BOOL] = {
RETURN [Rope.Match["*iconCore*←*", expr] OR Rope.Match["*wireCore*←*", expr]]
};
ExtractNull: Sinix.ExtractProc = {
category ← $Null;
};
This proc is called for cell icons. If a core definition is found then it is returned, otherwise a core cell of class Unspecified is returned.
Note that CDSymbolicObjects.EnumerateSymbolicObs enumerates all instances not just the ones on the interest rect, so pins internal to the icon will also count.
OldExtractIcon: PROC [icon: Object, cx: Context] RETURNS [cellType: CellType] = BEGIN
iconPins: LIST OF CD.Instance ← NIL;
ProcessEachSymbInst: CDSymbolicObjects.InstEnumerator = {
OldDecoratePublic[cellType.public, inst];
iconPins ← CONS[inst, iconPins];
};
cellType ← GetIconCore[cx];
IF cellType=NIL
THEN {
wires: Wires ← NIL;
CreateWireForEachSymbInst: CDSymbolicObjects.InstEnumerator = {
name: ROPE ← CDSymbolicObjects.GetName[inst];
FOR wl: Wires ← wires, wl.rest WHILE wl#NIL DO
IF CoreOps.IsFullWireName[wl.first, name] THEN RETURN;
ENDLOOP;
wires ← CONS [CoreOps.CreateWire[name: name], wires];
};
[] ← CDSymbolicObjects.EnumerateSymbolicObs[icon, CreateWireForEachSymbInst];
cellType ← CoreOps.CreateCellType[class: CoreClasses.unspecifiedCellClass, public: CoreOps.CreateWire[wires], name: CDDirectory.Name[icon]];
}
ELSE {
cellType ← CoreClasses.CreateIdentity[cellType: cellType, name: CDDirectory.Name[icon]];
};
[] ← CDSymbolicObjects.EnumerateSymbolicObs[icon, ProcessEachSymbInst];
CheckWireForMatchingSymbInst[cellType.public, iconPins, GlobalWires[cx]];
END;
This proc is called for cell icons. If a core definition is found then it is returned, otherwise a core cell of class Unspecified is returned.
ExtractIcon: PROC [icon: Object, cx: Context] RETURNS [cellType: CellType] = BEGIN
iconCT: CellType;
ProcessEachIconPublic: CoreOps.EachWireProc = {
DecoratePublic[cellType.public, wire];
};
MarkInvisibleInstances[icon];
iconCT ← Sinix.ExtractCell[icon, extractProcProp, NIL, cx].cellType;
Compute core for the schematic
cellType ← GetIconCore[cx];
IF cellType=NIL
THEN {
cellType ← CoreOps.CreateCellType[class: CoreClasses.unspecifiedCellClass, public: iconCT.public, name: CDDirectory.Name[icon]];
}
ELSE {
cellType ← CoreClasses.CreateIdentity[cellType: cellType, name: CDDirectory.Name[icon]];
};
[] ← CoreOps.VisitWire[iconCT.public, ProcessEachIconPublic];
CheckWireForMatchingWire[cellType.public, iconCT.public, GlobalWires[cx]];
IF ~CheckAndDecorate[iconCT.public, cellType.public, GlobalWires[cx]] THEN {
TerminalIO.WriteF["\n** Error: drawn public and result public for cell icon %g don't conform\n", IO.rope[CDDirectory.Name[icon]]];
TerminalIO.WriteF["Drawn public is:"];
CoreOps.PrintWire[iconCT.public, TerminalIO.TOS[]];
TerminalIO.WriteF["\n\nResult public is:"];
CoreOps.PrintWire[cellType.public, TerminalIO.TOS[]];
ERROR
}
END;
This proc is called for wire icons. If a core definition is found it is returned, otherwise an error is signalled. As for cell icons, pins provide the attatchment points to the wire.
Note that CDSymbolicObjects.EnumerateSymbolicObs enumerates all instances not just the ones on the interest rect, so pins internal to the icon also count.
OldExtractWireIcon: PROC [icon: Object, cx: Context] RETURNS [wire: Wire] = BEGIN
iconPins: LIST OF CD.Instance ← NIL;
ProcessEachSymbInst: CDSymbolicObjects.InstEnumerator = {
OldDecoratePublic[wire, inst];
iconPins ← CONS[inst, iconPins];
};
wire ← GetWireCore[cx];
IF wire=NIL THEN ERROR;
wire ← CoreOps.SetFullWireNames[wire];
[] ← CDSymbolicObjects.EnumerateSymbolicObs[icon, ProcessEachSymbInst];
CheckWireForMatchingSymbInst[wire, iconPins];
END;
This proc is called for wire icons. If a core definition is found it is returned, otherwise an error is signalled. As for cell icons, pins provide the attatchment points to the wire.
ExtractWireIcon: PROC [icon: Object, cx: Context] RETURNS [result: Wire] = BEGIN
iconCT: CellType;
iconWire: Wire;
ProcessEachIconPublic: CoreOps.EachWireProc = {
DecoratePublic[result, wire];
};
MarkInvisibleInstances[icon];
iconCT ← Sinix.ExtractCell[icon, extractProcProp, NIL, cx].cellType;
iconWire ← iconCT.public[0];
CoreProperties.PutWireProp[iconWire, $CoreFullWireName, NIL];
iconWire ← CoreOps.SetFullWireNames[iconWire];
result ← GetWireCore[cx];
IF result=NIL THEN ERROR;
result ← CoreOps.SetFullWireNames[result];
[] ← CoreOps.VisitWire[iconWire, ProcessEachIconPublic];
CheckWireForMatchingWire[result, iconWire];
IF ~CheckAndDecorate[iconWire, result] THEN {
TerminalIO.WriteF["\n** Error: drawn wire and result wire for wire icon %g don't conform\n", IO.rope[CDDirectory.Name[icon]]];
TerminalIO.WriteF["Drawn wire is:"];
CoreOps.PrintWire[iconWire, TerminalIO.TOS[]];
TerminalIO.WriteF["\n\nResult wire is:"];
CoreOps.PrintWire[result, TerminalIO.TOS[]];
ERROR
}
END;
Context Handling Procedures
InitLocalVariables: PUBLIC PROC [cx: Context] = BEGIN
IF cx=NIL THEN ERROR;
Store[cx, wireCoreRope, NEW [Wire ← NIL]];
Store[cx, iconCoreRope, NEW [CellType ← NIL]];
Store[cx, nameRope, NEW [ROPENIL]];
Store[cx, corePropsRope, NEW [Core.Properties ← NIL]]
END;
Create: PUBLIC PROC [design: CD.Design, globalNames: LIST OF ROPE ← defaultGlobalNames] RETURNS [cx: Context] = BEGIN
cx ← SymTab.Create[];
Store[cx, designRope, NEW [CD.Design ← design]];
Store[cx, globalNamesRope, NEW [LIST OF ROPE ← globalNames]];
InitLocalVariables[cx];
END;
Copy: PUBLIC PROC [cx: Context] RETURNS [newCx: Context] = BEGIN
CopyItem: SymTab.EachPairAction = {
[] ← SymTab.Store[newCx, key, val];
quit ← FALSE;
};
IF cx=NIL THEN ERROR;
newCx ← SymTab.Create[];
[] ← SymTab.Pairs[cx, CopyItem];
END;
Store: PUBLIC PROC [cx: Context, var: ROPE, value: REFNIL] = BEGIN
[] ← SymTab.Store[cx, var, TVFromRef[value]];
END;
Eval: PUBLIC PROC [cx: Context, expr: ROPE, cedarCx: AMModel.Context ← NIL] = TRUSTED BEGIN
result: AMTypes.TV;
errorRope: ROPE;
noResult: BOOL;
IF cedarCx=NIL THEN cedarCx ← AMModelBridge.ContextForFrame[
AMBridge.TVForFrame[
PrincOpsUtils.GetReturnFrame[]
]
];
[result, errorRope, noResult] ← Interpreter.Evaluate[rope: expr, context: cedarCx, symTab: cx];
IF errorRope # NIL THEN ERROR;
END;
Equal: PROC [cx1, cx2: Context] RETURNS [BOOL] = {
IsASubset: PROC [a, b: Context] RETURNS [result: BOOL] = {
CheckExistenceInb: SymTab.EachPairAction = {
found: BOOL;
bVal: SymTab.Val;
[found, bVal] ← SymTab.Fetch[b, key];
IF ~found THEN {result ← FALSE; RETURN};
IF ~AMTypes.TVEqual[bVal, val] THEN result ← FALSE;
};
result ← TRUE;
[] ← SymTab.Pairs[a, CheckExistenceInb]
};
IF SymTab.GetSize[cx1]#SymTab.GetSize[cx2] THEN RETURN [FALSE];
IF IsASubset[cx1, cx2] AND IsASubset[cx2, cx1] THEN RETURN [TRUE] ELSE RETURN [FALSE]
};
Private Procedures
The order of evaluation is: (1) expressions specified in expressionsProp property of object; (2) arguments specified in expressionsProp property of instance; (3) arguments specified in satellites of instance. Thus satellites take precedence over instance property exprs, which take precedence over object property exprs. The evaluation is performed in two passes: the second pass handles expressions of the form "wireCore ←" and "iconCore ←", while the first pass handles all others. When evaluating satellite exprs, an expression containing "←" is evaluated, an expression containing a ":" is assumed to be a property, while all other expressions are assumed to be a name.
EvaluateExpressions: PROC [cx: Context, obj: CD.Object, propList: CD.PropList] = {
objArgs: LIST OF ROPENARROW[CDProperties.GetPropFromObject[obj, expressionsProp]];
instArgs: LIST OF ROPENARROW[CDProperties.GetPropFromList[propList, expressionsProp]];
satArgs: LIST OF ROPE ← CDSatellites.GetSatelliteRopes[propList];
result: ROPENIL;
WHILE objArgs#NIL DO
IF IsResultExpression[objArgs.first]
THEN result ← objArgs.first
ELSE Eval[cx, objArgs.first];
objArgs ← objArgs.rest
ENDLOOP;
WHILE instArgs#NIL DO
IF IsResultExpression[instArgs.first]
THEN result ← instArgs.first ELSE
Eval[cx, instArgs.first];
instArgs ← instArgs.rest
ENDLOOP;
WHILE satArgs#NIL DO
SELECT TRUE FROM
Rope.Find[s1: satArgs.first, s2: "←"] # -1 => IF IsResultExpression[satArgs.first] THEN result ← satArgs.first ELSE Eval[cx, satArgs.first];
Rope.Find[s1: satArgs.first, s2: ":"] # -1 => {
atomRope: ROPE ← Rope.Substr[satArgs.first, 0, Rope.Find[s1: satArgs.first, s2: ":"]];
valueRope: ROPE ← Rope.Substr[satArgs.first, 1+Rope.Find[s1: satArgs.first, s2: ":"]];
satArgs.first ← Rope.Cat["coreProps ← CoreProperties.PutProp[coreProps, $",
atomRope, ", ", valueRope, "]"];
Eval[cx, satArgs.first]
};
ENDCASE => Store[cx, nameRope, NEW [ROPE ← satArgs.first]];
satArgs ← satArgs.rest;
ENDLOOP;
IF result#NIL THEN Eval[cx, result];
};
Finds the wire in public that has the same full name as inst and puts inst as the pinsProp on that wire. There must be exactly one such wire, or there is an error.
OldDecoratePublic: PROC [public: Wire, inst: CD.Instance] = BEGIN
pinName: ROPE ← CDSymbolicObjects.GetName[inst];
matchingWires: Wires ← NIL;
FindWireWithMatchingName: CoreOps.EachWireProc = {
IF CoreOps.IsFullWireName[wire, pinName] THEN matchingWires ← CONS [wire, matchingWires];
};
[] ← CoreOps.VisitWire[public, FindWireWithMatchingName];
IF matchingWires=NIL THEN ERROR; -- no public wire with this name
IF matchingWires.rest#NIL THEN ERROR; -- multiple public wires with this name
Sinix.AddPinPropOnWire[matchingWires.first, inst];
END;
Finds the wire in public that has the same full name as iconWire and puts the pinsProp of iconWire onto the pinsProp of the wire found. There must be exactly one such wire, or there is an error.
DecoratePublic: PROC [public, iconWire: Wire] = BEGIN
iconWireNames: LIST OF ROPE ← CoreOps.GetFullWireNames[iconWire];
iconWirePinList: LIST OF CD.Instance;
matchingWires: Wires ← NIL;
FindWireWithMatchingName: CoreOps.EachWireProc = {
FOR l: LIST OF ROPE ← iconWireNames, l.rest WHILE l#NIL DO
IF CoreOps.IsFullWireName[wire, l.first]
THEN {matchingWires ← CONS [wire, matchingWires]; RETURN}
ENDLOOP;
IF iconWireNames=NIL AND CoreOps.IsFullWireName[wire, NIL]
THEN matchingWires ← CONS [wire, matchingWires];
};
[] ← CoreOps.VisitWire[public, FindWireWithMatchingName];
IF matchingWires=NIL THEN ERROR; -- no public wire with this name
IF matchingWires.rest#NIL THEN ERROR; -- multiple public wires with this name
iconWirePinList ← NARROW [CoreProperties.GetWireProp[iconWire, Sinix.pinsProp]];
CoreProperties.PutWireProp[matchingWires.first, Sinix.pinsProp, iconWirePinList];
END;
CheckWireForMatchingSymbInst: PROC [wire: Wire, symbInstList: LIST OF CD.Instance, globalWires: Wires ← NIL] = {
If wire is promotable to public then a matching symbinst isn't necessary
FOR nl: LIST OF ROPE ← CoreOps.GetFullWireNames[wire], nl.rest WHILE nl#NIL DO
IF FindGlobalWire[nl.first, globalWires]#NIL AND CoreProperties.GetWireProp[wire, Sinix.pinsProp]=NIL THEN RETURN;
ENDLOOP;
FOR l: LIST OF CD.Instance ← symbInstList, l.rest WHILE l#NIL DO
IF CoreOps.IsFullWireName[wire, CDSymbolicObjects.GetName[l.first]] THEN RETURN;
ENDLOOP;
IF wire.size=0 THEN ERROR ELSE FOR i: NAT IN [0..wire.size) DO
CheckWireForMatchingSymbInst[wire[i], symbInstList, globalWires];
ENDLOOP;
};
CheckWireForMatchingWire: PROC [in, wire: Wire, globalWires: Wires ← NIL] = {
inNames: LIST OF ROPE ← CoreOps.GetFullWireNames[in];
If in is promotable to public then a matching symbinst isn't necessary
FOR nl: LIST OF ROPE ← inNames, nl.rest WHILE nl#NIL DO
IF FindGlobalWire[nl.first, globalWires]#NIL AND Sinix.GetPinsProp[in]=NIL THEN RETURN;
ENDLOOP;
FOR nl: LIST OF ROPE ← inNames, nl.rest WHILE nl#NIL DO
IF FindWire[nl.first, wire]#NIL THEN RETURN;
ENDLOOP;
IF inNames=NIL AND FindWire[NIL, wire]#NIL THEN RETURN;
IF in.size=0 THEN ERROR ELSE FOR i: NAT IN [0..in.size) DO
CheckWireForMatchingWire[in[i], wire, globalWires];
ENDLOOP;
};
CheckAndDecorate: PROC [dp, rp: Wire, globalWires: Wires ← NIL] RETURNS [BOOL]= {
dpInterfaceGeometry: LIST OF CD.Instance;
loraSize: NAT;
WireToLORA: PROC [wire: Wire, stripGlobalWires: BOOL] RETURNS [lora: List.LORA] = {
lora ← NIL; loraSize ← 0;
FOR i: NAT IN [0..wire.size) DO
name: ROPE ← CoreOps.GetShortWireName[wire.elements[i]];
IF stripGlobalWires AND FindGlobalWire[name, globalWires]#NIL THEN LOOP;
lora ← CONS [wire.elements[i], lora]; loraSize ← loraSize+1
ENDLOOP;
};
CompareWires: List.CompareProc = {
w1: Wire ← NARROW [ref1];
w2: Wire ← NARROW [ref2];
RETURN [Rope.Compare[CoreOps.GetShortWireName[w1], CoreOps.GetShortWireName[w2]]]
};
IF ~Rope.Equal[CoreOps.GetShortWireName[dp], CoreOps.GetShortWireName[rp]]
THEN RETURN [FALSE];
IF dp.size > 0 THEN {
dpElements: List.LORA ← List.Sort[WireToLORA[dp, FALSE], CompareWires];
rpElements: List.LORA ← List.Sort[WireToLORA[rp, TRUE], CompareWires];
IF dp.size#loraSize THEN RETURN [FALSE];
FOR i: NAT IN [0..dp.size) DO
dpWire: Wire ← NARROW [dpElements.first];
rpWire: Wire ← NARROW [rpElements.first];
IF ~CheckAndDecorate[dpWire, rpWire] THEN RETURN [FALSE];
dpElements ← dpElements.rest;
rpElements ← rpElements.rest
ENDLOOP;
};
dpInterfaceGeometry ← NARROW [CoreProperties.GetWireProp[dp, Sinix.pinsProp]];
CoreProperties.PutWireProp[rp, Sinix.pinsProp, dpInterfaceGeometry];
RETURN [TRUE];
};
MarkInvisibleInstances: PROC [obj: Object] = {
cellPtr: CD.CellPtr ← NARROW[obj.specificRef];
FOR l: LIST OF CD.Instance ← cellPtr.contents, l.rest WHILE l#NIL DO
IF CDProperties.GetPropFromList[l.first.properties, ignoreMeProp]#NIL
THEN CDProperties.PutProp[l.first, extractProcProp, NEW[Sinix.ExtractProc ← ExtractNull]]
ENDLOOP;
};
This proc causes global wires to be promoted to the public of cellType. The implementation is tricky, so don't mess with it unless you know what you're doing.
ProcessGlobalWires: PROC [cellType: CellType, globalWires: Wires] = BEGIN
recordCell: CoreClasses.RecordCellType ← NARROW[cellType.data];
toBeMadePublic: Wires ← NIL;
toBeDeleted: Wires ← NIL;
NewActual: PROC [instActual, instPublic: Wire] RETURNS [Wire] = BEGIN
instActualGeometry: LIST OF CD.Instance ← NARROW [CoreProperties.GetWireProp[instActual, Sinix.wireGeometryProp]];
IF instActual.size#instPublic.size THEN ERROR;
FOR i: NAT IN [0..instActual.size) DO
instActual[i] ← NewActual[instActual[i], instPublic[i]];
ENDLOOP;
FOR nl: LIST OF ROPE ← CoreOps.GetFullWireNames[instPublic], nl.rest WHILE nl#NIL DO
globalWithInstPublicName: Wire ← FindGlobalWire[nl.first, globalWires];
internalWithInstPublicName: Wire ← FindWire[nl.first, recordCell.internal];
publicWithInstPublicName: Wire ← FindWire[nl.first, cellType.public];
IF instActualGeometry=NIL AND globalWithInstPublicName#NIL THEN {
IF publicWithInstPublicName=NIL
THEN {
IF internalWithInstPublicName#NIL
THEN {
toBeMadePublic ← CONS [internalWithInstPublicName, toBeMadePublic];
toBeDeleted ← CONS[instActual, toBeDeleted];
RETURN [internalWithInstPublicName]
}
ELSE {
toBeMadePublic ← CONS [globalWithInstPublicName, toBeMadePublic];
recordCell.internal ← GrowWire[recordCell.internal, LIST [globalWithInstPublicName]];
toBeDeleted ← CONS[instActual, toBeDeleted];
RETURN [globalWithInstPublicName]
}
}
ELSE {
toBeDeleted ← CONS[instActual, toBeDeleted];
RETURN [publicWithInstPublicName]
}
};
ENDLOOP;
RETURN [instActual]
END;
CheckIfWireIsToBeMadePublic: CoreOps.EachWireProc = BEGIN
FOR nl: LIST OF ROPE ← CoreOps.GetFullWireNames[wire], nl.rest WHILE nl#NIL DO
IF FindGlobalWire[nl.first, globalWires]#NIL AND FindWire[nl.first, cellType.public]=NIL
THEN {toBeMadePublic ← CONS [wire, toBeMadePublic]; RETURN}
ENDLOOP;
END;
For each instance check if any part of its actual should be promoted
FOR i: NAT IN [0..recordCell.size) DO
inst: CoreClasses.CellInstance ← recordCell.instances[i];
inst.actual ← NewActual[inst.actual, inst.type.public];
ENDLOOP;
Delete toBeDeleted wires from the internal
FOR l: Wires ← toBeDeleted, l.rest WHILE l#NIL DO
recordCell.internal ← DeleteWire[l.first, recordCell.internal];
ENDLOOP;
Check if any part of the internal of cellType should be promoted
[] ← CoreOps.VisitWire[recordCell.internal, CheckIfWireIsToBeMadePublic];
toBeMadePublic ← RemoveDuplicates[toBeMadePublic];
Remove Sinix.pinsProp from all wires to be made public
FOR w: Wires ← toBeMadePublic, w.rest WHILE w#NIL DO
CoreProperties.PutWireProp[w.first, Sinix.pinsProp, NIL]
ENDLOOP;
cellType.public ← GrowWire[cellType.public, toBeMadePublic];
END;
RemoveDuplicates: PROC [wires: Wires] RETURNS [result: Wires] = BEGIN
result ← NIL;
FOR w: Wires ← wires, w.rest WHILE w#NIL DO
found: BOOLFALSE;
FOR r: Wires ← result, r.rest WHILE r#NIL DO
IF w.first=r.first THEN {found ← TRUE; EXIT}
ENDLOOP;
IF ~found THEN result ← CONS [w.first, result];
ENDLOOP;
END;
DeleteWire: PROC [victim, from: Wire] RETURNS [result: Wire] = BEGIN
survivors: Wires ← NIL;
IF from=victim THEN RETURN[NIL];
IF from.size=0 THEN RETURN [from];
FOR i: NAT DECREASING IN [0..from.size) DO
subResult: Wire ← DeleteWire[victim, from[i]];
IF subResult#NIL THEN survivors ← CONS [subResult, survivors];
ENDLOOP;
result ← CoreOps.CreateWire[elements: survivors, props: from.properties];
END;
Returns the wire in globalWires that has name as a short name; Note that this assumes global wires are atomic.
FindGlobalWire: PROC [name: ROPE, globalWires: Wires] RETURNS [Wire ← NIL] = BEGIN
FOR l: Wires ← globalWires, l.rest WHILE l#NIL DO
IF Rope.Equal[name, CoreOps.GetShortWireName[l.first]] THEN RETURN [l.first];
ENDLOOP;
END;
Returns the wire contained in w that has name as one of its full names.
FindWire: PROC [name: ROPE, w: Wire] RETURNS [result: Wire ← NIL] = BEGIN
ForEachWire: CoreOps.EachWireProc = {
IF CoreOps.IsFullWireName[wire, name] THEN {result ← wire; quit ← TRUE}
};
[] ← CoreOps.VisitWire[w, ForEachWire]
END;
GlobalWires: PROC [cx: Context] RETURNS [wires: Wires ← NIL] = BEGIN
globalNames: LIST OF ROPE ← GetGlobalNames[cx];
FOR names: LIST OF ROPE ← globalNames, names.rest WHILE names#NIL DO
wires ← CONS[CoreOps.CreateWire[name: names.first], wires];
ENDLOOP;
END;
Grow wire by adding in the wires from newWires to the top level of wire.
GrowWire: PROC [wire: Wire, newWires: Wires] RETURNS [result: Wire] = BEGIN
resultSize: NAT ← wire.size;
FOR w: Wires ← newWires, w.rest WHILE w#NIL DO
resultSize ← resultSize+1
ENDLOOP;
result ← CoreOps.CreateWires[resultSize, CoreOps.GetShortWireName[wire], wire.properties];
FOR i: NAT IN [0..wire.size) DO result[i] ← wire[i] ENDLOOP;
FOR i: NAT IN [wire.size..resultSize) DO
result[i] ← newWires.first; newWires ← newWires.rest;
ENDLOOP;
result ← CoreOps.SetFullWireNames[result];
END;
TouchRect: Sinix.TouchProc = {
IF instance2.ob.class#CDRects.bareRectClass THEN RETURN [Sinix.TouchRectObject[instance2, CDInstances.InstRectO[instance1], instance1.ob.layer, compareLayers]];
IF ~SilTouchRect[CDInstances.InstRectO[instance1], CDInstances.InstRectO[instance2]] THEN RETURN;
RETURN [~compareLayers OR CDLayers.AbstractToPaint[instance1.ob.layer]=CDLayers.AbstractToPaint[instance2.ob.layer]];
};
SilTouchRect: PROC [r1, r2: CD.Rect] RETURNS [BOOL] = INLINE {
Intersect: PROC [i1min, i1max, i2min, i2max: CD.Number] RETURNS [BOOL] = INLINE {
RETURN [(i1max >= i2min) AND (i2max >= i1min)];
};
Adjoin: PROC [i1min, i1max, i2min, i2max: CD.Number] RETURNS [BOOL] = INLINE {
RETURN [(i2min >= i1min AND i2min <= i1max AND i2max >= i1max) OR
(i1min >= i2min AND i1min <= i2max AND i1max >= i2max)];
};
RETURN [(Intersect[r1.x1, r1.x2, r2.x1, r2.x2] AND Adjoin[r1.y1, r1.y2, r2.y1, r2.y2]) OR (Intersect[r1.y1, r1.y2, r2.y1, r2.y2] AND Adjoin[r1.x1, r1.x2, r2.x1, r2.x2])]
};
GetCoreProps: PROC [cx: Context] RETURNS [Core.Properties] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, corePropsRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF Core.Properties]^]
ELSE ERROR
};
GetIconCore: PROC [cx: Context] RETURNS [Core.CellType] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, iconCoreRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF Core.CellType]^]
ELSE ERROR
};
GetWireCore: PROC [cx: Context] RETURNS [Core.Wire] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, wireCoreRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF Core.Wire]^]
ELSE ERROR
};
GetName: PROC [cx: Context] RETURNS [ROPE] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, nameRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF ROPE]^]
ELSE ERROR
};
GetGlobalNames: PROC [cx: Context] RETURNS [LIST OF ROPE] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, globalNamesRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF LIST OF ROPE]^]
ELSE ERROR
};
GetDesign: PROC [cx: Context] RETURNS [CD.Design] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, designRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF CD.Design]^]
ELSE ERROR
};
RefFromTV: PROC [tv: REF] RETURNS [REF] = {
IF tv=NIL THEN RETURN [NIL];
IF ~ISTYPE [tv, AMTypes.TV] THEN ERROR;
TRUSTED {RETURN [AMBridge.SomeRefFromTV[tv]]};
};
TVFromRef: PROC [ref: REF] RETURNS [AMTypes.TV] = TRUSTED {
RETURN [AMBridge.TVForReferent[ref]];
};
PutCoreProps: PROC [onto, from: Core.Properties] RETURNS [new: Core.Properties] = {
PutProp: PROC [prop: ATOM, val: REF ANY] = {
new ← CoreProperties.PutProp[new, prop, val];
};
new ← onto;
CoreProperties.Enumerate[from, PutProp];
};
Module Initialization
CDProperties.PutProp[CDCells.cellClass, extractProcProp, NEW [Sinix.ExtractProc ← ExtractSchematic]];
CDProperties.PutProp[CDCells.cellClass, Sinix.touchProcProp, NEW [Sinix.TouchProc ← Sinix.TouchCell]];
CDProperties.PutProp[CDPinObjects.pinObjectsClass, extractProcProp, NEW [Sinix.ExtractProc ← Sinix.ExtractPin]];
CDProperties.PutProp[CDPinObjects.pinObjectsClass, Sinix.touchProcProp, NEW [Sinix.TouchProc ← Sinix.TouchPin]];
CDProperties.PutProp[CDRects.bareRectClass, extractProcProp, NEW [Sinix.ExtractProc ← ExtractWire]];
CDProperties.PutProp[CDRects.bareRectClass, Sinix.touchProcProp, NEW [Sinix.TouchProc ← TouchRect]];
CDProperties.PutProp[CDTexts.textClass, extractProcProp, NEW [Sinix.ExtractProc ← ExtractNull]];
END.