1 /* Convert language-specific tree expression to rtl instructions,
3 Copyright (C) 1988, 92-97, 1998, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
35 static tree extract_aggr_init
PARAMS ((tree
, tree
));
36 static tree extract_scalar_init
PARAMS ((tree
, tree
));
38 static rtx cplus_expand_expr
PARAMS ((tree
, rtx
, enum machine_mode
,
39 enum expand_modifier
));
41 /* Hook used by output_constant to expand language-specific
45 cplus_expand_constant (cst
)
48 switch (TREE_CODE (cst
))
52 tree type
= TREE_TYPE (cst
);
56 /* Find the member. */
57 member
= PTRMEM_CST_MEMBER (cst
);
59 if (TREE_CODE (member
) == FIELD_DECL
)
61 /* Find the offset for the field. */
62 offset
= convert (sizetype
,
63 size_binop (EASY_DIV_EXPR
,
64 DECL_FIELD_BITPOS (member
),
65 size_int (BITS_PER_UNIT
)));
67 /* We offset all pointer to data members by 1 so that we
68 can distinguish between a null pointer to data member
69 and the first data member of a structure. */
70 offset
= size_binop (PLUS_EXPR
, offset
, size_int (1));
72 cst
= cp_convert (type
, offset
);
81 expand_ptrmemfunc_cst (cst
, &delta
, &idx
, &pfn
, &delta2
);
83 cst
= build_ptrmemfunc1 (type
, delta
, idx
,
90 /* There's nothing to do. */
97 /* Hook used by expand_expr to expand language-specific tree codes. */
100 cplus_expand_expr (exp
, target
, tmode
, modifier
)
103 enum machine_mode tmode
;
104 enum expand_modifier modifier
;
106 tree type
= TREE_TYPE (exp
);
107 register enum machine_mode mode
= TYPE_MODE (type
);
108 register enum tree_code code
= TREE_CODE (exp
);
109 int ignore
= target
== const0_rtx
;
114 /* No sense saving up arithmetic to be done
115 if it's all in the wrong mode to form part of an address.
116 And force_operand won't know whether to sign-extend or zero-extend. */
118 if (mode
!= Pmode
&& modifier
== EXPAND_SUM
)
119 modifier
= EXPAND_NORMAL
;
124 return expand_expr (cplus_expand_constant (exp
),
125 target
, tmode
, modifier
);
129 return expand_expr (default_conversion (resolve_offset_ref (exp
)),
130 target
, tmode
, EXPAND_NORMAL
);
134 my_friendly_assert (DECL_RTL (exp
) != NULL_RTX
, 20000115);
135 return DECL_RTL (exp
);
138 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
, 0);
139 expand_internal_throw ();
142 case EMPTY_CLASS_EXPR
:
143 /* We don't need to generate any code for an empty class. */
148 tree rtl_expr
= begin_stmt_expr ();
149 expand_stmt (STMT_EXPR_STMT (exp
));
150 finish_stmt_expr (rtl_expr
);
151 return expand_expr (rtl_expr
, target
, tmode
, modifier
);
158 my_friendly_abort (40);
166 lang_expand_expr
= cplus_expand_expr
;
167 lang_expand_constant
= cplus_expand_constant
;
170 /* If DECL had its rtl moved from where callers expect it
171 to be, fix it up. RESULT is the nominal rtl for the RESULT_DECL,
172 which may be a pseudo instead of a hard register. */
175 fixup_result_decl (decl
, result
)
181 if (REGNO (result
) >= FIRST_PSEUDO_REGISTER
)
183 rtx real_decl_result
;
185 #ifdef FUNCTION_OUTGOING_VALUE
187 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl
), current_function_decl
);
190 = FUNCTION_VALUE (TREE_TYPE (decl
), current_function_decl
);
192 REG_FUNCTION_VALUE_P (real_decl_result
) = 1;
193 result
= real_decl_result
;
195 store_expr (decl
, result
, 0);
196 emit_insn (gen_rtx (USE
, VOIDmode
, result
));
201 /* Expand this initialization inline and see if it's simple enough that
202 it can be done at compile-time. */
205 extract_aggr_init (decl
, init
)
212 extract_scalar_init (decl
, init
)
215 rtx value
, insns
, insn
;
216 extern struct obstack temporary_obstack
;
220 value
= expand_expr (init
, NULL_RTX
, VOIDmode
, 0);
221 insns
= get_insns ();
223 reg_scan (insns
, max_reg_num (), 0);
224 jump_optimize (insns
, 0, 0, 1);
226 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
230 if (GET_CODE (insn
) == NOTE
)
232 else if (GET_CODE (insn
) != INSN
)
236 if (GET_CODE (r
) != SET
)
242 || (GET_CODE (to
) == SUBREG
&& XEXP (to
, 0) == value
)))
247 switch (GET_CODE (r
))
250 t
= build_int_2 (XEXP (r
, 0), 0);
262 extract_init (decl
, init
)
263 tree decl ATTRIBUTE_UNUSED
, init ATTRIBUTE_UNUSED
;
268 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
269 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
270 init
= extract_aggr_init (decl
, init
);
272 init
= extract_scalar_init (decl
, init
);
274 if (init
== NULL_TREE
)
277 DECL_INITIAL (decl
) = init
;
286 tree value1
= NULL_TREE
, value2
= NULL_TREE
, label
;
288 if (start
!= NULL_TREE
&& TREE_TYPE (start
) != NULL_TREE
289 && POINTER_TYPE_P (TREE_TYPE (start
)))
290 error ("pointers are not permitted as case values");
293 pedwarn ("ANSI C++ forbids range expressions in switch statement");
296 value1
= check_cp_case_value (start
);
298 value2
= check_cp_case_value (end
);
300 label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
302 if (value1
!= error_mark_node
303 && value2
!= error_mark_node
)
309 success
= pushcase_range (value1
, value2
, convert_and_check
,
312 success
= pushcase (value1
, convert_and_check
, label
, &duplicate
);
314 success
= pushcase (NULL_TREE
, 0, label
, &duplicate
);
319 error ("case label not within a switch statement");
321 cp_error ("case label `%E' not within a switch statement", start
);
323 error ("default label not within a switch statement");
325 else if (success
== 2)
329 error ("duplicate (or overlapping) case value");
330 cp_error_at ("this is the first entry overlapping that value",
335 cp_error ("duplicate case value `%E'", start
);
336 cp_error_at ("previously used here", duplicate
);
340 error ("multiple default labels in one switch");
341 cp_error_at ("this is the first default label", duplicate
);
344 else if (success
== 3)
345 warning ("case value out of range");
346 else if (success
== 4)
347 warning ("empty range specified");
348 else if (success
== 5)
351 error ("case label within scope of cleanup or variable array");
353 error ("`default' label within scope of cleanup or variable array");
355 cp_error ("case label `%E' within scope of cleanup or variable array", start
);
359 current_function_return_value
= NULL_TREE
;