DIRECTORY
AMTypes USING [TV, TVEqual],
AMBridge USING [SomeRefFromTV, TVForFrame, TVForReferent],
AMModel USING [Context],
AMModelBridge USING [ContextForFrame],
CD, CDCells, CDDirectory, CDEvents, CDInstances, CDLayers, CDProperties, CDRects, CDSatellites, CDSymbolicObjects, CDTexts,
Core, CoreClasses, CoreOps, CoreProperties,
IO,
Interpreter USING [Evaluate],
List,
PrincOpsUtils,
PW,
PWPins,
Rope,
RopeList,
Sinix,
Sisyph,
SymTab,
TerminalIO;
SisyphImpl:
CEDAR
PROGRAM
IMPORTS AMBridge, AMModelBridge, AMTypes, CDCells, CDDirectory, CDEvents, CDInstances, CDLayers, CDProperties, CDRects, CDSatellites, CDSymbolicObjects, CDTexts, CoreClasses, CoreOps, CoreProperties, Interpreter, IO, List, PrincOpsUtils, PW, PWPins, Rope, RopeList, Sinix, SymTab, TerminalIO
EXPORTS Sisyph
SHARES CDCells, CDRects, CDSymbolicObjects, 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, ExtractCellIcon, 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 ← PW.RegisterProp[$SisyphExpressions, TRUE];
designRope: PUBLIC ROPE ← "design";
cellIconRope: PUBLIC ROPE ← "cI";
wireIconRope: PUBLIC ROPE ← "wI";
wireRope: PUBLIC ROPE ← "wire";
nameRope: PUBLIC ROPE ← "name";
globalNamesRope: PUBLIC ROPE ← "globalNames";
corePropsRope: PUBLIC ROPE ← "coreProps";
coreInstPropsRope: PUBLIC ROPE ← "coreInstProps";
cdObjRope: PUBLIC ROPE ← "cdObj";
iconicProp: PUBLIC ATOM ← PW.RegisterProp[$SisyphIcon, TRUE];
iconicCell: PUBLIC ATOM ← $SisyphIconicCell;
iconicWire: PUBLIC ATOM ← $SisyphIconicWire;
ignoreMeProp:
PRIVATE
ATOM ←
PW.RegisterProp[$SisyphIgnoreMe,
TRUE];
property whose presence indicates that the instance should be ignored during extraction. Present for backward compatibility only. Use $ExtractNull instead
parmNamesProp: PUBLIC ATOM ← PW.RegisterProp[$SisyphParmNames, TRUE];
cacheProp: PUBLIC ATOM ← PW.RegisterProp[$SisyphCache, FALSE, TRUE];
cachePropsProp: ATOM ← PW.RegisterProp[$SisyphCacheProps, FALSE, TRUE];
defaultGlobalNames: PUBLIC LIST OF ROPE ← LIST["Vdd", "Gnd"];
sisyphMode:
PUBLIC Sinix.Mode ←
NEW [Sinix.ModeRec ← [
name: "Sisyph",
extractProcProp: PW.RegisterProp[$SisyphExtractProc, TRUE, TRUE],
pinsProp: CoreProperties.RegisterProperty[$SisyphPins, CoreProperties.Props[[CoreProperties.propPrint, CoreProperties.PropDontPrint]]],
wireGeometryProp: CoreProperties.RegisterProperty[$SisyphWireGeometry, CoreProperties.Props[[CoreProperties.propCopy, CoreProperties.PropDoCopy], [CoreProperties.propPrint, CoreProperties.PropDontPrint]]],
instanceProp: CoreProperties.RegisterProperty[$SisyphInstance, CoreProperties.Props[[CoreProperties.propCopy, CoreProperties.PropDoCopy], [CoreProperties.propPrint, CoreProperties.PropDontPrint]]],
equalProc: ResultEqual,
cacheProp: cacheProp,
cachePropsProp: cachePropsProp
]];
This is the top-level extract proc. It evaluates the arguments to the schematic and then calls either ExtractCellIcon or Sinix.ExtractCell to do its job.
ExtractSchematic: Sinix.ExtractProc =
BEGIN
inheritedContext: Context ← NARROW [userData];
cx: Context ← Copy[inheritedContext];
coreProps: Core.Properties;
resultRope: ROPE;
InitLocalVariables[cx, obj];
resultRope ← EvaluateParameters[cx, obj, properties];
EvaluateResult[cx, resultRope];
coreProps ← GetCoreProps[cx];
props ← GetCoreInstProps[cx];
SELECT
TRUE
FROM
Rope.Match["*cI*←*", resultRope] => {
cellType: CellType ← ExtractCellIcon[obj, cx];
IF coreProps#NIL THEN cellType.properties ← PutCoreProps[cellType.properties, coreProps];
result ← cellType;
};
Rope.Match["*wI*←*", resultRope] => {
wire: Wire ← ExtractWireIcon[obj, cx];
IF coreProps#NIL THEN wire.properties ← PutCoreProps[wire.properties, coreProps];
result ← wire;
};
Rope.Match["*wire*←*", resultRope] => ERROR;
ENDCASE => {
cellType: CellType;
name: ROPE ← GetName[cx];
globalWires: Wires ← GlobalWires[cx];
[result] ← Sinix.ExtractCell[obj, sisyphMode, properties, cx];
cellType ← NARROW [result];
ProcessGlobalWires[cellType, globalWires];
IF name=NIL THEN name ← CDNameToCTName[CDDirectory.Name[obj], ".sch"];
cellType ← CoreOps.SetCellTypeName[cellType, name];
IF coreProps#NIL THEN cellType.properties ← PutCoreProps[cellType.properties, coreProps];
SortInstances[cellType, mode, obj];
};
END;
ExtractWire: Sinix.ExtractProc =
BEGIN
wire: Wire;
inheritedContext: Context ← NARROW [userData];
cx: Context ← Copy[inheritedContext];
name: ROPE;
coreInstProps: Core.Properties;
geometry: CD.Instance ← PWPins.NewInstance[obj];
IF obj.class#CDRects.bareRectClass THEN ERROR;
IF obj.layer#CD.commentLayer THEN ERROR;
InitLocalVariables[cx, obj];
EvaluateResult[cx, EvaluateParameters[cx, obj, properties]];
wire ← GetWireCore[cx];
name ← GetName[cx];
coreInstProps ← GetCoreInstProps[cx];
IF wire=NIL THEN wire ← CoreOps.CreateWire[name: name];
CDProperties.PutInstanceProp[geometry, Sinix.touchProcProp, NEW [Sinix.TouchProc ← TouchRect]];
Sinix.AddPinsProp[mode, wire, geometry];
IF coreInstProps#NIL THEN wire.properties ← PutCoreProps[wire.properties, coreInstProps];
result ← wire;
END;
ES,
ExtractSchematicByName:
PUBLIC
PROC [name:
ROPE, cx: Context]
RETURNS [CellType] = {
design: CD.Design ← GetDesign[cx];
RETURN [
NARROW [Sinix.Extract[
obj: CDDirectory.Fetch[design, name].object,
mode: sisyphMode,
properties: NIL,
userData: cx
].result]];
};
IsResultExpression:
PUBLIC
PROC [expr:
ROPE]
RETURNS [
BOOL] = {
RETURN [
Rope.Match["*cI*←*", expr] OR
Rope.Match["*wI*←*", expr] OR
Rope.Match["*wire*←*", expr]
]
};
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.
ExtractCellIcon:
PROC [icon: Object, cx: Context]
RETURNS [cellType: CellType] =
BEGIN
iconCT: CellType;
name: ROPE;
iconCT ← NARROW [Sinix.ExtractCell[icon, sisyphMode, NIL, cx].result];
Compute core for the schematic
cellType ← GetCellIconCore[cx];
name ← GetName[cx];
IF cellType=
NIL
THEN {
IF name=NIL THEN name ← CDNameToCTName[CDDirectory.Name[icon], ".icon"];
cellType ← CoreOps.CreateCellType[class: CoreClasses.unspecifiedCellClass, public: iconCT.public, name: name];
}
ELSE {
IF name=NIL THEN name ← CoreOps.GetCellTypeName[cellType];
IF name=NIL THEN name ← CDNameToCTName[CDDirectory.Name[icon], ".icon"];
cellType ← CoreClasses.CreateIdentity[cellType: cellType, name: name];
};
Check public
IF ~CheckAndDecorate[iconCT.public, cellType.public, iconCT.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[wire: iconCT.public, out: TerminalIO.TOS[], level: LAST [NAT]];
TerminalIO.WriteF["\n\nResult public is:"];
CoreOps.PrintWire[wire: cellType.public, out: TerminalIO.TOS[], level: LAST [NAT]];
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.
ExtractWireIcon:
PROC [icon: Object, cx: Context]
RETURNS [result: Wire] =
BEGIN
iconCT: CellType;
iconWire: Wire;
iconCT ← NARROW [Sinix.ExtractCell[icon, sisyphMode, NIL, cx].result];
iconWire ← iconCT.public[0];
result ← GetWireIconCore[cx];
IF result=NIL THEN ERROR;
Check wire
IF ~CheckAndDecorate[iconWire, result, iconWire]
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[wire: iconWire, out: TerminalIO.TOS[], level: LAST [NAT]];
TerminalIO.WriteF["\n\nResult wire is:"];
CoreOps.PrintWire[wire: result, out: TerminalIO.TOS[], level: LAST [NAT]];
ERROR
}
END;
Context Handling Procedures
InitLocalVariables:
PUBLIC
PROC [cx: Context, obj:
CD.Object] =
BEGIN
IF cx=NIL THEN ERROR;
Store[cx, cellIconRope, NEW [CellType ← NIL]];
Store[cx, wireIconRope, NEW [Wire ← NIL]];
Store[cx, wireRope, NEW [Wire ← NIL]];
Store[cx, nameRope, NEW [ROPE ← NIL]];
Store[cx, corePropsRope, NEW [Core.Properties ← NIL]];
Store[cx, coreInstPropsRope, NEW [Core.Properties ← NIL]];
Store[cx, cdObjRope, NEW [CD.Object ← obj]]
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]];
Store[cx, "&", NEW [INT ← 0]];
InitLocalVariables[cx, NIL];
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:
REF ←
NIL] =
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;
ContextEqual:
PROC [cx1, cx2: Context, parmNames:
LIST
OF
ROPE]
RETURNS [
BOOL] = {
Returns TRUE iff a is a subset of b
IsASubset:
PROC [a, b: Context]
RETURNS [isASubset:
BOOL] = {
CheckExistenceInb: SymTab.EachPairAction = {
found: BOOL;
bVal: SymTab.Val;
quit ← FALSE;
If its a local variable then return right away
IF Rope.Equal[key, "&"] OR Rope.Equal[key, cellIconRope] OR Rope.Equal[key, wireIconRope] OR Rope.Equal[key, wireRope] OR Rope.Equal[key, nameRope] OR Rope.Equal[key, corePropsRope] OR Rope.Equal[key, coreInstPropsRope] THEN RETURN;
If its not a parameter then return right away also
IF parmNames#
NIL
THEN {
isAParm: BOOL ← FALSE;
FOR l:
LIST
OF
ROPE ← parmNames, l.rest
WHILE l#
NIL
DO
IF Rope.Equal[key, l.first] THEN isAParm ← TRUE;
ENDLOOP;
IF ~isAParm THEN RETURN;
};
It is a parameter. Check if its there in the context and equal
[found, bVal] ← SymTab.Fetch[b, key];
IF ~found THEN {isASubset ← FALSE; RETURN};
IF ~AMTypes.TVEqual[bVal, val] THEN isASubset ← FALSE;
};
isASubset ← TRUE;
[] ← SymTab.Pairs[a, CheckExistenceInb]
};
IF IsASubset[cx1, cx2] AND IsASubset[cx2, cx1] THEN RETURN [TRUE] ELSE RETURN [FALSE]
ResultEqual:
PROC [obj:
CD.Object, p1:
CD.PropList, ud1:
REF, p2:
CD.PropList, ud2:
REF]
RETURNS [
BOOL] = {
cx1: Context ← NARROW [ud1];
cx2: Context ← NARROW [ud2];
instArgs1: LIST OF ROPE ← NARROW[CDProperties.GetListProp[p1, expressionsProp]];
satArgs1: LIST OF ROPE ← CDSatellites.GetSatelliteRopes[p1];
instArgs2: LIST OF ROPE ← NARROW[CDProperties.GetListProp[p2, expressionsProp]];
satArgs2: LIST OF ROPE ← CDSatellites.GetSatelliteRopes[p2];
parmNames: LIST OF ROPE ← NARROW[CDProperties.GetObjectProp[obj, parmNamesProp]];
Handle zero parameters as a special case
IF parmNames#NIL AND Rope.Equal[parmNames.first, "0"] THEN RETURN [TRUE];
IF RopeList.EqualLists[instArgs1, instArgs2] AND RopeList.EqualLists[satArgs1, satArgs2] AND ContextEqual[cx1, cx2, parmNames] 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 satellites of object (3) arguments specified in expressionsProp property of instance; (4) arguments specified in satellites of instance. Thus instance satellites take precedence over instance property exprs, which take precedence over object satellites, which take precedence over object property exprs. The evaluation is performed in two passes: the second pass handles result expressions 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.
EvaluateParameters:
PROC [cx: Context, obj:
CD.Object, propList:
CD.PropList]
RETURNS [resultRope:
ROPE] = {
objExprs: LIST OF ROPE ← NARROW[CDProperties.GetObjectProp[obj, expressionsProp]];
objSats: LIST OF ROPE ← CDSatellites.GetSatelliteRopes[obj];
instExprs: LIST OF ROPE ← NARROW[CDProperties.GetListProp[propList, expressionsProp]];
instSats: LIST OF ROPE ← CDSatellites.GetSatelliteRopes[propList];
EvalExprs:
PROC [exprs:
LIST
OF
ROPE, inst:
BOOL] = {
seenResult: BOOL ← FALSE;
WHILE exprs#
NIL
DO
expr: ROPE ← exprs.first;
SELECT
TRUE
FROM
Rope.Find[s1: expr, s2: "←"] # -1 => {
SELECT
TRUE
FROM
IsResultExpression[expr] => {
IF seenResult THEN {TerminalIO.WriteRope["\n** Error: multiple result expressions encountered"]; ERROR};
seenResult ← TRUE;
resultRope ← expr;
};
inst
AND Rope.Match["*name*←*", expr] => {
expr ← Rope.Replace[expr, Rope.Find[expr, "name"], 4, "&"];
Eval[cx, expr];
Store[cx, coreInstPropsRope, NEW [Core.Properties ← CoreProperties.PutProp[GetCoreInstProps[cx], CoreOps.nameProp, NARROW[RefFromTV[SymTab.Fetch[cx, "&"].val], REF ROPE]^]]];
};
ENDCASE => Eval[cx, expr]
};
Rope.Find[s1: expr, s2: ":"] # -1 => {
atomRope: ROPE ← Rope.Substr[expr, 0, Rope.Find[s1: expr, s2: ":"]];
valueRope: ROPE ← Rope.Substr[expr, 1+Rope.Find[s1: expr, s2: ":"]];
IF inst
THEN expr ← Rope.Cat["coreInstProps ← CoreProperties.PutProp[coreInstProps, $", atomRope, ", ", valueRope, "]"]
ELSE expr ← Rope.Cat["coreProps ← CoreProperties.PutProp[coreProps, $", atomRope, ", ", valueRope, "]"];
Eval[cx, expr]
};
ENDCASE => {
IF inst
THEN Store[cx, coreInstPropsRope, NEW [Core.Properties ← CoreProperties.PutProp[GetCoreInstProps[cx], CoreOps.nameProp, expr]]]
ELSE Store[cx, nameRope, NEW [ROPE ← expr]]
};
exprs ← exprs.rest;
ENDLOOP;
};
EvalExprs[objExprs, FALSE];
EvalExprs[objSats, FALSE];
EvalExprs[instExprs, TRUE];
EvalExprs[instSats, TRUE];
};
EvaluateResult:
PROC [cx: Context, resultRope:
ROPE] = {
IF resultRope#
NIL
THEN {
SpeedUp Hack -- avoids evaluating expressions containing ExtractSchematicByName
IF Rope.Match["cI ← ES[\"*\", cx]", resultRope]
THEN {
pos1: INT ← Rope.Find[s1: resultRope, s2: "\""];
pos2: INT ← Rope.Find[s1: resultRope, s2: "\"", pos1: pos1+1];
name: ROPE ← Rope.Substr[resultRope, pos1+1, pos2-pos1-1];
Store[cx, cellIconRope, NEW [CellType ← ES[name, cx]]];
RETURN
};
Eval[cx, resultRope];
};
};
CheckAndDecorate:
PROC [dp, rp, dpRoot: Wire, globalWires: Wires ←
NIL]
RETURNS [
BOOL]= {
dpInterfaceGeometry: LIST OF CD.Instance;
WireToLORA:
PROC [wire: Wire]
RETURNS [lora: List.
LORA] = {
lora ← NIL;
FOR i: NAT IN [0..wire.size) DO lora ← CONS [wire.elements[i], lora]; ENDLOOP;
};
CompareWires: List.CompareProc = {
w1: Wire ← NARROW [ref1];
w2: Wire ← NARROW [ref2];
RETURN [Rope.Compare[CoreOps.GetShortWireName[w1], CoreOps.GetShortWireName[w2]]]
};
dpName: ROPE ← CoreOps.GetShortWireName[dp];
rpName: ROPE ← CoreOps.GetShortWireName[rp];
IF ~Rope.Equal[dpName, rpName] OR (dpName=NIL AND dp#dpRoot) THEN RETURN [FALSE];
IF dp.size > 0
THEN {
dpElements: List.LORA ← List.Sort[WireToLORA[dp], CompareWires];
rpElements: List.LORA ← List.Sort[WireToLORA[rp], CompareWires];
IF rp.size<dp.size THEN RETURN [FALSE];
Check that every element in dpElements has a corresponding element in rpElements
FOR i:
NAT
IN [0..dp.size)
DO
dpWire: Wire ← NARROW [dpElements.first];
rpWire: Wire ← NARROW [rpElements.first];
WHILE ~CheckAndDecorate[dpWire, rpWire, dpRoot]
DO
name: ROPE ← CoreOps.GetShortWireName[NARROW[rpElements.first, Wire]];
IF FindGlobalWire[name, globalWires]=NIL THEN RETURN [FALSE];
IF rpElements.rest=
NIL
THEN RETURN [FALSE]
ELSE {rpElements ← rpElements.rest; rpWire ← NARROW [rpElements.first]}
ENDLOOP;
IF ~CheckAndDecorate[dpWire, rpWire, dpRoot] THEN RETURN [FALSE];
dpElements ← dpElements.rest;
rpElements ← rpElements.rest
ENDLOOP;
};
dpInterfaceGeometry ← Sinix.GetPinsProp[sisyphMode, dp];
Sinix.PutPinsProp[sisyphMode, rp, dpInterfaceGeometry];
RETURN [TRUE];
};
MarkInvisibleInstances: CDEvents.EventProc = {
MarkForEachCell: CDDirectory.EachEntryAction = {
IF CDCells.IsCell[ob]
THEN {
cellPtr: CD.CellPtr ← NARROW [ob.specificRef];
FOR l:
LIST
OF
CD.Instance ← cellPtr.contents, l.rest
WHILE l#
NIL
DO
IF CDProperties.GetListProp[l.first.properties, ignoreMeProp]#
NIL
THEN {CDProperties.PutProp[l.first, sisyphMode.extractProcProp, $ExtractNull]; CDProperties.PutProp[l.first, ignoreMeProp, NIL]};
ENDLOOP;
}
};
IF design=NIL THEN RETURN; -- design is sometimes NIL!!
[] ← CDDirectory.Enumerate[design, MarkForEachCell];
};
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 [rootPublic, instActual, instPublic: Wire]
RETURNS [Wire] =
BEGIN
IF instActual.size#instPublic.size THEN ERROR;
FOR i:
NAT
IN [0..instActual.size)
DO
instActual[i] ← NewActual[rootPublic, instActual[i], instPublic[i]];
ENDLOOP;
FOR nl:
LIST
OF
ROPE ← CoreOps.GetFullWireNames[rootPublic, instPublic], nl.rest
WHILE nl#
NIL
DO
globalWithInstPublicName: Wire ← FindGlobalWire[nl.first, globalWires];
IF globalWithInstPublicName#
NIL
AND Sinix.GetPinsProp[sisyphMode, instActual]=
NIL
THEN {
publicWithInstPublicName: Wire ← CoreOps.FindWire[cellType.public, nl.first];
IF publicWithInstPublicName=
NIL
THEN {
internalWithInstPublicName: Wire ← CoreOps.FindWire[recordCell.internal, nl.first];
IF internalWithInstPublicName#
NIL
THEN {
IF ~CoreOps.Member[toBeMadePublic, internalWithInstPublicName] THEN toBeMadePublic ← CONS [internalWithInstPublicName, toBeMadePublic];
toBeDeleted ← CONS[instActual, toBeDeleted];
RETURN [internalWithInstPublicName]
}
ELSE {
IF ~CoreOps.Member[toBeMadePublic, globalWithInstPublicName] THEN toBeMadePublic ← CONS [globalWithInstPublicName, toBeMadePublic];
recordCell.internal ← CoreOps.UnionWire[recordCell.internal, CoreOps.CreateWire[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[recordCell.internal, wire], nl.rest
WHILE nl#
NIL
DO
IF FindGlobalWire[nl.first, globalWires]#
NIL
AND CoreOps.FindWire[cellType.public, nl.first]=
NIL
THEN {IF ~CoreOps.Member[toBeMadePublic, wire] 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.type.public, inst.actual, inst.type.public];
ENDLOOP;
Delete toBeDeleted wires from the internal
recordCell.internal ← DeleteWires[recordCell.internal, toBeDeleted];
Check if any part of the internal of cellType should be promoted
[] ← CoreOps.VisitWire[recordCell.internal, CheckIfWireIsToBeMadePublic];
Remove Sinix.pinsProp from all wires to be made public
FOR w: Wires ← toBeMadePublic, w.rest
WHILE w#
NIL
DO
Sinix.PutPinsProp[sisyphMode, w.first, NIL]
ENDLOOP;
cellType.public ← CoreOps.UnionWire[cellType.public, CoreOps.CreateWire[toBeMadePublic]];
END;
SortInstances:
PROC [cellType: Core.CellType, mode: Sinix.Mode, obj:
CD.Object] = {
layoutProp: ATOM ← NARROW [CoreProperties.GetCellTypeProp[cellType, $Layout]];
recordCell: CoreClasses.RecordCellType ← NARROW[cellType.data];
LessThan:
PROC [i1, i2: CoreClasses.CellInstance]
RETURNS [
BOOL] = {
cdi1: CD.Instance ← NARROW[CoreProperties.GetCellInstanceProp[i1, mode.instanceProp]];
cdi2: CD.Instance ← NARROW[CoreProperties.GetCellInstanceProp[i2, mode.instanceProp]];
ir1Loc: CD.Position ← PW.GetLocation[cdi1, obj];
ir2Loc: CD.Position ← PW.GetLocation[cdi2, obj];
RETURN [(layoutProp=$AbutX AND ir1Loc.x<ir2Loc.x) OR (layoutProp=$AbutY AND ir1Loc.y<ir2Loc.y)]
};
IF layoutProp#$AbutX AND layoutProp#$AbutY THEN RETURN;
FOR i:
NAT
DECREASING
IN (0..recordCell.size)
DO
FOR j:
NAT
IN [0..i)
DO
IF LessThan[recordCell[i], recordCell[j]] THEN {temp: CoreClasses.CellInstance ← recordCell[i]; recordCell[i] ← recordCell[j]; recordCell[j] ← temp}
ENDLOOP;
ENDLOOP;
};
DeleteWires:
PROC [from: Wire, victims:
LIST
OF Wire]
RETURNS [result: Wire] =
BEGIN
survivors: Wires ← NIL;
FOR i:
NAT
DECREASING
IN [0 .. from.size)
DO
IF ~CoreOps.Member[victims, from[i]] THEN survivors ← CONS [from[i], survivors];
ENDLOOP;
result ← CoreOps.CreateWire[survivors];
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;
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;
TouchRect: Sinix.TouchProc = {
IF instance2.ob.class#CDRects.bareRectClass THEN RETURN [Sinix.TouchRectObject[mode, instance2, CDInstances.InstRectO[instance1], instance1.ob.layer]];
IF ~SilTouchRect[CDInstances.InstRectO[instance1], CDInstances.InstRectO[instance2]] THEN RETURN;
RETURN [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
};
GetCoreInstProps:
PROC [cx: Context]
RETURNS [Core.Properties] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, coreInstPropsRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF Core.Properties]^]
ELSE ERROR
};
GetCellIconCore:
PROC [cx: Context]
RETURNS [Core.CellType] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, cellIconRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF Core.CellType]^]
ELSE ERROR
};
GetWireIconCore:
PROC [cx: Context]
RETURNS [Core.Wire] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, wireIconRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF Core.Wire]^]
ELSE ERROR
};
GetWireCore:
PROC [cx: Context]
RETURNS [Core.Wire] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, wireRope];
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
};
GetCDObj:
PROC [cx: Context]
RETURNS [
CD.Object] = {
found: BOOL;
ref: SymTab.Val;
[found, ref] ← SymTab.Fetch[cx, cdObjRope];
IF found
THEN RETURN [NARROW [RefFromTV[ref], REF CD.Object]^]
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];
};
CDNameToCTName:
PROC [cdName, dropPart:
ROPE]
RETURNS [ctName:
ROPE] = {
ctName ← Rope.Substr[cdName, 0, Rope.Index[cdName, 0, dropPart]];
};
Module Initialization
Sinix.RegisterExtractProc[$SisyphExtractSchematic, ExtractSchematic];
Sinix.RegisterExtractProc[$SisyphExtractWire, ExtractWire];
CDProperties.PutProp[CDCells.cellClass, sisyphMode.extractProcProp, $SisyphExtractSchematic];
CDProperties.PutProp[CDCells.cellClass, Sinix.touchProcProp, NEW [Sinix.TouchProc ← Sinix.TouchCell]];
CDProperties.PutProp[CDSymbolicObjects.pinClass, sisyphMode.extractProcProp, $ExtractError];
CDProperties.PutProp[CDSymbolicObjects.segmentClass, sisyphMode.extractProcProp, $ExtractError];
CDProperties.PutProp[CDSymbolicObjects.markClass, sisyphMode.extractProcProp, $ExtractError];
CDProperties.PutProp[CDRects.bareRectClass, sisyphMode.extractProcProp, $SisyphExtractWire];
CDProperties.PutProp[CDTexts.textClass, sisyphMode.extractProcProp, $ExtractNull];
CDEvents.RegisterEventProc[$AfterInput, MarkInvisibleInstances];
END.