2. • The purpose of GENERIC is simply to provide a
language-independent way of representing an
entire function in trees.
• A statement is defined as any expression whose
value is ignored.
• A statement will always have TREE_SIDE_EFFECTS
set
3. • You can tell what kind of node a particular tree is
by using the TREE_CODE macro.
• All GENERIC trees have two fields in common.
• TREE_CHAIN
• a pointer be used as a singly-linked list
• TREE_TYPE
4. code & flags
tree type
tree chain
struct tree_base
struct tree_typed
struct tree_common
typedef union tree_node *tree
typedef const union tree_node *const_tree
union tree_node
5. IDENTIFIER_NODE
• There are never two distinct IDENTIFIER_NODEs
representing the same identifier.
• IDENTIFIER_POINTER
• IDENTIFIER_LENGTH
6. Container
• Two kinds of container
• TREE_LIST
• TREE_PURPOSE
• TREE_VALUE
• The next node is found by following the TREE_CHAIN
• TREE_VEC
• TREE_VEC_LENGTH
• TREE_VEC_ELT
7. code & flags
tree type
tree chain
struct tree_base
struct tree_typed
struct tree_common
tree_list
purposetree
valuetree
code & flags
tree type
tree chain
purpose
value
tree_list
NULL_TREE
8. code & flags
tree type
tree chain
struct tree_base
struct tree_typed
struct tree_common
tree_vec
a[1]tree
10. Declarations
• LABEL_DECL
• CONST_DECL
• enumeration constants
• RESULT_DECL
• the value returned by a function
• TYPE_DECL
• typedef declarations
• VAR_DECL
• variables with namespace or block scope
• static data members
• PARM_DECL
• a parameter to a function
• DEBUG_EXPR_DECL
• FIELD_DECL
• non-static data members
• NAMESPACE_DECL
11. VAR_DECL
• DECL_SIZE
• DECL_ALIGN
• DECL_THIS_STATIC
• static variable
• DECL_THIS_EXTERN
• extern variable
• DECL_INITIAL
• an expression for the initialiser
13. Attributes
• TREE_LIST
• TREE_PURPOSE
• the name of the attribute
• TREE_VALUE
• TREE_LIST of the arguments of the attribute
• TREE_CHAIN
• next attribute
• DECL_ATTRIBUTES (tree decl)
• DECL_ATTRIBUTES (tree type)
14. Statements
• ASM_EXPR
• inline assembly
• DECL_EXPR
• a local declaration
• LABEL_EXPR
• GOTO_EXPR
• goto statement
• RETURN_EXPR
• return statement
• LOOP_EXPR
• infinite loop
• EXIT_EXPR
• conditional exit from the nearest LOOP_EXPR
• SWITCH_EXPR
• switch statement
• CASE_LABEL_EXPR
• a case label
17. FUNCTION_DECL
BIND_EXPR
saved_tree
gimplify_stmt
int test_gimple(int param_a, char param_b, float param_c)
{
int local;
local = param_a + param_b;
local = (int)((float)local * param_c);
return local;
}
locus
VOID_TYPE
type
VAR_DECL
operands[0]
INTEGER_TYPE
type
BLOCK
operands[2]
STATEMENT_LIST
operands[1]
DECL_EXPR
head
VAR_DECL
operands[0]
INTEGER_TYPE
type
MODIFY_EXPR
VAR_DECL PLUS_EXPR
operands[0] operands[1]
INTEGER_TYPE
type
NOP_EXPR PARM_DECL
operands[0] operands[1]
PARM_DECL
operands[0]
18. Functions
• A function is represented by a FUNCTION_DECL node.
• DECL_NAME
• DECL_ASSEMBLER_NAME
• DECL_ARGUMENTS
• PARM_DECL for the first argument
• Subsequent PARM_DECL nodes can be obtained by following the TREE_CHAIN links.
• DECL_RESULT
• RESULT_DECL
• DECL_SAVED_TREE
• the complete body of the function
• TREE_TYPE
• FUNCTION_TYPE
• METHOD_TYPE