DIRECTORY Basics, ComparePrivate, DFUtilities, FS, IO, List, OrderedSymbolTableRef, Rope, ViewerIO; CompareRead: CEDAR PROGRAM IMPORTS ComparePrivate, DFUtilities, FS, IO, List, OrderedSymbolTableRef, Rope, ViewerIO EXPORTS ComparePrivate = BEGIN OPEN ComparePrivate; LORA: TYPE = LIST OF REF ANY; Int: TYPE = REF INT; graphIDToRope: PUBLIC ARRAY GraphID OF ROPE _ ["A", "B"]; log: IO.STREAM _ ViewerIO.CreateViewerStreams["Compare Read"].out; cellDefs: ARRAY GraphID OF SymbolTable; Log: PUBLIC PROC [format: ROPE, v1, v2, v3, v4, v5: IO.Value _ [null[]]] = {log.PutF[format, v1, v2, v3, v4, v5]}; DFTest: PROC [dfName: ROPE] = BEGIN PerItem: PROC [item: REF ANY] RETURNS [stop: BOOL _ FALSE] = {Log["%g\n", IO.refAny[item]]}; from: IO.STREAM _ FS.StreamOpen[dfName]; Log["\nTesting DF file %g\n", IO.rope[dfName]]; DFUtilities.ParseFromStream[in: from, proc: PerItem, filter: [comments: TRUE]]; from.Close[]; Log["\nDone testing DF file %g\n", IO.rope[dfName]]; END; ReadDesign: PROC [graphID: GraphID, dfName: ROPE] = BEGIN commentText: ROPE _ NIL; PerItem: PROC [item: REF ANY] RETURNS [stop: BOOL _ FALSE] = BEGIN WITH item SELECT FROM di: REF DFUtilities.DirectoryItem => NULL; fi: REF DFUtilities.FileItem => IF NOT dfName.Equal[fi.name] THEN { cs: IO.STREAM _ IO.RIS[commentText]; typeName, fullFName, fileName: ROPE; ct: ComponentType; cp: FS.ComponentPositions; [fullFName, cp, ] _ FS.ExpandName[fi.name]; fileName _ fullFName.Substr[start: 0, len: cp.ext.start + cp.ext.length]; IF cs.GetChar[] # '- THEN ERROR; IF cs.GetChar[] # '- THEN ERROR; typeName _ cs.GetRopeLiteral[]; cs.Close[]; ct _ NEW [ComponentTypeRep _ [name: typeName, file: fileName]]; cellDefs[graphID].Insert[ct]; }; ii: REF DFUtilities.ImportsItem => ERROR; ii: REF DFUtilities.IncludeItem => ERROR; ci: REF DFUtilities.CommentItem => commentText _ ci.text; wi: REF DFUtilities.WhiteSpaceItem => NULL; ENDCASE => ERROR; END; from: IO.STREAM _ FS.StreamOpen[dfName]; cellDefs[graphID] _ OrderedSymbolTableRef.CreateTable[CompareCellTypes]; DFUtilities.ParseFromStream[in: from, proc: PerItem, filter: [comments: TRUE]]; from.Close[]; END; Test: PROC [names: ARRAY GraphID OF ROPE] = BEGIN vertices: SymbolTablePair _ [OrderedSymbolTableRef.CreateTable[CompareVertices], OrderedSymbolTableRef.CreateTable[CompareVertices]]; Log["\nTesting %g %g\n", IO.rope[names[A]], IO.rope[names[B]]]; ReadGraph[A, names[A], vertices[A]]; ReadGraph[B, names[B], vertices[B]]; CompareCDs[vertices]; Log["\nDone\n"]; log.Flush[]; END; ReadGraph: PROC [graphID: GraphID, fileName: ROPE, symbolTable: SymbolTable] = BEGIN Add: PROC [v: Vertex] = BEGIN color: Color _ v.curColor; IF v.curColor # v.oldColor THEN ERROR; symbolTable.Insert[v]; END; Connect: PROC [i: CARDINAL, cv: ComponentVertex, nv: NetVertex] = BEGIN cv.neighbors[i] _ nv; nv.neighbors[nv.used] _ [cv, cv.ports[i].color]; nv.used _ nv.used + 1; END; GetStart: PROC = BEGIN IF from.GetChar[] # '- THEN ERROR; IF from.GetChar[] # '- THEN ERROR; IF NOT from.GetTokenRope[IO.IDProc].token.Equal["CellType"] THEN ERROR; graphTypeName _ from.GetRopeLiteral[]; [] _ from.GetLineRope[]; ports _ NARROW[from.GetRefAny[]]; IF ports.first # $Ports THEN ERROR; END; AddWorld: PROC = BEGIN ct: ComponentType; cv: ComponentVertex; ct _ NARROW[cellDefs[graphID].Lookup[graphTypeName]]; IF ct.ports = NIL THEN ReadPorts[ct]; cv _ NEW [VertexRep[component][ct.ports.length]]; cv.name _ "world"; cv.QNext _ notInQ; cv.colorNext _ cv.equiv _ NIL; cv.oldColor _ cv.curColor _ 0; cv.graph _ graphID; cv.unique _ FALSE; cv.suspect _ FALSE; cv.ports _ ct.ports; FOR i: CARDINAL IN [0 .. ct.ports.length) DO port: Port _ ct.ports[i]; nv: NetVertex _ NARROW[symbolTable.Lookup[port.name]]; Connect[i, cv, nv]; ENDLOOP; Add[cv]; END; from: IO.STREAM _ FS.StreamOpen[fileName]; graphTypeName: ROPE; ports: LORA; GetStart[]; DO item: LORA; [] _ from.SkipWhitespace[]; IF from.EndOf[] THEN EXIT; item _ NARROW[from.GetRefAny[]]; SELECT item.first FROM $N => BEGIN netName, netType: ROPE; connections: CARDINAL; nv: NetVertex; netName _ NARROW[item.rest.first]; netType _ NARROW[item.rest.rest.first]; connections _ NARROW[item.rest.rest.rest.first, Int]^; nv _ NEW [VertexRep[net][connections]]; nv.name _ netName; nv.QNext _ notInQ; nv.colorNext _ nv.equiv _ NIL; nv.oldColor _ nv.curColor _ HashRope[netType, MinHashSize]; nv.graph _ graphID; nv.unique _ FALSE; nv.suspect _ FALSE; nv.used _ 0; Add[nv]; END; $C => BEGIN instName, typeName: ROPE; cv: ComponentVertex; ct: ComponentType; connections: CARDINAL; con: LORA _ item.rest.rest.rest; instName _ NARROW[item.rest.first]; typeName _ NARROW[item.rest.rest.first]; connections _ List.Length[con]; cv _ NEW [VertexRep[component][connections]]; cv.name _ instName; cv.QNext _ notInQ; cv.colorNext _ cv.equiv _ NIL; cv.oldColor _ cv.curColor _ HashRope[typeName, MinHashSize]; cv.graph _ graphID; cv.unique _ FALSE; cv.suspect _ FALSE; ct _ NARROW[cellDefs[graphID].Lookup[typeName]]; IF ct.ports = NIL THEN ReadPorts[ct]; cv.ports _ ct.ports; FOR i: CARDINAL IN [0 .. connections) DO pair: LORA _ NARROW[con.first]; portName: ROPE _ NARROW[pair.first]; netName: ROPE _ NARROW[pair.rest.first]; net: NetVertex _ NARROW[symbolTable.Lookup[netName]]; IF NOT portName.Equal[cv.ports[i].name] THEN ERROR; Connect[i, cv, net]; con _ con.rest; ENDLOOP; Add[cv]; END; $Leaf => ERROR; ENDCASE => ERROR; ENDLOOP; AddWorld[]; from.Close[]; END; ReadPorts: PROC [ct: ComponentType] = BEGIN from: IO.STREAM _ FS.StreamOpen[ct.file]; ports: LORA _ NARROW[from.GetRefAny[]]; i, len: CARDINAL _ 0; IF ports.first # $Ports THEN ERROR; len _ List.Length[ports]-1; ct.ports _ NEW [PortSeq[len]]; FOR pl: LORA _ ports.rest, pl.rest WHILE pl # NIL DO item: LORA _ NARROW[pl.first]; portName: ROPE _ NARROW[item.first]; portClass: ROPE _ NARROW[item.rest.first]; portType: ROPE _ NARROW[item.rest.rest.first]; ct.ports[i] _ [name: portName, color: HashRope[portClass, MinHashSize]]; i _ i + 1; ENDLOOP; IF i # len THEN ERROR; from.Close[]; END; WriteAll: PUBLIC PROC [when: ROPE, vertices: SymbolTablePair, hashTable: HashTable] = BEGIN Log["\n%g\n", IO.rope[when]]; WriteHashTable[hashTable]; WriteSymbolTable["A", vertices[A]]; WriteSymbolTable["B", vertices[B]]; Log["\nDone %g\n", IO.rope[when]]; END; WriteHashTable: PROC [hashTable: HashTable] = BEGIN Log["\nHashTable:\n"]; FOR hti: HashTableIndex _ hashTable.firstNonEmpty, hashTable[hti].nextNonEmpty WHILE hti # NullIndex DO hte: HashTableEntry _ hashTable[hti]; Log["%05d %g %g", IO.card[hti], IO.card[hte.count[A]], IO.card[hte.count[B]]]; Log[" %05d %g %g", IO.card[hte.newColor], IO.bool[hte.multicolored], IO.bool[hte.suspect]]; FOR v: Vertex _ hte.v, v.colorNext WHILE v # NIL DO Log[" %g.%g", IO.rope[graphIDToRope[v.graph]], IO.rope[v.name]]; ENDLOOP; Log["\n"]; ENDLOOP; END; WriteSymbolTable: PROC [graphID: ROPE, vertices: SymbolTable] = BEGIN WriteVertex: PROC [any: REF ANY] RETURNS [stop: BOOL] = BEGIN v: Vertex _ NARROW[any]; stop _ FALSE; Log["(%05d)\t%05d\t%g\t%g\t%g", IO.card[v.oldColor], IO.card[v.curColor], bool[v.unique], bool[v.suspect], IO.rope[v.name]]; IF v.equiv # NIL THEN Log["\t%g\n", IO.rope[v.equiv.name]] ELSE Log["\n"]; END; Log["\nGraph %g vertices:\n", IO.rope[graphID]]; vertices.EnumerateIncreasing[WriteVertex]; END; bool: PROC [b: BOOL] RETURNS [v: IO.Value[rope]] = {v.value _ IF b THEN "TRUE " ELSE "FALSE"}; HashRope: PUBLIC PROC [r: ROPE, hashTableSize: CARDINAL] RETURNS [c: Color] = BEGIN rot: LONG CARDINAL = 128 + 32 + 2; len: INT = r.Length[]; c _ 1; FOR i: INT DECREASING IN [0 .. len) DO char: CHAR _ r.Fetch[i]; long: LONG CARDINAL _ rot*c + (char-0C); c _ long MOD hashTableSize; ENDLOOP; END; CompareCellTypes: PROC [r1, r2: REF ANY] RETURNS [c: Basics.Comparison] = BEGIN Key: PROC [r: REF ANY] RETURNS [k: ROPE] = { WITH r SELECT FROM rr: ROPE => k _ rr; ct: ComponentType => k _ ct.name; ENDCASE => ERROR}; c _ Key[r1].Compare[Key[r2]]; END; CompareVertices: PROC [r1, r2: REF ANY] RETURNS [c: Basics.Comparison] = BEGIN Key: PROC [r: REF ANY] RETURNS [k: ROPE] = { WITH r SELECT FROM rr: ROPE => k _ rr; v: Vertex => k _ v.name; ENDCASE => ERROR}; c _ Key[r1].Compare[Key[r2]]; END; END. PCompareRead.Mesa Last Edited by: Spreitzer, July 10, 1984 4:50:43 pm PDT Κ – "cedar" style˜Icode™J™7K˜KšΟk œ&œœ.˜cK˜šΠbx œœ˜Kšœœœ-˜XKšœ˜—K˜Kšœœ˜K˜Kš œœœœœœ˜Kšœœœœ˜K˜Kš œœœ œœ˜9K˜Kšœœœ4˜BKšœ œ œ ˜'K˜š Οnœœœ œœ˜JK˜'—K˜šŸœœ œ˜Kš˜šŸœœœœœœœ˜