SaffronTypeSizeImpl.Mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
James Rauen, July 12, 1988 3:43:47 pm PDT
Last edited by: James Rauen July 12, 1988 4:34:53 pm PDT
This module contains procedures which determine the amount of space occupied by instances of a type.
DIRECTORY
BigIntegers USING [BigINT, BigFromSmall],
SaffronBaseDef USING [CastIntegerValue, CompilerStateNode, GetIntrinsicIntegerTypes, ValueNode],
SaffronContextPrivateTypes USING [ElementTGNBody, TypeGraphNodeNodeBody],
SaffronErrorHandling USING [InternalError];
SaffronTypeSizeImpl: CEDAR PROGRAM
IMPORTS BigIntegers, SaffronBaseDef, SaffronErrorHandling
EXPORTS SaffronBaseDef
= BEGIN
OPEN BD: SaffronBaseDef, PT: SaffronContextPrivateTypes;
Borrowed Types
From PT
TypeGraphNodeNode: TYPE = REF TypeGraphNodeNodeBody;
TypeGraphNodeNodeBody: PUBLIC TYPE = PT.TypeGraphNodeNodeBody;
Public Procedures
NumberOfBits: PUBLIC PROC [type: TypeGraphNodeNode, n: BD.ValueNode, cs: BD.CompilerStateNode] RETURNS [BD.ValueNode] ~ BEGIN
nBits: BigIntegers.BigINT ← BigIntegers.BigFromSmall[0];
RETURN[BD.CastIntegerValue[nBits, BD.GetIntrinsicIntegerTypes[cs]]];
END;
NumberOfBytes: PUBLIC PROC [type: TypeGraphNodeNode, n: BD.ValueNode, cs: BD.CompilerStateNode] RETURNS [BD.ValueNode] ~ BEGIN
nBits: BigIntegers.BigINT ← BigIntegers.BigFromSmall[0];
RETURN[BD.CastIntegerValue[nBits, BD.GetIntrinsicIntegerTypes[cs]]];
END;
NumberOfWords: PUBLIC PROC [type: TypeGraphNodeNode, n: BD.ValueNode, cs: BD.CompilerStateNode] RETURNS [BD.ValueNode] ~ BEGIN
nBits: BigIntegers.BigINT ← BigIntegers.BigFromSmall[0];
RETURN[BD.CastIntegerValue[nBits, BD.GetIntrinsicIntegerTypes[cs]]];
END;
Dispatch Procedure
BitSizeOf: PROC [type: TypeGraphNodeNode, cs: BD.CompilerStateNode] RETURNS [BD.ValueNode] ~ BEGIN
RETURN [
WITH type.body SELECT FROM
u: REF atom PT.BaseTypeTGNBody => BitSizeOfAtomBaseType[u, cs],
u: REF boolean base PT.ElementTGNBody => StaticIntInstance[1, cs],
u: REF integer base PT.ElementTGNBody => BitSizeOfIntegerBaseType[u, cs],
u: PT.SpecialTGN  => BitSizeOfSpecial[u, cs],
u: PT.SubrangeTGN  => BitSizeOfSubrange[u, cs],
u: PT.RecordTGN  => BitSizeOfRecord[u, cs],
u: PT.PointerTGN  => BitSizeOfPointer[u, cs],
u: PT.RefTGN  => BitSizeOfRef[u, cs],
u: PT.VarTGN  => BitSizeOfVar[u, cs],
u: PT.RelativeTGN  => BitSizeOfRelative[u, cs],
u: PT.ReferentTGN  => BitSizeOfReferent[u, cs],
u: PT.ListTGN  => BitSizeOfList[u, cs],
u: PT.EnumTGN  => BitSizeOfEnum[u, cs],
u: PT.VariantPartTGN  => BitSizeOfVariantPart[u, cs],
u: PT.SequenceTGN  => BitSizeOfSequence[u, cs],
u: PT.ArrayTGN  => BitSizeOfArray[u, cs],
u: PT.DescriptorTGN  => BitSizeOfDescriptor[u, cs],
u: PT.TransferTGN  => BitSizeOfTransfer[u, cs],
u: PT.ZoneTGN  => BitSizeOfZone[u, cs],
u: PT.LongTGN  => BitSizeOfLong[u, cs],
u: PT.InterfaceTGN  => BitSizeOfInterface[u, cs],
u: PT.LinkTGN  => BitSizeOfLink[u, cs],
u: PT.FrameTGN  => BitSizeOfFrame[u, cs],
u: PT.SpecianatedTGN  => BitSizeOfSpecianated[u, cs],
u: PT.OpaqueTGN  => BitSizeOfOpaque[u, cs],
ENDCASE =>
ERROR SaffronErrorHandling.InternalError["Unrecognized type passed as first
argument to SaffronTypeSizeImpl.BitSizeOf"]
];
END;
Easy Values
StaticIntInstance: PROC [j: INT, cs: BD.CompilerStateNode] RETURNS [BD.ValueNode] ~ {
RETURN[BD.CastIntegerValue[
BigIntegers.BigFromSmall[j],
BD.GetIntrinsicIntegerTypes[cs]]];
};
Methods
BitSizeOfIntegerBaseType: PROC [u: REF integer base PT.ElementTGNBody, cs: BD.CompilerStateNode] RETURNS [BD.ValueNode] ~ BEGIN
RETURN[StaticIntInstance[u.body.nBits + u.body.nUnusedBits + (IF u.body.signed THEN 1 ELSE 0), cs]];
END;
END.