<> <> DIRECTORY Asserting, AssertingIO, Basics, FS, IO, Rope, RoseCreate, RoseTranslateTypes, RoseTranslateInsides, RoseTypes; RopePorts: CEDAR PROGRAM IMPORTS AssertingIO, FS, IO, RoseTranslateInsides, RoseTypes EXPORTS RoseCreate = BEGIN OPEN RoseTypes, RoseTranslateTypes, RoseTranslateInsides; PortsFromROPE: PUBLIC PROC [asRope: ROPE] RETURNS [ports: Ports] = {ports _ PortsFromStream[IO.RIS[asRope]]}; PortsFromFile: PUBLIC PROC [fileName: ROPE] RETURNS [ports: Ports] = {ports _ PortsFromStream[FS.StreamOpen[fileName]]}; PortsFromStream: PUBLIC PROC [stream: STREAM] RETURNS [ports: Ports] = BEGIN length: CARDINAL _ stream.GetCard[]; ports _ NEW [PortsRep[length]]; FOR portIndex: CARDINAL IN [0 .. length) DO CheckField: PROC [f: Field, type: NodeType, flavor: ROPE] = { need: NAT _ type.procs.Bits[type].container; IF f.bitCount # need THEN Error[IO.PutFR[ "port %g's width is %g, but its type (%g) wants %g", [rope[name]], [integer[f.bitCount]], [rope[type.procs.UserDescription[type]]], [integer[need]] ]]; }; simple: Field _ GetField[stream]; switch: Field _ GetField[stream]; name: ROPE _ stream.GetRopeLiteral[]; typeAsRope: ROPE _ stream.GetRopeLiteral[]; job: Job _ NEW [JobRep _ [ exec: NIL, rootName: NIL, from: IO.RIS[typeAsRope], log: viewerLog, type: Other]]; any: REF ANY _ ParseExpression[job]; type: NodeType _ WITH any SELECT FROM sti: SignalTypeInvocation => sti.st, id: ID => InstantiateSignalType[job, id.rope, NIL].st, ENDCASE => ERROR; simpleType, switchType: NodeType; flags: [0 .. 16) _ stream.GetCard[]; other: Assertions _ AssertingIO.Read[stream]; [simpleType, switchType] _ BothTypes[type]; ports[portIndex] _ [ simple: simple, switch: switch, name: name, type: type, input: (flags MOD 2) >= 1, output: (flags MOD 4) >= 2, XPhobic: (flags MOD 8) >= 4, instructionsSimple: (flags MOD 16) >= 8, other: other]; IF simpleType # NIL THEN CheckField[simple, simpleType, "simple"]; IF switchType # NIL THEN CheckField[switch, switchType, "switch"]; ENDLOOP; [] _ stream.SkipWhitespace[flushComments: FALSE]; IF NOT stream.EndOf[] THEN ERROR; END; GetField: PROC [from: STREAM] RETURNS [f: Field] = { bitOffset: CARDINAL _ from.GetCard[]; bitLength: CARDINAL _ from.GetCard[]; wordOffset: CARDINAL _ bitOffset/Basics.bitsPerWord; wordoffbits: CARDINAL _ wordOffset*Basics.bitsPerWord; f _ [wordOffset, bitOffset - wordoffbits, bitLength]; }; END.