1 /* Convert language-specific tree expression to rtl instructions,
2 for GNU CHILL compiler.
3 Copyright (C) 1992, 93, 1994 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
34 extern char **boolean_code_name
;
35 extern int flag_old_strings
;
36 extern tree long_unsigned_type_node
;
37 extern int ignore_case
;
38 extern int special_UC
;
40 /* definitions for duration built-ins */
41 #define MILLISECS_MULTIPLIER 1
42 #define SECS_MULTIPLIER MILLISECS_MULTIPLIER * 1000
43 #define MINUTES_MULTIPLIER SECS_MULTIPLIER * 60
44 #define HOURS_MULTIPLIER MINUTES_MULTIPLIER * 60
45 #define DAYS_MULTIPLIER HOURS_MULTIPLIER * 24
47 /* the maximum value for each of the calls */
48 #define MILLISECS_MAX 0xffffffff
49 #define SECS_MAX 4294967
50 #define MINUTES_MAX 71582
51 #define HOURS_MAX 1193
54 /* forward declaration */
55 rtx chill_expand_expr
PROTO((tree
, rtx
, enum machine_mode
,
56 enum expand_modifier
));
58 /* variable to hold the type the DESCR built-in returns */
59 static tree descr_type
= NULL_TREE
;
62 /* called from ch-lex.l */
66 lang_expand_expr
= chill_expand_expr
;
69 /* Take the address of something that needs to be passed by reference. */
74 /* FIXME. Move to memory, if needed. */
75 if (TREE_CODE (value
) == INDIRECT_REF
)
76 return convert_to_pointer (ptr_type_node
, TREE_OPERAND (value
, 0));
77 mark_addressable (value
);
78 return build1 (ADDR_EXPR
, ptr_type_node
, value
);
81 /* Check that EXP has a known type. */
84 check_have_mode (exp
, context
)
88 if (TREE_CODE (exp
) != ERROR_MARK
&& TREE_TYPE (exp
) == NULL_TREE
)
90 if (TREE_CODE (exp
) == CONSTRUCTOR
)
91 error ("tuple without specified mode not allowed in %s", context
);
92 else if (TREE_CODE (exp
) == COND_EXPR
|| TREE_CODE (exp
) == CASE_EXPR
)
93 error ("conditional expression not allowed in %s", context
);
95 error ("internal error: unknown expression mode in %s", context
);
97 return error_mark_node
;
102 /* Check that EXP is discrete. Handle conversion if flag_old_strings. */
105 check_case_selector (exp
)
108 if (exp
!= NULL_TREE
&& TREE_TYPE (exp
) != NULL_TREE
)
109 exp
= convert_to_discrete (exp
);
112 error ("CASE selector is not a discrete expression");
113 return error_mark_node
;
117 check_case_selector_list (list
)
120 tree selector
, exp
, return_list
= NULL_TREE
;
122 for (selector
= list
; selector
!= NULL_TREE
; selector
= TREE_CHAIN (selector
))
124 exp
= check_case_selector (TREE_VALUE (selector
));
125 if (exp
== error_mark_node
)
127 return_list
= error_mark_node
;
130 return_list
= tree_cons (TREE_PURPOSE (selector
), exp
, return_list
);
133 return nreverse(return_list
);
137 chill_expand_case_expr (expr
)
140 tree selector_list
= TREE_OPERAND (expr
, 0), selector
;
141 tree alternatives
= TREE_OPERAND (expr
, 1);
142 tree type
= TREE_TYPE (expr
);
146 if (TREE_CODE (selector_list
) != TREE_LIST
147 || TREE_CODE (alternatives
) != TREE_LIST
)
149 if (TREE_CHAIN (selector_list
) != NULL_TREE
)
152 /* make a temp for the case result */
153 result
= decl_temp1 (get_unique_identifier ("CASE_EXPR"),
154 type
, 0, NULL_TREE
, 0, 0);
156 selector
= check_case_selector (TREE_VALUE (selector_list
));
158 expand_start_case (1, selector
, TREE_TYPE (selector
), "CASE expression");
160 alternatives
= nreverse (alternatives
);
161 for ( ; alternatives
!= NULL_TREE
; alternatives
= TREE_CHAIN (alternatives
))
163 tree labels
= TREE_PURPOSE (alternatives
), t
;
165 if (labels
== NULL_TREE
)
167 chill_handle_case_default ();
173 if (labels
!= NULL_TREE
)
175 for (label
= TREE_VALUE (labels
);
176 label
!= NULL_TREE
; label
= TREE_CHAIN (label
))
177 chill_handle_case_label (TREE_VALUE (label
), selector
);
178 labels
= TREE_CHAIN (labels
);
179 if (labels
!= NULL_TREE
)
180 error ("The number of CASE selectors does not match the number "
181 "of CASE label lists");
186 t
= build (MODIFY_EXPR
, type
, result
,
187 convert (type
, TREE_VALUE (alternatives
)));
188 TREE_SIDE_EFFECTS (t
) = 1;
189 expand_expr_stmt (t
);
190 expand_exit_something ();
195 chill_handle_case_default ();
196 expand_exit_something ();
201 check_missing_cases (TREE_TYPE (selector
));
204 expand_end_case (selector
);
208 /* Hook used by expand_expr to expand CHILL-specific tree codes. */
211 chill_expand_expr (exp
, target
, tmode
, modifier
)
214 enum machine_mode tmode
;
215 enum expand_modifier modifier
;
217 tree type
= TREE_TYPE (exp
);
218 register enum machine_mode mode
= TYPE_MODE (type
);
219 register enum tree_code code
= TREE_CODE (exp
);
220 rtx original_target
= target
;
222 int ignore
= target
== const0_rtx
;
223 char *lib_func
; /* name of library routine */
226 target
= 0, original_target
= 0;
228 /* No sense saving up arithmetic to be done
229 if it's all in the wrong mode to form part of an address.
230 And force_operand won't know whether to sign-extend or zero-extend. */
232 if (mode
!= Pmode
&& modifier
== EXPAND_SUM
)
233 modifier
= EXPAND_NORMAL
;
240 rtx func
= gen_rtx (SYMBOL_REF
, Pmode
,
241 code
== STRING_EQ_EXPR
? "__eqstring"
243 tree exp0
= TREE_OPERAND (exp
, 0);
244 tree exp1
= TREE_OPERAND (exp
, 1);
246 rtx op0
, op1
, siz0
, siz1
;
247 if (chill_varying_type_p (TREE_TYPE (exp0
)))
249 exp0
= save_if_needed (exp0
);
250 size0
= convert (integer_type_node
,
251 build_component_ref (exp0
, var_length_id
));
252 exp0
= build_component_ref (exp0
, var_data_id
);
255 size0
= size_in_bytes (TREE_TYPE (exp0
));
256 if (chill_varying_type_p (TREE_TYPE (exp1
)))
258 exp1
= save_if_needed (exp1
);
259 size1
= convert (integer_type_node
,
260 build_component_ref (exp1
, var_length_id
));
261 exp1
= build_component_ref (exp1
, var_data_id
);
264 size1
= size_in_bytes (TREE_TYPE (exp1
));
266 op0
= expand_expr (force_addr_of (exp0
),
267 NULL_RTX
, MEM
, EXPAND_CONST_ADDRESS
);
268 op1
= expand_expr (force_addr_of (exp1
),
269 NULL_RTX
, MEM
, EXPAND_CONST_ADDRESS
);
270 siz0
= expand_expr (size0
, NULL_RTX
, VOIDmode
, 0);
271 siz1
= expand_expr (size1
, NULL_RTX
, VOIDmode
, 0);
272 return emit_library_call_value (func
, target
,
275 siz0
, TYPE_MODE (sizetype
),
277 siz1
, TYPE_MODE (sizetype
));
281 return expand_expr (chill_expand_case_expr (exp
),
282 NULL_RTX
, VOIDmode
, 0);
288 tree array
= TREE_OPERAND (exp
, 0);
289 tree min_value
= TREE_OPERAND (exp
, 1);
290 tree length
= TREE_OPERAND (exp
, 2);
291 tree new_type
= TREE_TYPE (exp
);
292 tree temp
= decl_temp1 (get_unique_identifier ("BITSTRING"),
293 new_type
, 0, NULL_TREE
, 0, 0);
294 if (! CH_REFERABLE (array
) && TYPE_MODE (TREE_TYPE (array
)) != BLKmode
)
295 array
= decl_temp1 (get_unique_identifier ("BSTRINGVAL"),
296 TREE_TYPE (array
), 0, array
, 0, 0);
297 func_call
= build_chill_function_call (
298 lookup_name (get_identifier ("__psslice")),
299 tree_cons (NULL_TREE
,
300 build_chill_addr_expr (temp
, (char *)0),
301 tree_cons (NULL_TREE
, length
,
302 tree_cons (NULL_TREE
,
303 force_addr_of (array
),
304 tree_cons (NULL_TREE
, powersetlen (array
),
305 tree_cons (NULL_TREE
, convert (integer_type_node
, min_value
),
306 tree_cons (NULL_TREE
, length
, NULL_TREE
)))))));
307 expand_expr (func_call
, const0_rtx
, VOIDmode
, 0);
309 return expand_expr (temp
, ignore
? const0_rtx
: target
,
313 /* void __concatstring (char *out, char *left, unsigned left_len,
314 char *right, unsigned right_len) */
317 tree exp0
= TREE_OPERAND (exp
, 0);
318 tree exp1
= TREE_OPERAND (exp
, 1);
322 if (TREE_CODE (exp1
) == UNDEFINED_EXPR
)
324 if (TYPE_MODE (TREE_TYPE (exp0
)) == BLKmode
325 && TYPE_MODE (TREE_TYPE (exp
)) == BLKmode
)
327 rtx temp
= expand_expr (exp0
, target
, tmode
, modifier
);
328 if (temp
== target
|| target
== NULL_RTX
)
330 emit_block_move (target
, temp
, expr_size (exp0
),
331 TYPE_ALIGN (TREE_TYPE(exp0
)) / BITS_PER_UNIT
);
336 exp0
= force_addr_of (exp0
);
337 exp0
= convert (build_pointer_type (TREE_TYPE (exp
)), exp0
);
338 exp0
= build1 (INDIRECT_REF
, TREE_TYPE (exp
), exp0
);
339 return expand_expr (exp0
,
340 NULL_RTX
, Pmode
, EXPAND_CONST_ADDRESS
);
344 if (TREE_CODE (type
) == ARRAY_TYPE
)
346 /* No need to handle scalars or varying strings here, since that
347 was done in convert or build_concat_expr. */
348 size0
= expand_expr (size_in_bytes (TREE_TYPE (exp0
)),
349 NULL_RTX
, Pmode
, EXPAND_CONST_ADDRESS
);
351 size1
= expand_expr (size_in_bytes (TREE_TYPE (exp1
)),
352 NULL_RTX
, Pmode
, EXPAND_CONST_ADDRESS
);
354 /* build a temp for the result, target is its address */
355 if (target
== NULL_RTX
)
357 tree type0
= TREE_TYPE (exp0
);
358 tree type1
= TREE_TYPE (exp1
);
359 int len0
= int_size_in_bytes (type0
);
360 int len1
= int_size_in_bytes (type1
);
362 if (len0
< 0 && TYPE_ARRAY_MAX_SIZE (type0
)
363 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type0
)) == INTEGER_CST
)
364 len0
= TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type0
));
366 if (len1
< 0 && TYPE_ARRAY_MAX_SIZE (type1
)
367 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type1
)) == INTEGER_CST
)
368 len1
= TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type1
));
370 if (len0
< 0 || len1
< 0)
371 fatal ("internal error - don't know how much space is needed for concatenation");
372 target
= assign_stack_temp (mode
, len0
+ len1
, 0);
373 preserve_temp_slots (target
);
376 else if (TREE_CODE (type
) == SET_TYPE
)
378 if (target
== NULL_RTX
)
380 target
= assign_stack_temp (mode
, int_size_in_bytes (type
), 0);
381 preserve_temp_slots (target
);
387 if (GET_CODE (target
) == MEM
)
390 targetx
= assign_stack_temp (mode
, GET_MODE_SIZE (mode
), 0);
392 /* expand 1st operand to a pointer to the array */
393 op0
= expand_expr (force_addr_of (exp0
),
394 NULL_RTX
, MEM
, EXPAND_CONST_ADDRESS
);
396 /* expand 2nd operand to a pointer to the array */
397 op1
= expand_expr (force_addr_of (exp1
),
398 NULL_RTX
, MEM
, EXPAND_CONST_ADDRESS
);
400 if (TREE_CODE (type
) == SET_TYPE
)
402 size0
= expand_expr (powersetlen (exp0
),
403 NULL_RTX
, VOIDmode
, 0);
404 size1
= expand_expr (powersetlen (exp1
),
405 NULL_RTX
, VOIDmode
, 0);
407 emit_library_call (gen_rtx(SYMBOL_REF
, Pmode
, "__concatps"),
408 0, Pmode
, 5, XEXP (targetx
, 0), Pmode
,
410 convert_to_mode (TYPE_MODE (sizetype
),
411 size0
, TREE_UNSIGNED (sizetype
)),
412 TYPE_MODE (sizetype
),
414 convert_to_mode (TYPE_MODE (sizetype
),
415 size1
, TREE_UNSIGNED (sizetype
)),
416 TYPE_MODE (sizetype
));
420 /* copy left, then right array to target */
421 emit_library_call (gen_rtx(SYMBOL_REF
, Pmode
, "__concatstring"),
422 0, Pmode
, 5, XEXP (targetx
, 0), Pmode
,
424 convert_to_mode (TYPE_MODE (sizetype
),
425 size0
, TREE_UNSIGNED (sizetype
)),
426 TYPE_MODE (sizetype
),
428 convert_to_mode (TYPE_MODE (sizetype
),
429 size1
, TREE_UNSIGNED (sizetype
)),
430 TYPE_MODE (sizetype
));
432 if (targetx
!= target
)
433 emit_move_insn (target
, targetx
);
437 /* FIXME: the set_length computed below is a compile-time constant;
438 you'll need to re-write that part for VARYING bit arrays, and
439 possibly the set pointer will need to be adjusted to point past
440 the word containing its dynamic length. */
442 /* void __notpowerset (char *out, char *src,
443 unsigned long bitlength) */
447 tree expr
= TREE_OPERAND (exp
, 0);
448 tree tsize
= powersetlen (expr
);
451 if (TREE_CODE (TREE_TYPE (expr
)) != SET_TYPE
)
452 tsize
= fold (build (MULT_EXPR
, sizetype
, tsize
,
453 size_int (BITS_PER_UNIT
)));
455 /* expand 1st operand to a pointer to the set */
456 op0
= expand_expr (force_addr_of (expr
),
457 NULL_RTX
, MEM
, EXPAND_CONST_ADDRESS
);
459 /* build a temp for the result, target is its address */
460 if (target
== NULL_RTX
)
462 target
= assign_stack_temp (TYPE_MODE (TREE_TYPE (exp
)),
463 int_size_in_bytes (TREE_TYPE (exp
)),
465 preserve_temp_slots (target
);
467 if (GET_CODE (target
) == MEM
)
470 targetx
= assign_stack_temp (GET_MODE (target
),
471 GET_MODE_SIZE (GET_MODE (target
)),
473 emit_library_call (gen_rtx(SYMBOL_REF
, Pmode
, "__notpowerset"),
474 0, VOIDmode
, 3, XEXP (targetx
, 0), Pmode
,
476 expand_expr (tsize
, NULL_RTX
, MEM
,
477 EXPAND_CONST_ADDRESS
),
478 TYPE_MODE (long_unsigned_type_node
));
479 if (targetx
!= target
)
480 emit_move_insn (target
, targetx
);
485 lib_func
= "__diffpowerset";
489 lib_func
= "__orpowerset";
493 lib_func
= "__xorpowerset";
496 /* void __diffpowerset (char *out, char *left, char *right,
497 unsigned bitlength) */
499 lib_func
= "__andpowerset";
502 tree expr
= TREE_OPERAND (exp
, 0);
503 tree tsize
= powersetlen (expr
);
506 if (TREE_CODE (TREE_TYPE (expr
)) != SET_TYPE
)
507 tsize
= fold (build (MULT_EXPR
, long_unsigned_type_node
,
509 size_int (BITS_PER_UNIT
)));
511 /* expand 1st operand to a pointer to the set */
512 op0
= expand_expr (force_addr_of (expr
),
513 NULL_RTX
, MEM
, EXPAND_CONST_ADDRESS
);
515 /* expand 2nd operand to a pointer to the set */
516 op1
= expand_expr (force_addr_of (TREE_OPERAND (exp
, 1)),
518 EXPAND_CONST_ADDRESS
);
520 /* FIXME: re-examine this code - the unary operator code above has recently
521 (93/03/12) been changed a lot. Should this code also change? */
522 /* build a temp for the result, target is its address */
523 if (target
== NULL_RTX
)
525 target
= assign_stack_temp (TYPE_MODE (TREE_TYPE (exp
)),
526 int_size_in_bytes (TREE_TYPE (exp
)),
528 preserve_temp_slots (target
);
530 if (GET_CODE (target
) == MEM
)
533 targetx
= assign_stack_temp (GET_MODE (target
),
534 GET_MODE_SIZE (GET_MODE (target
)), 0);
535 emit_library_call (gen_rtx(SYMBOL_REF
, Pmode
, lib_func
),
536 0, VOIDmode
, 4, XEXP (targetx
, 0), Pmode
,
537 op0
, GET_MODE (op0
), op1
, GET_MODE (op1
),
538 expand_expr (tsize
, NULL_RTX
, MEM
,
539 EXPAND_CONST_ADDRESS
),
540 TYPE_MODE (long_unsigned_type_node
));
541 if (target
!= targetx
)
542 emit_move_insn (target
, targetx
);
548 tree set
= TREE_OPERAND (exp
, 1);
549 tree pos
= convert (long_unsigned_type_node
, TREE_OPERAND (exp
, 0));
550 tree set_type
= TREE_TYPE (set
);
551 tree set_length
= discrete_count (TYPE_DOMAIN (set_type
));
552 tree min_val
= convert (long_integer_type_node
,
553 TYPE_MIN_VALUE (TYPE_DOMAIN (set_type
)));
556 /* FIXME: Function-call not needed if pos and width are constant! */
557 if (! mark_addressable (set
))
559 error ("powerset is not addressable");
562 /* we use different functions for bitstrings and powersets */
563 if (CH_BOOLS_TYPE_P (set_type
))
565 build_chill_function_call (
566 lookup_name (get_identifier ("__inbitstring")),
567 tree_cons (NULL_TREE
,
568 convert (long_unsigned_type_node
, pos
),
569 tree_cons (NULL_TREE
,
570 build1 (ADDR_EXPR
, build_pointer_type (set_type
), set
),
571 tree_cons (NULL_TREE
,
572 convert (long_unsigned_type_node
, set_length
),
573 tree_cons (NULL_TREE
, min_val
,
574 tree_cons (NULL_TREE
, force_addr_of (get_chill_filename ()),
575 build_tree_list (NULL_TREE
, get_chill_linenumber ())))))));
578 build_chill_function_call (
579 lookup_name (get_identifier ("__inpowerset")),
580 tree_cons (NULL_TREE
,
581 convert (long_unsigned_type_node
, pos
),
582 tree_cons (NULL_TREE
,
583 build1 (ADDR_EXPR
, build_pointer_type (set_type
), set
),
584 tree_cons (NULL_TREE
,
585 convert (long_unsigned_type_node
, set_length
),
586 build_tree_list (NULL_TREE
, min_val
)))));
587 return expand_expr (fcall
, NULL_RTX
, VOIDmode
, 0);
590 case PACKED_ARRAY_REF
:
592 tree array
= TREE_OPERAND (exp
, 0);
593 tree pos
= save_expr (TREE_OPERAND (exp
, 1));
594 tree array_type
= TREE_TYPE (array
);
595 tree array_length
= discrete_count (TYPE_DOMAIN (array_type
));
596 tree min_val
= convert (long_integer_type_node
,
597 TYPE_MIN_VALUE (TYPE_DOMAIN (array_type
)));
600 /* FIXME: Function-call not needed if pos and width are constant! */
601 /* TODO: make sure this makes sense. */
602 if (! mark_addressable (array
))
604 error ("array is not addressable");
608 build_chill_function_call (
609 lookup_name (get_identifier ("__inpowerset")),
610 tree_cons (NULL_TREE
,
611 convert (long_unsigned_type_node
, pos
),
612 tree_cons (NULL_TREE
,
613 build1 (ADDR_EXPR
, build_pointer_type (array_type
), array
),
614 tree_cons (NULL_TREE
,
615 convert (long_unsigned_type_node
, array_length
),
616 build_tree_list (NULL_TREE
, min_val
)))));
617 return expand_expr (fcall
, NULL_RTX
, VOIDmode
, 0);
623 target
= assign_stack_temp (TYPE_MODE (TREE_TYPE (exp
)),
624 int_size_in_bytes (TREE_TYPE (exp
)), 0);
625 preserve_temp_slots (target
);
627 /* We don't actually need to *do* anything ... */
638 /* Check that the argument list has a length in [min_length .. max_length].
639 (max_length == -1 means "infinite".)
640 If so return the actual length.
641 Otherwise, return an error message and return -1. */
644 check_arglist_length (args
, min_length
, max_length
, name
)
650 int length
= list_length (args
);
651 if (length
< min_length
)
652 error ("Too few arguments in call to `%s'", IDENTIFIER_POINTER (name
));
653 else if (max_length
!= -1 && length
> max_length
)
654 error ("Too many arguments in call to `%s'", IDENTIFIER_POINTER (name
));
661 * This is the code from c-typeck.c, with the C-specific cruft
662 * removed (possibly I just didn't understand it, but it was
663 * apparently simply discarding part of my LIST).
666 internal_build_compound_expr (list
, first_p
)
668 int first_p ATTRIBUTE_UNUSED
;
672 if (TREE_CHAIN (list
) == 0)
673 return TREE_VALUE (list
);
675 rest
= internal_build_compound_expr (TREE_CHAIN (list
), FALSE
);
677 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
680 return build (COMPOUND_EXPR
, TREE_TYPE (rest
), TREE_VALUE (list
), rest
);
684 /* Given a list of expressions, return a compound expression
685 that performs them all and returns the value of the last of them. */
686 /* FIXME: this should be merged with the C version */
688 build_chill_compound_expr (list
)
691 return internal_build_compound_expr (list
, TRUE
);
694 /* Given an expression PTR for a pointer, return an expression
695 for the value pointed to.
696 do_empty_check is 0, don't perform a NULL pointer check,
700 build_chill_indirect_ref (ptr
, mode
, do_empty_check
)
707 if (ptr
== NULL_TREE
|| TREE_CODE (ptr
) == ERROR_MARK
)
709 if (mode
!= NULL_TREE
&& TREE_CODE (mode
) == ERROR_MARK
)
710 return error_mark_node
;
712 type
= TREE_TYPE (ptr
);
714 if (TREE_CODE (type
) == REFERENCE_TYPE
)
716 type
= TREE_TYPE (type
);
717 ptr
= convert (type
, ptr
);
720 /* check for ptr is really a POINTER */
721 if (TREE_CODE (type
) != POINTER_TYPE
)
723 error ("cannot dereference, not a pointer.");
724 return error_mark_node
;
727 if (mode
&& TREE_CODE (mode
) == IDENTIFIER_NODE
)
729 tree decl
= lookup_name (mode
);
730 if (decl
== NULL_TREE
|| TREE_CODE (decl
) != TYPE_DECL
)
733 error ("missing '.' operator or undefined mode name `%s'.",
734 IDENTIFIER_POINTER (mode
));
736 error ("You have forgotten the '.' operator which must");
737 error (" precede a STRUCT field reference, or `%s' is an undefined mode",
738 IDENTIFIER_POINTER (mode
));
740 return error_mark_node
;
746 mode
= get_type_of (mode
);
747 ptr
= convert (build_pointer_type (mode
), ptr
);
749 else if (type
== ptr_type_node
)
751 error ("Can't dereference PTR value using unary `->'.");
752 return error_mark_node
;
756 ptr
= check_non_null (ptr
);
758 type
= TREE_TYPE (ptr
);
760 if (TREE_CODE (type
) == POINTER_TYPE
)
762 if (TREE_CODE (ptr
) == ADDR_EXPR
764 && (TREE_TYPE (TREE_OPERAND (ptr
, 0))
765 == TREE_TYPE (type
)))
766 return TREE_OPERAND (ptr
, 0);
769 tree t
= TREE_TYPE (type
);
770 register tree ref
= build1 (INDIRECT_REF
,
771 TYPE_MAIN_VARIANT (t
), ptr
);
773 if (TYPE_SIZE (t
) == 0 && TREE_CODE (t
) != ARRAY_TYPE
)
775 error ("dereferencing pointer to incomplete type");
776 return error_mark_node
;
778 if (TREE_CODE (t
) == VOID_TYPE
)
779 warning ("dereferencing `void *' pointer");
781 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
782 so that we get the proper error message if the result is used
783 to assign to. Also, &* is supposed to be a no-op.
784 And ANSI C seems to specify that the type of the result
785 should be the const type. */
786 /* A de-reference of a pointer to const is not a const. It is valid
787 to change it via some other pointer. */
788 TREE_READONLY (ref
) = TYPE_READONLY (t
);
789 TREE_SIDE_EFFECTS (ref
)
790 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (ptr
) || flag_volatile
;
791 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
) || flag_volatile
;
795 else if (TREE_CODE (ptr
) != ERROR_MARK
)
796 error ("invalid type argument of `->'");
797 return error_mark_node
;
800 /* NODE is a COMPONENT_REF whose mode is an IDENTIFIER,
801 which is replaced by the proper FIELD_DECL.
802 Also do the right thing for variant records. */
805 resolve_component_ref (node
)
808 tree datum
= TREE_OPERAND (node
, 0);
809 tree field_name
= TREE_OPERAND (node
, 1);
810 tree type
= TREE_TYPE (datum
);
812 if (TREE_CODE (datum
) == ERROR_MARK
)
813 return error_mark_node
;
814 if (TREE_CODE (type
) == REFERENCE_TYPE
)
816 type
= TREE_TYPE (type
);
817 TREE_OPERAND (node
, 0) = datum
= convert (type
, datum
);
819 if (TREE_CODE (type
) != RECORD_TYPE
)
821 error ("operand of '.' is not a STRUCT");
822 return error_mark_node
;
825 TREE_READONLY (node
) = TREE_READONLY (datum
);
826 TREE_SIDE_EFFECTS (node
) = TREE_SIDE_EFFECTS (datum
);
828 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
830 if (TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
833 for (variant
= TYPE_FIELDS (TREE_TYPE (field
));
834 variant
; variant
= TREE_CHAIN (variant
))
837 for (vfield
= TYPE_FIELDS (TREE_TYPE (variant
));
838 vfield
; vfield
= TREE_CHAIN (vfield
))
840 if (DECL_NAME (vfield
) == field_name
)
841 { /* Found a variant field */
842 datum
= build (COMPONENT_REF
, TREE_TYPE (field
),
844 datum
= build (COMPONENT_REF
, TREE_TYPE (variant
),
846 TREE_OPERAND (node
, 0) = datum
;
847 TREE_OPERAND (node
, 1) = vfield
;
848 TREE_TYPE (node
) = TREE_TYPE (vfield
);
849 TREE_READONLY (node
) |= TYPE_READONLY (TREE_TYPE (node
));
851 if (flag_testing_tags
)
853 tree tagtest
= NOT IMPLEMENTED
;
854 tree tagf
= ridpointers
[(int) RID_RANGEFAIL
];
855 node
= check_expression (node
, tagtest
,
865 if (DECL_NAME (field
) == field_name
)
866 { /* Found a fixed field */
867 TREE_OPERAND (node
, 1) = field
;
868 TREE_TYPE (node
) = TREE_TYPE (field
);
869 TREE_READONLY (node
) |= TYPE_READONLY (TREE_TYPE (node
));
874 error ("No field named `%s'", IDENTIFIER_POINTER (field_name
));
875 return error_mark_node
;
879 build_component_ref (datum
, field_name
)
880 tree datum
, field_name
;
882 tree node
= build_nt (COMPONENT_REF
, datum
, field_name
);
884 node
= resolve_component_ref (node
);
889 function checks (for build_chill_component_ref) if a given
890 type is really an instance type. CH_IS_INSTANCE_MODE is not
891 strict enough in this case, i.e. SYNMODE foo = STRUCT (a, b UINT)
892 is compatible to INSTANCE. */
895 is_really_instance (type
)
898 tree decl
= TYPE_NAME (type
);
900 if (decl
== NULL_TREE
)
901 /* this is not an instance */
904 if (DECL_NAME (decl
) == ridpointers
[(int)RID_INSTANCE
])
905 /* this is an instance */
908 if (TYPE_FIELDS (type
) == TYPE_FIELDS (instance_type_node
))
909 /* we have a NEWMODE'd instance */
915 /* This function is called by the parse.
916 Here we check if the user tries to access a field in a type which is
917 layouted as a structure but isn't like INSTANCE, BUFFER, EVENT, ASSOCIATION,
918 ACCESS, TEXT, or VARYING array or character string.
919 We don't do this in build_component_ref cause this function gets
920 called from the compiler to access fields in one of the above mentioned
923 build_chill_component_ref (datum
, field_name
)
924 tree datum
, field_name
;
926 tree type
= TREE_TYPE (datum
);
927 if ((type
!= NULL_TREE
&& TREE_CODE (type
) == RECORD_TYPE
) &&
928 ((CH_IS_INSTANCE_MODE (type
) && is_really_instance (type
)) ||
929 CH_IS_BUFFER_MODE (type
) ||
930 CH_IS_EVENT_MODE (type
) || CH_IS_ASSOCIATION_MODE (type
) ||
931 CH_IS_ACCESS_MODE (type
) || CH_IS_TEXT_MODE (type
) ||
932 chill_varying_type_p (type
)))
934 error ("operand of '.' is not a STRUCT");
935 return error_mark_node
;
937 return build_component_ref (datum
, field_name
);
941 * Check for invalid binary operands & unary operands
942 * RIGHT is 1 if checking right operand or unary operand;
943 * it is 0 if checking left operand.
945 * return 1 if the given operand is NOT compatible as the
946 * operand of the given operator
948 * return 0 if they might be compatible
951 invalid_operand (code
, type
, right
)
952 enum chill_tree_code code
;
954 int right
; /* 1 if right operand */
969 case CONCAT_EXPR
: /* must be static or varying char array */
970 if (TREE_CODE (type
) == CHAR_TYPE
)
972 if (TREE_CODE (type
) == ARRAY_TYPE
973 && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
975 if (!chill_varying_type_p (type
))
977 if (TREE_CODE (TREE_TYPE (CH_VARYING_ARRAY_TYPE (type
)))
982 /* note: CHILL conditional expressions (COND_EXPR) won't come
983 * through here; they're routed straight to C-specific code */
985 return 0; /* ANYTHING can be compared equal */
987 if (TREE_CODE (type
) == REAL_TYPE
)
994 if (TREE_CODE (type
) == SET_TYPE
)
998 case PACKED_ARRAY_REF
:
999 if (TREE_CODE (type
) == ARRAY_TYPE
)
1006 switch ((int)TREE_CODE(type
)) /* right operand must be set/bitarray type */
1009 if (TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
1030 if (chill_varying_type_p (type
)
1031 && TREE_CODE (TREE_TYPE (CH_VARYING_ARRAY_TYPE (type
))) == CHAR_TYPE
)
1035 case REFERENCE_TYPE
:
1046 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
1051 return 0; /* ANYTHING can be compared unequal */
1053 return 0; /* ANYTHING can be converted */
1056 switch ((int)TREE_CODE(type
)) /* left operand must be discrete type */
1059 if (right
|| TREE_CODE (TREE_TYPE (type
)) != BOOLEAN_TYPE
)
1073 case REFERENCE_TYPE
:
1090 case REPLICATE_EXPR
:
1091 switch ((int)TREE_CODE(type
)) /* right operand must be set/bitarray type */
1112 case REFERENCE_TYPE
:
1117 case TRUNC_DIV_EXPR
:
1119 case TRUNC_MOD_EXPR
:
1120 if (TREE_CODE (type
) == REAL_TYPE
)
1123 case TRUTH_ANDIF_EXPR
:
1124 case TRUTH_AND_EXPR
:
1125 case TRUTH_NOT_EXPR
:
1126 case TRUTH_ORIF_EXPR
:
1129 switch ((int)TREE_CODE(type
)) /* left operand must be discrete type */
1145 case REFERENCE_TYPE
:
1157 return 1; /* perhaps you forgot to add a new DEFTREECODE? */
1164 invalid_right_operand (code
, type
)
1165 enum chill_tree_code code
;
1168 return invalid_operand (code
, type
, 1);
1172 build_chill_abs (expr
)
1177 if (TREE_CODE (TREE_TYPE (expr
)) == REAL_TYPE
1178 || discrete_type_p (TREE_TYPE (expr
)))
1179 temp
= fold (build1 (ABS_EXPR
, TREE_TYPE (expr
), expr
));
1182 error("ABS argument must be discrete or real mode");
1183 return error_mark_node
;
1185 /* FIXME: should call
1186 * cond_type_range_exception (temp);
1192 build_chill_abstime (exprlist
)
1195 int mask
= 0, i
, numargs
;
1196 tree args
= NULL_TREE
;
1197 tree filename
, lineno
;
1201 if (exprlist
!= NULL_TREE
&& TREE_CODE (exprlist
) == ERROR_MARK
)
1202 return error_mark_node
;
1204 /* check for integer expressions */
1207 while (tmp
!= NULL_TREE
)
1209 tree exp
= TREE_VALUE (tmp
);
1211 if (exp
== NULL_TREE
|| TREE_CODE (exp
) == ERROR_MARK
)
1213 else if (TREE_CODE (TREE_TYPE (exp
)) != INTEGER_TYPE
)
1215 error ("argument %d to ABSTIME must be of integer type.", i
);
1218 tmp
= TREE_CHAIN (tmp
);
1222 return error_mark_node
;
1224 numargs
= list_length (exprlist
);
1225 for (i
= 0; i
< numargs
; i
++)
1228 /* make it all arguments */
1229 for (i
= numargs
; i
< 6; i
++)
1230 exprlist
= tree_cons (NULL_TREE
, integer_zero_node
, exprlist
);
1232 args
= tree_cons (NULL_TREE
, build_int_2 (mask
, 0), exprlist
);
1234 filename
= force_addr_of (get_chill_filename ());
1235 lineno
= get_chill_linenumber ();
1236 args
= chainon (args
, tree_cons (NULL_TREE
, filename
,
1237 tree_cons (NULL_TREE
, lineno
, NULL_TREE
)));
1239 return build_chill_function_call (
1240 lookup_name (get_identifier ("_abstime")), args
);
1245 build_allocate_memory_call (ptr
, size
)
1250 /* check for ptr is referable */
1251 if (! CH_REFERABLE (ptr
))
1253 error ("parameter 1 must be referable.");
1256 /* check for pointer */
1257 else if (TREE_CODE (TREE_TYPE (ptr
)) != POINTER_TYPE
)
1259 error ("mode mismatch in parameter 1.");
1263 /* check for size > 0 if it is a constant */
1264 if (TREE_CODE (size
) == INTEGER_CST
&& TREE_INT_CST_LOW (size
) <= 0)
1266 error ("parameter 2 must be a positive integer.");
1270 return error_mark_node
;
1272 if (TREE_TYPE (ptr
) != ptr_type_node
)
1273 ptr
= build_chill_cast (ptr_type_node
, ptr
);
1275 return build_chill_function_call (
1276 lookup_name (get_identifier ("_allocate_memory")),
1277 tree_cons (NULL_TREE
, ptr
,
1278 tree_cons (NULL_TREE
, size
,
1279 tree_cons (NULL_TREE
, force_addr_of (get_chill_filename ()),
1280 tree_cons (NULL_TREE
, get_chill_linenumber (),
1286 build_allocate_global_memory_call (ptr
, size
)
1291 /* check for ptr is referable */
1292 if (! CH_REFERABLE (ptr
))
1294 error ("parameter 1 must be referable.");
1297 /* check for pointer */
1298 else if (TREE_CODE (TREE_TYPE (ptr
)) != POINTER_TYPE
)
1300 error ("mode mismatch in parameter 1.");
1304 /* check for size > 0 if it is a constant */
1305 if (TREE_CODE (size
) == INTEGER_CST
&& TREE_INT_CST_LOW (size
) <= 0)
1307 error ("parameter 2 must be a positive integer.");
1311 return error_mark_node
;
1313 if (TREE_TYPE (ptr
) != ptr_type_node
)
1314 ptr
= build_chill_cast (ptr_type_node
, ptr
);
1316 return build_chill_function_call (
1317 lookup_name (get_identifier ("_allocate_global_memory")),
1318 tree_cons (NULL_TREE
, ptr
,
1319 tree_cons (NULL_TREE
, size
,
1320 tree_cons (NULL_TREE
, force_addr_of (get_chill_filename ()),
1321 tree_cons (NULL_TREE
, get_chill_linenumber (),
1327 build_return_memory (ptr
)
1331 if (ptr
== NULL_TREE
|| TREE_CODE (ptr
) == ERROR_MARK
)
1332 return error_mark_node
;
1334 /* check for pointer */
1335 if (TREE_CODE (TREE_TYPE (ptr
)) != POINTER_TYPE
)
1337 error ("mode mismatch in parameter 1.");
1338 return error_mark_node
;
1341 if (TREE_TYPE (ptr
) != ptr_type_node
)
1342 ptr
= build_chill_cast (ptr_type_node
, ptr
);
1344 return build_chill_function_call (
1345 lookup_name (get_identifier ("_return_memory")),
1346 tree_cons (NULL_TREE
, ptr
,
1347 tree_cons (NULL_TREE
, force_addr_of (get_chill_filename ()),
1348 tree_cons (NULL_TREE
, get_chill_linenumber (),
1353 /* Compute the number of runtime members of the
1357 build_chill_card (powerset
)
1363 tree card_func
= lookup_name (get_identifier ("__cardpowerset"));
1365 if (powerset
== NULL_TREE
|| TREE_CODE (powerset
) == ERROR_MARK
)
1366 return error_mark_node
;
1368 if (TREE_CODE (powerset
) == IDENTIFIER_NODE
)
1369 powerset
= lookup_name (powerset
);
1371 if (TREE_CODE (TREE_TYPE(powerset
)) == SET_TYPE
)
1374 /* Do constant folding, if possible. */
1375 if (TREE_CODE (powerset
) == CONSTRUCTOR
1376 && TREE_CONSTANT (powerset
)
1377 && (size
= int_size_in_bytes (TREE_TYPE (powerset
))) >= 0)
1379 int bit_size
= size
* BITS_PER_UNIT
;
1380 char* buffer
= (char*) alloca (bit_size
);
1381 temp
= get_set_constructor_bits (powerset
, buffer
, bit_size
);
1385 for (i
= 0; i
< bit_size
; i
++)
1388 temp
= build_int_2 (count
, 0);
1389 TREE_TYPE (temp
) = TREE_TYPE (TREE_TYPE (card_func
));
1393 temp
= build_chill_function_call (card_func
,
1394 tree_cons (NULL_TREE
, force_addr_of (powerset
),
1395 tree_cons (NULL_TREE
, powersetlen (powerset
), NULL_TREE
)));
1396 /* FIXME: should call
1397 * cond_type_range_exception (op0);
1401 error("CARD argument must be powerset mode");
1402 return error_mark_node
;
1407 /* function to build the type needed for the DESCR-built-in
1410 void build_chill_descr_type ()
1414 if (descr_type
!= NULL_TREE
)
1418 decl1
= build_decl (FIELD_DECL
, get_identifier ("datap"), ptr_type_node
);
1419 decl2
= build_decl (FIELD_DECL
, get_identifier ("len"),
1420 TREE_TYPE (lookup_name (
1421 get_identifier ((ignore_case
|| ! special_UC
) ? "ulong" : "ULONG"))));
1422 TREE_CHAIN (decl1
) = decl2
;
1423 TREE_CHAIN (decl2
) = NULL_TREE
;
1424 decl2
= build_chill_struct_type (decl1
);
1425 descr_type
= build_decl (TYPE_DECL
, get_identifier ("__tmp_DESCR_type"), decl2
);
1426 pushdecl (descr_type
);
1427 DECL_SOURCE_LINE (descr_type
) = 0;
1428 satisfy_decl (descr_type
, 0);
1431 /* build a pointer to a descriptor.
1432 * descriptor = STRUCT (datap PTR,
1434 * This descriptor is build in variable descr_type.
1438 build_chill_descr (expr
)
1443 tree tuple
, decl
, descr_var
, datap
, len
, tmp
;
1446 if (expr
== NULL_TREE
|| TREE_CODE (expr
) == ERROR_MARK
)
1447 return error_mark_node
;
1449 /* check for expression is referable */
1450 if (! CH_REFERABLE (expr
))
1452 error ("expression for DESCR-builtin must be referable.");
1453 return error_mark_node
;
1456 mark_addressable (expr
);
1458 datap
= build1 (ADDR_EXPR
, build_chill_pointer_type (descr_type
), expr
);
1460 datap
= build_chill_arrow_expr (expr
, 1);
1462 len
= size_in_bytes (TREE_TYPE (expr
));
1464 descr_var
= get_unique_identifier ("DESCR");
1465 tuple
= build_nt (CONSTRUCTOR
, NULL_TREE
,
1466 tree_cons (NULL_TREE
, datap
,
1467 tree_cons (NULL_TREE
, len
, NULL_TREE
)));
1469 is_static
= (current_function_decl
== global_function_decl
) && TREE_STATIC (expr
);
1470 decl
= decl_temp1 (descr_var
, TREE_TYPE (descr_type
), is_static
,
1473 tmp
= force_addr_of (decl
);
1475 tmp
= build_chill_arrow_expr (decl
, 1);
1482 /* this function process the builtin's
1483 MILLISECS, SECS, MINUTES, HOURS and DAYS.
1484 The built duration value is in milliseconds. */
1487 build_chill_duration (expr
, multiplier
, fnname
, maxvalue
)
1489 unsigned long multiplier
;
1491 unsigned long maxvalue
;
1495 if (expr
== NULL_TREE
|| TREE_CODE (expr
) == ERROR_MARK
)
1496 return error_mark_node
;
1498 if (TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
)
1500 error ("argument to `%s' must be of integer type.", IDENTIFIER_POINTER (fnname
));
1501 return error_mark_node
;
1504 temp
= convert (duration_timing_type_node
, expr
);
1505 temp
= fold (build (MULT_EXPR
, duration_timing_type_node
,
1506 temp
, build_int_2 (multiplier
, 0)));
1509 temp
= check_range (temp
, expr
, integer_zero_node
, build_int_2 (maxvalue
, 0));
1514 /* build function call to one of the floating point functions */
1516 build_chill_floatcall (expr
, chillname
, funcname
)
1524 if (expr
== NULL_TREE
|| TREE_CODE (expr
) == ERROR_MARK
)
1525 return error_mark_node
;
1527 /* look if expr is a REAL_TYPE */
1528 type
= TREE_TYPE (expr
);
1529 if (type
== NULL_TREE
|| TREE_CODE (type
) == ERROR_MARK
)
1530 return error_mark_node
;
1531 if (TREE_CODE (type
) != REAL_TYPE
)
1533 error ("argument 1 to `%s' must be of floating point mode", chillname
);
1534 return error_mark_node
;
1536 result
= build_chill_function_call (
1537 lookup_name (get_identifier (funcname
)),
1538 tree_cons (NULL_TREE
, expr
, NULL_TREE
));
1542 /* common function for ALLOCATE and GETSTACK */
1544 build_allocate_getstack (mode
, value
, chill_name
, fnname
, filename
, linenumber
)
1553 tree expr
= NULL_TREE
;
1554 tree args
, tmpvar
, fncall
, ptr
, outlist
= NULL_TREE
;
1556 if (mode
== NULL_TREE
|| TREE_CODE (mode
) == ERROR_MARK
)
1557 return error_mark_node
;
1559 if (TREE_CODE (mode
) == TYPE_DECL
)
1560 type
= TREE_TYPE (mode
);
1564 /* check if we have a mode */
1565 if (TREE_CODE_CLASS (TREE_CODE (type
)) != 't')
1567 error ("First argument to `%s' must be a mode", chill_name
);
1568 return error_mark_node
;
1571 /* check if we have a value if type is READonly */
1572 if (TYPE_READONLY_PROPERTY (type
) && value
== NULL_TREE
)
1574 error ("READonly modes for %s must have a value", chill_name
);
1575 return error_mark_node
;
1578 if (value
!= NULL_TREE
)
1580 if (TREE_CODE (value
) == ERROR_MARK
)
1581 return error_mark_node
;
1582 expr
= chill_convert_for_assignment (type
, value
, "assignment");
1585 /* build function arguments */
1586 if (filename
== NULL_TREE
)
1587 args
= tree_cons (NULL_TREE
, size_in_bytes (type
), NULL_TREE
);
1589 args
= tree_cons (NULL_TREE
, size_in_bytes (type
),
1590 tree_cons (NULL_TREE
, force_addr_of (filename
),
1591 tree_cons (NULL_TREE
, linenumber
, NULL_TREE
)));
1593 ptr
= build_chill_pointer_type (type
);
1594 tmpvar
= decl_temp1 (get_unique_identifier (chill_name
),
1595 ptr
, 0, NULL_TREE
, 0, 0);
1596 fncall
= build_chill_function_call (
1597 lookup_name (get_identifier (fnname
)), args
);
1598 outlist
= tree_cons (NULL_TREE
,
1599 build_chill_modify_expr (tmpvar
, fncall
), outlist
);
1600 if (expr
== NULL_TREE
)
1602 /* set allocated memory to 0 */
1603 fncall
= build_chill_function_call (
1604 lookup_name (get_identifier ("memset")),
1605 tree_cons (NULL_TREE
, convert (ptr_type_node
, tmpvar
),
1606 tree_cons (NULL_TREE
, integer_zero_node
,
1607 tree_cons (NULL_TREE
, size_in_bytes (type
), NULL_TREE
))));
1608 outlist
= tree_cons (NULL_TREE
, fncall
, outlist
);
1612 /* write the init value to allocated memory */
1613 outlist
= tree_cons (NULL_TREE
,
1614 build_chill_modify_expr (build_chill_indirect_ref (tmpvar
, NULL_TREE
, 0),
1618 outlist
= tree_cons (NULL_TREE
, tmpvar
, outlist
);
1619 result
= build_chill_compound_expr (nreverse (outlist
));
1623 /* process the ALLOCATE built-in */
1625 build_chill_allocate (mode
, value
)
1629 return build_allocate_getstack (mode
, value
, "ALLOCATE", "__allocate",
1630 get_chill_filename (), get_chill_linenumber ());
1633 /* process the GETSTACK built-in */
1635 build_chill_getstack (mode
, value
)
1639 return build_allocate_getstack (mode
, value
, "GETSTACK", "__builtin_alloca",
1640 NULL_TREE
, NULL_TREE
);
1643 /* process the TERMINATE built-in */
1645 build_chill_terminate (ptr
)
1651 if (ptr
== NULL_TREE
|| TREE_CODE (ptr
) == ERROR_MARK
)
1652 return error_mark_node
;
1654 type
= TREE_TYPE (ptr
);
1655 if (type
== NULL_TREE
|| TREE_CODE (type
) != POINTER_TYPE
)
1657 error ("argument to TERMINATE must be a reference primitive value");
1658 return error_mark_node
;
1660 result
= build_chill_function_call (
1661 lookup_name (get_identifier ("__terminate")),
1662 tree_cons (NULL_TREE
, convert (ptr_type_node
, ptr
),
1663 tree_cons (NULL_TREE
, force_addr_of (get_chill_filename ()),
1664 tree_cons (NULL_TREE
, get_chill_linenumber (), NULL_TREE
))));
1668 /* build the type passed to _inttime function */
1670 build_chill_inttime_type ()
1676 idxlist
= build_tree_list (NULL_TREE
,
1677 build_chill_range_type (NULL_TREE
,
1679 build_int_2 (5, 0)));
1680 arrtype
= build_chill_array_type (ptr_type_node
, idxlist
, 0, NULL_TREE
);
1682 decl
= build_decl (TYPE_DECL
, get_identifier ("__tmp_INTTIME_type"), arrtype
);
1684 DECL_SOURCE_LINE (decl
) = 0;
1685 satisfy_decl (decl
, 0);
1689 build_chill_inttime (t
, loclist
)
1692 int had_errors
= 0, cnt
;
1694 tree init
= NULL_TREE
;
1698 if (t
== NULL_TREE
|| TREE_CODE (t
) == ERROR_MARK
)
1699 return error_mark_node
;
1700 if (loclist
== NULL_TREE
|| TREE_CODE (loclist
) == ERROR_MARK
)
1701 return error_mark_node
;
1703 /* check first argument to be NEWMODE TIME */
1704 if (TREE_TYPE (t
) != abs_timing_type_node
)
1706 error ("argument 1 to INTTIME must be of mode TIME.");
1712 while (tmp
!= NULL_TREE
)
1714 tree loc
= TREE_VALUE (tmp
);
1717 int write_error
= 0;
1719 sprintf (errmsg
, "argument %d to INTTIME must be ", cnt
);
1720 p
= errmsg
+ strlen (errmsg
);
1723 if (loc
== NULL_TREE
|| TREE_CODE (loc
) == ERROR_MARK
)
1727 if (! CH_REFERABLE (loc
))
1729 strcpy (p
, "referable");
1734 if (TREE_CODE (TREE_TYPE (loc
)) != INTEGER_TYPE
)
1738 strcpy (p
, " and ");
1741 strcpy (p
, "of integer type");
1745 /* FIXME: what's about ranges can't hold the result ?? */
1747 error ("%s.", errmsg
);
1750 tmp
= TREE_CHAIN (tmp
);
1755 return error_mark_node
;
1757 /* make it always 6 arguments */
1758 numargs
= list_length (loclist
);
1759 for (cnt
= numargs
; cnt
< 6; cnt
++)
1760 init
= tree_cons (NULL_TREE
, null_pointer_node
, init
);
1762 /* append the given one's */
1764 while (tmp
!= NULL_TREE
)
1766 init
= chainon (init
,
1767 build_tree_list (NULL_TREE
,
1768 build_chill_descr (TREE_VALUE (tmp
))));
1769 tmp
= TREE_CHAIN (tmp
);
1772 tuple
= build_nt (CONSTRUCTOR
, NULL_TREE
, init
);
1773 var
= decl_temp1 (get_unique_identifier ("INTTIME"),
1774 TREE_TYPE (lookup_name (get_identifier ("__tmp_INTTIME_type"))),
1777 return build_chill_function_call (
1778 lookup_name (get_identifier ("_inttime")),
1779 tree_cons (NULL_TREE
, t
,
1780 tree_cons (NULL_TREE
, force_addr_of (var
),
1785 /* Compute the runtime length of the given string variable
1789 build_chill_length (expr
)
1796 if (expr
== NULL_TREE
|| TREE_CODE (expr
) == ERROR_MARK
)
1797 return error_mark_node
;
1799 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1800 expr
= lookup_name (expr
);
1802 type
= TREE_TYPE (expr
);
1804 if (TREE_CODE(type
) == ERROR_MARK
)
1806 if (chill_varying_type_p (type
))
1808 tree temp
= convert (integer_type_node
,
1809 build_component_ref (expr
, var_length_id
));
1810 /* FIXME: should call
1811 * cond_type_range_exception (temp);
1816 if ((TREE_CODE (type
) == ARRAY_TYPE
||
1817 /* should work for a bitstring too */
1818 (TREE_CODE (type
) == SET_TYPE
&& TREE_CODE (TREE_TYPE (type
)) == BOOLEAN_TYPE
)) &&
1819 integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
1821 tree temp
= fold (build (PLUS_EXPR
, chill_integer_type_node
,
1823 TYPE_MAX_VALUE (TYPE_DOMAIN (type
))));
1824 return convert (chill_integer_type_node
, temp
);
1827 if (CH_IS_BUFFER_MODE (type
) || CH_IS_EVENT_MODE (type
))
1829 tree len
= max_queue_size (type
);
1831 if (len
== NULL_TREE
)
1832 len
= integer_minus_one_node
;
1836 if (CH_IS_TEXT_MODE (type
))
1838 if (TREE_CODE (expr
) == TYPE_DECL
)
1840 /* text mode name */
1841 return text_length (type
);
1846 tree temp
= build_component_ref (
1847 build_component_ref (expr
, get_identifier ("tloc")),
1849 return convert (integer_type_node
, temp
);
1853 error("LENGTH argument must be string, buffer, event mode, text location or mode");
1854 return error_mark_node
;
1859 /* Compute the declared minimum/maximum value of the variable,
1860 * expression or declared type
1863 build_chill_lower_or_upper (what
, is_upper
)
1865 int is_upper
; /* o -> LOWER; 1 -> UPPER */
1870 struct ch_class
class;
1872 if (what
== NULL_TREE
|| TREE_CODE (what
) == ERROR_MARK
)
1873 return error_mark_node
;
1875 if (TREE_CODE_CLASS (TREE_CODE (what
)) == 't')
1878 type
= TREE_TYPE (what
);
1879 if (type
== NULL_TREE
)
1882 error ("UPPER argument must have a mode, or be a mode");
1884 error ("LOWER argument must have a mode, or be a mode");
1885 return error_mark_node
;
1887 while (TREE_CODE (type
) == REFERENCE_TYPE
)
1888 type
= TREE_TYPE (type
);
1889 if (chill_varying_type_p (type
))
1890 type
= CH_VARYING_ARRAY_TYPE (type
);
1892 if (discrete_type_p (type
))
1894 tree val
= is_upper
? TYPE_MAX_VALUE (type
) : TYPE_MIN_VALUE (type
);
1895 class.kind
= CH_VALUE_CLASS
;
1897 return convert_to_class (class, val
);
1899 else if (TREE_CODE (type
) == ARRAY_TYPE
|| TREE_CODE (type
) == SET_TYPE
)
1901 if (TYPE_STRING_FLAG (type
))
1903 class.kind
= CH_DERIVED_CLASS
;
1904 class.mode
= integer_type_node
;
1908 class.kind
= CH_VALUE_CLASS
;
1909 class.mode
= TYPE_DOMAIN (type
);
1911 type
= TYPE_DOMAIN (type
);
1912 return convert_to_class (class,
1914 ? TYPE_MAX_VALUE (type
)
1915 : TYPE_MIN_VALUE (type
));
1918 error("UPPER argument must be string, array, mode or integer");
1920 error("LOWER argument must be string, array, mode or integer");
1921 return error_mark_node
;
1927 build_chill_lower (what
)
1930 return build_chill_lower_or_upper (what
, 0);
1934 build_max_min (expr
, max_min
)
1936 int max_min
; /* 0: calculate MIN; 1: calculate MAX */
1940 tree type
, temp
, setminval
;
1944 if (expr
== NULL_TREE
|| TREE_CODE (expr
) == ERROR_MARK
)
1945 return error_mark_node
;
1947 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1948 expr
= lookup_name (expr
);
1950 type
= TREE_TYPE (expr
);
1951 set_base_type
= TYPE_DOMAIN (type
);
1952 setminval
= TYPE_MIN_VALUE (set_base_type
);
1954 if (TREE_CODE (type
) != SET_TYPE
)
1956 error("%s argument must be POWERSET mode",
1957 max_min
? "MAX" : "MIN");
1958 return error_mark_node
;
1961 /* find max/min of constant powerset at compile time */
1962 if (TREE_CODE (expr
) == CONSTRUCTOR
&& TREE_CONSTANT (expr
)
1963 && (size_in_bytes
= int_size_in_bytes (type
)) >= 0)
1965 HOST_WIDE_INT min_val
= -1, max_val
= -1;
1966 HOST_WIDE_INT i
, i_hi
= 0;
1967 HOST_WIDE_INT size_in_bits
= size_in_bytes
* BITS_PER_UNIT
;
1968 char *buffer
= (char*) alloca (size_in_bits
);
1970 || get_set_constructor_bits (expr
, buffer
, size_in_bits
))
1972 for (i
= 0; i
< size_in_bits
; i
++)
1982 error ("%s called for empty POWERSET", max_min
? "MAX" : "MIN");
1983 i
= max_min
? max_val
: min_val
;
1984 temp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (expr
)));
1985 add_double (i
, i_hi
,
1986 TREE_INT_CST_LOW (temp
), TREE_INT_CST_HIGH (temp
),
1988 temp
= build_int_2 (i
, i_hi
);
1989 TREE_TYPE (temp
) = set_base_type
;
1994 tree parmlist
, filename
, lineno
;
1997 /* set up to call appropriate runtime function */
1999 funcname
= "__flsetpowerset";
2001 funcname
= "__ffsetpowerset";
2003 setminval
= convert (long_integer_type_node
, setminval
);
2004 filename
= force_addr_of (get_chill_filename());
2005 lineno
= get_chill_linenumber();
2006 parmlist
= tree_cons (NULL_TREE
, force_addr_of (expr
),
2007 tree_cons (NULL_TREE
, powersetlen (expr
),
2008 tree_cons (NULL_TREE
, setminval
,
2009 tree_cons (NULL_TREE
, filename
,
2010 build_tree_list (NULL_TREE
, lineno
)))));
2011 temp
= lookup_name (get_identifier (funcname
));
2012 temp
= build_chill_function_call (temp
, parmlist
);
2013 TREE_TYPE (temp
) = set_base_type
;
2021 /* Compute the current runtime maximum value of the powerset
2024 build_chill_max (expr
)
2027 return build_max_min (expr
, 1);
2031 /* Compute the current runtime minimum value of the powerset
2034 build_chill_min (expr
)
2037 return build_max_min (expr
, 0);
2041 /* Build a conversion from the given expression to an INT,
2042 * but only when the expression's type is the same size as
2046 build_chill_num (expr
)
2054 if (expr
== NULL_TREE
|| TREE_CODE(expr
) == ERROR_MARK
)
2055 return error_mark_node
;
2057 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
2058 expr
= lookup_name (expr
);
2060 expr
= convert_to_discrete (expr
);
2061 if (expr
== NULL_TREE
)
2063 error ("argument to NUM is not discrete");
2064 return error_mark_node
;
2067 /* enumeral types and string slices of length 1 must be kept unsigned */
2068 need_unsigned
= (TREE_CODE (TREE_TYPE (expr
)) == ENUMERAL_TYPE
)
2069 || TREE_UNSIGNED (TREE_TYPE (expr
));
2071 temp
= type_for_size (TYPE_PRECISION (TREE_TYPE (expr
)),
2073 if (temp
== NULL_TREE
)
2075 error ("No integer mode which matches expression's mode");
2076 return integer_zero_node
;
2078 temp
= convert (temp
, expr
);
2080 if (TREE_CONSTANT (temp
))
2082 if (tree_int_cst_lt (temp
,
2083 TYPE_MIN_VALUE (TREE_TYPE (temp
))))
2084 error ("NUM's parameter is below its mode range");
2085 if (tree_int_cst_lt (TYPE_MAX_VALUE (TREE_TYPE (temp
)),
2087 error ("NUM's parameter is above its mode range");
2093 cond_overflow_exception (temp
,
2094 TYPE_MIN_VALUE (TREE_TYPE (temp
)),
2095 TYPE_MAX_VALUE (TREE_TYPE (temp
)));
2099 /* NUM delivers the INT derived class */
2100 CH_DERIVED_FLAG (temp
) = 1;
2109 build_chill_pred_or_succ (expr
, op
)
2111 enum tree_code op
; /* PLUS_EXPR for SUCC; MINUS_EXPR for PRED. */
2113 struct ch_class
class;
2119 if (expr
== NULL_TREE
|| TREE_CODE (expr
) == ERROR_MARK
)
2120 return error_mark_node
;
2122 /* disallow numbered SETs */
2123 if (TREE_CODE (TREE_TYPE (expr
)) == ENUMERAL_TYPE
2124 && CH_ENUM_IS_NUMBERED (TREE_TYPE (expr
)))
2126 error ("Cannot take SUCC or PRED of a numbered SET");
2127 return error_mark_node
;
2130 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
2132 if (TREE_TYPE (TREE_TYPE (expr
)) == void_type_node
)
2134 error ("SUCC or PRED must not be done on a PTR.");
2135 return error_mark_node
;
2137 pedwarn ("SUCC or PRED for a reference type is not standard.");
2138 return fold (build (op
, TREE_TYPE (expr
),
2140 size_in_bytes (TREE_TYPE (TREE_TYPE (expr
)))));
2143 expr
= convert_to_discrete (expr
);
2145 if (expr
== NULL_TREE
)
2147 error ("SUCC or PRED argument must be a discrete mode");
2148 return error_mark_node
;
2151 class = chill_expr_class (expr
);
2153 class.mode
= CH_ROOT_MODE (class.mode
);
2155 expr
= convert (etype
, expr
);
2157 /* Exception if expression is already at the
2158 min (PRED)/max(SUCC) valid value for its type. */
2159 cond
= fold (build (op
== PLUS_EXPR
? GE_EXPR
: LE_EXPR
,
2163 op
== PLUS_EXPR
? TYPE_MAX_VALUE (etype
)
2164 : TYPE_MIN_VALUE (etype
))));
2165 if (TREE_CODE (cond
) == INTEGER_CST
2166 && tree_int_cst_equal (cond
, integer_one_node
))
2168 error ("Taking the %s of a value already at its %s value",
2169 op
== PLUS_EXPR
? "SUCC" : "PRED",
2170 op
== PLUS_EXPR
? "maximum" : "minimum");
2171 return error_mark_node
;
2175 expr
= check_expression (expr
, cond
,
2176 ridpointers
[(int) RID_OVERFLOW
]);
2178 expr
= fold (build (op
, etype
, expr
,
2179 convert (etype
, integer_one_node
)));
2180 return convert_to_class (class, expr
);
2183 /* Compute the value of the CHILL `size' operator just
2184 * like the C 'sizeof' operator (code stolen from c-typeck.c)
2185 * TYPE may be a location or mode tree. In pass 1, we build
2186 * a function-call syntax tree; in pass 2, we evaluate it.
2189 build_chill_sizeof (type
)
2195 struct ch_class
class;
2196 enum tree_code code
;
2197 tree signame
= NULL_TREE
;
2199 if (type
== NULL_TREE
|| TREE_CODE (type
) == ERROR_MARK
)
2200 return error_mark_node
;
2202 if (TREE_CODE (type
) == IDENTIFIER_NODE
)
2203 type
= lookup_name (type
);
2205 code
= TREE_CODE (type
);
2206 if (code
== ERROR_MARK
)
2207 return error_mark_node
;
2209 if (TREE_CODE_CLASS (TREE_CODE (type
)) != 't')
2211 if (TREE_CODE (type
) == TYPE_DECL
&& CH_DECL_SIGNAL (type
))
2212 signame
= DECL_NAME (type
);
2213 type
= TREE_TYPE (type
);
2216 if (code
== FUNCTION_TYPE
)
2218 if (pedantic
|| warn_pointer_arith
)
2219 pedwarn ("size applied to a function mode");
2220 return error_mark_node
;
2222 if (code
== VOID_TYPE
)
2224 if (pedantic
|| warn_pointer_arith
)
2225 pedwarn ("sizeof applied to a void mode");
2226 return error_mark_node
;
2228 if (TYPE_SIZE (type
) == 0)
2230 error ("sizeof applied to an incomplete mode");
2231 return error_mark_node
;
2234 temp
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
2235 size_int (TYPE_PRECISION (char_type_node
)));
2236 if (signame
!= NULL_TREE
)
2238 /* we have a signal definition. This signal may have no
2239 data items specified. The definition however says that
2240 there are data, cause we cannot build a structure without
2241 fields. In this case return 0. */
2242 if (IDENTIFIER_SIGNAL_DATA (signame
) == 0)
2243 temp
= integer_zero_node
;
2246 /* FIXME: should call
2247 * cond_type_range_exception (temp);
2249 class.kind
= CH_DERIVED_CLASS
;
2250 class.mode
= integer_type_node
;
2251 return convert_to_class (class, temp
);
2256 /* Compute the declared maximum value of the variable,
2257 * expression or declared type
2260 build_chill_upper (what
)
2263 return build_chill_lower_or_upper (what
, 1);
2267 * Here at the site of a function/procedure call.. We need to build
2268 * temps for the INOUT and OUT parameters, and copy the actual parameters
2269 * into the temps. After the call, we 'copy back' the values from the
2270 * temps to the actual parameter variables. This somewhat verbose pol-
2271 * icy meets the requirement that the actual parameters are undisturbed
2272 * if the function/procedure causes an exception. They are updated only
2273 * upon a normal return from the function.
2275 * Note: the expr_list, which collects all of the above assignments, etc,
2276 * is built in REVERSE execution order. The list is corrected by nreverse
2277 * inside the build_chill_compound_expr call.
2280 build_chill_function_call (function
, expr
)
2281 tree function
, expr
;
2283 register tree typetail
, valtail
, typelist
;
2284 register tree temp
, actual_args
= NULL_TREE
;
2285 tree name
= NULL_TREE
;
2288 int parmno
= 1; /* parameter number for error message */
2289 int callee_raise_exception
= 0;
2291 /* list of assignments to run after the actual call,
2292 copying from the temps back to the user's variables. */
2293 tree copy_back
= NULL_TREE
;
2295 /* list of expressions to run before the call, copying from
2296 the user's variable to the temps that are passed to the function */
2297 tree expr_list
= NULL_TREE
;
2299 if (function
== NULL_TREE
|| TREE_CODE (function
) == ERROR_MARK
)
2300 return error_mark_node
;
2302 if (expr
!= NULL_TREE
&& TREE_CODE (expr
) == ERROR_MARK
)
2303 return error_mark_node
;
2306 return error_mark_node
;
2308 fntype
= TREE_TYPE (function
);
2309 if (TREE_CODE (function
) == FUNCTION_DECL
)
2311 callee_raise_exception
= TYPE_RAISES_EXCEPTIONS (fntype
) != NULL_TREE
;
2313 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2314 (because calling an inline function does not mean the function
2315 needs to be separately compiled). */
2316 fntype
= build_type_variant (fntype
,
2317 TREE_READONLY (function
),
2318 TREE_THIS_VOLATILE (function
));
2319 name
= DECL_NAME (function
);
2321 /* check that function is not a PROCESS */
2322 if (CH_DECL_PROCESS (function
))
2324 error ("cannot call a PROCESS, you START a PROCESS");
2325 return error_mark_node
;
2328 function
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), function
);
2330 else if (TREE_CODE (fntype
) == POINTER_TYPE
)
2332 fntype
= TREE_TYPE (fntype
);
2333 callee_raise_exception
= TYPE_RAISES_EXCEPTIONS (fntype
) != NULL_TREE
;
2335 /* Z.200 6.7 Call Action:
2336 "A procedure call causes the EMPTY exception if the
2337 procedure primitive value delivers NULL. */
2338 if (TREE_CODE (function
) != ADDR_EXPR
2339 || TREE_CODE (TREE_OPERAND (function
, 0)) != FUNCTION_DECL
)
2340 function
= check_non_null (function
);
2343 typelist
= TYPE_ARG_TYPES (fntype
);
2344 if (callee_raise_exception
)
2346 /* remove last two arguments from list for subsequent checking.
2347 They will get added automatically after checking */
2348 int len
= list_length (typelist
);
2350 tree newtypelist
= NULL_TREE
;
2351 tree wrk
= typelist
;
2353 for (i
= 0; i
< len
- 3; i
++)
2355 newtypelist
= tree_cons (TREE_PURPOSE (wrk
), TREE_VALUE (wrk
), newtypelist
);
2356 wrk
= TREE_CHAIN (wrk
);
2358 /* add the void_type_node */
2359 newtypelist
= tree_cons (NULL_TREE
, void_type_node
, newtypelist
);
2360 typelist
= nreverse (newtypelist
);
2363 /* Scan the given expressions and types, producing individual
2364 converted arguments and pushing them on ACTUAL_ARGS in
2366 for (valtail
= expr
, typetail
= typelist
;
2367 valtail
!= NULL_TREE
&& typetail
!= NULL_TREE
; parmno
++,
2368 valtail
= TREE_CHAIN (valtail
), typetail
= TREE_CHAIN (typetail
))
2370 register tree actual
= TREE_VALUE (valtail
);
2371 register tree attr
= TREE_PURPOSE (typetail
)
2372 ? TREE_PURPOSE (typetail
) : ridpointers
[(int) RID_IN
];
2373 register tree type
= TREE_VALUE (typetail
);
2375 sprintf (place
, "parameter %d", parmno
);
2377 /* if we have reached void_type_node in typelist we are at the
2378 end of formal parameters and then we have too many actual
2380 if (type
== void_type_node
)
2383 /* check if actual is a TYPE_DECL. FIXME: what else ? */
2384 if (TREE_CODE (actual
) == TYPE_DECL
)
2386 error ("invalid %s", place
);
2387 actual
= error_mark_node
;
2389 /* INOUT or OUT param to handle? */
2390 else if (attr
== ridpointers
[(int) RID_OUT
]
2391 || attr
== ridpointers
[(int)RID_INOUT
])
2395 tree in_actual
= NULL_TREE
, out_actual
;
2397 /* actual parameter must be a location so we can
2398 build a reference to it */
2399 if (!CH_LOCATION_P (actual
))
2401 error ("%s parameter %d must be a location",
2402 (attr
== ridpointers
[(int) RID_OUT
]) ?
2403 "OUT" : "INOUT", parmno
);
2406 if (TYPE_READONLY_PROPERTY (TREE_TYPE (actual
))
2407 || TREE_READONLY (actual
))
2409 error ("%s parameter %d is READ-only",
2410 (attr
== ridpointers
[(int) RID_OUT
]) ?
2411 "OUT" : "INOUT", parmno
);
2415 sprintf (temp_name
, "PARM_%d_%s", parmno
,
2416 (attr
== ridpointers
[(int)RID_OUT
]) ?
2418 parmtmp
= decl_temp1 (get_unique_identifier (temp_name
),
2419 TREE_TYPE (type
), 0, NULL_TREE
, 0, 0);
2420 /* this temp *must not* be optimized into a register */
2421 mark_addressable (parmtmp
);
2423 if (attr
== ridpointers
[(int)RID_INOUT
])
2425 tree in_actual
= chill_convert_for_assignment (TREE_TYPE (type
),
2427 tree tmp
= build_chill_modify_expr (parmtmp
, in_actual
);
2428 expr_list
= tree_cons (NULL_TREE
, tmp
, expr_list
);
2430 if (in_actual
!= error_mark_node
)
2432 /* list of copy back assignments to perform, from the temp
2433 back to the actual parameter */
2434 out_actual
= chill_convert_for_assignment (TREE_TYPE (actual
),
2436 copy_back
= tree_cons (NULL_TREE
,
2437 build_chill_modify_expr (actual
,
2441 /* we can do this because build_chill_function_type
2442 turned these parameters into REFERENCE_TYPEs. */
2443 actual
= build1 (ADDR_EXPR
, type
, parmtmp
);
2445 else if (attr
== ridpointers
[(int) RID_LOC
])
2447 int is_location
= chill_location (actual
);
2450 if (is_location
== 1)
2452 error ("LOC actual parameter %d is a non-referable location",
2454 actual
= error_mark_node
;
2456 else if (! CH_READ_COMPATIBLE (type
, TREE_TYPE (actual
)))
2458 error ("mode mismatch in parameter %d", parmno
);
2459 actual
= error_mark_node
;
2462 actual
= convert (type
, actual
);
2466 sprintf (place
, "parameter_%d", parmno
);
2467 actual
= decl_temp1 (get_identifier (place
),
2468 TREE_TYPE (type
), 0, actual
, 0, 0);
2469 actual
= convert (type
, actual
);
2471 mark_addressable (actual
);
2474 actual
= chill_convert_for_assignment (type
, actual
, place
);
2476 actual_args
= tree_cons (NULL_TREE
, actual
, actual_args
);
2479 if (valtail
!= 0 && TREE_VALUE (valtail
) != void_type_node
)
2481 char *errstr
= "too many arguments to procedure";
2483 error ("%s `%s'", errstr
, IDENTIFIER_POINTER (name
));
2486 return error_mark_node
;
2488 else if (typetail
!= 0 && TREE_VALUE (typetail
) != void_type_node
)
2490 char *errstr
= "too few arguments to procedure";
2492 error ("%s `%s'", errstr
, IDENTIFIER_POINTER (name
));
2495 return error_mark_node
;
2498 if (callee_raise_exception
)
2500 /* add linenumber and filename of the caller as arguments */
2501 actual_args
= tree_cons (NULL_TREE
, force_addr_of (get_chill_filename ()),
2503 actual_args
= tree_cons (NULL_TREE
, get_chill_linenumber (), actual_args
);
2506 function_call
= build (CALL_EXPR
, TREE_TYPE (fntype
),
2507 function
, nreverse (actual_args
), NULL_TREE
);
2508 TREE_SIDE_EFFECTS (function_call
) = 1;
2510 if (copy_back
== NULL_TREE
&& expr_list
== NULL_TREE
)
2511 return function_call
; /* no copying to do, either way */
2514 tree result_type
= TREE_TYPE (fntype
);
2515 tree result_tmp
= NULL_TREE
;
2517 /* no result wanted from procedure call */
2518 if (result_type
== NULL_TREE
|| result_type
== void_type_node
)
2519 expr_list
= tree_cons (NULL_TREE
, function_call
, expr_list
);
2522 /* create a temp for the function's result. this is so that we can
2523 evaluate this temp as the last expression in the list, which will
2524 make the function's return value the value of the whole list of
2525 expressions (by the C rules for compound expressions) */
2526 result_tmp
= decl_temp1 (get_unique_identifier ("FUNC_RESULT"),
2527 result_type
, 0, NULL_TREE
, 0, 0);
2528 expr_list
= tree_cons (NULL_TREE
,
2529 build_chill_modify_expr (result_tmp
, function_call
),
2533 expr_list
= chainon (copy_back
, expr_list
);
2535 /* last, but not least, the function's result */
2536 if (result_tmp
!= NULL_TREE
)
2537 expr_list
= tree_cons (NULL_TREE
, result_tmp
, expr_list
);
2538 temp
= build_chill_compound_expr (nreverse (expr_list
));
2543 /* We saw something that looks like a function call,
2544 but if it's pass 1, we're not sure. */
2547 build_generalized_call (func
, args
)
2550 tree type
= TREE_TYPE (func
);
2553 return build (CALL_EXPR
, NULL_TREE
, func
, args
, NULL_TREE
);
2555 /* Handle string repetition */
2556 if (TREE_CODE (func
) == INTEGER_CST
)
2558 if (args
== NULL_TREE
|| TREE_CHAIN (args
) != NULL_TREE
)
2560 error ("syntax error (integer used as function)");
2561 return error_mark_node
;
2563 if (TREE_CODE (args
) == TREE_LIST
)
2564 args
= TREE_VALUE (args
);
2565 return build_chill_repetition_op (func
, args
);
2568 if (args
!= NULL_TREE
)
2570 if (TREE_CODE (args
) == RANGE_EXPR
)
2572 tree lo
= TREE_OPERAND (args
, 0), hi
= TREE_OPERAND (args
, 1);
2573 if (TREE_CODE_CLASS (TREE_CODE (func
)) == 't')
2574 return build_chill_range_type (func
, lo
, hi
);
2576 return build_chill_slice_with_range (func
, lo
, hi
);
2578 else if (TREE_CODE (args
) != TREE_LIST
)
2580 error ("syntax error - missing operator, comma, or '('?");
2581 return error_mark_node
;
2585 if (TREE_CODE (func
) == TYPE_DECL
)
2587 if (CH_DECL_SIGNAL (func
))
2588 return build_signal_descriptor (func
, args
);
2589 func
= TREE_TYPE (func
);
2592 if (TREE_CODE_CLASS (TREE_CODE (func
)) == 't'
2593 && args
!= NULL_TREE
&& TREE_CHAIN (args
) == NULL_TREE
)
2594 return build_chill_cast (func
, TREE_VALUE (args
));
2596 if (TREE_CODE (type
) == FUNCTION_TYPE
2597 || (TREE_CODE (type
) == POINTER_TYPE
2598 && TREE_TYPE (type
) != NULL_TREE
2599 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
2601 /* Check for a built-in Chill function. */
2602 if (TREE_CODE (func
) == FUNCTION_DECL
2603 && DECL_BUILT_IN (func
)
2604 && DECL_FUNCTION_CODE (func
) > END_BUILTINS
)
2606 tree fnname
= DECL_NAME (func
);
2607 switch ((enum chill_built_in_function
)DECL_FUNCTION_CODE (func
))
2609 case BUILT_IN_CH_ABS
:
2610 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2611 return error_mark_node
;
2612 return build_chill_abs (TREE_VALUE (args
));
2613 case BUILT_IN_ABSTIME
:
2614 if (check_arglist_length (args
, 0, 6, fnname
) < 0)
2615 return error_mark_node
;
2616 return build_chill_abstime (args
);
2618 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2619 return error_mark_node
;
2621 return build_chill_addr_expr (TREE_VALUE (args
), (char *)0);
2623 return build_chill_arrow_expr (TREE_VALUE (args
), 0);
2625 case BUILT_IN_ALLOCATE_GLOBAL_MEMORY
:
2626 if (check_arglist_length (args
, 2, 2, fnname
) < 0)
2627 return error_mark_node
;
2628 return build_allocate_global_memory_call
2630 TREE_VALUE (TREE_CHAIN (args
)));
2631 case BUILT_IN_ALLOCATE
:
2632 if (check_arglist_length (args
, 1, 2, fnname
) < 0)
2633 return error_mark_node
;
2634 return build_chill_allocate (TREE_VALUE (args
),
2635 TREE_CHAIN (args
) == NULL_TREE
? NULL_TREE
: TREE_VALUE (TREE_CHAIN (args
)));
2636 case BUILT_IN_ALLOCATE_MEMORY
:
2637 if (check_arglist_length (args
, 2, 2, fnname
) < 0)
2638 return error_mark_node
;
2639 return build_allocate_memory_call
2641 TREE_VALUE (TREE_CHAIN (args
)));
2642 case BUILT_IN_ASSOCIATE
:
2643 if (check_arglist_length (args
, 2, 3, fnname
) < 0)
2644 return error_mark_node
;
2645 return build_chill_associate
2647 TREE_VALUE (TREE_CHAIN (args
)),
2648 TREE_CHAIN (TREE_CHAIN (args
)));
2649 case BUILT_IN_ARCCOS
:
2650 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2651 return error_mark_node
;
2652 return build_chill_floatcall (TREE_VALUE (args
),
2653 IDENTIFIER_POINTER (fnname
),
2655 case BUILT_IN_ARCSIN
:
2656 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2657 return error_mark_node
;
2658 return build_chill_floatcall (TREE_VALUE (args
),
2659 IDENTIFIER_POINTER (fnname
),
2661 case BUILT_IN_ARCTAN
:
2662 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2663 return error_mark_node
;
2664 return build_chill_floatcall (TREE_VALUE (args
),
2665 IDENTIFIER_POINTER (fnname
),
2668 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2669 return error_mark_node
;
2670 return build_chill_card (TREE_VALUE (args
));
2671 case BUILT_IN_CONNECT
:
2672 if (check_arglist_length (args
, 3, 5, fnname
) < 0)
2673 return error_mark_node
;
2674 return build_chill_connect
2676 TREE_VALUE (TREE_CHAIN (args
)),
2677 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))),
2678 TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (args
))));
2679 case BUILT_IN_COPY_NUMBER
:
2680 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2681 return error_mark_node
;
2682 return build_copy_number (TREE_VALUE (args
));
2683 case BUILT_IN_CH_COS
:
2684 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2685 return error_mark_node
;
2686 return build_chill_floatcall (TREE_VALUE (args
),
2687 IDENTIFIER_POINTER (fnname
),
2689 case BUILT_IN_CREATE
:
2690 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2691 return error_mark_node
;
2692 return build_chill_create (TREE_VALUE (args
));
2694 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2695 return error_mark_node
;
2696 return build_chill_duration (TREE_VALUE (args
), DAYS_MULTIPLIER
,
2698 case BUILT_IN_CH_DELETE
:
2699 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2700 return error_mark_node
;
2701 return build_chill_delete (TREE_VALUE (args
));
2702 case BUILT_IN_DESCR
:
2703 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2704 return error_mark_node
;
2705 return build_chill_descr (TREE_VALUE (args
));
2706 case BUILT_IN_DISCONNECT
:
2707 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2708 return error_mark_node
;
2709 return build_chill_disconnect (TREE_VALUE (args
));
2710 case BUILT_IN_DISSOCIATE
:
2711 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2712 return error_mark_node
;
2713 return build_chill_dissociate (TREE_VALUE (args
));
2715 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2716 return error_mark_node
;
2717 return build_chill_eoln (TREE_VALUE (args
));
2718 case BUILT_IN_EXISTING
:
2719 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2720 return error_mark_node
;
2721 return build_chill_existing (TREE_VALUE (args
));
2723 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2724 return error_mark_node
;
2725 return build_chill_floatcall (TREE_VALUE (args
),
2726 IDENTIFIER_POINTER (fnname
),
2728 case BUILT_IN_GEN_CODE
:
2729 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2730 return error_mark_node
;
2731 return build_gen_code (TREE_VALUE (args
));
2732 case BUILT_IN_GEN_INST
:
2733 if (check_arglist_length (args
, 2, 2, fnname
) < 0)
2734 return error_mark_node
;
2735 return build_gen_inst (TREE_VALUE (args
),
2736 TREE_VALUE (TREE_CHAIN (args
)));
2737 case BUILT_IN_GEN_PTYPE
:
2738 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2739 return error_mark_node
;
2740 return build_gen_ptype (TREE_VALUE (args
));
2741 case BUILT_IN_GETASSOCIATION
:
2742 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2743 return error_mark_node
;
2744 return build_chill_getassociation (TREE_VALUE (args
));
2745 case BUILT_IN_GETSTACK
:
2746 if (check_arglist_length (args
, 1, 2, fnname
) < 0)
2747 return error_mark_node
;
2748 return build_chill_getstack (TREE_VALUE (args
),
2749 TREE_CHAIN (args
) == NULL_TREE
? NULL_TREE
: TREE_VALUE (TREE_CHAIN (args
)));
2750 case BUILT_IN_GETTEXTACCESS
:
2751 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2752 return error_mark_node
;
2753 return build_chill_gettextaccess (TREE_VALUE (args
));
2754 case BUILT_IN_GETTEXTINDEX
:
2755 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2756 return error_mark_node
;
2757 return build_chill_gettextindex (TREE_VALUE (args
));
2758 case BUILT_IN_GETTEXTRECORD
:
2759 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2760 return error_mark_node
;
2761 return build_chill_gettextrecord (TREE_VALUE (args
));
2762 case BUILT_IN_GETUSAGE
:
2763 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2764 return error_mark_node
;
2765 return build_chill_getusage (TREE_VALUE (args
));
2766 case BUILT_IN_HOURS
:
2767 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2768 return error_mark_node
;
2769 return build_chill_duration (TREE_VALUE (args
), HOURS_MULTIPLIER
,
2771 case BUILT_IN_INDEXABLE
:
2772 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2773 return error_mark_node
;
2774 return build_chill_indexable (TREE_VALUE (args
));
2775 case BUILT_IN_INTTIME
:
2776 if (check_arglist_length (args
, 2, 7, fnname
) < 0)
2777 return error_mark_node
;
2778 return build_chill_inttime (TREE_VALUE (args
),
2780 case BUILT_IN_ISASSOCIATED
:
2781 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2782 return error_mark_node
;
2783 return build_chill_isassociated (TREE_VALUE (args
));
2784 case BUILT_IN_LENGTH
:
2785 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2786 return error_mark_node
;
2787 return build_chill_length (TREE_VALUE (args
));
2789 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2790 return error_mark_node
;
2791 return build_chill_floatcall (TREE_VALUE (args
),
2792 IDENTIFIER_POINTER (fnname
),
2795 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2796 return error_mark_node
;
2797 return build_chill_floatcall (TREE_VALUE (args
),
2798 IDENTIFIER_POINTER (fnname
),
2800 case BUILT_IN_LOWER
:
2801 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2802 return error_mark_node
;
2803 return build_chill_lower (TREE_VALUE (args
));
2805 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2806 return error_mark_node
;
2807 return build_chill_max (TREE_VALUE (args
));
2808 case BUILT_IN_MILLISECS
:
2809 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2810 return error_mark_node
;
2811 return build_chill_duration (TREE_VALUE (args
), MILLISECS_MULTIPLIER
,
2812 fnname
, MILLISECS_MAX
);
2814 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2815 return error_mark_node
;
2816 return build_chill_min (TREE_VALUE (args
));
2817 case BUILT_IN_MINUTES
:
2818 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2819 return error_mark_node
;
2820 return build_chill_duration (TREE_VALUE (args
), MINUTES_MULTIPLIER
,
2821 fnname
, MINUTES_MAX
);
2822 case BUILT_IN_MODIFY
:
2823 if (check_arglist_length (args
, 1, -1, fnname
) < 0)
2824 return error_mark_node
;
2825 return build_chill_modify (TREE_VALUE (args
), TREE_CHAIN (args
));
2827 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2828 return error_mark_node
;
2829 return build_chill_num (TREE_VALUE (args
));
2830 case BUILT_IN_OUTOFFILE
:
2831 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2832 return error_mark_node
;
2833 return build_chill_outoffile (TREE_VALUE (args
));
2835 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2836 return error_mark_node
;
2837 return build_chill_pred_or_succ (TREE_VALUE (args
), MINUS_EXPR
);
2838 case BUILT_IN_PROC_TYPE
:
2839 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2840 return error_mark_node
;
2841 return build_proc_type (TREE_VALUE (args
));
2842 case BUILT_IN_QUEUE_LENGTH
:
2843 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2844 return error_mark_node
;
2845 return build_queue_length (TREE_VALUE (args
));
2846 case BUILT_IN_READABLE
:
2847 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2848 return error_mark_node
;
2849 return build_chill_readable (TREE_VALUE (args
));
2850 case BUILT_IN_READRECORD
:
2851 if (check_arglist_length (args
, 1, 3, fnname
) < 0)
2852 return error_mark_node
;
2853 return build_chill_readrecord (TREE_VALUE (args
), TREE_CHAIN (args
));
2854 case BUILT_IN_READTEXT
:
2855 if (check_arglist_length (args
, 2, -1, fnname
) < 0)
2856 return error_mark_node
;
2857 return build_chill_readtext (TREE_VALUE (args
),
2859 case BUILT_IN_RETURN_MEMORY
:
2860 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2861 return error_mark_node
;
2862 return build_return_memory (TREE_VALUE (args
));
2864 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2865 return error_mark_node
;
2866 return build_chill_duration (TREE_VALUE (args
), SECS_MULTIPLIER
,
2868 case BUILT_IN_SEQUENCIBLE
:
2869 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2870 return error_mark_node
;
2871 return build_chill_sequencible (TREE_VALUE (args
));
2872 case BUILT_IN_SETTEXTACCESS
:
2873 if (check_arglist_length (args
, 2, 2, fnname
) < 0)
2874 return error_mark_node
;
2875 return build_chill_settextaccess (TREE_VALUE (args
),
2876 TREE_VALUE (TREE_CHAIN (args
)));
2877 case BUILT_IN_SETTEXTINDEX
:
2878 if (check_arglist_length (args
, 2, 2, fnname
) < 0)
2879 return error_mark_node
;
2880 return build_chill_settextindex (TREE_VALUE (args
),
2881 TREE_VALUE (TREE_CHAIN (args
)));
2882 case BUILT_IN_SETTEXTRECORD
:
2883 if (check_arglist_length (args
, 2, 2, fnname
) < 0)
2884 return error_mark_node
;
2885 return build_chill_settextrecord (TREE_VALUE (args
),
2886 TREE_VALUE (TREE_CHAIN (args
)));
2887 case BUILT_IN_CH_SIN
:
2888 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2889 return error_mark_node
;
2890 return build_chill_floatcall (TREE_VALUE (args
),
2891 IDENTIFIER_POINTER (fnname
),
2894 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2895 return error_mark_node
;
2896 return build_chill_sizeof (TREE_VALUE (args
));
2898 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2899 return error_mark_node
;
2900 return build_chill_floatcall (TREE_VALUE (args
),
2901 IDENTIFIER_POINTER (fnname
),
2904 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2905 return error_mark_node
;
2906 return build_chill_pred_or_succ (TREE_VALUE (args
), PLUS_EXPR
);
2908 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2909 return error_mark_node
;
2910 return build_chill_floatcall (TREE_VALUE (args
),
2911 IDENTIFIER_POINTER (fnname
),
2913 case BUILT_IN_TERMINATE
:
2914 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2915 return error_mark_node
;
2916 return build_chill_terminate (TREE_VALUE (args
));
2917 case BUILT_IN_UPPER
:
2918 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2919 return error_mark_node
;
2920 return build_chill_upper (TREE_VALUE (args
));
2921 case BUILT_IN_VARIABLE
:
2922 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2923 return error_mark_node
;
2924 return build_chill_variable (TREE_VALUE (args
));
2925 case BUILT_IN_WRITEABLE
:
2926 if (check_arglist_length (args
, 1, 1, fnname
) < 0)
2927 return error_mark_node
;
2928 return build_chill_writeable (TREE_VALUE (args
));
2929 case BUILT_IN_WRITERECORD
:
2930 if (check_arglist_length (args
, 2, 3, fnname
) < 0)
2931 return error_mark_node
;
2932 return build_chill_writerecord (TREE_VALUE (args
), TREE_CHAIN (args
));
2933 case BUILT_IN_WRITETEXT
:
2934 if (check_arglist_length (args
, 2, -1, fnname
) < 0)
2935 return error_mark_node
;
2936 return build_chill_writetext (TREE_VALUE (args
),
2939 case BUILT_IN_EXPIRED
:
2941 sorry ("unimplemented builtin function `%s'",
2942 IDENTIFIER_POINTER (fnname
));
2945 error ("internal error - bad builtin function `%s'",
2946 IDENTIFIER_POINTER (fnname
));
2949 return build_chill_function_call (func
, args
);
2952 if (chill_varying_type_p (TREE_TYPE (func
)))
2953 type
= TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (type
)));
2955 if (CH_STRING_TYPE_P (type
))
2957 if (args
== NULL_TREE
)
2959 error ("empty expression in string index");
2960 return error_mark_node
;
2962 if (TREE_CHAIN (args
) != NULL
)
2964 error ("only one expression allowed in string index");
2965 return error_mark_node
;
2967 if (flag_old_strings
)
2968 return build_chill_slice_with_length (func
,
2971 else if (CH_BOOLS_TYPE_P (type
))
2972 return build_chill_bitref (func
, args
);
2974 return build_chill_array_ref (func
, args
);
2977 else if (TREE_CODE (type
) == ARRAY_TYPE
)
2978 return build_chill_array_ref (func
, args
);
2980 if (TREE_CODE (func
) != ERROR_MARK
)
2981 error ("invalid: primval ( untyped_exprlist )");
2982 return error_mark_node
;
2985 /* Given a set stored as one bit per char (in BUFFER[0 .. BIT_SIZE-1]),
2986 return a CONTRUCTOR, of type TYPE (a SET_TYPE). */
2988 expand_packed_set (buffer
, bit_size
, type
)
2993 /* The ordinal number corresponding to the first stored bit. */
2994 HOST_WIDE_INT first_bit_no
=
2995 TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
2996 tree list
= NULL_TREE
;
2999 for (i
= 0; i
< bit_size
; i
++)
3003 for (next_0
= i
+ 1;
3004 next_0
< bit_size
&& buffer
[next_0
]; next_0
++)
3006 if (next_0
== i
+ 1)
3007 list
= tree_cons (NULL_TREE
,
3008 build_int_2 (i
+ first_bit_no
, 0), list
);
3011 list
= tree_cons (build_int_2 (i
+ first_bit_no
, 0),
3012 build_int_2 (next_0
- 1 + first_bit_no
, 0), list
);
3013 /* advance i past the range of 1-bits */
3017 list
= build (CONSTRUCTOR
, type
, NULL_TREE
, nreverse (list
));
3018 TREE_CONSTANT (list
) = 1;
3023 * fold a set represented as a CONSTRUCTOR list.
3024 * An empty set has a NULL_TREE in its TREE_OPERAND (set, 1) slot.
3027 fold_set_expr (code
, op0
, op1
)
3028 enum chill_tree_code code
;
3032 char *buffer0
, *buffer1
, *bufferr
;
3033 int i
, size0
, size1
, first_unused_bit
;
3035 if (! TREE_CONSTANT (op0
) || TREE_CODE (op0
) != CONSTRUCTOR
)
3039 && (! TREE_CONSTANT (op1
) || TREE_CODE (op1
) != CONSTRUCTOR
))
3042 size0
= int_size_in_bytes (TREE_TYPE (op0
)) * BITS_PER_UNIT
;
3045 error ("operand is variable-size bitstring/power-set");
3046 return error_mark_node
;
3048 buffer0
= (char*) alloca (size0
);
3050 temp
= get_set_constructor_bits (op0
, buffer0
, size0
);
3056 size1
= int_size_in_bytes (TREE_TYPE (op1
)) * BITS_PER_UNIT
;
3059 error ("operand is variable-size bitstring/power-set");
3060 return error_mark_node
;
3064 buffer1
= (char*) alloca (size1
);
3065 temp
= get_set_constructor_bits (op1
, buffer1
, size1
);
3070 bufferr
= (char*) alloca (size0
); /* result buffer */
3076 for (i
= 0; i
< size0
; i
++)
3077 bufferr
[i
] = 1 & ~buffer0
[i
];
3081 for (i
= 0; i
< size0
; i
++)
3082 bufferr
[i
] = buffer0
[i
] & buffer1
[i
];
3086 for (i
= 0; i
< size0
; i
++)
3087 bufferr
[i
] = buffer0
[i
] | buffer1
[i
];
3091 for (i
= 0; i
< size0
; i
++)
3092 bufferr
[i
] = (buffer0
[i
] ^ buffer1
[i
]) & 1;
3096 for (i
= 0; i
< size0
; i
++)
3097 bufferr
[i
] = buffer0
[i
] & ~buffer1
[i
];
3100 /* mask out unused bits. Same as runtime library does. */
3101 first_unused_bit
= TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (op0
))))
3102 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (op0
)))) + 1;
3103 for (i
= first_unused_bit
; i
< size0
; i
++)
3105 return expand_packed_set (bufferr
, size0
, TREE_TYPE (op0
));
3107 for (i
= 0; i
< size0
; i
++)
3108 if (buffer0
[i
] != buffer1
[i
])
3109 return boolean_false_node
;
3110 return boolean_true_node
;
3113 for (i
= 0; i
< size0
; i
++)
3114 if (buffer0
[i
] != buffer1
[i
])
3115 return boolean_true_node
;
3116 return boolean_false_node
;
3124 * build a set or bit-array expression. Type-checking is
3128 build_compare_set_expr (code
, op0
, op1
)
3129 enum tree_code code
;
3132 tree result_type
= NULL_TREE
;
3136 /* These conversions are needed if -fold-strings. */
3137 if (TREE_CODE (TREE_TYPE (op0
)) == BOOLEAN_TYPE
)
3139 if (CH_BOOLS_ONE_P (TREE_TYPE (op1
)))
3140 return build_compare_discrete_expr (code
,
3142 convert (boolean_type_node
, op1
));
3144 op0
= convert (bitstring_one_type_node
, op0
);
3146 if (TREE_CODE (TREE_TYPE (op1
)) == BOOLEAN_TYPE
)
3148 if (CH_BOOLS_ONE_P (TREE_TYPE (op0
)))
3149 return build_compare_discrete_expr (code
,
3150 convert (boolean_type_node
, op0
),
3153 op1
= convert (bitstring_one_type_node
, op1
);
3160 tree temp
= fold_set_expr (EQ_EXPR
, op0
, op1
);
3163 fnname
= "__eqpowerset";
3164 goto compare_powerset
;
3169 /* switch operands and fall thru */
3175 fnname
= "__lepowerset";
3176 goto compare_powerset
;
3179 /* switch operands and fall thru */
3185 fnname
= "__ltpowerset";
3186 goto compare_powerset
;
3189 return invert_truthvalue (build_compare_set_expr (EQ_EXPR
, op0
, op1
));
3193 tree tsize
= powersetlen (op0
);
3195 if (TREE_CODE (TREE_TYPE (op0
)) != SET_TYPE
)
3196 tsize
= fold (build (MULT_EXPR
, sizetype
, tsize
,
3197 size_int (BITS_PER_UNIT
)));
3199 return build_chill_function_call (lookup_name (get_identifier (fnname
)),
3200 tree_cons (NULL_TREE
, force_addr_of (op0
),
3201 tree_cons (NULL_TREE
, force_addr_of (op1
),
3202 tree_cons (NULL_TREE
, tsize
, NULL_TREE
))));
3207 if ((int) code
>= (int)LAST_AND_UNUSED_TREE_CODE
)
3209 error ("tree code `%s' unhandled in build_compare_set_expr",
3210 tree_code_name
[(int)code
]);
3211 return error_mark_node
;
3216 return build ((enum tree_code
)code
, result_type
,
3220 /* Convert a varying string (or array) to dynamic non-varying string:
3221 EXP becomes EXP.var_data(0 UP EXP.var_length). */
3224 varying_to_slice (exp
)
3227 if (!chill_varying_type_p (TREE_TYPE (exp
)))
3230 { tree size
, data
, data_domain
, min
;
3231 tree novelty
= CH_NOVELTY (TREE_TYPE (exp
));
3232 exp
= save_if_needed (exp
);
3233 size
= build_component_ref (exp
, var_length_id
);
3234 data
= build_component_ref (exp
, var_data_id
);
3235 TREE_TYPE (data
) = copy_novelty (novelty
, TREE_TYPE (data
));
3236 data_domain
= TYPE_DOMAIN (TREE_TYPE (data
));
3237 if (data_domain
!= NULL_TREE
3238 && TYPE_MIN_VALUE (data_domain
) != NULL_TREE
)
3239 min
= TYPE_MIN_VALUE (data_domain
);
3241 min
= integer_zero_node
;
3242 return build_chill_slice (data
, min
, size
);
3246 /* Convert a scalar argument to a string or array type. This is a subroutine
3247 of `build_concat_expr'. */
3250 scalar_to_string (exp
)
3253 tree type
= TREE_TYPE (exp
);
3255 if (SCALAR_P (type
))
3257 int was_const
= TREE_CONSTANT (exp
);
3258 if (TREE_TYPE (exp
) == char_type_node
)
3259 exp
= convert (string_one_type_node
, exp
);
3260 else if (TREE_TYPE (exp
) == boolean_type_node
)
3261 exp
= convert (bitstring_one_type_node
, exp
);
3263 exp
= convert (build_array_type_for_scalar (type
), exp
);
3264 TREE_CONSTANT (exp
) = was_const
;
3267 return varying_to_slice (exp
);
3270 /* FIXME: Generalize this to general arrays (not just strings),
3271 at least for the compiler-generated case of padding fixed-length arrays. */
3274 build_concat_expr (op0
, op1
)
3277 tree orig_op0
= op0
, orig_op1
= op1
;
3278 tree type0
, type1
, size0
, size1
, res
;
3280 op0
= scalar_to_string (op0
);
3281 type0
= TREE_TYPE (op0
);
3282 op1
= scalar_to_string (op1
);
3283 type1
= TREE_TYPE (op1
);
3284 size1
= size_in_bytes (type1
);
3286 /* try to fold constant string literals */
3287 if (TREE_CODE (op0
) == STRING_CST
3288 && (TREE_CODE (op1
) == STRING_CST
3289 || TREE_CODE (op1
) == UNDEFINED_EXPR
)
3290 && TREE_CODE (size1
) == INTEGER_CST
)
3292 int len0
= TREE_STRING_LENGTH (op0
);
3293 int len1
= TREE_INT_CST_LOW (size1
);
3294 char *result
= xmalloc (len0
+ len1
+ 1);
3295 memcpy (result
, TREE_STRING_POINTER (op0
), len0
);
3296 if (TREE_CODE (op1
) == UNDEFINED_EXPR
)
3297 memset (&result
[len0
], '\0', len1
);
3299 memcpy (&result
[len0
], TREE_STRING_POINTER (op1
), len1
);
3300 return build_chill_string (len0
+ len1
, result
);
3302 else if (TREE_CODE (type0
) == TREE_CODE (type1
))
3305 struct ch_class result_class
;
3306 struct ch_class class0
;
3307 struct ch_class class1
;
3309 class0
= chill_expr_class (orig_op0
);
3310 class1
= chill_expr_class (orig_op1
);
3312 if (TREE_CODE (type0
) == SET_TYPE
)
3314 result_size
= size_binop (PLUS_EXPR
,
3315 discrete_count (TYPE_DOMAIN (type0
)),
3316 discrete_count (TYPE_DOMAIN (type1
)));
3317 result_class
.mode
= build_bitstring_type (result_size
);
3321 tree max0
= TYPE_MAX_VALUE (type0
);
3322 tree max1
= TYPE_MAX_VALUE (type1
);
3324 /* new array's dynamic size (in bytes). */
3325 size0
= size_in_bytes (type0
);
3326 /* size1 was computed above. */
3328 result_size
= size_binop (PLUS_EXPR
, size0
, size1
);
3329 /* new array's type. */
3330 result_class
.mode
= build_string_type (char_type_node
, result_size
);
3334 max0
= max0
== 0 ? size0
: convert (sizetype
, max0
);
3335 max1
= max1
== 0 ? size1
: convert (sizetype
, max1
);
3336 TYPE_MAX_VALUE (result_class
.mode
)
3337 = size_binop (PLUS_EXPR
, max0
, max1
);
3341 if (class0
.kind
== CH_VALUE_CLASS
|| class1
.kind
== CH_VALUE_CLASS
)
3343 tree novelty0
= CH_NOVELTY (TREE_TYPE (orig_op0
));
3344 result_class
.kind
= CH_VALUE_CLASS
;
3345 if (class0
.kind
== CH_VALUE_CLASS
&& novelty0
!= NULL_TREE
)
3346 SET_CH_NOVELTY_NONNIL (result_class
.mode
, novelty0
);
3347 else if (class1
.kind
== CH_VALUE_CLASS
)
3348 SET_CH_NOVELTY (result_class
.mode
,
3349 CH_NOVELTY (TREE_TYPE (orig_op1
)));
3352 result_class
.kind
= CH_DERIVED_CLASS
;
3354 if (TREE_CODE (result_class
.mode
) == SET_TYPE
3355 && TREE_CONSTANT (op0
) && TREE_CONSTANT (op1
)
3356 && TREE_CODE (op0
) == CONSTRUCTOR
&& TREE_CODE (op1
) == CONSTRUCTOR
)
3358 HOST_WIDE_INT size0
, size1
; char *buffer
;
3359 size0
= TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type0
))) + 1;
3360 size1
= TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type1
))) + 1;
3361 buffer
= (char*) alloca (size0
+ size1
);
3362 if (size0
< 0 || size1
< 0
3363 || get_set_constructor_bits (op0
, buffer
, size0
)
3364 || get_set_constructor_bits (op1
, buffer
+ size0
, size1
))
3366 res
= expand_packed_set (buffer
, size0
+ size1
, result_class
.mode
);
3369 res
= build (CONCAT_EXPR
, result_class
.mode
, op0
, op1
);
3370 return convert_to_class (result_class
, res
);
3374 error ("incompatible modes in concat expression");
3375 return error_mark_node
;
3380 * handle varying and fixed array compare operations
3383 build_compare_string_expr (code
, op0
, op1
)
3384 enum tree_code code
;
3387 if (op0
== NULL_TREE
|| TREE_CODE (op0
) == ERROR_MARK
)
3388 return error_mark_node
;
3389 if (op1
== NULL_TREE
|| TREE_CODE (op1
) == ERROR_MARK
)
3390 return error_mark_node
;
3392 if (tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (op0
)),
3393 TYPE_SIZE (TREE_TYPE (op1
)))
3394 && ! chill_varying_type_p (TREE_TYPE (op0
))
3395 && ! chill_varying_type_p (TREE_TYPE (op1
)))
3397 tree size
= size_in_bytes (TREE_TYPE (op0
));
3398 tree temp
= lookup_name (get_identifier ("memcmp"));
3399 temp
= build_chill_function_call (temp
,
3400 tree_cons (NULL_TREE
, force_addr_of (op0
),
3401 tree_cons (NULL_TREE
, force_addr_of (op1
),
3402 tree_cons (NULL_TREE
, size
, NULL_TREE
))));
3403 return build_compare_discrete_expr (code
, temp
, integer_zero_node
);
3409 code
= STRING_EQ_EXPR
;
3412 return invert_truthvalue (build_compare_string_expr (LT_EXPR
, op0
, op1
));
3414 return invert_truthvalue (build_compare_string_expr (LT_EXPR
, op1
, op0
));
3416 return build_compare_string_expr (LT_EXPR
, op1
, op0
);
3418 code
= STRING_LT_EXPR
;
3421 return invert_truthvalue (build_compare_string_expr (EQ_EXPR
, op0
, op1
));
3423 error ("Invalid operation on array of chars");
3424 return error_mark_node
;
3427 return build (code
, boolean_type_node
, op0
, op1
);
3431 compare_records (exp0
, exp1
)
3434 tree type
= TREE_TYPE (exp0
);
3436 int have_variants
= 0;
3438 tree result
= boolean_true_node
;
3439 extern int maximum_field_alignment
;
3441 if (TREE_CODE (type
) != RECORD_TYPE
)
3444 exp0
= save_if_needed (exp0
);
3445 exp1
= save_if_needed (exp1
);
3447 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
3449 if (DECL_NAME (field
) == NULL_TREE
)
3456 /* in case of -fpack we always do a memcmp */
3457 if (maximum_field_alignment
!= 0)
3459 tree memcmp_func
= lookup_name (get_identifier ("memcmp"));
3460 tree arg1
= force_addr_of (exp0
);
3461 tree arg2
= force_addr_of (exp1
);
3462 tree arg3
= size_in_bytes (type
);
3463 tree fcall
= build_chill_function_call (memcmp_func
,
3464 tree_cons (NULL_TREE
, arg1
,
3465 tree_cons (NULL_TREE
, arg2
,
3466 tree_cons (NULL_TREE
, arg3
, NULL_TREE
))));
3469 warning ("comparison of variant structures is unsafe");
3470 result
= build_chill_binary_op (EQ_EXPR
, fcall
, integer_zero_node
);
3476 sorry ("compare with variant records");
3477 return error_mark_node
;
3480 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
3482 tree exp0fld
= build_component_ref (exp0
, DECL_NAME (field
));
3483 tree exp1fld
= build_component_ref (exp1
, DECL_NAME (field
));
3484 tree eq_flds
= build_chill_binary_op (EQ_EXPR
, exp0fld
, exp1fld
);
3485 result
= build_chill_binary_op (TRUTH_AND_EXPR
, result
, eq_flds
);
3491 compare_int_csts (op
, val1
, val2
)
3497 tree type1
= TREE_TYPE (val1
);
3498 tree type2
= TREE_TYPE (val2
);
3503 tmp
= val1
; val1
= val2
; val2
= tmp
;
3504 tmp
= type1
; type1
= type2
; type2
= tmp
;
3505 op
= (op
== GT_EXPR
) ? LT_EXPR
: LE_EXPR
;
3506 /* ... fall through ... */
3509 if (!TREE_UNSIGNED (type1
))
3511 if (!TREE_UNSIGNED (type2
))
3512 result
= INT_CST_LT (val1
, val2
);
3513 else if (TREE_INT_CST_HIGH (val1
) < 0)
3516 result
= INT_CST_LT_UNSIGNED (val1
, val2
);
3520 if (!TREE_UNSIGNED (type2
) && TREE_INT_CST_HIGH (val2
) < 0)
3523 result
= INT_CST_LT_UNSIGNED (val1
, val2
);
3525 if (op
== LT_EXPR
|| result
== 1)
3527 /* else fall through ... */
3530 if (TREE_INT_CST_LOW (val1
) == TREE_INT_CST_LOW (val2
)
3531 && TREE_INT_CST_HIGH (val1
) == TREE_INT_CST_HIGH (val2
)
3532 /* They're bitwise equal.
3533 Check for one being negative and the other unsigned. */
3534 && (TREE_INT_CST_HIGH (val2
) >= 0
3535 || TREE_UNSIGNED (TREE_TYPE (val1
))
3536 == TREE_UNSIGNED (TREE_TYPE (val2
))))
3549 /* Build an expression to compare discrete values VAL1 and VAL2.
3550 This does not check that they are discrete, nor that they are
3551 compatible; if you need such checks use build_compare_expr. */
3554 build_compare_discrete_expr (op
, val1
, val2
)
3558 tree type1
= TREE_TYPE (val1
);
3559 tree type2
= TREE_TYPE (val2
);
3562 if (TREE_CODE (val1
) == INTEGER_CST
&& TREE_CODE (val2
) == INTEGER_CST
)
3564 if (compare_int_csts (op
, val1
, val2
))
3565 return boolean_true_node
;
3567 return boolean_false_node
;
3570 if (TREE_UNSIGNED (type1
) != TREE_UNSIGNED (type2
))
3576 tmp
= val1
; val1
= val2
; val2
= tmp
;
3577 tmp
= type1
; type1
= type2
; type2
= tmp
;
3578 op
= (op
== GT_EXPR
) ? LT_EXPR
: LE_EXPR
;
3579 /* ... fall through ... */
3582 if (TREE_UNSIGNED (type2
))
3584 tmp
= build_int_2_wide (0, 0);
3585 TREE_TYPE (tmp
) = type1
;
3586 val1
= save_expr (val1
);
3587 tmp
= fold (build (LT_EXPR
, boolean_type_node
, val1
, tmp
));
3588 if (TYPE_PRECISION (type2
) < TYPE_PRECISION (type1
))
3590 type2
= unsigned_type (type1
);
3591 val2
= convert_to_integer (type2
, val2
);
3593 val1
= convert_to_integer (type2
, val1
);
3594 return fold (build (TRUTH_OR_EXPR
, boolean_type_node
,
3596 fold (build (op
, boolean_type_node
,
3599 unsigned_vs_signed
: /* val1 is unsigned, val2 is signed */
3600 tmp
= build_int_2_wide (0, 0);
3601 TREE_TYPE (tmp
) = type2
;
3602 val2
= save_expr (val2
);
3603 tmp
= fold (build (GE_EXPR
, boolean_type_node
, val2
, tmp
));
3604 if (TYPE_PRECISION (type1
) < TYPE_PRECISION (type2
))
3606 type1
= unsigned_type (type2
);
3607 val1
= convert_to_integer (type1
, val1
);
3609 val2
= convert_to_integer (type1
, val2
);
3610 return fold (build (TRUTH_AND_EXPR
, boolean_type_node
, tmp
,
3611 fold (build (op
, boolean_type_node
,
3614 if (TREE_UNSIGNED (val2
))
3616 tmp
= val1
; val1
= val2
; val2
= tmp
;
3617 tmp
= type1
; type1
= type2
; type2
= tmp
;
3619 goto unsigned_vs_signed
;
3621 tmp
= build_compare_expr (EQ_EXPR
, val1
, val2
);
3622 return build_chill_unary_op (TRUTH_NOT_EXPR
, tmp
);
3627 if (TYPE_PRECISION (type1
) > TYPE_PRECISION (type2
))
3628 val2
= convert (type1
, val2
);
3629 else if (TYPE_PRECISION (type1
) < TYPE_PRECISION (type2
))
3630 val1
= convert (type2
, val1
);
3631 return fold (build (op
, boolean_type_node
, val1
, val2
));
3635 build_compare_expr (op
, val1
, val2
)
3641 val1
= check_have_mode (val1
, "relational expression");
3642 val2
= check_have_mode (val2
, "relational expression");
3643 if (val1
== NULL_TREE
|| TREE_CODE (val1
) == ERROR_MARK
)
3644 return error_mark_node
;
3645 if (val2
== NULL_TREE
|| TREE_CODE (val2
) == ERROR_MARK
)
3646 return error_mark_node
;
3649 return build (op
, NULL_TREE
, val1
, val2
);
3651 if (!CH_COMPATIBLE_CLASSES (val1
, val2
))
3653 error ("incompatible operands to %s", boolean_code_name
[op
]);
3654 return error_mark_node
;
3657 tmp
= CH_ROOT_MODE (TREE_TYPE (val1
));
3658 if (tmp
!= TREE_TYPE (val1
))
3659 val1
= convert (tmp
, val1
);
3660 tmp
= CH_ROOT_MODE (TREE_TYPE (val2
));
3661 if (tmp
!= TREE_TYPE (val2
))
3662 val2
= convert (tmp
, val2
);
3664 type1
= TREE_TYPE (val1
);
3665 type2
= TREE_TYPE (val2
);
3667 if (TREE_CODE (type1
) == SET_TYPE
)
3668 tmp
= build_compare_set_expr (op
, val1
, val2
);
3670 else if (discrete_type_p (type1
))
3671 tmp
= build_compare_discrete_expr (op
, val1
, val2
);
3673 else if (chill_varying_type_p (type1
) || chill_varying_type_p (type2
)
3674 || (TREE_CODE (type1
) == ARRAY_TYPE
3675 && TREE_CODE (TREE_TYPE (type1
)) == CHAR_TYPE
)
3676 || (TREE_CODE (type2
) == ARRAY_TYPE
3677 && TREE_CODE (TREE_TYPE (type2
)) == CHAR_TYPE
) )
3678 tmp
= build_compare_string_expr (op
, val1
, val2
);
3680 else if ((TREE_CODE (type1
) == RECORD_TYPE
3681 || TREE_CODE (type2
) == RECORD_TYPE
)
3682 && (op
== EQ_EXPR
|| op
== NE_EXPR
))
3684 /* This is for handling INSTANCEs being compared against NULL. */
3685 if (val1
== null_pointer_node
)
3686 val1
= convert (type2
, val1
);
3687 if (val2
== null_pointer_node
)
3688 val2
= convert (type1
, val2
);
3690 tmp
= compare_records (val1
, val2
);
3692 tmp
= build_chill_unary_op (TRUTH_NOT_EXPR
, tmp
);
3695 else if (TREE_CODE (type1
) == REAL_TYPE
|| TREE_CODE (type2
) == REAL_TYPE
3696 || (op
== EQ_EXPR
|| op
== NE_EXPR
))
3698 tmp
= build (op
, boolean_type_node
, val1
, val2
);
3699 CH_DERIVED_FLAG (tmp
) = 1; /* Optimization to avoid copy_node. */
3705 error ("relational operator not allowed for this mode");
3706 return error_mark_node
;
3709 if (!CH_DERIVED_FLAG (tmp
))
3711 tmp
= copy_node (tmp
);
3712 CH_DERIVED_FLAG (tmp
) = 1;
3718 finish_chill_binary_op (node
)
3721 tree op0
= check_have_mode (TREE_OPERAND (node
, 0), "binary expression");
3722 tree op1
= check_have_mode (TREE_OPERAND (node
, 1), "binary expression");
3723 tree type0
= TREE_TYPE (op0
);
3724 tree type1
= TREE_TYPE (op1
);
3727 if (TREE_CODE (op0
) == ERROR_MARK
|| TREE_CODE (op1
) == ERROR_MARK
)
3728 return error_mark_node
;
3730 if (UNSATISFIED (op0
) || UNSATISFIED (op1
))
3732 UNSATISFIED_FLAG (node
) = 1;
3736 /* assure that both operands have a type */
3737 if (! type0
&& type1
)
3739 op0
= convert (type1
, op0
);
3740 type0
= TREE_TYPE (op0
);
3742 if (! type1
&& type0
)
3744 op1
= convert (type0
, op1
);
3745 type1
= TREE_TYPE (op1
);
3748 UNSATISFIED_FLAG (node
) = 0;
3751 { int op0f
= TREE_CODE (op0
) == FUNCTION_DECL
;
3752 int op1f
= TREE_CODE (op1
) == FUNCTION_DECL
;
3754 op0
= convert (build_pointer_type (TREE_TYPE (op0
)), op0
);
3756 op1
= convert (build_pointer_type (TREE_TYPE (op1
)), op1
);
3758 && code
!= EQ_EXPR
&& code
!= NE_EXPR
)
3759 error ("Cannot use %s operator on PROC mode variable",
3760 tree_code_name
[(int)code
]);
3763 if (invalid_left_operand (type0
, code
))
3765 error ("invalid left operand of %s", tree_code_name
[(int)code
]);
3766 return error_mark_node
;
3768 if (invalid_right_operand (code
, type1
))
3770 error ("invalid right operand of %s", tree_code_name
[(int)code
]);
3771 return error_mark_node
;
3775 switch (TREE_CODE (node
))
3778 return build_concat_expr (op0
, op1
);
3780 case REPLICATE_EXPR
:
3782 if (!TREE_CONSTANT (op0
) || !TREE_CONSTANT (op1
))
3784 error ("repetition expression must be constant");
3785 return error_mark_node
;
3788 return build_chill_repetition_op (op0
, op1
);
3790 case FLOOR_MOD_EXPR
:
3791 case TRUNC_MOD_EXPR
:
3792 if (TREE_CODE (type0
) != INTEGER_TYPE
)
3794 error ("left argument to MOD/REM operator must be integral");
3795 return error_mark_node
;
3797 if (TREE_CODE (type1
) != INTEGER_TYPE
)
3799 error ("right argument to MOD/REM operator must be integral");
3800 return error_mark_node
;
3805 if (TREE_CODE (type1
) == SET_TYPE
)
3807 tree temp
= fold_set_expr (MINUS_EXPR
, op0
, op1
);
3811 if (TYPE_MODE (type1
) == BLKmode
)
3812 TREE_SET_CODE (node
, SET_DIFF_EXPR
);
3815 op1
= build_chill_unary_op (BIT_NOT_EXPR
, op1
);
3816 TREE_OPERAND (node
, 1) = op1
;
3817 TREE_SET_CODE (node
, BIT_AND_EXPR
);
3822 case TRUNC_DIV_EXPR
:
3823 if (TREE_CODE (type0
) == REAL_TYPE
|| TREE_CODE (type1
) == REAL_TYPE
)
3824 TREE_SET_CODE (node
, RDIV_EXPR
);
3828 if (TYPE_MODE (type1
) == BLKmode
)
3829 TREE_SET_CODE (node
, SET_AND_EXPR
);
3830 goto fold_set_binop
;
3832 if (TYPE_MODE (type1
) == BLKmode
)
3833 TREE_SET_CODE (node
, SET_IOR_EXPR
);
3834 goto fold_set_binop
;
3836 if (TYPE_MODE (type1
) == BLKmode
)
3837 TREE_SET_CODE (node
, SET_XOR_EXPR
);
3838 goto fold_set_binop
;
3844 if (TREE_CODE (type0
) == SET_TYPE
)
3846 tree temp
= fold_set_expr (TREE_CODE (node
), op0
, op1
);
3854 if (TREE_CODE (type1
) != SET_TYPE
|| CH_BOOLS_TYPE_P (type1
))
3856 error ("right operand of IN is not a powerset");
3857 return error_mark_node
;
3859 if (!CH_COMPATIBLE (op0
, TYPE_DOMAIN (type1
)))
3861 error ("left operand of IN incompatible with right operand");
3862 return error_mark_node
;
3864 type0
= CH_ROOT_MODE (type0
);
3865 if (type0
!= TREE_TYPE (op0
))
3866 TREE_OPERAND (node
, 0) = op0
= convert (type0
, op0
);
3867 TREE_TYPE (node
) = boolean_type_node
;
3868 CH_DERIVED_FLAG (node
) = 1;
3870 if (!CH_DERIVED_FLAG (node
))
3872 node
= copy_node (node
);
3873 CH_DERIVED_FLAG (node
) = 1;
3882 return build_compare_expr (TREE_CODE (node
), op0
, op1
);
3887 if (!CH_COMPATIBLE_CLASSES (op0
, op1
))
3889 error ("incompatible operands to %s", tree_code_name
[(int) TREE_CODE (node
)]);
3890 return error_mark_node
;
3893 if (TREE_TYPE (node
) == NULL_TREE
)
3895 struct ch_class
class;
3896 class = CH_ROOT_RESULTING_CLASS (op0
, op1
);
3897 TREE_OPERAND (node
, 0) = op0
= convert_to_class (class, op0
);
3898 type0
= TREE_TYPE (op0
);
3899 TREE_OPERAND (node
, 1) = op1
= convert_to_class (class, op1
);
3900 type1
= TREE_TYPE (op1
);
3901 TREE_TYPE (node
) = class.mode
;
3902 folded
= convert_to_class (class, fold (node
));
3905 folded
= fold (node
);
3908 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3910 if (TREE_CODE (node
) == TRUNC_DIV_EXPR
)
3912 if (TREE_CONSTANT (op1
))
3914 if (tree_int_cst_equal (op1
, integer_zero_node
))
3916 error ("division by zero");
3917 return integer_zero_node
;
3920 else if (range_checking
)
3924 build (EQ_EXPR
, boolean_type_node
, op1
, integer_zero_node
);
3925 /* Should this be overflow? */
3926 folded
= check_expression (folded
, test
,
3927 ridpointers
[(int) RID_RANGEFAIL
]);
3935 * This implements the '->' operator, which, like the '&' in C,
3936 * returns a pointer to an object, which has the type of
3937 * pointer-to-that-object.
3939 * FORCE is 0 when we're evaluating a user-level syntactic construct,
3940 * and 1 when we're calling from inside the compiler.
3943 build_chill_arrow_expr (ref
, force
)
3952 error ("-> operator not allow in constant expression");
3953 return error_mark_node
;
3956 if (ref
== NULL_TREE
|| TREE_CODE (ref
) == ERROR_MARK
)
3959 while (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
3960 ref
= convert (TREE_TYPE (TREE_TYPE (ref
)), ref
);
3962 if (!force
&& ! CH_LOCATION_P (ref
))
3964 if (TREE_CODE (ref
) == STRING_CST
)
3965 pedwarn ("taking the address of a string literal is non-standard");
3966 else if (TREE_CODE (TREE_TYPE (ref
)) == FUNCTION_TYPE
)
3967 pedwarn ("taking the address of a function is non-standard");
3970 error ("ADDR requires a LOCATION argument");
3971 return error_mark_node
;
3973 /* FIXME: Should we be sure that ref isn't a
3974 function if we're being pedantic? */
3977 addr_type
= build_pointer_type (TREE_TYPE (ref
));
3980 /* This transformation makes chill_expr_class return CH_VALUE_CLASS
3981 when it should return CH_REFERENCE_CLASS. That could be fixed,
3982 but we probably don't want this transformation anyway. */
3983 if (TREE_CODE (ref
) == NOP_EXPR
) /* RETYPE_EXPR */
3986 while (TREE_CODE (ref
) == NOP_EXPR
) /* RETYPE_EXPR */
3987 ref
= TREE_OPERAND (ref
, 0);
3988 mark_addressable (ref
);
3989 addr
= build1 (ADDR_EXPR
,
3990 build_pointer_type (TREE_TYPE (ref
)), ref
);
3991 return build1 (NOP_EXPR
, /* RETYPE_EXPR */
3998 if (! mark_addressable (ref
))
4000 error ("-> expression is not addressable");
4001 return error_mark_node
;
4003 result
= build1 (ADDR_EXPR
, addr_type
, ref
);
4005 && ! (TREE_CODE (ref
) == FUNCTION_DECL
4006 && DECL_CONTEXT (ref
) != 0))
4007 TREE_CONSTANT (result
) = 1;
4013 * This implements the ADDR builtin function, which returns a
4014 * free reference, analogous to the C 'void *'.
4017 build_chill_addr_expr (ref
, errormsg
)
4021 if (ref
== error_mark_node
)
4024 if (! CH_LOCATION_P (ref
)
4025 && TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
)
4027 error ("ADDR parameter must be a LOCATION");
4028 return error_mark_node
;
4030 ref
= build_chill_arrow_expr (ref
, 1);
4032 if (ref
!= NULL_TREE
&& TREE_CODE (ref
) != ERROR_MARK
)
4033 TREE_TYPE (ref
) = ptr_type_node
;
4034 else if (errormsg
== NULL
)
4036 error ("possible internal error in build_chill_arrow_expr");
4037 return error_mark_node
;
4041 error ("%s is not addressable", errormsg
);
4042 return error_mark_node
;
4048 build_chill_binary_op (code
, op0
, op1
)
4049 enum chill_tree_code code
;
4052 register tree result
;
4054 if (op0
== NULL_TREE
|| TREE_CODE (op0
) == ERROR_MARK
)
4055 return error_mark_node
;
4056 if (op1
== NULL_TREE
|| TREE_CODE (op1
) == ERROR_MARK
)
4057 return error_mark_node
;
4059 result
= build (code
, NULL_TREE
, op0
, op1
);
4062 result
= finish_chill_binary_op (result
);
4067 * process a string repetition phrase '(' COUNT ')' STRING
4070 string_char_rep (count
, string
)
4074 int slen
, charindx
, repcnt
;
4081 if (string
== NULL_TREE
|| TREE_CODE (string
) == ERROR_MARK
)
4082 return error_mark_node
;
4084 type
= TREE_TYPE (string
);
4085 slen
= int_size_in_bytes (type
);
4086 temp
= xmalloc (slen
* count
);
4089 if (TREE_CODE (string
) == STRING_CST
)
4090 inp
= TREE_STRING_POINTER (string
);
4091 else /* single character */
4092 ch
= (char)TREE_INT_CST_LOW (string
);
4094 /* copy the string/char COUNT times into the output buffer */
4095 for (outp
= temp
, repcnt
= 0; repcnt
< count
; repcnt
++)
4096 for (charindx
= 0; charindx
< slen
; charindx
++)
4097 *outp
++ = inp
[charindx
];
4098 return build_chill_string (slen
* count
, temp
);
4101 /* Build a bit-string constant containing with the given LENGTH
4102 containing all ones (if VALUE is true), or all zeros (if VALUE is false). */
4105 build_boring_bitstring (length
, value
)
4110 tree list
; /* Value of CONSTRUCTOR_ELTS in the result. */
4111 if (value
&& length
> 0)
4112 list
= tree_cons (integer_zero_node
, size_int (length
- 1), NULL_TREE
);
4116 result
= build (CONSTRUCTOR
,
4117 build_bitstring_type (size_int (length
)),
4120 TREE_CONSTANT (result
) = 1;
4121 CH_DERIVED_FLAG (result
) = 1;
4126 * handle a string repetition, with the syntax:
4127 * ( COUNT ) 'STRING'
4128 * COUNT is required to be constant, positive and folded.
4131 build_chill_repetition_op (count_op
, string
)
4136 tree type
= TREE_TYPE (string
);
4138 if (TREE_CODE (count_op
) != INTEGER_CST
)
4140 error ("repetition count is not an integer constant");
4141 return error_mark_node
;
4144 count
= TREE_INT_CST_LOW (count_op
);
4148 error ("repetition count < 0");
4149 return error_mark_node
;
4151 if (! TREE_CONSTANT (string
))
4153 error ("repetition value not constant");
4154 return error_mark_node
;
4157 if (TREE_CODE (string
) == STRING_CST
)
4158 return string_char_rep (count
, string
);
4160 switch ((int)TREE_CODE (type
))
4163 if (TREE_CODE (string
) == INTEGER_CST
)
4164 return build_boring_bitstring (count
, TREE_INT_CST_LOW (string
));
4165 error ("bitstring repetition of non-constant boolean");
4166 return error_mark_node
;
4169 return string_char_rep (count
, string
);
4172 { int i
, tree_const
= 1;
4173 tree new_list
= NULL_TREE
;
4176 tree domain
= TYPE_DOMAIN (type
);
4178 HOST_WIDE_INT orig_len
;
4180 if (!CH_BOOLS_TYPE_P (type
)) /* cannot replicate a powerset */
4183 orig_length
= discrete_count (domain
);
4185 if (TREE_CODE (string
) != CONSTRUCTOR
|| !TREE_CONSTANT (string
)
4186 || TREE_CODE (orig_length
) != INTEGER_CST
)
4188 error ("string repetition operand is non-constant bitstring");
4189 return error_mark_node
;
4193 orig_len
= TREE_INT_CST_LOW (orig_length
);
4195 /* if the set is empty, this is NULL */
4196 vallist
= TREE_OPERAND (string
, 1);
4198 if (vallist
== NULL_TREE
) /* No bits are set. */
4199 return build_boring_bitstring (count
* orig_len
, 0);
4200 else if (TREE_CHAIN (vallist
) == NULL_TREE
4201 && (TREE_PURPOSE (vallist
) == NULL_TREE
4203 && tree_int_cst_equal (TYPE_MIN_VALUE (domain
),
4204 TREE_VALUE (vallist
)))
4205 : (tree_int_cst_equal (TYPE_MIN_VALUE (domain
),
4206 TREE_PURPOSE (vallist
))
4207 && tree_int_cst_equal (TYPE_MAX_VALUE (domain
),
4208 TREE_VALUE (vallist
)))))
4209 return build_boring_bitstring (count
* orig_len
, 1);
4211 for (i
= 0; i
< count
; i
++)
4213 tree origin
= build_int_2 (i
* orig_len
, 0);
4216 /* scan down the given value list, building
4217 new bit-positions */
4218 for (temp
= vallist
; temp
; temp
= TREE_CHAIN (temp
))
4221 = fold (size_binop (PLUS_EXPR
, origin
, TREE_VALUE (temp
)));
4222 tree new_purpose
= NULL_TREE
;
4223 if (! TREE_CONSTANT (TREE_VALUE (temp
)))
4225 if (TREE_PURPOSE (temp
))
4227 new_purpose
= fold (size_binop (PLUS_EXPR
,
4229 TREE_PURPOSE (temp
)));
4230 if (! TREE_CONSTANT (TREE_PURPOSE (temp
)))
4234 new_list
= tree_cons (new_purpose
,
4235 new_value
, new_list
);
4238 result
= build (CONSTRUCTOR
,
4239 build_bitstring_type (size_int (count
* orig_len
)),
4240 NULL_TREE
, nreverse (new_list
));
4241 TREE_CONSTANT (result
) = tree_const
;
4242 CH_DERIVED_FLAG (result
) = CH_DERIVED_FLAG (string
);
4247 error ("non-char, non-bit string repetition");
4248 return error_mark_node
;
4250 return error_mark_node
;
4254 finish_chill_unary_op (node
)
4257 enum chill_tree_code code
= TREE_CODE (node
);
4258 tree op0
= check_have_mode (TREE_OPERAND (node
, 0), "unary expression");
4259 tree type0
= TREE_TYPE (op0
);
4260 struct ch_class
class;
4262 if (TREE_CODE (op0
) == ERROR_MARK
)
4263 return error_mark_node
;
4264 /* The expression codes of the data types of the arguments tell us
4265 whether the arguments are integers, floating, pointers, etc. */
4267 if (TREE_CODE (type0
) == REFERENCE_TYPE
)
4269 op0
= convert (TREE_TYPE (type0
), op0
);
4270 type0
= TREE_TYPE (op0
);
4273 if (invalid_right_operand (code
, type0
))
4275 error ("invalid operand of %s",
4276 tree_code_name
[(int)code
]);
4277 return error_mark_node
;
4279 switch ((int)TREE_CODE (type0
))
4282 if (TREE_CODE ( TREE_TYPE (type0
)) == BOOLEAN_TYPE
)
4283 code
= SET_NOT_EXPR
;
4286 error ("right operand of %s is not array of boolean",
4287 tree_code_name
[(int)code
]);
4288 return error_mark_node
;
4295 case TRUTH_NOT_EXPR
:
4296 return invert_truthvalue (truthvalue_conversion (op0
));
4299 error ("%s operator applied to boolean variable",
4300 tree_code_name
[(int)code
]);
4301 return error_mark_node
;
4311 tree temp
= fold_set_expr (BIT_NOT_EXPR
, op0
, NULL_TREE
);
4316 code
= SET_NOT_EXPR
;
4321 error ("invalid right operand of %s", tree_code_name
[(int)code
]);
4322 return error_mark_node
;
4327 class = chill_expr_class (op0
);
4329 class.mode
= CH_ROOT_MODE (class.mode
);
4330 TREE_SET_CODE (node
, code
);
4331 TREE_OPERAND (node
, 0) = op0
= convert_to_class (class, op0
);
4332 TREE_TYPE (node
) = TREE_TYPE (op0
);
4334 node
= convert_to_class (class, fold (node
));
4336 /* FIXME: should call
4337 * cond_type_range_exception (op0);
4342 /* op is TRUTH_NOT_EXPR, BIT_NOT_EXPR, or NEGATE_EXPR */
4345 build_chill_unary_op (code
, op0
)
4346 enum chill_tree_code code
;
4349 register tree result
= NULL_TREE
;
4351 if (op0
== NULL_TREE
|| TREE_CODE (op0
) == ERROR_MARK
)
4352 return error_mark_node
;
4354 result
= build1 (code
, NULL_TREE
, op0
);
4357 result
= finish_chill_unary_op (result
);
4362 truthvalue_conversion (expr
)
4365 if (expr
== NULL_TREE
|| TREE_CODE (expr
) == ERROR_MARK
)
4366 return error_mark_node
;
4368 #if 0 /* what about a LE_EXPR (integer_type, integer_type ) */
4369 if (TREE_CODE (TREE_TYPE (expr
)) != BOOLEAN_TYPE
)
4370 error ("non-boolean mode in conditional expression");
4373 switch ((int)TREE_CODE (expr
))
4375 /* It is simpler and generates better code to have only TRUTH_*_EXPR
4376 or comparison expressions as truth values at this level. */
4379 /* A one-bit unsigned bit-field is already acceptable. */
4380 if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr
, 1)))
4381 && TREE_UNSIGNED (TREE_OPERAND (expr
, 1)))
4387 /* It is simpler and generates better code to have only TRUTH_*_EXPR
4388 or comparison expressions as truth values at this level. */
4389 case NE_EXPR
: case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
4390 case TRUTH_ANDIF_EXPR
:
4391 case TRUTH_ORIF_EXPR
:
4392 case TRUTH_AND_EXPR
:
4398 return integer_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
4401 return real_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
4404 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 0)))
4405 return build (COMPOUND_EXPR
, boolean_type_node
,
4406 TREE_OPERAND (expr
, 0), boolean_true_node
);
4408 return boolean_true_node
;
4414 /* These don't change whether an object is non-zero or zero. */
4415 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
4419 /* These don't change whether an object is zero or non-zero, but
4420 we can't ignore them if their second arg has side-effects. */
4421 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
4422 return build (COMPOUND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 1),
4423 truthvalue_conversion (TREE_OPERAND (expr
, 0)));
4425 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
4428 /* Distribute the conversion into the arms of a COND_EXPR. */
4429 return fold (build (COND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 0),
4430 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
4431 truthvalue_conversion (TREE_OPERAND (expr
, 2))));
4434 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4435 since that affects how `default_conversion' will behave. */
4436 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
4437 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
4439 /* fall through... */
4441 /* If this is widening the argument, we can ignore it. */
4442 if (TYPE_PRECISION (TREE_TYPE (expr
))
4443 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
4444 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
4449 /* These can be changed into a comparison of the two objects. */
4450 if (TREE_TYPE (TREE_OPERAND (expr
, 0))
4451 == TREE_TYPE (TREE_OPERAND (expr
, 1)))
4452 return build_chill_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
4453 TREE_OPERAND (expr
, 1));
4454 return build_chill_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
4455 fold (build1 (NOP_EXPR
,
4456 TREE_TYPE (TREE_OPERAND (expr
, 0)),
4457 TREE_OPERAND (expr
, 1))));
4460 return build_chill_binary_op (NE_EXPR
, expr
, boolean_false_node
);
4465 * return a folded tree for the powerset's length in bits. If a
4466 * non-set is passed, we assume it's an array or boolean bytes.
4469 powersetlen (powerset
)
4472 if (powerset
== NULL_TREE
|| TREE_CODE (powerset
) == ERROR_MARK
)
4473 return error_mark_node
;
4475 return discrete_count (TYPE_DOMAIN (TREE_TYPE (powerset
)));