<> <> <> <<>> <> <<>> DIRECTORY AMBridge, AMModelBridge, AMTypes, CD, CDBasics, CDDirectory, CDProperties, CDRects, CDTexts, Core, CoreOps, CoreGeometry, Interpreter, IO, PrincOpsUtils, PW, Rope, Sinix, Sisyph, WireIcons; WireIconsImpl: CEDAR PROGRAM IMPORTS AMBridge, AMModelBridge, CD, CDBasics, CDDirectory, CDProperties, CDRects, CDTexts, CoreOps, CoreGeometry, Interpreter, IO, PrincOpsUtils, PW, Rope, Sinix, Sisyph EXPORTS WireIcons SHARES Sisyph = BEGIN OPEN WireIcons; <> font: CDTexts.CDFont _ CDTexts.MakeFont["Xerox/TiogaFonts/Helvetica8", 4]; PutPin: PROC [wire: Wire, obj: CD.Object, size, pos: CD.Position] = { pin: CD.Instance = PW.IncludeInCell[obj, CDRects.CreateRect[size, CD.commentLayer], pos]; CoreGeometry.PutPin[Sisyph.mode.decoration, wire, pin]; }; EvaluateParameters: PUBLIC PROC [userData: REF, obj: CD.Object, properties: CD.PropList] RETURNS [cx: Sisyph.Context] = { resultRope: ROPE; [cx, resultRope] _ Sisyph.EvaluateParameters[userData, obj, properties]; IF resultRope#NIL THEN ERROR; }; EvalNat: PROC [cx: Sisyph.Context, expr: ROPE] RETURNS [nat: NAT] = { result: AMTypes.TV; errorRope: ROPE; noResult: BOOL; refInt: REF INT; TRUSTED {[result, errorRope, noResult] _ Interpreter.Evaluate[ rope: expr, context: AMModelBridge.ContextForFrame[ AMBridge.TVForFrame[PrincOpsUtils.GetReturnFrame[]] ], symTab: cx ]}; IF errorRope#NIL THEN SIGNAL Sisyph.InterpreterError[cx, expr, errorRope]; TRUSTED {refInt _ NARROW [AMBridge.SomeRefFromTV[result]]}; RETURN [NAT [refInt^]]; }; <> MakeComposer: PUBLIC PROC [design: CD.Design, size: NAT] RETURNS [wire: Wire, obj: CD.Object] = { increment: INT _ SELECT TRUE FROM size<4 => 8, size<6 => 6, size<8 => 4, size<16 => 2, size<32 => 2, ENDCASE => 1; wire _ CoreOps.CreateWires[size: size]; obj _ PW.CreateEmptyCell[]; <> [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[increment*(size-1)* <> PutPin[wire, obj, [ <> FOR i: NAT IN [0 .. size) DO wire[i] _ CoreOps.CreateWire[]; PutPin[wire[i], obj, [ ENDLOOP; <> [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[ CDProperties.PutObjectProp[obj, $ComposerSize, NEW [INT _ size]]; CDProperties.PutObjectProp[obj, Sisyph.mode.extractProcProp, $WireIconsExtractComposer]; PW.RepositionCell[obj]; CDCells.SetSimplificationTreshhold[obj, 10.0]; }; Composer: PW.UserProc = { name: ROPE; int: INT _ PW.RequestInt["Size of the composer? "]; IF int<1 THEN RETURN; name _ IO.PutFR["::Composer[%g].icon", IO.int[int]]; ob _ CDDirectory.Fetch[design, name].object; IF ob=NIL THEN { ob _ MakeComposer[design, NAT [int]].obj; [] _ CDDirectory.Include[design, ob, name]; }; }; ExtractComposer: Sinix.ExtractProc = { cx: Sisyph.Context = NARROW [userData]; refNat: REF INT _ NARROW [CDProperties.GetObjectProp[obj, $ComposerSize]]; size: NAT _ NAT [refNat^]; result _ MakeComposer[Sisyph.GetDesign[cx], size].wire; }; <> MakeSlash: PROC [design: CD.Design] RETURNS [obj: CD.Object] = { obj _ PW.CreateEmptyCell[]; FOR i: INT IN [0 .. 2* [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[ ENDLOOP; PW.RepositionCell[obj]; CDCells.SetSimplificationTreshhold[obj, 10.0]; }; MakeBus: PUBLIC PROC [design: CD.Design, size: NAT, slash: CD.Object _ NIL] RETURNS [wire: Wire, obj: CD.Object] = { wire _ CoreOps.CreateWires[size: size]; obj _ PW.CreateEmptyCell[]; <> IF slash#NIL THEN [] _ PW.IncludeInCell[obj, slash, [ <> PutPin[wire, obj, [9* <> FOR i: NAT IN [0 .. size) DO wire[i] _ CoreOps.CreateWire[]; ENDLOOP; <> [] _ PW.IncludeInCell[obj, CDTexts.CreateText[IO.PutR1[IO.int[size]], font], [6* CDProperties.PutObjectProp[obj, $BusSize, NEW [INT _ size]]; CDProperties.PutObjectProp[obj, Sisyph.mode.extractProcProp, $WireIconsExtractBus]; PW.SetInterestRect[obj, [9* PW.RepositionCell[obj]; CDCells.SetSimplificationTreshhold[obj, 10.0]; }; Bus: PW.UserProc = { slash: CD.Object; int: INT _ PW.RequestInt["Size of the bus? "]; IF int<1 THEN RETURN; slash _ CDDirectory.Fetch[design, "::SlashForBusIcon"].object; IF slash=NIL THEN { slash _ MakeSlash[design]; [] _ CDDirectory.Include[design, slash, "::SlashForBusIcon"]; }; ob _ MakeBus[design, NAT [int], slash].obj; [] _ CDDirectory.Include[design, ob]; }; ExtractBus: Sinix.ExtractProc = { cx: Sisyph.Context = NARROW [userData]; refNat: REF INT _ NARROW [CDProperties.GetObjectProp[obj, $BusSize]]; size: NAT _ NAT [refNat^]; result _ MakeBus[Sisyph.GetDesign[cx], size].wire; }; <> MakeExtractor: PUBLIC PROC [design: CD.Design, index, size: NAT] RETURNS [wire: Wire, obj: CD.Object] = { wire _ CoreOps.CreateWires[size: size]; <> FOR i: NAT IN [0 .. size) DO wire[i] _ CoreOps.CreateWire[] ENDLOOP; obj _ PW.CreateEmptyCell[]; <> PutPin[wire, obj, [9* <> PutPin[wire[index], obj, [ <> [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[3* [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[3* [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[ [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[ <> [] _ PW.IncludeInCell[obj, CDTexts.CreateText[IO.PutR1[IO.int[index]], font], [9* [] _ PW.IncludeInCell[obj, CDTexts.CreateText[IO.PutR1[IO.int[size]], font], [9* CDProperties.PutObjectProp[obj, $ExtractorIndex, NEW [INT _ index]]; CDProperties.PutObjectProp[obj, $ExtractorSize, NEW [INT _ size]]; CDProperties.PutObjectProp[obj, Sisyph.mode.extractProcProp, $WireIconsExtractExtractor]; PW.SetInterestRect[obj, [9* PW.RepositionCell[obj]; CDCells.SetSimplificationTreshhold[obj, 10.0]; }; Extractor: PW.UserProc = { int: INT _ PW.RequestInt["Index of the extracted wire? "]; int2: INT _ PW.RequestInt["Size of the structured wire? "]; IF int<0 OR int2<1 OR int>=int2 THEN RETURN; ob _ MakeExtractor[design, NAT [int], NAT [int2]].obj; [] _ CDDirectory.Include[design, ob]; }; ExtractExtractor: Sinix.ExtractProc = { cx: Sisyph.Context = NARROW [userData]; refNat: REF INT _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorIndex]]; refNat2: REF INT _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorSize]]; index: NAT _ NAT [refNat^]; size: NAT _ NAT [refNat2^]; result _ MakeExtractor[Sisyph.GetDesign[cx], index, size].wire; }; <> MakeRangeExtractor: PUBLIC PROC [design: CD.Design, index, subSize, size: NAT] RETURNS [wires: Wires, obj: CD.Object] = { <> structWire: Wire _ CoreOps.CreateWires[size: size]; subWire: Wire _ CoreOps.CreateWires[size: subSize]; wires _ LIST [subWire, structWire]; <> FOR i: NAT IN [0 .. size) DO structWire[i] _ CoreOps.CreateWire[] ENDLOOP; FOR i: NAT IN [0 .. subSize) DO subWire[i] _ structWire[i+index] ENDLOOP; obj _ PW.CreateEmptyCell[]; <> PutPin[structWire, obj, [19* <> [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[ PutPin[subWire, obj, [ <> [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[5* [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[5* [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[ [] _ PW.IncludeInCell[obj, CDRects.CreateRect[[ <> [] _ PW.IncludeInCell[obj, CDTexts.CreateText[IO.PutFR["%g/%g", IO.int[index], IO.int[subSize]], font], [13* [] _ PW.IncludeInCell[obj, CDTexts.CreateText[IO.PutR1[IO.int[size]], font], [13* CDProperties.PutObjectProp[obj, $ExtractorIndex, NEW [INT _ index]]; CDProperties.PutObjectProp[obj, $ExtractorSubSize, NEW [INT _ subSize]]; CDProperties.PutObjectProp[obj, $ExtractorSize, NEW [INT _ size]]; CDProperties.PutObjectProp[obj, Sisyph.mode.extractProcProp, $WireIconsExtractRangeExtractor]; PW.SetInterestRect[obj, [19* PW.RepositionCell[obj]; CDCells.SetSimplificationTreshhold[obj, 10.0]; }; RangeExtractor: PW.UserProc = { int: INT _ PW.RequestInt["Index of the extracted wire? "]; int2: INT _ PW.RequestInt["Size of the extracted wire? "]; int3: INT _ PW.RequestInt["Size of the structured wire? "]; IF int<0 OR int2<1 OR int3<1 OR int>=int3 OR int+int2>int3 THEN RETURN; ob _ MakeRangeExtractor[design, NAT [int], NAT [int2], NAT [int3]].obj; [] _ CDDirectory.Include[design, ob]; }; ExtractRangeExtractor: Sinix.ExtractProc = { cx: Sisyph.Context = NARROW [userData]; refNat: REF INT _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorIndex]]; refNat2: REF INT _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorSubSize]]; refNat3: REF INT _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorSize]]; index: NAT _ NAT [refNat^]; subSize: NAT _ NAT [refNat2^]; size: NAT _ NAT [refNat3^]; result _ MakeRangeExtractor[Sisyph.GetDesign[cx], index, subSize, size].wires; }; <> ParametrizedBus: PW.UserProc = { slash: CD.Object _ CDDirectory.Fetch[design, "::SlashForBusIcon"].object; sizeRope: ROPE _ PW.RequestRope["Size of the parametrized bus? "]; IF slash=NIL THEN { slash _ MakeSlash[design]; [] _ CDDirectory.Include[design, slash, "::SlashForBusIcon"]; }; ob _ PW.CreateEmptyCell[]; [] _ PW.IncludeInCell[ob, slash, [ PutPin[CoreOps.CreateWire[], ob, [9* <> [] _ PW.IncludeInCell[ob, CDTexts.CreateText[sizeRope, font], [6* CDProperties.PutObjectProp[ob, $BusSize, sizeRope]; CDProperties.PutObjectProp[ob, Sisyph.mode.extractProcProp, $WireIconsExtractParametrizedBus]; PW.SetInterestRect[ob, [9* PW.RepositionCell[ob]; CDCells.SetSimplificationTreshhold[ob, 10.0]; [] _ CDDirectory.Include[design, ob]; }; ExtractParametrizedBus: Sinix.ExtractProc = { cx: Sisyph.Context _ EvaluateParameters[userData, obj, properties]; design: CD.Design _ Sisyph.GetDesign[cx]; slash: CD.Object _ CDDirectory.Fetch[design, "::SlashForBusIcon"].object; sizeRope: ROPE _ NARROW [CDProperties.GetObjectProp[obj, $BusSize]]; size: NAT _ EvalNat[cx, sizeRope]; wire: Wire; ob: CD.Object _ PW.CreateEmptyCell[]; -- we need this because of repositionment!!! IF size<1 THEN ERROR; IF slash=NIL THEN slash _ MakeSlash[design]; wire _ CoreOps.CreateWires[size: size]; [] _ PW.IncludeInCell[ob, slash, [ <> PutPin[wire, ob, [9* [] _ PW.IncludeInCell[ob, CDTexts.CreateText[sizeRope, font], [6* PW.SetInterestRect[ob, [9* PW.RepositionCell[ob]; <> FOR i: NAT IN [0 .. size) DO wire[i] _ CoreOps.CreateWire[]; ENDLOOP; result _ wire; }; <> ParametrizedExtractor: PW.UserProc = { indexRope: ROPE _ PW.RequestRope["Parametrized index of the extracted wire? "]; sizeRope: ROPE _ PW.RequestRope["Size of the parametrized bus? "]; ob _ PW.CreateEmptyCell[]; <> PutPin[CoreOps.CreateWire[], ob, [9* <> PutPin[CoreOps.CreateWire[], ob, [ <> [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[3* [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[3* [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ <> [] _ PW.IncludeInCell[ob, CDTexts.CreateText[indexRope, font], [9* [] _ PW.IncludeInCell[ob, CDTexts.CreateText[sizeRope, font], [9* CDProperties.PutObjectProp[ob, $ExtractorIndex, indexRope]; CDProperties.PutObjectProp[ob, $ExtractorSize, sizeRope]; CDProperties.PutObjectProp[ob, Sisyph.mode.extractProcProp, $WireIconsExtractParametrizedExtractor]; PW.SetInterestRect[ob, [9* PW.RepositionCell[ob]; CDCells.SetSimplificationTreshhold[ob, 10.0]; [] _ CDDirectory.Include[design, ob]; }; ExtractParametrizedExtractor: Sinix.ExtractProc = { cx: Sisyph.Context _ EvaluateParameters[userData, obj, properties]; design: CD.Design _ Sisyph.GetDesign[cx]; indexRope: ROPE _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorIndex]]; sizeRope: ROPE _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorSize]]; index: NAT _ EvalNat[cx, indexRope]; size: NAT _ EvalNat[cx, sizeRope]; wire: Wire; ob: CD.Object _ PW.CreateEmptyCell[]; -- we need this because of repositionment!!! IF index<0 OR size<1 OR index>=size THEN ERROR; wire _ CoreOps.CreateWires[size: size]; FOR i: NAT IN [0 .. size) DO wire[i] _ CoreOps.CreateWire[] ENDLOOP; <> PutPin[wire, ob, [9* <> PutPin[wire[index], ob, [ <> [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[3* [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[3* [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ <> [] _ PW.IncludeInCell[ob, CDTexts.CreateText[indexRope, font], [9* [] _ PW.IncludeInCell[ob, CDTexts.CreateText[sizeRope, font], [9* PW.SetInterestRect[ob, [9* PW.RepositionCell[ob]; result _ wire; }; <> ParametrizedRangeExtractor: PW.UserProc = { indexRope: ROPE _ PW.RequestRope["Parametrized index of the extracted wire? "]; subSizeRope: ROPE _ PW.RequestRope["Size of the parametrized sub wire? "]; sizeRope: ROPE _ PW.RequestRope["Size of the parametrized bus? "]; ob _ PW.CreateEmptyCell[]; <> PutPin[CoreOps.CreateWire[], ob, [19* <> [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ PutPin[CoreOps.CreateWire[], ob, [ <> [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[5* [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[5* [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ <> [] _ PW.IncludeInCell[ob, CDTexts.CreateText[IO.PutFR["%g/%g", IO.rope[indexRope], IO.rope[subSizeRope]], font], [13* [] _ PW.IncludeInCell[ob, CDTexts.CreateText[sizeRope, font], [13* CDProperties.PutObjectProp[ob, $ExtractorIndex, indexRope]; CDProperties.PutObjectProp[ob, $ExtractorSubSize, subSizeRope]; CDProperties.PutObjectProp[ob, $ExtractorSize, sizeRope]; CDProperties.PutObjectProp[ob, Sisyph.mode.extractProcProp, $WireIconsExtractParametrizedRangeExtractor]; PW.SetInterestRect[ob, [19* PW.RepositionCell[ob]; CDCells.SetSimplificationTreshhold[ob, 10.0]; [] _ CDDirectory.Include[design, ob]; }; ExtractParametrizedRangeExtractor: Sinix.ExtractProc = { cx: Sisyph.Context _ EvaluateParameters[userData, obj, properties]; design: CD.Design _ Sisyph.GetDesign[cx]; indexRope: ROPE _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorIndex]]; subSizeRope: ROPE _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorSubSize]]; sizeRope: ROPE _ NARROW [CDProperties.GetObjectProp[obj, $ExtractorSize]]; index: NAT _ EvalNat[cx, indexRope]; subSize: NAT _ EvalNat[cx, subSizeRope]; size: NAT _ EvalNat[cx, sizeRope]; wire, subWire: Wire; wires: Wires; ob: CD.Object _ PW.CreateEmptyCell[]; -- we need this because of repositionment!!! IF index<0 OR subSize<1 OR size<1 OR index>=size OR index+subSize>size THEN RETURN; wire _ CoreOps.CreateWires[size: size]; subWire _ CoreOps.CreateWires[size: subSize]; FOR i: NAT IN [0 .. size) DO wire[i] _ CoreOps.CreateWire[] ENDLOOP; FOR i: NAT IN [0 .. subSize) DO subWire[i] _ wire[i+index] ENDLOOP; <> PutPin[wire, ob, [19* <> PutPin[subWire, obj, [ <> [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[5* [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[5* [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ [] _ PW.IncludeInCell[ob, CDRects.CreateRect[[ <> [] _ PW.IncludeInCell[ob, CDTexts.CreateText[IO.PutFR["%g/%g", IO.rope[indexRope], IO.rope[subSizeRope]], font], [13* [] _ PW.IncludeInCell[ob, CDTexts.CreateText[sizeRope, font], [13* PW.SetInterestRect[ob, [9* PW.RepositionCell[ob]; wires _ LIST [subWire, wire]; result _ wires; }; <> Convert: PROC [design: CD.Design] = { EachObj: CDDirectory.EachEntryAction = { SELECT TRUE FROM Rope.Match[":Composer[*].icon", name] => { refNat: REF INT _ NARROW [CDProperties.GetObjectProp[ob, $ComposerSize]]; size: NAT _ NAT [refNat^]; new: CD.Object = MakeComposer[design, size].obj; off: CD.Position = CDBasics.SubPoints[CDBasics.BaseOfRect[CD.InterestRect[ob]], CDBasics.BaseOfRect[CD.InterestRect[new]]]; CDDirectory.ReplaceObject[design, ob, new, off]; }; Rope.Match[":Bus[*].icon", name] => { refNat: REF INT _ NARROW [CDProperties.GetObjectProp[ob, $BusSize]]; size: NAT _ NAT [refNat^]; new: CD.Object = MakeBus[design, size].obj; off: CD.Position = CDBasics.SubPoints[CDBasics.BaseOfRect[CD.InterestRect[ob]], CDBasics.BaseOfRect[CD.InterestRect[new]]]; CDDirectory.ReplaceObject[design, ob, new, off]; }; Rope.Match[":Extractor[*, *].icon", name] => { refNat: REF INT _ NARROW [CDProperties.GetObjectProp[ob, $ExtractorIndex]]; refNat2: REF INT _ NARROW [CDProperties.GetObjectProp[ob, $ExtractorSize]]; index: NAT _ NAT [refNat^]; size: NAT _ NAT [refNat2^]; new: CD.Object = MakeExtractor[design, index, size].obj; off: CD.Position = CDBasics.SubPoints[CDBasics.BaseOfRect[CD.InterestRect[ob]], CDBasics.BaseOfRect[CD.InterestRect[new]]]; CDDirectory.ReplaceObject[design, ob, new, off]; }; Rope.Match[":RangeExtractor[*/*, *].icon", name] => { refNat: REF INT _ NARROW [CDProperties.GetObjectProp[ob, $ExtractorIndex]]; refNat2: REF INT _ NARROW [CDProperties.GetObjectProp[ob, $ExtractorSubSize]]; refNat3: REF INT _ NARROW [CDProperties.GetObjectProp[ob, $ExtractorSize]]; index: NAT _ NAT [refNat^]; subSize: NAT _ NAT [refNat2^]; size: NAT _ NAT [refNat3^]; new: CD.Object = MakeRangeExtractor[design, index, subSize, size].obj; off: CD.Position = CDBasics.SubPoints[CDBasics.BaseOfRect[CD.InterestRect[ob]], CDBasics.BaseOfRect[CD.InterestRect[new]]]; CDDirectory.ReplaceObject[design, ob, new, off]; }; ENDCASE => {}; }; [] _ CDDirectory.Enumerate[design, EachObj]; }; <> PW.Register[Composer, "Composer"]; Sinix.RegisterExtractProc[$WireIconsExtractComposer, ExtractComposer]; PW.Register[Bus, "Bus"]; Sinix.RegisterExtractProc[$WireIconsExtractBus, ExtractBus]; PW.Register[Extractor, "Extractor"]; Sinix.RegisterExtractProc[$WireIconsExtractExtractor, ExtractExtractor]; PW.Register[RangeExtractor, "Range Extractor"]; Sinix.RegisterExtractProc[$WireIconsExtractRangeExtractor, ExtractRangeExtractor]; PW.Register[ParametrizedBus, "Parametrized Bus"]; Sinix.RegisterExtractProc[$WireIconsExtractParametrizedBus, ExtractParametrizedBus]; PW.Register[ParametrizedExtractor, "Parametrized Extractor"]; Sinix.RegisterExtractProc[$WireIconsExtractParametrizedExtractor, ExtractParametrizedExtractor]; PW.Register[ParametrizedRangeExtractor, "Parametrized Range Extractor"]; Sinix.RegisterExtractProc[$WireIconsExtractParametrizedRangeExtractor, ExtractParametrizedRangeExtractor]; END.