]>
Commit | Line | Data |
---|---|---|
862f468c | 1 | /* This file contains subroutine used by the C front-end to construct GENERIC. |
d353bf18 | 2 | Copyright (C) 2000-2015 Free Software Foundation, Inc. |
efbe600e | 3 | Written by Benjamin Chelf (chelf@codesourcery.com). |
5c3247a9 | 4 | |
f12b58b3 | 5 | This file is part of GCC. |
5c3247a9 | 6 | |
f12b58b3 | 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 | |
8c4c00c1 | 9 | Software Foundation; either version 3, or (at your option) any later |
f12b58b3 | 10 | version. |
5c3247a9 | 11 | |
f12b58b3 | 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. | |
5c3247a9 | 16 | |
17 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
5c3247a9 | 20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
805e22b2 | 23 | #include "coretypes.h" |
24 | #include "tm.h" | |
b20a8bb4 | 25 | #include "alias.h" |
b20a8bb4 | 26 | #include "tree.h" |
9ef16211 | 27 | #include "options.h" |
b20a8bb4 | 28 | #include "hard-reg-set.h" |
5c3247a9 | 29 | #include "function.h" |
30 | #include "splay-tree.h" | |
5c3247a9 | 31 | #include "c-common.h" |
5c3247a9 | 32 | #include "flags.h" |
75a70cf9 | 33 | #include "tree-iterator.h" |
3b584d94 | 34 | |
a08e60ae | 35 | /* Create an empty statement tree rooted at T. */ |
36 | ||
2363ef00 | 37 | tree |
38 | push_stmt_list (void) | |
a08e60ae | 39 | { |
2363ef00 | 40 | tree t; |
41 | t = alloc_stmt_list (); | |
f1f41a6c | 42 | vec_safe_push (stmt_list_stack, t); |
2363ef00 | 43 | return t; |
44 | } | |
45 | ||
2363ef00 | 46 | /* Finish the statement tree rooted at T. */ |
47 | ||
48 | tree | |
49 | pop_stmt_list (tree t) | |
50 | { | |
cacfdc02 | 51 | tree u = NULL_TREE; |
2363ef00 | 52 | |
53 | /* Pop statement lists until we reach the target level. The extra | |
54 | nestings will be due to outstanding cleanups. */ | |
55 | while (1) | |
56 | { | |
f1f41a6c | 57 | u = stmt_list_stack->pop (); |
58 | if (!stmt_list_stack->is_empty ()) | |
cacfdc02 | 59 | { |
f1f41a6c | 60 | tree x = stmt_list_stack->last (); |
cacfdc02 | 61 | STATEMENT_LIST_HAS_LABEL (x) |= STATEMENT_LIST_HAS_LABEL (u); |
62 | } | |
2363ef00 | 63 | if (t == u) |
64 | break; | |
2363ef00 | 65 | } |
cacfdc02 | 66 | |
67 | gcc_assert (u != NULL_TREE); | |
2363ef00 | 68 | |
69 | /* If the statement list is completely empty, just return it. This is | |
a0c938f0 | 70 | just as good small as build_empty_stmt, with the advantage that |
2363ef00 | 71 | statement lists are merged when they appended to one another. So |
72 | using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P | |
73 | statements. */ | |
74 | if (TREE_SIDE_EFFECTS (t)) | |
75 | { | |
76 | tree_stmt_iterator i = tsi_start (t); | |
77 | ||
78 | /* If the statement list contained exactly one statement, then | |
79 | extract it immediately. */ | |
80 | if (tsi_one_before_end_p (i)) | |
81 | { | |
82 | u = tsi_stmt (i); | |
83 | tsi_delink (&i); | |
84 | free_stmt_list (t); | |
85 | t = u; | |
86 | } | |
87 | } | |
88 | ||
89 | return t; | |
a08e60ae | 90 | } |
91 | ||
389acd0a | 92 | /* Build a generic statement based on the given type of node and |
93 | arguments. Similar to `build_nt', except that we set | |
e60a6f7b | 94 | EXPR_LOCATION to LOC. */ |
7cad36f4 | 95 | /* ??? This should be obsolete with the lineno_stmt productions |
96 | in the grammar. */ | |
389acd0a | 97 | |
98 | tree | |
e60a6f7b | 99 | build_stmt (location_t loc, enum tree_code code, ...) |
389acd0a | 100 | { |
4ee9c684 | 101 | tree ret; |
102 | int length, i; | |
ee582a61 | 103 | va_list p; |
4ee9c684 | 104 | bool side_effects; |
2b30d46c | 105 | |
c2f47e15 | 106 | /* This function cannot be used to construct variably-sized nodes. */ |
107 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); | |
108 | ||
ee582a61 | 109 | va_start (p, code); |
389acd0a | 110 | |
4ee9c684 | 111 | ret = make_node (code); |
daf6dff5 | 112 | TREE_TYPE (ret) = void_type_node; |
389acd0a | 113 | length = TREE_CODE_LENGTH (code); |
e60a6f7b | 114 | SET_EXPR_LOCATION (ret, loc); |
389acd0a | 115 | |
db8577ff | 116 | /* TREE_SIDE_EFFECTS will already be set for statements with |
117 | implicit side effects. Here we make sure it is set for other | |
118 | expressions by checking whether the parameters have side | |
119 | effects. */ | |
5c3247a9 | 120 | |
db8577ff | 121 | side_effects = false; |
4ee9c684 | 122 | for (i = 0; i < length; i++) |
5c3247a9 | 123 | { |
4ee9c684 | 124 | tree t = va_arg (p, tree); |
5dd4318b | 125 | if (t && !TYPE_P (t)) |
a0c938f0 | 126 | side_effects |= TREE_SIDE_EFFECTS (t); |
4ee9c684 | 127 | TREE_OPERAND (ret, i) = t; |
5c3247a9 | 128 | } |
4ee9c684 | 129 | |
db8577ff | 130 | TREE_SIDE_EFFECTS (ret) |= side_effects; |
4ee9c684 | 131 | |
132 | va_end (p); | |
133 | return ret; | |
5c3247a9 | 134 | } |
135 | ||
0b5fc5d6 | 136 | /* Build a REALPART_EXPR or IMAGPART_EXPR, according to CODE, from ARG. */ |
137 | ||
138 | tree | |
139 | build_real_imag_expr (location_t location, enum tree_code code, tree arg) | |
140 | { | |
141 | tree ret; | |
142 | tree arg_type = TREE_TYPE (arg); | |
143 | ||
144 | gcc_assert (code == REALPART_EXPR || code == IMAGPART_EXPR); | |
145 | ||
146 | if (TREE_CODE (arg_type) == COMPLEX_TYPE) | |
147 | { | |
148 | ret = build1 (code, TREE_TYPE (TREE_TYPE (arg)), arg); | |
149 | SET_EXPR_LOCATION (ret, location); | |
150 | } | |
151 | else if (INTEGRAL_TYPE_P (arg_type) || SCALAR_FLOAT_TYPE_P (arg_type)) | |
152 | { | |
153 | ret = (code == REALPART_EXPR | |
154 | ? arg | |
155 | : omit_one_operand_loc (location, arg_type, | |
156 | integer_zero_node, arg)); | |
157 | } | |
158 | else | |
159 | { | |
160 | error_at (location, "wrong type argument to %s", | |
161 | code == REALPART_EXPR ? "__real" : "__imag"); | |
162 | ret = error_mark_node; | |
163 | } | |
164 | ||
165 | return ret; | |
166 | } |