RopePorts.Mesa
last edited by Spreitzer September 9, 1985 9:41:50 pm PDT
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.