Mercurial > cospy
annotate src/cospy.c @ 19:e1197013c423 tip
A simple try on parsing code fragements
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 11 Sep 2010 14:46:04 +0800 |
parents | 882a80582a64 |
children |
rev | line source |
---|---|
0 | 1 #include "gcc-plugin.h" |
2 #include "plugin-version.h" | |
4
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
3 #include "system.h" |
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
4 #include "coretypes.h" |
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
5 #include "tree-pass.h" |
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
6 #include "tree.h" |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
7 #include "tree-iterator.h" |
4
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
8 #include "gimple.h" |
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
9 #include "cgraph.h" |
19
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
10 #include "c-pragma.h" |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
11 #include "cpplib.h" |
0 | 12 #include <stdio.h> |
19
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
13 #include <string.h> |
0 | 14 |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
15 /* This is required for GCC plugin, or it is can not be loaded */ |
0 | 16 int plugin_is_GPL_compatible; |
17 | |
19
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
18 /*! \brief Compile a code fragement */ |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
19 static tree |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
20 compile_code_frag(const uchar *code) { |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
21 int code_len; |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
22 tree body; |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
23 uchar *buf; |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
24 static cnt = 0; |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
25 |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
26 printf("frag\n"); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
27 if(cnt++ != 0) |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
28 return; |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
29 |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
30 /* |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
31 * We need GCC to export more interface of parser to provide the |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
32 * capability of parsing code fragements. |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
33 */ |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
34 code = ""; |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
35 code_len = strlen((char *)code); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
36 buf = (uchar *)ggc_alloc(code_len + 1); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
37 strcpy(buf, code); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
38 code = buf; |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
39 cpp_push_buffer(parse_in, code, code_len, false); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
40 printf("Start parsing\n"); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
41 //c_parse_file(); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
42 printf("Parsed\n"); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
43 //ggc_free(buf); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
44 //body = c_parser_compound_statement(the_parser); /* code between {} */ |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
45 } |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
46 |
7 | 47 /*! \brief Parse a tree of type and return respective string. |
48 * | |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
49 * The struncture of a pointer type |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
50 * - pointer:pointer_type |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
51 * - type:*_type |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
52 * - name:type_decl |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
53 * - name:identifier |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
54 * |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
55 * For a constant type, it is flaged as a readonly. |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
56 * |
7 | 57 * \return a string for the type. It must be free through ggc_free(). |
58 */ | |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
59 static char * |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
60 parse_type(tree type_node) { |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
61 tree type_v; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
62 tree *pointers; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
63 tree type_decl, type_name; |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
64 int ptr_lvl = 0; |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
65 int const_cnt = 0; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
66 char *type_str; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
67 const char *base_type_name; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
68 int type_str_len; |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
69 int str_i, ptr_i; |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
70 |
7 | 71 /* Collect pointers */ |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
72 type_v = type_node; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
73 while(TREE_CODE(type_v) == POINTER_TYPE) { |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
74 if(TREE_READONLY(type_v)) |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
75 const_cnt++; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
76 type_v = TREE_TYPE(type_v); |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
77 ptr_lvl++; |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
78 } |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
79 |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
80 pointers = (tree *)ggc_alloc(sizeof(tree) * ptr_lvl); |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
81 type_v = type_node; |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
82 for(ptr_i = 0; ptr_i < ptr_lvl; ptr_i++) { |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
83 pointers[ptr_i] = type_v; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
84 type_v = TREE_TYPE(type_v); |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
85 } |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
86 |
7 | 87 /* Get name of base type */ |
88 type_decl = TYPE_NAME(type_v); | |
89 type_name = DECL_NAME(type_decl); | |
90 base_type_name = IDENTIFIER_POINTER(type_name); | |
91 | |
92 /* Compute total length of string of full type */ | |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
93 type_str_len = ptr_lvl + strlen(base_type_name) + |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
94 const_cnt * 5; /* "const" */ |
7 | 95 if(TREE_READONLY(type_v)) |
96 type_str_len += 6; /* "const " */ | |
97 type_str = (char *)ggc_alloc(type_str_len + 1); | |
98 | |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
99 /* base type and constant modification */ |
7 | 100 type_str[0] = 0; |
101 if(TREE_READONLY(type_v)) | |
102 strcpy(type_str, "const "); | |
103 strcat(type_str, base_type_name); | |
104 | |
105 /* Add pointers and const modifications after base type */ | |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
106 str_i = strlen(type_str); |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
107 for(ptr_i = ptr_lvl - 1; ptr_i >= 0; ptr_i--) { |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
108 type_v = pointers[ptr_i]; |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
109 type_str[str_i++] = '*'; |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
110 if(TREE_READONLY(type_v)) { |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
111 strcpy(type_str + str_i, "const"); |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
112 str_i += 5; |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
113 } |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
114 } |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
115 type_str[str_i] = 0; |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
116 |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
117 ggc_free(pointers); |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
118 |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
119 return type_str; |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
120 } |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
121 |
8
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
122 /*! \brief Show functions that called by a specified function. |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
123 * |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
124 * \param cgn is cgraph_node of a function. |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
125 */ |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
126 static void |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
127 show_callees(struct cgraph_node *cgn) { |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
128 struct cgraph_edge *edge; |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
129 struct cgraph_node *callee_cgn; |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
130 tree callee, callee_name; |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
131 |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
132 /* Follow edges to called functions */ |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
133 edge = cgn->callees; |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
134 while(edge) { |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
135 callee_cgn = edge->callee; |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
136 callee = callee_cgn->decl; |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
137 callee_name = DECL_NAME(callee); |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
138 |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
139 printf(" call %s\n", IDENTIFIER_POINTER(callee_name)); |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
140 |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
141 edge = edge->next_callee; |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
142 } |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
143 } |
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
144 |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
145 /*! \defgroup tree_travel Tree traveling and manipulation tools. |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
146 * @{ |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
147 */ |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
148 typedef struct _stmt_link { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
149 tree stmt; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
150 struct _stmt_link *parent; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
151 } stmt_link; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
152 |
14
566b62a49462
More information about walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
13
diff
changeset
|
153 /*! \brief Trival tree of GIMPLE code with a callback. |
566b62a49462
More information about walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
13
diff
changeset
|
154 * |
566b62a49462
More information about walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
13
diff
changeset
|
155 * walk_code_free() would call the function given by cb with |
566b62a49462
More information about walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
13
diff
changeset
|
156 * expression and data as arguments. The cb is called only for the |
566b62a49462
More information about walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
13
diff
changeset
|
157 * node with tree code value given by accept_code. |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
158 * |
17
2bf246207140
Doc for visit argument of _walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
16
diff
changeset
|
159 * This fuction is also used to clean visited flag of nodes in a tree. |
2bf246207140
Doc for visit argument of _walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
16
diff
changeset
|
160 * Parameter visit is true for doing normal traveling. Visit is false |
2bf246207140
Doc for visit argument of _walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
16
diff
changeset
|
161 * for doing cleaning. |
2bf246207140
Doc for visit argument of _walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
16
diff
changeset
|
162 * |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
163 * \param accept_code is tree code of nodes that calling cb for or -1 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
164 * to call cb for every node. |
18
882a80582a64
Doc on arguments of _walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
17
diff
changeset
|
165 * \param cb is callback that you want to use for visiting selected nodes. |
882a80582a64
Doc on arguments of _walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
17
diff
changeset
|
166 * \param data is user data passed to cb. |
882a80582a64
Doc on arguments of _walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
17
diff
changeset
|
167 * \param parent is a link node to parent and ancestors. |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
168 * \param visit is true for traveling and false for cleaning. |
14
566b62a49462
More information about walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
13
diff
changeset
|
169 */ |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
170 static void |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
171 _walk_code_tree(tree expr, int accept_code, |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
172 void (*cb)(tree, void *, stmt_link *), void *data, |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
173 stmt_link *parent, bool visit) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
174 stmt_link me = {expr, parent}; |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
175 int code; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
176 tree child; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
177 int i, sz; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
178 tree_stmt_iterator stmt_itr; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
179 |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
180 if(expr == NULL) |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
181 return; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
182 |
16
3808a6ffc881
Fix logical bug walk_code_tree() and duplicate function calls
Thinker K.F. Li <thinker@codemud.net>
parents:
15
diff
changeset
|
183 if(visit && TREE_VISITED(expr)) |
3808a6ffc881
Fix logical bug walk_code_tree() and duplicate function calls
Thinker K.F. Li <thinker@codemud.net>
parents:
15
diff
changeset
|
184 return; |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
185 TREE_VISITED(expr) = visit; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
186 |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
187 code = TREE_CODE(expr); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
188 |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
189 if(cb && (accept_code == -1 || code == accept_code)) |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
190 cb(expr, data, parent); |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
191 |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
192 switch(code) { |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
193 case ERROR_MARK: /* 0 */ |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
194 case IDENTIFIER_NODE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
195 case TREE_LIST: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
196 case TREE_VEC: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
197 case BLOCK: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
198 case OFFSET_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
199 case ENUMERAL_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
200 case BOOLEAN_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
201 case INTEGER_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
202 case REAL_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
203 case POINTER_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
204 case FIXED_POINT_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
205 case REFERENCE_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
206 case COMPLEX_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
207 case VECTOR_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
208 case ARRAY_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
209 case RECORD_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
210 case UNION_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
211 case QUAL_UNION_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
212 case VOID_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
213 case FUNCTION_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
214 case METHOD_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
215 case LANG_TYPE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
216 case INTEGER_CST: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
217 case REAL_CST: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
218 case FIXED_CST: /* 25 */ |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
219 case COMPLEX_CST: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
220 case VECTOR_CST: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
221 case STRING_CST: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
222 case FUNCTION_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
223 case LABEL_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
224 case FIELD_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
225 case VAR_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
226 case CONST_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
227 case PARM_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
228 case TYPE_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
229 case RESULT_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
230 case DEBUG_EXPR_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
231 case NAMESPACE_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
232 case IMPORTED_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
233 case TRANSLATION_UNIT_DECL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
234 case COMPONENT_REF: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
235 case BIT_FIELD_REF: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
236 case REALPART_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
237 case IMAGPART_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
238 case ARRAY_REF: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
239 case ARRAY_RANGE_REF: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
240 case INDIRECT_REF: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
241 case ALIGN_INDIRECT_REF: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
242 case MISALIGNED_INDIRECT_REF: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
243 case OBJ_TYPE_REF: /* 50 */ |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
244 case CONSTRUCTOR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
245 case COMPOUND_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
246 case MODIFY_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
247 case INIT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
248 case TARGET_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
249 case COND_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
250 case VEC_COND_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
251 sz = TREE_OPERAND_LENGTH(expr); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
252 for(i = 0; i < sz; i++) { |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
253 child = TREE_OPERAND(expr, i); |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
254 _walk_code_tree(child, accept_code, cb, data, &me, visit); |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
255 } |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
256 break; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
257 |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
258 case BIND_EXPR: |
14
566b62a49462
More information about walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
13
diff
changeset
|
259 /* See BIND_EXPR in tree.def */ |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
260 child = BIND_EXPR_BODY(expr); |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
261 _walk_code_tree(child, accept_code, cb, data, &me, visit); |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
262 break; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
263 |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
264 case CALL_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
265 case WITH_CLEANUP_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
266 case CLEANUP_POINT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
267 case PLACEHOLDER_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
268 case PLUS_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
269 case MINUS_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
270 case MULT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
271 case POINTER_PLUS_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
272 case TRUNC_DIV_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
273 case CEIL_DIV_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
274 case FLOOR_DIV_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
275 case ROUND_DIV_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
276 case TRUNC_MOD_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
277 case CEIL_MOD_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
278 case FLOOR_MOD_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
279 case ROUND_MOD_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
280 case RDIV_EXPR: /* 75 */ |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
281 case EXACT_DIV_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
282 case FIX_TRUNC_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
283 case FLOAT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
284 case NEGATE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
285 case MIN_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
286 case MAX_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
287 case ABS_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
288 case LSHIFT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
289 case RSHIFT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
290 case LROTATE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
291 case RROTATE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
292 case BIT_IOR_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
293 case BIT_XOR_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
294 case BIT_AND_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
295 case BIT_NOT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
296 case TRUTH_ANDIF_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
297 case TRUTH_ORIF_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
298 case TRUTH_AND_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
299 case TRUTH_OR_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
300 case TRUTH_XOR_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
301 case TRUTH_NOT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
302 case LT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
303 case LE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
304 case GT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
305 case GE_EXPR: /* 100 */ |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
306 case EQ_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
307 case NE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
308 case UNORDERED_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
309 case ORDERED_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
310 case UNLT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
311 case UNLE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
312 case UNGT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
313 case UNGE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
314 case UNEQ_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
315 case LTGT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
316 case RANGE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
317 case PAREN_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
318 case CONVERT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
319 case ADDR_SPACE_CONVERT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
320 case FIXED_CONVERT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
321 case NOP_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
322 case NON_LVALUE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
323 case VIEW_CONVERT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
324 case COMPOUND_LITERAL_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
325 case SAVE_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
326 case ADDR_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
327 case FDESC_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
328 case COMPLEX_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
329 case CONJ_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
330 case PREDECREMENT_EXPR: /* 125 */ |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
331 case PREINCREMENT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
332 case POSTDECREMENT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
333 case POSTINCREMENT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
334 case VA_ARG_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
335 case TRY_CATCH_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
336 case TRY_FINALLY_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
337 case DECL_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
338 case LABEL_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
339 case GOTO_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
340 case RETURN_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
341 case EXIT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
342 case LOOP_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
343 case SWITCH_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
344 case CASE_LABEL_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
345 case ASM_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
346 case SSA_NAME: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
347 case CATCH_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
348 case EH_FILTER_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
349 case SCEV_KNOWN: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
350 case SCEV_NOT_KNOWN: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
351 case POLYNOMIAL_CHREC: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
352 sz = TREE_OPERAND_LENGTH(expr); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
353 for(i = 0; i < sz; i++) { |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
354 child = TREE_OPERAND(expr, i); |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
355 _walk_code_tree(child, accept_code, cb, data, &me, visit); |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
356 } |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
357 break; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
358 |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
359 case STATEMENT_LIST: |
14
566b62a49462
More information about walk_code_tree()
Thinker K.F. Li <thinker@codemud.net>
parents:
13
diff
changeset
|
360 /* See STATEMENT_LIST in tree.def of GCC */ |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
361 for(stmt_itr = tsi_start(expr); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
362 !tsi_end_p(stmt_itr); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
363 tsi_next(&stmt_itr)) { |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
364 child = tsi_stmt(stmt_itr); |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
365 _walk_code_tree(child, accept_code, cb, data, &me, visit); |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
366 } |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
367 break; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
368 |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
369 case ASSERT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
370 case TREE_BINFO: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
371 case WITH_SIZE_EXPR: /* 150 */ |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
372 case REALIGN_LOAD_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
373 case TARGET_MEM_REF: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
374 case OMP_PARALLEL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
375 case OMP_TASK: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
376 case OMP_FOR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
377 case OMP_SECTIONS: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
378 case OMP_SINGLE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
379 case OMP_SECTION: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
380 case OMP_MASTER: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
381 case OMP_ORDERED: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
382 case OMP_CRITICAL: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
383 case OMP_ATOMIC: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
384 case OMP_CLAUSE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
385 case REDUC_MAX_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
386 case REDUC_MIN_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
387 case REDUC_PLUS_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
388 case DOT_PROD_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
389 case WIDEN_SUM_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
390 case WIDEN_MULT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
391 case VEC_LSHIFT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
392 case VEC_RSHIFT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
393 case VEC_WIDEN_MULT_HI_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
394 case VEC_WIDEN_MULT_LO_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
395 case VEC_UNPACK_HI_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
396 case VEC_UNPACK_LO_EXPR: /* 175 */ |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
397 case VEC_UNPACK_FLOAT_HI_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
398 case VEC_UNPACK_FLOAT_LO_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
399 case VEC_PACK_TRUNC_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
400 case VEC_PACK_SAT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
401 case VEC_PACK_FIX_TRUNC_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
402 case VEC_EXTRACT_EVEN_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
403 case VEC_EXTRACT_ODD_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
404 case VEC_INTERLEAVE_HIGH_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
405 case VEC_INTERLEAVE_LOW_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
406 case PREDICT_EXPR: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
407 case OPTIMIZATION_NODE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
408 case TARGET_OPTION_NODE: |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
409 sz = TREE_OPERAND_LENGTH(expr); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
410 for(i = 0; i < sz; i++) { |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
411 child = TREE_OPERAND(expr, i); |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
412 _walk_code_tree(child, accept_code, cb, data, &me, visit); |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
413 } |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
414 break; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
415 } |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
416 } |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
417 |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
418 static void |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
419 walk_code_tree(tree expr, int accept_code, |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
420 void (*cb)(tree, void *, stmt_link *), void *data) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
421 _walk_code_tree(expr, accept_code, cb, data, NULL, true); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
422 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
423 /* cleaning visited flag for every node */ |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
424 _walk_code_tree(expr, -1, NULL, NULL, NULL, false); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
425 } |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
426 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
427 static void |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
428 tree_insert_before_stmt(tree new_node, tree old_node, tree parent) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
429 tree_stmt_iterator itr; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
430 tree visit; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
431 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
432 for(itr = tsi_start(parent); !tsi_end_p(itr); tsi_next(&itr)) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
433 visit = tsi_stmt(itr); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
434 if(visit == old_node) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
435 tsi_link_before(&itr, new_node, TSI_SAME_STMT); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
436 TREE_VISITED(new_node) = true; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
437 break; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
438 } |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
439 } |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
440 } |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
441 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
442 static void |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
443 tree_insert_before_arg(tree new_node, tree old_node, tree parent) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
444 tree visit; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
445 tree compound; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
446 int len; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
447 int i; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
448 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
449 len = TREE_OPERAND_LENGTH(parent); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
450 for(i = 0; i < len; i++) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
451 visit = TREE_OPERAND(parent, i); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
452 if(visit == old_node) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
453 compound = build2(COMPOUND_EXPR, TREE_TYPE(old_node), |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
454 new_node, old_node); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
455 TREE_VISITED(compound) = true; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
456 TREE_OPERAND(parent, i) = compound; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
457 break; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
458 } |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
459 } |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
460 } |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
461 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
462 /*! \brief Insert a new node before an old node under a parent. |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
463 * |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
464 * \param new_node is the node to be inserted. |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
465 * \param old_node is the node where the new one being inserted before. |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
466 * \param parent is the parent node of old_node. |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
467 */ |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
468 static void |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
469 tree_insert_before(tree new_node, tree old_node, tree parent) { |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
470 int pcode; |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
471 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
472 pcode = TREE_CODE(parent); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
473 if(pcode == STATEMENT_LIST) |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
474 tree_insert_before_stmt(new_node, old_node, parent); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
475 else |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
476 tree_insert_before_arg(new_node, old_node, parent); |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
477 } |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
478 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
479 /* @} */ |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
480 |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
481 /*! \brief Called for found CALL_EXPR in a tree when trevaling. |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
482 */ |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
483 static void |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
484 found_call(tree expr, void *data, stmt_link *parent_link) { |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
485 tree addr; |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
486 tree fn, fn_name; |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
487 tree parent = parent_link->stmt; |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
488 |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
489 addr = TREE_OPERAND(expr, 1); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
490 fn = TREE_OPERAND(addr, 0); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
491 fn_name = DECL_NAME(fn); |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
492 |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
493 printf(" CALL %s:%s:%d from a %d\n", |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
494 IDENTIFIER_POINTER(fn_name), |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
495 EXPR_FILENAME(expr), |
15
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
496 EXPR_LINENO(expr), |
cf0d24827624
Tree traveling and manipulation functions
Thinker K.F. Li <thinker@codemud.net>
parents:
14
diff
changeset
|
497 TREE_CODE(parent)); |
16
3808a6ffc881
Fix logical bug walk_code_tree() and duplicate function calls
Thinker K.F. Li <thinker@codemud.net>
parents:
15
diff
changeset
|
498 |
3808a6ffc881
Fix logical bug walk_code_tree() and duplicate function calls
Thinker K.F. Li <thinker@codemud.net>
parents:
15
diff
changeset
|
499 /* Do a function call twice */ |
3808a6ffc881
Fix logical bug walk_code_tree() and duplicate function calls
Thinker K.F. Li <thinker@codemud.net>
parents:
15
diff
changeset
|
500 tree_insert_before(expr, expr, parent); |
19
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
501 |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
502 //compile_code_frag("void ttt(){printf(\"Hello Wolrd!!\\n\");}"); |
e1197013c423
A simple try on parsing code fragements
Thinker K.F. Li <thinker@codemud.net>
parents:
18
diff
changeset
|
503 compile_code_frag("void ts() {ts();}\n"); |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
504 } |
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
505 |
10 | 506 /*! \brief Find all call expression in a code block. |
12
6fdb0cfdc2a7
More information about GIMPLE
Thinker K.F. Li <thinker@codemud.net>
parents:
11
diff
changeset
|
507 * |
6fdb0cfdc2a7
More information about GIMPLE
Thinker K.F. Li <thinker@codemud.net>
parents:
11
diff
changeset
|
508 * This function find CALL_EXPR in body of a function that represented |
6fdb0cfdc2a7
More information about GIMPLE
Thinker K.F. Li <thinker@codemud.net>
parents:
11
diff
changeset
|
509 * as a GIMPE tree. See gcc/tree.def and gcc/c-gimplify.c of GCC for |
6fdb0cfdc2a7
More information about GIMPLE
Thinker K.F. Li <thinker@codemud.net>
parents:
11
diff
changeset
|
510 * more information of tree code of GIMPLE. |
10 | 511 */ |
512 static void | |
513 find_call_expr(tree fn) { | |
11
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
514 tree bind, body; |
10 | 515 |
12
6fdb0cfdc2a7
More information about GIMPLE
Thinker K.F. Li <thinker@codemud.net>
parents:
11
diff
changeset
|
516 bind = DECL_SAVED_TREE(fn); /* BIND_EXPR */ |
11
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
517 body = BIND_EXPR_BODY(bind); |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
518 walk_code_tree(body, CALL_EXPR, found_call, NULL); |
10 | 519 } |
520 | |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
521 /*! \brief This function is called before running all_passes. |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
522 * |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
523 * all_passes is a list of optimization passes of GCC. See |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
524 * init_optimization_passes() in gcc/passes.c of GCC. |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
525 * |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
526 * This function is called for every function. |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
527 */ |
4
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
528 static void |
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
529 handle_all_passes(void *gcc_data, void *user_data) { |
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
530 tree decl; |
8
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
531 struct cgraph_node *cgn; |
4
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
532 |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
533 /* |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
534 * GCC uses cgraph_node to save information of functions and |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
535 * relationships between functions (a.k.a call graphy). |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
536 */ |
4
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
537 decl = cfun->decl; |
8
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
538 cgn = cgraph_node(decl); |
10 | 539 |
8
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
540 printf("%s:%d:%s\n", current_function_name(), |
5
a32f4bd19eda
Show line number and source file after function name
Thinker K.F. Li <thinker@codemud.net>
parents:
4
diff
changeset
|
541 DECL_SOURCE_LINE(decl), |
a32f4bd19eda
Show line number and source file after function name
Thinker K.F. Li <thinker@codemud.net>
parents:
4
diff
changeset
|
542 DECL_SOURCE_FILE(decl)); |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
543 |
8
5502f175d348
Show functions being called
Thinker K.F. Li <thinker@codemud.net>
parents:
7
diff
changeset
|
544 show_callees(cgn); |
11
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
545 } |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
546 |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
547 /*! \brief Called before every optimization pass. |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
548 */ |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
549 static void |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
550 handle_every_pass(void *gcc_data, void *user_data) { |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
551 #if 0 |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
552 printf("PASS %s (type=%x)\n", current_pass->name, current_pass->type); |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
553 #endif |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
554 } |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
555 |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
556 /*! \brief Callback before any optimization pass. |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
557 * |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
558 * It supposed to get function body in GIMPLE statements. If we don't |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
559 * do this, here, it, GIMPLE statements, would be destroyed by |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
560 * optimization passes. |
12
6fdb0cfdc2a7
More information about GIMPLE
Thinker K.F. Li <thinker@codemud.net>
parents:
11
diff
changeset
|
561 |
11
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
562 */ |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
563 static void |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
564 handle_pre_genericize(void *gcc_data, void *user_data) { |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
565 tree fndecl; |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
566 /* for arguments */ |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
567 tree arg, arg_name; |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
568 tree arg_type; |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
569 char *arg_type_str; |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
570 |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
571 fndecl = cfun->decl; |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
572 |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
573 printf("%s:%d:%s\n", current_function_name(), |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
574 DECL_SOURCE_LINE(fndecl), |
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
575 DECL_SOURCE_FILE(fndecl)); |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
576 |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
577 /* |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
578 * Parse and show arguments of the function. |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
579 */ |
11
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
580 arg = DECL_ARGUMENTS(fndecl); |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
581 while(arg) { |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
582 /* |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
583 * The structure of an argument. |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
584 * - parm |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
585 * - name:identifier |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
586 * - type:type |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
587 * - name:type_decl |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
588 * - name:identifier |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
589 */ |
6
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
590 arg_name = DECL_NAME(arg); |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
591 arg_type = TREE_TYPE(arg); |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
592 arg_type_str = parse_type(arg_type); |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
593 printf(" %s:%s\n", |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
594 IDENTIFIER_POINTER(arg_name), |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
595 arg_type_str); |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
596 ggc_free(arg_type_str); |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
597 arg = TREE_CHAIN(arg); |
165781cb4cdd
Parase pointers and const type
Thinker K.F. Li <thinker@codemud.net>
parents:
5
diff
changeset
|
598 } |
11
bf14d3ed008e
Move code of show arguments from before all_pass to before genericize
Thinker K.F. Li <thinker@codemud.net>
parents:
10
diff
changeset
|
599 |
10 | 600 find_call_expr(fndecl); |
601 } | |
602 | |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
603 /*! \brief Initialize function for the plugin. |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
604 */ |
0 | 605 int |
606 plugin_init(struct plugin_name_args *plugin_info, | |
607 struct plugin_gcc_version *version) { | |
608 if (!plugin_default_version_check (version, &gcc_version)) | |
609 return 1; | |
610 printf("Initialize plugin %s\n", plugin_info->base_name); | |
4
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
611 |
9
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
612 /* |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
613 * Register a callback called before running passes in all_passes. |
958c2366e682
More information about design and consideration
Thinker K.F. Li <thinker@codemud.net>
parents:
8
diff
changeset
|
614 */ |
4
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
615 register_callback(plugin_info->base_name, PLUGIN_ALL_PASSES_START, |
8855f7d934ae
Get name of functions before exceuting all_passes
Thinker K.F. Li <thinker@codemud.net>
parents:
3
diff
changeset
|
616 handle_all_passes, NULL); |
10 | 617 |
618 register_callback(plugin_info->base_name, PLUGIN_PASS_EXECUTION, | |
619 handle_every_pass, NULL); | |
620 | |
621 /* | |
622 * Call handle_pre_genericize before genericize a function. | |
623 * | |
624 * This callback is run before any optimization pass. It is just | |
625 * after finishing (parsing) a function. | |
626 */ | |
627 register_callback(plugin_info->base_name, PLUGIN_PRE_GENERICIZE, | |
628 handle_pre_genericize, NULL); | |
0 | 629 return 0; |
630 } | |
13
708921504d6d
Find CALL_EXPR and show information of the call
Thinker K.F. Li <thinker@codemud.net>
parents:
12
diff
changeset
|
631 |