IntTypesTranslation.Mesa
Last Edited by: Spreitzer, April 20, 1983 11:16 am
DIRECTORY
IO, Rope, RoseTranslateTypes;
IntTypesTranslation:
CEDAR
PROGRAM
IMPORTS IO, RoseTranslateTypes =
BEGIN
ROPE: TYPE = Rope.ROPE;
IntSignalType: TYPE = REF IntSignalTypeRep;
IntSignalTypeRep:
TYPE =
RECORD [
bits: CARDINAL];
intTypes: LIST OF RoseTranslateTypes.SignalType ← NIL;
one: REF ANY ← NEW [INT ← 1];
IntSignalTypeConstructor: RoseTranslateTypes.SignalTypeConstructor =
BEGIN
asAny: REF ANY ← RoseTranslateTypes.GetParm[1, "bits", parms, one];
bits: CARDINAL;
type ← NIL;
WITH asAny
SELECT
FROM
ri: REF INT => bits ← ri^;
ENDCASE => ERROR RoseTranslateTypes.TypeConstructionError["Signal Type INT not given an integer"];
FOR stl:
LIST
OF RoseTranslateTypes.SignalType ← intTypes, stl.rest
WHILE stl #
NIL
DO
istd: IntSignalType ← NARROW[stl.first.data];
IF istd.bits = bits THEN {type ← stl.first; EXIT};
ENDLOOP;
IF type =
NIL
THEN
intTypes ←
CONS[
type ←
NEW [RoseTranslateTypes.SignalTypeRep ← [
intTypeProcs,
NEW[IntSignalTypeRep ← [bits]] ]],
intTypes];
END;
intTypeProcs: RoseTranslateTypes.SignalTypeProcs ←
NEW [RoseTranslateTypes.SignalTypeProcsRep ← [
Info: IntTypeInfo,
Describe: DescribeIntType,
Cannonize: CannonizeIntType,
MesaTypeDecl: MesaForIntType]];
IntTypeInfo:
PROC [data:
REF
ANY]
RETURNS [bitWidth:
INT, roseType, mesaType:
ROPE] =
BEGIN
intSignalType: IntSignalType ← NARROW[data];
bitWidth ← IF intSignalType.bits <= 16 THEN intSignalType.bits ELSE ((intSignalType.bits+15)/16)*16;
roseType ← IO.PutFR["IntType[%g]", IO.int[intSignalType.bits]];
mesaType ← IF intSignalType.bits = 1 THEN "BOOLEAN" ELSE IF intSignalType.bits <= 16 THEN IO.PutFR["[0..%g]", IO.card[uppers[intSignalType.bits]]] ELSE IF intSignalType.bits <= 32 THEN "LONG CARDINAL" ELSE IO.PutFR["ARRAY [0 .. %g) OF CARDINAL", IO.card[(intSignalType.bits+15)/16]];
END;
DescribeIntType:
PROC [data:
REF
ANY]
RETURNS [description:
ROPE] =
BEGIN
intSignalType: IntSignalType ← NARROW[data];
description ← IO.PutFR["INT[%g]", IO.card[intSignalType.bits]];
END;
CannonizeIntType:
PROC [data:
REF
ANY]
RETURNS [cannonized:
REF
ANY] =
{cannonized ← data};
MesaForIntType:
PROC [data:
REF
ANY]
RETURNS [mesaTypeDecl:
ROPE] =
{mesaTypeDecl ← NIL};
uppers: ARRAY [1..16] OF CARDINAL = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535];
RoseTranslateTypes.RegisterSignalTypeConstructor["INT", IntSignalTypeConstructor];
RoseTranslateTypes.SetDefaultSignalType[IntSignalTypeConstructor[NEW [RoseTranslateTypes.ArgsRep ← [LIST[NEW [INT ← 1]]]]]];
END.