]>
Commit | Line | Data |
---|---|---|
2ec5deb5 | 1 | /* This file contains subroutine used by the C front-end to construct GENERIC. |
5624e564 | 2 | Copyright (C) 2000-2015 Free Software Foundation, Inc. |
4f78b9a8 | 3 | Written by Benjamin Chelf (chelf@codesourcery.com). |
f2c5f623 | 4 | |
1322177d | 5 | This file is part of GCC. |
f2c5f623 | 6 | |
1322177d LB |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 10 | version. |
f2c5f623 | 11 | |
1322177d LB |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
f2c5f623 BC |
16 | |
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
f2c5f623 BC |
20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
4977bab6 ZW |
23 | #include "coretypes.h" |
24 | #include "tm.h" | |
f2c5f623 | 25 | #include "tree.h" |
83685514 AM |
26 | #include "hashtab.h" |
27 | #include "hash-set.h" | |
28 | #include "vec.h" | |
29 | #include "machmode.h" | |
30 | #include "hard-reg-set.h" | |
31 | #include "input.h" | |
f2c5f623 BC |
32 | #include "function.h" |
33 | #include "splay-tree.h" | |
f2c5f623 | 34 | #include "c-common.h" |
f2c5f623 | 35 | #include "flags.h" |
726a989a | 36 | #include "tree-iterator.h" |
96c6931d | 37 | |
ae499cce MM |
38 | /* Create an empty statement tree rooted at T. */ |
39 | ||
325c3691 RH |
40 | tree |
41 | push_stmt_list (void) | |
ae499cce | 42 | { |
325c3691 RH |
43 | tree t; |
44 | t = alloc_stmt_list (); | |
9771b263 | 45 | vec_safe_push (stmt_list_stack, t); |
325c3691 RH |
46 | return t; |
47 | } | |
48 | ||
325c3691 RH |
49 | /* Finish the statement tree rooted at T. */ |
50 | ||
51 | tree | |
52 | pop_stmt_list (tree t) | |
53 | { | |
38e01f9e | 54 | tree u = NULL_TREE; |
325c3691 RH |
55 | |
56 | /* Pop statement lists until we reach the target level. The extra | |
57 | nestings will be due to outstanding cleanups. */ | |
58 | while (1) | |
59 | { | |
9771b263 DN |
60 | u = stmt_list_stack->pop (); |
61 | if (!stmt_list_stack->is_empty ()) | |
38e01f9e | 62 | { |
9771b263 | 63 | tree x = stmt_list_stack->last (); |
38e01f9e NF |
64 | STATEMENT_LIST_HAS_LABEL (x) |= STATEMENT_LIST_HAS_LABEL (u); |
65 | } | |
325c3691 RH |
66 | if (t == u) |
67 | break; | |
325c3691 | 68 | } |
38e01f9e NF |
69 | |
70 | gcc_assert (u != NULL_TREE); | |
325c3691 RH |
71 | |
72 | /* If the statement list is completely empty, just return it. This is | |
c22cacf3 | 73 | just as good small as build_empty_stmt, with the advantage that |
325c3691 RH |
74 | statement lists are merged when they appended to one another. So |
75 | using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P | |
76 | statements. */ | |
77 | if (TREE_SIDE_EFFECTS (t)) | |
78 | { | |
79 | tree_stmt_iterator i = tsi_start (t); | |
80 | ||
81 | /* If the statement list contained exactly one statement, then | |
82 | extract it immediately. */ | |
83 | if (tsi_one_before_end_p (i)) | |
84 | { | |
85 | u = tsi_stmt (i); | |
86 | tsi_delink (&i); | |
87 | free_stmt_list (t); | |
88 | t = u; | |
89 | } | |
90 | } | |
91 | ||
92 | return t; | |
ae499cce MM |
93 | } |
94 | ||
0dfdeca6 BC |
95 | /* Build a generic statement based on the given type of node and |
96 | arguments. Similar to `build_nt', except that we set | |
c2255bc4 | 97 | EXPR_LOCATION to LOC. */ |
64094f6a RH |
98 | /* ??? This should be obsolete with the lineno_stmt productions |
99 | in the grammar. */ | |
0dfdeca6 BC |
100 | |
101 | tree | |
c2255bc4 | 102 | build_stmt (location_t loc, enum tree_code code, ...) |
0dfdeca6 | 103 | { |
6de9cd9a DN |
104 | tree ret; |
105 | int length, i; | |
e34d07f2 | 106 | va_list p; |
6de9cd9a | 107 | bool side_effects; |
2f6e4e97 | 108 | |
5039610b SL |
109 | /* This function cannot be used to construct variably-sized nodes. */ |
110 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); | |
111 | ||
e34d07f2 | 112 | va_start (p, code); |
0dfdeca6 | 113 | |
6de9cd9a | 114 | ret = make_node (code); |
9e14e18f | 115 | TREE_TYPE (ret) = void_type_node; |
0dfdeca6 | 116 | length = TREE_CODE_LENGTH (code); |
c2255bc4 | 117 | SET_EXPR_LOCATION (ret, loc); |
0dfdeca6 | 118 | |
bbcfd969 ILT |
119 | /* TREE_SIDE_EFFECTS will already be set for statements with |
120 | implicit side effects. Here we make sure it is set for other | |
121 | expressions by checking whether the parameters have side | |
122 | effects. */ | |
f2c5f623 | 123 | |
bbcfd969 | 124 | side_effects = false; |
6de9cd9a | 125 | for (i = 0; i < length; i++) |
f2c5f623 | 126 | { |
6de9cd9a | 127 | tree t = va_arg (p, tree); |
3f724eb8 | 128 | if (t && !TYPE_P (t)) |
c22cacf3 | 129 | side_effects |= TREE_SIDE_EFFECTS (t); |
6de9cd9a | 130 | TREE_OPERAND (ret, i) = t; |
f2c5f623 | 131 | } |
6de9cd9a | 132 | |
bbcfd969 | 133 | TREE_SIDE_EFFECTS (ret) |= side_effects; |
6de9cd9a DN |
134 | |
135 | va_end (p); | |
136 | return ret; | |
f2c5f623 BC |
137 | } |
138 | ||
fb52b50a NF |
139 | /* Build a REALPART_EXPR or IMAGPART_EXPR, according to CODE, from ARG. */ |
140 | ||
141 | tree | |
142 | build_real_imag_expr (location_t location, enum tree_code code, tree arg) | |
143 | { | |
144 | tree ret; | |
145 | tree arg_type = TREE_TYPE (arg); | |
146 | ||
147 | gcc_assert (code == REALPART_EXPR || code == IMAGPART_EXPR); | |
148 | ||
149 | if (TREE_CODE (arg_type) == COMPLEX_TYPE) | |
150 | { | |
151 | ret = build1 (code, TREE_TYPE (TREE_TYPE (arg)), arg); | |
152 | SET_EXPR_LOCATION (ret, location); | |
153 | } | |
154 | else if (INTEGRAL_TYPE_P (arg_type) || SCALAR_FLOAT_TYPE_P (arg_type)) | |
155 | { | |
156 | ret = (code == REALPART_EXPR | |
157 | ? arg | |
158 | : omit_one_operand_loc (location, arg_type, | |
159 | integer_zero_node, arg)); | |
160 | } | |
161 | else | |
162 | { | |
163 | error_at (location, "wrong type argument to %s", | |
164 | code == REALPART_EXPR ? "__real" : "__imag"); | |
165 | ret = error_mark_node; | |
166 | } | |
167 | ||
168 | return ret; | |
169 | } |