C2CIntCodeUtils.mesa
Copyright Ó 1987, 1988, 1989, 1990, 1991, 1993 by Xerox Corporation. All rights reserved.
Christian Jacobi, 1987
Christian Jacobi, January 25, 1993 9:57 am PST
DIRECTORY
C2CBasics, C2CTarget, IntCodeDefs;
C2CIntCodeUtils: CEDAR DEFINITIONS =
BEGIN OPEN IntCodeDefs;
NewVariableId: PROC [] RETURNS [id: VariableId];
--makes up a new unique VariableId
CountNodes: PROC [nodes: NodeList] RETURNS [INT];
--count nodes in list
NodeHasCode: PROC [node: Node] RETURNS [BOOL];
--returns whether node generates some code [is not only comment]
AnyNodeHasCode: PROC [nodes: NodeList] RETURNS [BOOL];
--returns whether nodes generates some code [are not only comments]
LastNodeWithCode: PROC [nodes: NodeList] RETURNS [node: Node];
--returns last node in list which generates some code [is not only comment]
CheckArgCount: PROC [args: NodeList, n: INT];
--Raises an error if args has not n elements
IsSimpleConst: PROC [node: Node] RETURNS [is: BOOL, val: CARD];
--checks whether node is simple, numeric constant
--which fits in a single word
IsFieldVar: PROC [node: Node] RETURNS [BOOL];
--checks whether node is field variable
GenConst: PROC [value: INT, bits: INT ¬ C2CTarget.bitsPerWord] RETURNS [ConstNode];
--generates a node for a constant [with value which fits into an int]
UseTemporaryIfReused: PROC [arg: Node, addr: BOOL ¬ FALSE] RETURNS [BOOL];
--Checks whether duplication of arg should be done by using a temporary variable.
--This is particularly true if arg has side effects (but not errors).
--addr: If true means return if use of addr of arg should have a temporary.
--If no side effects, tries to figure out whether duplication or use of temporary is faster.
--IF USAGE GENERATES STATEMENT-CODE FIX THE FOLLOWING (UsingTemporaryWhichGeneratesStatementCode) PROC TO SAY SO.
UsingTemporaryWhichGeneratesStatementCode: PROC [arg: Node] RETURNS [BOOL];
StatementCode: PROC [node: Node] RETURNS [BOOL];
--Checks whether node contains a label, goto, need for temporary, deep in tree.
--To detect statement code which is not ok in conditional expressions
--This is the stronger test
--Caveat
--Fails to recognize cases of lHSMaskNShift; but that case wont occur unbounded by
--assignment node. [Which is assumed to generate statement code anyway]. Check
--at each application of StatementCode whether lHSMaskNShift might occur...
StatementJumps: PROC [node: Node] RETURNS [BOOL];
--Checks whether node contains a label, goto, shallow in tree
--Does not care about assignments in statement part.
--For detection of the so called block assignments
SizeIsProvableOk: PROC [node: Node] RETURNS [BOOL];
--nasty problem: the intermediate code gives wrong size information where it is not used
--finds out whether this can't happen for a particular node
HasLabel: PROC [node: Node] RETURNS [BOOL];
--Determines whether control flow might enter node
--If node has no label and its predecessor is not live, node can be skipped
END.