1 /* Implement grant-file output & seize-file input for CHILL.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
35 #define APPEND(X,Y) X = append (X, Y)
36 #define PREPEND(X,Y) X = prepend (X, Y);
37 #define FREE(x) strfree (x)
38 #define ALLOCAMOUNT 10000
39 /* may be we can handle this in a more exciting way,
40 but this also should work for the moment */
41 #define MAYBE_NEWLINE(X) \
44 if (X->len && X->str[X->len - 1] != '\n') \
48 extern tree process_type
;
49 extern char *asm_file_name
;
50 extern char *dump_base_name
;
52 /* forward declarations */
54 /* variable indicates compilation at module level */
55 int chill_at_module_level
= 0;
58 /* mark that a SPEC MODULE was generated */
59 static int spec_module_generated
= 0;
61 /* define a faster string handling */
69 /* structure used for handling multiple grant files */
70 char *grant_file_name
;
71 MYSTRING
*gstring
= NULL
;
72 MYSTRING
*selective_gstring
= NULL
;
74 static MYSTRING
*decode_decl
PARAMS ((tree
));
75 static MYSTRING
*decode_constant
PARAMS ((tree
));
76 static void grant_one_decl
PARAMS ((tree
));
77 static MYSTRING
*get_type
PARAMS ((tree
));
78 static MYSTRING
*decode_mode
PARAMS ((tree
));
79 static MYSTRING
*decode_prefix_rename
PARAMS ((tree
));
80 static MYSTRING
*decode_constant_selective
PARAMS ((tree
, tree
));
81 static MYSTRING
*decode_mode_selective
PARAMS ((tree
, tree
));
82 static MYSTRING
*get_type_selective
PARAMS ((tree
, tree
));
83 static MYSTRING
*decode_decl_selective
PARAMS ((tree
, tree
));
84 static MYSTRING
*newstring
PARAMS ((const char *));
85 static void strfree
PARAMS ((MYSTRING
*));
86 static MYSTRING
*append
PARAMS ((MYSTRING
*, const char *));
87 static MYSTRING
*prepend
PARAMS ((MYSTRING
*, const char *));
88 static void grant_use_seizefile
PARAMS ((const char *));
89 static MYSTRING
*decode_layout
PARAMS ((tree
));
90 static MYSTRING
*grant_array_type
PARAMS ((tree
));
91 static MYSTRING
*grant_array_type_selective
PARAMS ((tree
, tree
));
92 static MYSTRING
*get_tag_value
PARAMS ((tree
));
93 static MYSTRING
*get_tag_value_selective
PARAMS ((tree
, tree
));
94 static MYSTRING
*print_enumeral
PARAMS ((tree
));
95 static MYSTRING
*print_enumeral_selective
PARAMS ((tree
, tree
));
96 static MYSTRING
*print_integer_type
PARAMS ((tree
));
97 static tree find_enum_parent
PARAMS ((tree
, tree
));
98 static MYSTRING
*print_integer_selective
PARAMS ((tree
, tree
));
99 static MYSTRING
*print_struct
PARAMS ((tree
));
100 static MYSTRING
*print_struct_selective
PARAMS ((tree
, tree
));
101 static MYSTRING
*print_proc_exceptions
PARAMS ((tree
));
102 static MYSTRING
*print_proc_tail
PARAMS ((tree
, tree
, int));
103 static MYSTRING
*print_proc_tail_selective
PARAMS ((tree
, tree
, tree
));
104 static tree find_in_decls
PARAMS ((tree
, tree
));
105 static int in_ridpointers
PARAMS ((tree
));
106 static void grant_seized_identifier
PARAMS ((tree
));
107 static void globalize_decl
PARAMS ((tree
));
108 static void grant_one_decl_selective
PARAMS ((tree
, tree
));
109 static int compare_memory_file
PARAMS ((const char *, const char *));
110 static int search_in_list
PARAMS ((tree
, tree
));
111 static int really_grant_this
PARAMS ((tree
, tree
));
113 /* list of the VAR_DECLs of the module initializer entries */
114 tree module_init_list
= NULL_TREE
;
116 /* handle different USE_SEIZE_FILE's in case of selective granting */
117 typedef struct SEIZEFILELIST
119 struct SEIZEFILELIST
*next
;
124 static seizefile_list
*selective_seizes
= 0;
131 MYSTRING
*tmp
= (MYSTRING
*) xmalloc (sizeof (MYSTRING
));
132 unsigned len
= strlen (str
);
134 tmp
->allocated
= len
+ ALLOCAMOUNT
;
135 tmp
->str
= xmalloc ((unsigned)tmp
->allocated
);
136 strcpy (tmp
->str
, str
);
154 int inlen
= strlen (in
);
155 int amount
= ALLOCAMOUNT
;
159 if ((inout
->len
+ inlen
) >= inout
->allocated
)
160 inout
->str
= xrealloc (inout
->str
, inout
->allocated
+= amount
);
161 strcpy (inout
->str
+ inout
->len
, in
);
171 MYSTRING
*res
= inout
;
174 res
= newstring (in
);
175 res
= APPEND (res
, inout
->str
);
182 grant_use_seizefile (seize_filename
)
183 const char *seize_filename
;
185 APPEND (gstring
, "<> USE_SEIZE_FILE \"");
186 APPEND (gstring
, seize_filename
);
187 APPEND (gstring
, "\" <>\n");
191 decode_layout (layout
)
195 tree stepsize
= NULL_TREE
;
197 MYSTRING
*result
= newstring ("");
200 if (layout
== integer_zero_node
) /* NOPACK */
202 APPEND (result
, " NOPACK");
206 if (layout
== integer_one_node
) /* PACK */
208 APPEND (result
, " PACK");
212 APPEND (result
, " ");
214 if (TREE_PURPOSE (temp
) == NULL_TREE
)
216 APPEND (result
, "STEP(");
218 temp
= TREE_VALUE (temp
);
219 stepsize
= TREE_VALUE (temp
);
221 APPEND (result
, "POS(");
223 /* Get the starting word */
224 temp
= TREE_PURPOSE (temp
);
225 work
= decode_constant (TREE_PURPOSE (temp
));
226 APPEND (result
, work
->str
);
229 temp
= TREE_VALUE (temp
);
230 if (temp
!= NULL_TREE
)
232 /* Get the starting bit */
233 APPEND (result
, ", ");
234 work
= decode_constant (TREE_PURPOSE (temp
));
235 APPEND (result
, work
->str
);
238 temp
= TREE_VALUE (temp
);
239 if (temp
!= NULL_TREE
)
241 /* Get the length or the ending bit */
242 tree what
= TREE_PURPOSE (temp
);
243 if (what
== integer_zero_node
) /* length */
245 APPEND (result
, ", ");
249 APPEND (result
, ":");
251 work
= decode_constant (TREE_VALUE (temp
));
252 APPEND (result
, work
->str
);
256 APPEND (result
, ")");
260 if (stepsize
!= NULL_TREE
)
262 APPEND (result
, ", ");
263 work
= decode_constant (stepsize
);
264 APPEND (result
, work
->str
);
267 APPEND (result
, ")");
274 grant_array_type (type
)
277 MYSTRING
*result
= newstring ("");
278 MYSTRING
*mode_string
;
282 if (chill_varying_type_p (type
))
285 type
= CH_VARYING_ARRAY_TYPE (type
);
287 if (CH_STRING_TYPE_P (type
))
289 tree fields
= TYPE_DOMAIN (type
);
290 tree maxval
= TYPE_MAX_VALUE (fields
);
292 if (TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
293 APPEND (result
, "CHARS (");
295 APPEND (result
, "BOOLS (");
296 if (TREE_CODE (maxval
) == INTEGER_CST
)
299 sprintf (wrk
, HOST_WIDE_INT_PRINT_DEC
,
300 TREE_INT_CST_LOW (maxval
) + 1);
301 APPEND (result
, wrk
);
303 else if (TREE_CODE (maxval
) == MINUS_EXPR
304 && TREE_OPERAND (maxval
, 1) == integer_one_node
)
306 mode_string
= decode_constant (TREE_OPERAND (maxval
, 0));
307 APPEND (result
, mode_string
->str
);
312 mode_string
= decode_constant (maxval
);
313 APPEND (result
, mode_string
->str
);
315 APPEND (result
, "+1");
317 APPEND (result
, ")");
319 APPEND (result
, " VARYING");
323 APPEND (result
, "ARRAY (");
324 if (TREE_CODE (TYPE_DOMAIN (type
)) == INTEGER_TYPE
325 && TREE_TYPE (TYPE_DOMAIN (type
)) == ridpointers
[(int) RID_RANGE
])
327 mode_string
= decode_constant (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
328 APPEND (result
, mode_string
->str
);
331 APPEND (result
, ":");
332 mode_string
= decode_constant (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
333 APPEND (result
, mode_string
->str
);
338 mode_string
= decode_mode (TYPE_DOMAIN (type
));
339 APPEND (result
, mode_string
->str
);
342 APPEND (result
, ") ");
344 APPEND (result
, "VARYING ");
346 mode_string
= get_type (TREE_TYPE (type
));
347 APPEND (result
, mode_string
->str
);
350 layout
= TYPE_ATTRIBUTES (type
);
351 if (layout
!= NULL_TREE
)
353 mode_string
= decode_layout (layout
);
354 APPEND (result
, mode_string
->str
);
362 grant_array_type_selective (type
, all_decls
)
366 MYSTRING
*result
= newstring ("");
367 MYSTRING
*mode_string
;
370 if (chill_varying_type_p (type
))
373 type
= CH_VARYING_ARRAY_TYPE (type
);
375 if (CH_STRING_TYPE_P (type
))
377 tree fields
= TYPE_DOMAIN (type
);
378 tree maxval
= TYPE_MAX_VALUE (fields
);
380 if (TREE_CODE (maxval
) != INTEGER_CST
)
382 if (TREE_CODE (maxval
) == MINUS_EXPR
383 && TREE_OPERAND (maxval
, 1) == integer_one_node
)
385 mode_string
= decode_constant_selective (TREE_OPERAND (maxval
, 0), all_decls
);
386 if (mode_string
->len
)
387 APPEND (result
, mode_string
->str
);
392 mode_string
= decode_constant_selective (maxval
, all_decls
);
393 if (mode_string
->len
)
394 APPEND (result
, mode_string
->str
);
401 if (TREE_CODE (TYPE_DOMAIN (type
)) == INTEGER_TYPE
402 && TREE_TYPE (TYPE_DOMAIN (type
)) == ridpointers
[(int) RID_RANGE
])
404 mode_string
= decode_constant_selective (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), all_decls
);
405 if (mode_string
->len
)
406 APPEND (result
, mode_string
->str
);
409 mode_string
= decode_constant_selective (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), all_decls
);
410 if (mode_string
->len
)
412 MAYBE_NEWLINE (result
);
413 APPEND (result
, mode_string
->str
);
419 mode_string
= decode_mode_selective (TYPE_DOMAIN (type
), all_decls
);
420 if (mode_string
->len
)
421 APPEND (result
, mode_string
->str
);
425 mode_string
= get_type_selective (TREE_TYPE (type
), all_decls
);
426 if (mode_string
->len
)
428 MAYBE_NEWLINE (result
);
429 APPEND (result
, mode_string
->str
);
442 if (TREE_CODE (val
) == CONST_DECL
&& DECL_NAME (val
))
444 result
= newstring (IDENTIFIER_POINTER (DECL_NAME (val
)));
446 else if (TREE_CODE (val
) == CONST_DECL
)
448 /* it's a synonym -- get the value */
449 result
= decode_constant (DECL_INITIAL (val
));
453 result
= decode_constant (val
);
459 get_tag_value_selective (val
, all_decls
)
465 if (TREE_CODE (val
) == CONST_DECL
&& DECL_NAME (val
))
466 result
= newstring ("");
467 else if (TREE_CODE (val
) == CONST_DECL
)
469 /* it's a synonym -- get the value */
470 result
= decode_constant_selective (DECL_INITIAL (val
), all_decls
);
474 result
= decode_constant_selective (val
, all_decls
);
480 print_enumeral (type
)
483 MYSTRING
*result
= newstring ("");
487 if (TYPE_LANG_SPECIFIC (type
) == NULL
)
491 APPEND (result
, "SET (");
492 for (fields
= TYPE_VALUES (type
);
494 fields
= TREE_CHAIN (fields
))
496 if (TREE_PURPOSE (fields
) == NULL_TREE
)
497 APPEND (result
, "*");
500 tree decl
= TREE_VALUE (fields
);
501 APPEND (result
, IDENTIFIER_POINTER (TREE_PURPOSE (fields
)));
502 if (TREE_CODE (decl
) == CONST_DECL
&& DECL_INITIAL (decl
))
504 MYSTRING
*val_string
= decode_constant (DECL_INITIAL (decl
));
505 APPEND (result
, " = ");
506 APPEND (result
, val_string
->str
);
510 if (TREE_CHAIN (fields
) != NULL_TREE
)
511 APPEND (result
, ",\n ");
513 APPEND (result
, ")");
519 print_enumeral_selective (type
, all_decls
)
523 MYSTRING
*result
= newstring ("");
526 for (fields
= TYPE_VALUES (type
);
528 fields
= TREE_CHAIN (fields
))
530 if (TREE_PURPOSE (fields
) != NULL_TREE
)
532 tree decl
= TREE_VALUE (fields
);
533 if (TREE_CODE (decl
) == CONST_DECL
&& DECL_INITIAL (decl
))
535 MYSTRING
*val_string
= decode_constant_selective (DECL_INITIAL (decl
), all_decls
);
537 APPEND (result
, val_string
->str
);
546 print_integer_type (type
)
549 MYSTRING
*result
= newstring ("");
550 MYSTRING
*mode_string
;
551 const char *name_ptr
;
554 if (TREE_TYPE (type
))
556 mode_string
= decode_mode (TREE_TYPE (type
));
557 APPEND (result
, mode_string
->str
);
560 APPEND (result
, "(");
561 mode_string
= decode_constant (TYPE_MIN_VALUE (type
));
562 APPEND (result
, mode_string
->str
);
565 if (TREE_TYPE (type
) != ridpointers
[(int) RID_BIN
])
567 APPEND (result
, ":");
568 mode_string
= decode_constant (TYPE_MAX_VALUE (type
));
569 APPEND (result
, mode_string
->str
);
573 APPEND (result
, ")");
576 /* We test TYPE_MAIN_VARIANT because pushdecl often builds
577 a copy of a built-in type node, which is logically id-
578 entical but has a different address, and the same
579 TYPE_MAIN_VARIANT. */
580 /* FIXME this should not be needed! */
582 base_type
= TREE_TYPE (type
) ? TREE_TYPE (type
) : type
;
584 if (TREE_UNSIGNED (base_type
))
586 if (base_type
== chill_unsigned_type_node
587 || TYPE_MAIN_VARIANT(base_type
) ==
588 TYPE_MAIN_VARIANT (chill_unsigned_type_node
))
590 else if (base_type
== long_integer_type_node
591 || TYPE_MAIN_VARIANT(base_type
) ==
592 TYPE_MAIN_VARIANT (long_unsigned_type_node
))
594 else if (type
== unsigned_char_type_node
595 || TYPE_MAIN_VARIANT(base_type
) ==
596 TYPE_MAIN_VARIANT (unsigned_char_type_node
))
598 else if (type
== duration_timing_type_node
599 || TYPE_MAIN_VARIANT (base_type
) ==
600 TYPE_MAIN_VARIANT (duration_timing_type_node
))
601 name_ptr
= "DURATION";
602 else if (type
== abs_timing_type_node
603 || TYPE_MAIN_VARIANT (base_type
) ==
604 TYPE_MAIN_VARIANT (abs_timing_type_node
))
611 if (base_type
== chill_integer_type_node
612 || TYPE_MAIN_VARIANT (base_type
) ==
613 TYPE_MAIN_VARIANT (chill_integer_type_node
))
615 else if (base_type
== long_integer_type_node
616 || TYPE_MAIN_VARIANT (base_type
) ==
617 TYPE_MAIN_VARIANT (long_integer_type_node
))
619 else if (type
== signed_char_type_node
620 || TYPE_MAIN_VARIANT (base_type
) ==
621 TYPE_MAIN_VARIANT (signed_char_type_node
))
627 APPEND (result
, name_ptr
);
629 /* see if we have a range */
630 if (TREE_TYPE (type
) != NULL
)
632 mode_string
= decode_constant (TYPE_MIN_VALUE (type
));
633 APPEND (result
, mode_string
->str
);
635 APPEND (result
, ":");
636 mode_string
= decode_constant (TYPE_MAX_VALUE (type
));
637 APPEND (result
, mode_string
->str
);
645 find_enum_parent (enumname
, all_decls
)
651 for (wrk
= all_decls
; wrk
!= NULL_TREE
; wrk
= TREE_CHAIN (wrk
))
653 if (TREE_TYPE (wrk
) != NULL_TREE
&& TREE_CODE (wrk
) != CONST_DECL
&&
654 TREE_CODE (TREE_TYPE (wrk
)) == ENUMERAL_TYPE
)
657 for (list
= TYPE_VALUES (TREE_TYPE (wrk
)); list
!= NULL_TREE
; list
= TREE_CHAIN (list
))
659 if (DECL_NAME (TREE_VALUE (list
)) == enumname
)
668 print_integer_selective (type
, all_decls
)
672 MYSTRING
*result
= newstring ("");
673 MYSTRING
*mode_string
;
675 if (TREE_TYPE (type
))
677 mode_string
= decode_mode_selective (TREE_TYPE (type
), all_decls
);
678 if (mode_string
->len
)
679 APPEND (result
, mode_string
->str
);
682 if (TREE_TYPE (type
) == ridpointers
[(int)RID_RANGE
] &&
683 TREE_CODE (TYPE_MIN_VALUE (type
)) == IDENTIFIER_NODE
&&
684 TREE_CODE (TYPE_MAX_VALUE (type
)) == IDENTIFIER_NODE
)
686 /* we have a range of a set. Find parant mode and write it
687 to SPEC MODULE. This will loose if the parent mode was SEIZED from
689 tree minparent
= find_enum_parent (TYPE_MIN_VALUE (type
), all_decls
);
690 tree maxparent
= find_enum_parent (TYPE_MAX_VALUE (type
), all_decls
);
692 if (minparent
!= NULL_TREE
)
694 if (! CH_ALREADY_GRANTED (minparent
))
696 mode_string
= decode_decl (minparent
);
697 if (mode_string
->len
)
698 APPEND (result
, mode_string
->str
);
700 CH_ALREADY_GRANTED (minparent
) = 1;
703 if (minparent
!= maxparent
&& maxparent
!= NULL_TREE
)
705 if (!CH_ALREADY_GRANTED (maxparent
))
707 mode_string
= decode_decl (maxparent
);
708 if (mode_string
->len
)
710 MAYBE_NEWLINE (result
);
711 APPEND (result
, mode_string
->str
);
714 CH_ALREADY_GRANTED (maxparent
) = 1;
720 mode_string
= decode_constant_selective (TYPE_MIN_VALUE (type
), all_decls
);
721 if (mode_string
->len
)
723 MAYBE_NEWLINE (result
);
724 APPEND (result
, mode_string
->str
);
728 mode_string
= decode_constant_selective (TYPE_MAX_VALUE (type
), all_decls
);
729 if (mode_string
->len
)
731 MAYBE_NEWLINE (result
);
732 APPEND (result
, mode_string
->str
);
739 /* see if we have a range */
740 if (TREE_TYPE (type
) != NULL
)
742 mode_string
= decode_constant_selective (TYPE_MIN_VALUE (type
), all_decls
);
743 if (mode_string
->len
)
744 APPEND (result
, mode_string
->str
);
747 mode_string
= decode_constant_selective (TYPE_MAX_VALUE (type
), all_decls
);
748 if (mode_string
->len
)
750 MAYBE_NEWLINE (result
);
751 APPEND (result
, mode_string
->str
);
763 MYSTRING
*result
= newstring ("");
764 MYSTRING
*mode_string
;
767 if (chill_varying_type_p (type
))
769 mode_string
= grant_array_type (type
);
770 APPEND (result
, mode_string
->str
);
775 fields
= TYPE_FIELDS (type
);
777 APPEND (result
, "STRUCT (");
778 while (fields
!= NULL_TREE
)
780 if (TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
783 /* Format a tagged variant record type. */
784 APPEND (result
, " CASE ");
785 if (TYPE_TAGFIELDS (TREE_TYPE (fields
)) != NULL_TREE
)
787 tree tag_list
= TYPE_TAGFIELDS (TREE_TYPE (fields
));
790 tree tag_name
= DECL_NAME (TREE_VALUE (tag_list
));
791 APPEND (result
, IDENTIFIER_POINTER (tag_name
));
792 tag_list
= TREE_CHAIN (tag_list
);
793 if (tag_list
== NULL_TREE
)
795 APPEND (result
, ", ");
798 APPEND (result
, " OF\n");
799 variants
= TYPE_FIELDS (TREE_TYPE (fields
));
801 /* Each variant is a FIELD_DECL whose type is an anonymous
802 struct within the anonymous union. */
803 while (variants
!= NULL_TREE
)
805 tree tag_list
= TYPE_TAG_VALUES (TREE_TYPE (variants
));
806 tree struct_elts
= TYPE_FIELDS (TREE_TYPE (variants
));
808 while (tag_list
!= NULL_TREE
)
810 tree tag_values
= TREE_VALUE (tag_list
);
811 APPEND (result
, " (");
812 while (tag_values
!= NULL_TREE
)
814 mode_string
= get_tag_value (TREE_VALUE (tag_values
));
815 APPEND (result
, mode_string
->str
);
817 if (TREE_CHAIN (tag_values
) != NULL_TREE
)
819 APPEND (result
, ",\n ");
820 tag_values
= TREE_CHAIN (tag_values
);
824 APPEND (result
, ")");
825 tag_list
= TREE_CHAIN (tag_list
);
827 APPEND (result
, ",");
831 APPEND (result
, " : ");
833 while (struct_elts
!= NULL_TREE
)
835 mode_string
= decode_decl (struct_elts
);
836 APPEND (result
, mode_string
->str
);
839 if (TREE_CHAIN (struct_elts
) != NULL_TREE
)
840 APPEND (result
, ",\n ");
841 struct_elts
= TREE_CHAIN (struct_elts
);
844 variants
= TREE_CHAIN (variants
);
845 if (variants
!= NULL_TREE
846 && TREE_CHAIN (variants
) == NULL_TREE
847 && DECL_NAME (variants
) == ELSE_VARIANT_NAME
)
849 tree else_elts
= TYPE_FIELDS (TREE_TYPE (variants
));
850 APPEND (result
, "\n ELSE ");
851 while (else_elts
!= NULL_TREE
)
853 mode_string
= decode_decl (else_elts
);
854 APPEND (result
, mode_string
->str
);
856 if (TREE_CHAIN (else_elts
) != NULL_TREE
)
857 APPEND (result
, ",\n ");
858 else_elts
= TREE_CHAIN (else_elts
);
862 if (variants
!= NULL_TREE
)
863 APPEND (result
, ",\n");
866 APPEND (result
, "\n ESAC");
870 mode_string
= decode_decl (fields
);
871 APPEND (result
, mode_string
->str
);
875 fields
= TREE_CHAIN (fields
);
876 if (fields
!= NULL_TREE
)
877 APPEND (result
, ",\n ");
879 APPEND (result
, ")");
885 print_struct_selective (type
, all_decls
)
889 MYSTRING
*result
= newstring ("");
890 MYSTRING
*mode_string
;
893 if (chill_varying_type_p (type
))
895 mode_string
= grant_array_type_selective (type
, all_decls
);
896 if (mode_string
->len
)
897 APPEND (result
, mode_string
->str
);
902 fields
= TYPE_FIELDS (type
);
904 while (fields
!= NULL_TREE
)
906 if (TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
909 /* Format a tagged variant record type. */
911 variants
= TYPE_FIELDS (TREE_TYPE (fields
));
913 /* Each variant is a FIELD_DECL whose type is an anonymous
914 struct within the anonymous union. */
915 while (variants
!= NULL_TREE
)
917 tree tag_list
= TYPE_TAG_VALUES (TREE_TYPE (variants
));
918 tree struct_elts
= TYPE_FIELDS (TREE_TYPE (variants
));
920 while (tag_list
!= NULL_TREE
)
922 tree tag_values
= TREE_VALUE (tag_list
);
923 while (tag_values
!= NULL_TREE
)
925 mode_string
= get_tag_value_selective (TREE_VALUE (tag_values
),
927 if (mode_string
->len
)
929 MAYBE_NEWLINE (result
);
930 APPEND (result
, mode_string
->str
);
933 if (TREE_CHAIN (tag_values
) != NULL_TREE
)
934 tag_values
= TREE_CHAIN (tag_values
);
937 tag_list
= TREE_CHAIN (tag_list
);
942 while (struct_elts
!= NULL_TREE
)
944 mode_string
= decode_decl_selective (struct_elts
, all_decls
);
945 if (mode_string
->len
)
947 MAYBE_NEWLINE (result
);
948 APPEND (result
, mode_string
->str
);
952 struct_elts
= TREE_CHAIN (struct_elts
);
955 variants
= TREE_CHAIN (variants
);
956 if (variants
!= NULL_TREE
957 && TREE_CHAIN (variants
) == NULL_TREE
958 && DECL_NAME (variants
) == ELSE_VARIANT_NAME
)
960 tree else_elts
= TYPE_FIELDS (TREE_TYPE (variants
));
961 while (else_elts
!= NULL_TREE
)
963 mode_string
= decode_decl_selective (else_elts
, all_decls
);
964 if (mode_string
->len
)
966 MAYBE_NEWLINE (result
);
967 APPEND (result
, mode_string
->str
);
970 else_elts
= TREE_CHAIN (else_elts
);
978 mode_string
= decode_decl_selective (fields
, all_decls
);
979 APPEND (result
, mode_string
->str
);
983 fields
= TREE_CHAIN (fields
);
990 print_proc_exceptions (ex
)
993 MYSTRING
*result
= newstring ("");
997 APPEND (result
, "\n EXCEPTIONS (");
998 for ( ; ex
!= NULL_TREE
; ex
= TREE_CHAIN (ex
))
1000 APPEND (result
, IDENTIFIER_POINTER (TREE_VALUE (ex
)));
1001 if (TREE_CHAIN (ex
) != NULL_TREE
)
1002 APPEND (result
, ",\n ");
1004 APPEND (result
, ")");
1010 print_proc_tail (type
, args
, print_argnames
)
1015 MYSTRING
*result
= newstring ("");
1016 MYSTRING
*mode_string
;
1018 int stopat
= list_length (args
) - 3;
1020 /* do the argument modes */
1021 for ( ; args
!= NULL_TREE
;
1022 args
= TREE_CHAIN (args
), count
++)
1025 tree argmode
= TREE_VALUE (args
);
1026 tree attribute
= TREE_PURPOSE (args
);
1028 if (argmode
== void_type_node
)
1031 /* if we have exceptions don't print last 2 arguments */
1032 if (TYPE_RAISES_EXCEPTIONS (type
) && count
== stopat
)
1036 APPEND (result
, ",\n ");
1039 sprintf(buf
, "arg%d ", count
);
1040 APPEND (result
, buf
);
1043 if (attribute
== ridpointers
[(int) RID_LOC
])
1044 argmode
= TREE_TYPE (argmode
);
1045 mode_string
= get_type (argmode
);
1046 APPEND (result
, mode_string
->str
);
1049 if (attribute
!= NULL_TREE
)
1051 sprintf (buf
, " %s", IDENTIFIER_POINTER (attribute
));
1052 APPEND (result
, buf
);
1055 APPEND (result
, ")");
1059 tree retn_type
= TREE_TYPE (type
);
1061 if (retn_type
!= NULL_TREE
1062 && TREE_CODE (retn_type
) != VOID_TYPE
)
1064 mode_string
= get_type (retn_type
);
1065 APPEND (result
, "\n RETURNS (");
1066 APPEND (result
, mode_string
->str
);
1068 if (TREE_CODE (retn_type
) == REFERENCE_TYPE
)
1069 APPEND (result
, " LOC");
1070 APPEND (result
, ")");
1074 mode_string
= print_proc_exceptions (TYPE_RAISES_EXCEPTIONS (type
));
1075 APPEND (result
, mode_string
->str
);
1082 print_proc_tail_selective (type
, args
, all_decls
)
1087 MYSTRING
*result
= newstring ("");
1088 MYSTRING
*mode_string
;
1090 int stopat
= list_length (args
) - 3;
1092 /* do the argument modes */
1093 for ( ; args
!= NULL_TREE
;
1094 args
= TREE_CHAIN (args
), count
++)
1096 tree argmode
= TREE_VALUE (args
);
1097 tree attribute
= TREE_PURPOSE (args
);
1099 if (argmode
== void_type_node
)
1102 /* if we have exceptions don't process last 2 arguments */
1103 if (TYPE_RAISES_EXCEPTIONS (type
) && count
== stopat
)
1106 if (attribute
== ridpointers
[(int) RID_LOC
])
1107 argmode
= TREE_TYPE (argmode
);
1108 mode_string
= get_type_selective (argmode
, all_decls
);
1109 if (mode_string
->len
)
1111 MAYBE_NEWLINE (result
);
1112 APPEND (result
, mode_string
->str
);
1119 tree retn_type
= TREE_TYPE (type
);
1121 if (retn_type
!= NULL_TREE
1122 && TREE_CODE (retn_type
) != VOID_TYPE
)
1124 mode_string
= get_type_selective (retn_type
, all_decls
);
1125 if (mode_string
->len
)
1127 MAYBE_NEWLINE (result
);
1128 APPEND (result
, mode_string
->str
);
1137 /* output a mode (or type). */
1143 MYSTRING
*result
= newstring ("");
1144 MYSTRING
*mode_string
;
1146 switch ((enum chill_tree_code
)TREE_CODE (type
))
1149 if (DECL_NAME (type
))
1151 APPEND (result
, IDENTIFIER_POINTER (DECL_NAME (type
)));
1154 type
= TREE_TYPE (type
);
1157 case IDENTIFIER_NODE
:
1158 APPEND (result
, IDENTIFIER_POINTER (type
));
1162 /* LANG_TYPE are only used until satisfy is done,
1163 as place-holders for 'READ T', NEWMODE/SYNMODE modes,
1164 parameterised modes, and old-fashioned CHAR(N). */
1165 if (TYPE_READONLY (type
))
1166 APPEND (result
, "READ ");
1168 mode_string
= get_type (TREE_TYPE (type
));
1169 APPEND (result
, mode_string
->str
);
1170 if (TYPE_DOMAIN (type
) != NULL_TREE
)
1172 /* Parameterized mode,
1173 or old-fashioned CHAR(N) string declaration.. */
1174 APPEND (result
, "(");
1175 mode_string
= decode_constant (TYPE_DOMAIN (type
));
1176 APPEND (result
, mode_string
->str
);
1177 APPEND (result
, ")");
1183 mode_string
= grant_array_type (type
);
1184 APPEND (result
, mode_string
->str
);
1189 APPEND (result
, "BOOL");
1193 APPEND (result
, "CHAR");
1197 mode_string
= print_enumeral (type
);
1198 APPEND (result
, mode_string
->str
);
1204 tree args
= TYPE_ARG_TYPES (type
);
1206 APPEND (result
, "PROC (");
1208 mode_string
= print_proc_tail (type
, args
, 0);
1209 APPEND (result
, mode_string
->str
);
1215 mode_string
= print_integer_type (type
);
1216 APPEND (result
, mode_string
->str
);
1221 if (CH_IS_INSTANCE_MODE (type
))
1223 APPEND (result
, "INSTANCE");
1226 else if (CH_IS_BUFFER_MODE (type
) || CH_IS_EVENT_MODE (type
))
1227 { tree bufsize
= max_queue_size (type
);
1228 APPEND (result
, CH_IS_BUFFER_MODE (type
) ? "BUFFER " : "EVENT ");
1229 if (bufsize
!= NULL_TREE
)
1231 APPEND (result
, "(");
1232 mode_string
= decode_constant (bufsize
);
1233 APPEND (result
, mode_string
->str
);
1234 APPEND (result
, ") ");
1237 if (CH_IS_BUFFER_MODE (type
))
1239 mode_string
= decode_mode (buffer_element_mode (type
));
1240 APPEND (result
, mode_string
->str
);
1245 else if (CH_IS_ACCESS_MODE (type
))
1247 tree indexmode
, recordmode
, dynamic
;
1249 APPEND (result
, "ACCESS");
1250 recordmode
= access_recordmode (type
);
1251 indexmode
= access_indexmode (type
);
1252 dynamic
= access_dynamic (type
);
1254 if (indexmode
!= void_type_node
)
1256 mode_string
= decode_mode (indexmode
);
1257 APPEND (result
, " (");
1258 APPEND (result
, mode_string
->str
);
1259 APPEND (result
, ")");
1262 if (recordmode
!= void_type_node
)
1264 mode_string
= decode_mode (recordmode
);
1265 APPEND (result
, " ");
1266 APPEND (result
, mode_string
->str
);
1269 if (dynamic
!= integer_zero_node
)
1270 APPEND (result
, " DYNAMIC");
1273 else if (CH_IS_TEXT_MODE (type
))
1275 tree indexmode
, dynamic
, length
;
1277 APPEND (result
, "TEXT (");
1278 length
= text_length (type
);
1279 indexmode
= text_indexmode (type
);
1280 dynamic
= text_dynamic (type
);
1282 mode_string
= decode_constant (length
);
1283 APPEND (result
, mode_string
->str
);
1285 APPEND (result
, ")");
1286 if (indexmode
!= void_type_node
)
1288 APPEND (result
, " ");
1289 mode_string
= decode_mode (indexmode
);
1290 APPEND (result
, mode_string
->str
);
1293 if (dynamic
!= integer_zero_node
)
1294 APPEND (result
, " DYNAMIC");
1297 mode_string
= print_struct (type
);
1298 APPEND (result
, mode_string
->str
);
1303 if (TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
)
1304 APPEND (result
, "PTR");
1307 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1309 mode_string
= get_type (TREE_TYPE (type
));
1310 APPEND (result
, mode_string
->str
);
1315 APPEND (result
, "REF ");
1316 mode_string
= get_type (TREE_TYPE (type
));
1317 APPEND (result
, mode_string
->str
);
1324 if (TREE_INT_CST_LOW (TYPE_SIZE (type
)) == 32)
1325 APPEND (result
, "REAL");
1327 APPEND (result
, "LONG_REAL");
1331 if (CH_BOOLS_TYPE_P (type
))
1332 mode_string
= grant_array_type (type
);
1335 APPEND (result
, "POWERSET ");
1336 mode_string
= get_type (TYPE_DOMAIN (type
));
1338 APPEND (result
, mode_string
->str
);
1342 case REFERENCE_TYPE
:
1343 mode_string
= get_type (TREE_TYPE (type
));
1344 APPEND (result
, mode_string
->str
);
1349 APPEND (result
, "/* ---- not implemented ---- */");
1357 find_in_decls (id
, all_decls
)
1363 for (wrk
= all_decls
; wrk
!= NULL_TREE
; wrk
= TREE_CHAIN (wrk
))
1365 if (DECL_NAME (wrk
) == id
|| DECL_POSTFIX (wrk
) == id
)
1376 for (i
= RID_UNUSED
; i
< RID_MAX
; i
++)
1378 if (id
== ridpointers
[i
])
1385 grant_seized_identifier (decl
)
1388 seizefile_list
*wrk
= selective_seizes
;
1389 MYSTRING
*mode_string
;
1391 CH_ALREADY_GRANTED (decl
) = 1;
1393 /* comes from a SPEC MODULE in the module */
1394 if (DECL_SEIZEFILE (decl
) == NULL_TREE
)
1397 /* search file already in process */
1400 if (wrk
->filename
== DECL_SEIZEFILE (decl
))
1406 wrk
= (seizefile_list
*)xmalloc (sizeof (seizefile_list
));
1407 wrk
->next
= selective_seizes
;
1408 selective_seizes
= wrk
;
1409 wrk
->filename
= DECL_SEIZEFILE (decl
);
1410 wrk
->seizes
= newstring ("<> USE_SEIZE_FILE \"");
1411 APPEND (wrk
->seizes
, IDENTIFIER_POINTER (DECL_SEIZEFILE (decl
)));
1412 APPEND (wrk
->seizes
, "\" <>\n");
1414 APPEND (wrk
->seizes
, "SEIZE ");
1415 mode_string
= decode_prefix_rename (decl
);
1416 APPEND (wrk
->seizes
, mode_string
->str
);
1418 APPEND (wrk
->seizes
, ";\n");
1422 decode_mode_selective (type
, all_decls
)
1426 MYSTRING
*result
= newstring ("");
1427 MYSTRING
*mode_string
;
1430 switch ((enum chill_tree_code
)TREE_CODE (type
))
1433 /* FIXME: could this ever happen ?? */
1434 if (DECL_NAME (type
))
1437 result
= decode_mode_selective (DECL_NAME (type
), all_decls
);
1442 case IDENTIFIER_NODE
:
1443 if (in_ridpointers (type
))
1444 /* it's a predefined, we must not search the whole list */
1447 decl
= find_in_decls (type
, all_decls
);
1448 if (decl
!= NULL_TREE
)
1450 if (CH_ALREADY_GRANTED (decl
))
1451 /* already processed */
1454 if (TREE_CODE (decl
) == ALIAS_DECL
&& DECL_POSTFIX (decl
) != NULL_TREE
)
1456 /* If CH_DECL_GRANTED, decl was granted into this scope, and
1457 so wasn't in the source code. */
1458 if (!CH_DECL_GRANTED (decl
))
1460 grant_seized_identifier (decl
);
1465 result
= decode_decl (decl
);
1466 mode_string
= decode_decl_selective (decl
, all_decls
);
1467 if (mode_string
->len
)
1469 PREPEND (result
, mode_string
->str
);
1477 mode_string
= get_type_selective (TREE_TYPE (type
), all_decls
);
1478 APPEND (result
, mode_string
->str
);
1483 mode_string
= grant_array_type_selective (type
, all_decls
);
1484 APPEND (result
, mode_string
->str
);
1497 mode_string
= print_enumeral_selective (type
, all_decls
);
1498 if (mode_string
->len
)
1499 APPEND (result
, mode_string
->str
);
1505 tree args
= TYPE_ARG_TYPES (type
);
1507 mode_string
= print_proc_tail_selective (type
, args
, all_decls
);
1508 if (mode_string
->len
)
1509 APPEND (result
, mode_string
->str
);
1515 mode_string
= print_integer_selective (type
, all_decls
);
1516 if (mode_string
->len
)
1517 APPEND (result
, mode_string
->str
);
1522 if (CH_IS_INSTANCE_MODE (type
))
1526 else if (CH_IS_BUFFER_MODE (type
) || CH_IS_EVENT_MODE (type
))
1528 tree bufsize
= max_queue_size (type
);
1529 if (bufsize
!= NULL_TREE
)
1531 mode_string
= decode_constant_selective (bufsize
, all_decls
);
1532 if (mode_string
->len
)
1533 APPEND (result
, mode_string
->str
);
1536 if (CH_IS_BUFFER_MODE (type
))
1538 mode_string
= decode_mode_selective (buffer_element_mode (type
), all_decls
);
1539 if (mode_string
->len
)
1541 MAYBE_NEWLINE (result
);
1542 APPEND (result
, mode_string
->str
);
1548 else if (CH_IS_ACCESS_MODE (type
))
1550 tree indexmode
= access_indexmode (type
);
1551 tree recordmode
= access_recordmode (type
);
1553 if (indexmode
!= void_type_node
)
1555 mode_string
= decode_mode_selective (indexmode
, all_decls
);
1556 if (mode_string
->len
)
1558 if (result
->len
&& result
->str
[result
->len
- 1] != '\n')
1559 APPEND (result
, ";\n");
1560 APPEND (result
, mode_string
->str
);
1564 if (recordmode
!= void_type_node
)
1566 mode_string
= decode_mode_selective (recordmode
, all_decls
);
1567 if (mode_string
->len
)
1569 if (result
->len
&& result
->str
[result
->len
- 1] != '\n')
1570 APPEND (result
, ";\n");
1571 APPEND (result
, mode_string
->str
);
1577 else if (CH_IS_TEXT_MODE (type
))
1579 tree indexmode
= text_indexmode (type
);
1580 tree length
= text_length (type
);
1582 mode_string
= decode_constant_selective (length
, all_decls
);
1583 if (mode_string
->len
)
1584 APPEND (result
, mode_string
->str
);
1586 if (indexmode
!= void_type_node
)
1588 mode_string
= decode_mode_selective (indexmode
, all_decls
);
1589 if (mode_string
->len
)
1591 if (result
->len
&& result
->str
[result
->len
- 1] != '\n')
1592 APPEND (result
, ";\n");
1593 APPEND (result
, mode_string
->str
);
1599 mode_string
= print_struct_selective (type
, all_decls
);
1600 if (mode_string
->len
)
1602 MAYBE_NEWLINE (result
);
1603 APPEND (result
, mode_string
->str
);
1609 if (TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
)
1613 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1615 mode_string
= get_type_selective (TREE_TYPE (type
), all_decls
);
1616 if (mode_string
->len
)
1617 APPEND (result
, mode_string
->str
);
1622 mode_string
= get_type_selective (TREE_TYPE (type
), all_decls
);
1623 if (mode_string
->len
)
1624 APPEND (result
, mode_string
->str
);
1635 if (CH_BOOLS_TYPE_P (type
))
1636 mode_string
= grant_array_type_selective (type
, all_decls
);
1638 mode_string
= get_type_selective (TYPE_DOMAIN (type
), all_decls
);
1639 if (mode_string
->len
)
1640 APPEND (result
, mode_string
->str
);
1644 case REFERENCE_TYPE
:
1645 mode_string
= get_type_selective (TREE_TYPE (type
), all_decls
);
1646 if (mode_string
->len
)
1647 APPEND (result
, mode_string
->str
);
1652 APPEND (result
, "/* ---- not implemented ---- */");
1663 if (type
== NULL_TREE
|| TREE_CODE (type
) == ERROR_MARK
)
1664 return newstring ("");
1666 return (decode_mode (type
));
1670 get_type_selective (type
, all_decls
)
1674 if (type
== NULL_TREE
|| TREE_CODE (type
) == ERROR_MARK
)
1675 return newstring ("");
1677 return (decode_mode_selective (type
, all_decls
));
1682 is_forbidden (str
, forbid
)
1686 if (forbid
== NULL_TREE
)
1689 if (TREE_CODE (forbid
) == INTEGER_CST
)
1692 while (forbid
!= NULL_TREE
)
1694 if (TREE_VALUE (forbid
) == str
)
1696 forbid
= TREE_CHAIN (forbid
);
1704 decode_constant (init
)
1707 MYSTRING
*result
= newstring ("");
1708 MYSTRING
*tmp_string
;
1709 tree type
= TREE_TYPE (init
);
1713 MYSTRING
*mode_string
;
1715 switch ((enum chill_tree_code
)TREE_CODE (val
))
1718 tmp_string
= decode_constant (TREE_OPERAND (val
, 0));
1719 APPEND (result
, tmp_string
->str
);
1721 val
= TREE_OPERAND (val
, 1); /* argument list */
1722 if (val
!= NULL_TREE
&& TREE_CODE (val
) != TREE_LIST
)
1724 APPEND (result
, " ");
1725 tmp_string
= decode_constant (val
);
1726 APPEND (result
, tmp_string
->str
);
1731 APPEND (result
, " (");
1732 if (val
!= NULL_TREE
)
1736 tmp_string
= decode_constant (TREE_VALUE (val
));
1737 APPEND (result
, tmp_string
->str
);
1739 val
= TREE_CHAIN (val
);
1740 if (val
== NULL_TREE
)
1742 APPEND (result
, ", ");
1745 APPEND (result
, ")");
1750 /* Generate an "expression conversion" expression (a cast). */
1751 tmp_string
= decode_mode (type
);
1753 APPEND (result
, tmp_string
->str
);
1755 APPEND (result
, "(");
1756 val
= TREE_OPERAND (val
, 0);
1757 type
= TREE_TYPE (val
);
1759 /* If the coercee is a tuple, make sure it is prefixed by its mode. */
1760 if (TREE_CODE (val
) == CONSTRUCTOR
1761 && !CH_BOOLS_TYPE_P (type
) && !chill_varying_type_p (type
))
1763 tmp_string
= decode_mode (type
);
1764 APPEND (result
, tmp_string
->str
);
1766 APPEND (result
, " ");
1769 tmp_string
= decode_constant (val
);
1770 APPEND (result
, tmp_string
->str
);
1772 APPEND (result
, ")");
1775 case IDENTIFIER_NODE
:
1776 APPEND (result
, IDENTIFIER_POINTER (val
));
1780 APPEND (result
, "(");
1781 tmp_string
= decode_constant (TREE_OPERAND (val
, 0));
1782 APPEND (result
, tmp_string
->str
);
1784 APPEND (result
, ")");
1787 case UNDEFINED_EXPR
:
1788 APPEND (result
, "*");
1791 case PLUS_EXPR
: op
= "+"; goto binary
;
1792 case MINUS_EXPR
: op
= "-"; goto binary
;
1793 case MULT_EXPR
: op
= "*"; goto binary
;
1794 case TRUNC_DIV_EXPR
: op
= "/"; goto binary
;
1795 case FLOOR_MOD_EXPR
: op
= " MOD "; goto binary
;
1796 case TRUNC_MOD_EXPR
: op
= " REM "; goto binary
;
1797 case CONCAT_EXPR
: op
= "//"; goto binary
;
1798 case BIT_IOR_EXPR
: op
= " OR "; goto binary
;
1799 case BIT_XOR_EXPR
: op
= " XOR "; goto binary
;
1800 case TRUTH_ORIF_EXPR
: op
= " ORIF "; goto binary
;
1801 case BIT_AND_EXPR
: op
= " AND "; goto binary
;
1802 case TRUTH_ANDIF_EXPR
: op
= " ANDIF "; goto binary
;
1803 case GT_EXPR
: op
= ">"; goto binary
;
1804 case GE_EXPR
: op
= ">="; goto binary
;
1805 case SET_IN_EXPR
: op
= " IN "; goto binary
;
1806 case LT_EXPR
: op
= "<"; goto binary
;
1807 case LE_EXPR
: op
= "<="; goto binary
;
1808 case EQ_EXPR
: op
= "="; goto binary
;
1809 case NE_EXPR
: op
= "/="; goto binary
;
1811 if (TREE_OPERAND (val
, 0) == NULL_TREE
)
1813 APPEND (result
, TREE_OPERAND (val
, 1) == NULL_TREE
? "*" : "ELSE");
1816 op
= ":"; goto binary
;
1818 tmp_string
= decode_constant (TREE_OPERAND (val
, 0));
1819 APPEND (result
, tmp_string
->str
);
1821 APPEND (result
, op
);
1822 tmp_string
= decode_constant (TREE_OPERAND (val
, 1));
1823 APPEND (result
, tmp_string
->str
);
1827 case REPLICATE_EXPR
:
1828 APPEND (result
, "(");
1829 tmp_string
= decode_constant (TREE_OPERAND (val
, 0));
1830 APPEND (result
, tmp_string
->str
);
1832 APPEND (result
, ")");
1833 tmp_string
= decode_constant (TREE_OPERAND (val
, 1));
1834 APPEND (result
, tmp_string
->str
);
1838 case NEGATE_EXPR
: op
= "-"; goto unary
;
1839 case BIT_NOT_EXPR
: op
= " NOT "; goto unary
;
1840 case ADDR_EXPR
: op
= "->"; goto unary
;
1842 APPEND (result
, op
);
1843 tmp_string
= decode_constant (TREE_OPERAND (val
, 0));
1844 APPEND (result
, tmp_string
->str
);
1849 APPEND (result
, display_int_cst (val
));
1853 #ifndef REAL_IS_NOT_DOUBLE
1854 sprintf (wrk
, "%.20g", TREE_REAL_CST (val
));
1856 REAL_VALUE_TO_DECIMAL (TREE_REAL_CST (val
), "%.20g", wrk
);
1858 APPEND (result
, wrk
);
1863 const char *ptr
= TREE_STRING_POINTER (val
);
1864 int i
= TREE_STRING_LENGTH (val
);
1865 APPEND (result
, "\"");
1869 unsigned char c
= *ptr
++;
1871 APPEND (result
, "^^");
1873 APPEND (result
, "\"\"");
1875 APPEND (result
, "^J");
1876 else if (c
< ' ' || c
> '~')
1878 sprintf (buf
, "^(%u)", c
);
1879 APPEND (result
, buf
);
1885 APPEND (result
, buf
);
1888 APPEND (result
, "\"");
1893 val
= TREE_OPERAND (val
, 1);
1894 if (type
!= NULL
&& TREE_CODE (type
) == SET_TYPE
1895 && CH_BOOLS_TYPE_P (type
))
1897 /* It's a bitstring. */
1898 tree domain
= TYPE_DOMAIN (type
);
1899 tree domain_max
= TYPE_MAX_VALUE (domain
);
1903 if (TREE_CODE (domain_max
) != INTEGER_CST
1904 || (val
&& TREE_CODE (val
) != TREE_LIST
))
1907 len
= TREE_INT_CST_LOW (domain_max
) + 1;
1908 if (TREE_CODE (init
) != CONSTRUCTOR
)
1910 buf
= (char *) alloca (len
+ 10);
1915 if (get_set_constructor_bits (init
, ptr
, len
))
1917 for (; --len
>= 0; ptr
++)
1921 APPEND (result
, buf
);
1925 { /* It's some kind of tuple */
1926 if (type
!= NULL_TREE
)
1928 mode_string
= get_type (type
);
1929 APPEND (result
, mode_string
->str
);
1931 APPEND (result
, " ");
1933 if (val
== NULL_TREE
1934 || TREE_CODE (val
) == ERROR_MARK
)
1935 APPEND (result
, "[ ]");
1936 else if (TREE_CODE (val
) != TREE_LIST
)
1940 APPEND (result
, "[");
1943 tree lo_val
= TREE_PURPOSE (val
);
1944 tree hi_val
= TREE_VALUE (val
);
1945 MYSTRING
*val_string
;
1946 if (TUPLE_NAMED_FIELD (val
))
1947 APPEND(result
, ".");
1948 if (lo_val
!= NULL_TREE
)
1950 val_string
= decode_constant (lo_val
);
1951 APPEND (result
, val_string
->str
);
1953 APPEND (result
, ":");
1955 val_string
= decode_constant (hi_val
);
1956 APPEND (result
, val_string
->str
);
1958 val
= TREE_CHAIN (val
);
1959 if (val
== NULL_TREE
)
1961 APPEND (result
, ", ");
1963 APPEND (result
, "]");
1971 mode_string
= decode_constant (TREE_OPERAND (init
, 0));
1972 APPEND (result
, mode_string
->str
);
1974 op1
= TREE_OPERAND (init
, 1);
1975 if (TREE_CODE (op1
) != IDENTIFIER_NODE
)
1977 error ("decode_constant: invalid component_ref");
1980 APPEND (result
, ".");
1981 APPEND (result
, IDENTIFIER_POINTER (op1
));
1985 error ("decode_constant: mode and value mismatch");
1988 error ("decode_constant: cannot decode this mode");
1995 decode_constant_selective (init
, all_decls
)
1999 MYSTRING
*result
= newstring ("");
2000 MYSTRING
*tmp_string
;
2001 tree type
= TREE_TYPE (init
);
2003 MYSTRING
*mode_string
;
2005 switch ((enum chill_tree_code
)TREE_CODE (val
))
2008 tmp_string
= decode_constant_selective (TREE_OPERAND (val
, 0), all_decls
);
2009 if (tmp_string
->len
)
2010 APPEND (result
, tmp_string
->str
);
2012 val
= TREE_OPERAND (val
, 1); /* argument list */
2013 if (val
!= NULL_TREE
&& TREE_CODE (val
) != TREE_LIST
)
2015 tmp_string
= decode_constant_selective (val
, all_decls
);
2016 if (tmp_string
->len
)
2018 MAYBE_NEWLINE (result
);
2019 APPEND (result
, tmp_string
->str
);
2025 if (val
!= NULL_TREE
)
2029 tmp_string
= decode_constant_selective (TREE_VALUE (val
), all_decls
);
2030 if (tmp_string
->len
)
2032 MAYBE_NEWLINE (result
);
2033 APPEND (result
, tmp_string
->str
);
2036 val
= TREE_CHAIN (val
);
2037 if (val
== NULL_TREE
)
2045 /* Generate an "expression conversion" expression (a cast). */
2046 tmp_string
= decode_mode_selective (type
, all_decls
);
2047 if (tmp_string
->len
)
2048 APPEND (result
, tmp_string
->str
);
2050 val
= TREE_OPERAND (val
, 0);
2051 type
= TREE_TYPE (val
);
2053 /* If the coercee is a tuple, make sure it is prefixed by its mode. */
2054 if (TREE_CODE (val
) == CONSTRUCTOR
2055 && !CH_BOOLS_TYPE_P (type
) && !chill_varying_type_p (type
))
2057 tmp_string
= decode_mode_selective (type
, all_decls
);
2058 if (tmp_string
->len
)
2059 APPEND (result
, tmp_string
->str
);
2063 tmp_string
= decode_constant_selective (val
, all_decls
);
2064 if (tmp_string
->len
)
2065 APPEND (result
, tmp_string
->str
);
2069 case IDENTIFIER_NODE
:
2070 tmp_string
= decode_mode_selective (val
, all_decls
);
2071 if (tmp_string
->len
)
2072 APPEND (result
, tmp_string
->str
);
2077 tmp_string
= decode_constant_selective (TREE_OPERAND (val
, 0), all_decls
);
2078 if (tmp_string
->len
)
2079 APPEND (result
, tmp_string
->str
);
2083 case UNDEFINED_EXPR
:
2089 case TRUNC_DIV_EXPR
:
2090 case FLOOR_MOD_EXPR
:
2091 case TRUNC_MOD_EXPR
:
2095 case TRUTH_ORIF_EXPR
:
2097 case TRUTH_ANDIF_EXPR
:
2107 if (TREE_OPERAND (val
, 0) == NULL_TREE
)
2111 tmp_string
= decode_constant_selective (TREE_OPERAND (val
, 0), all_decls
);
2112 if (tmp_string
->len
)
2113 APPEND (result
, tmp_string
->str
);
2115 tmp_string
= decode_constant_selective (TREE_OPERAND (val
, 1), all_decls
);
2116 if (tmp_string
->len
)
2118 MAYBE_NEWLINE (result
);
2119 APPEND (result
, tmp_string
->str
);
2124 case REPLICATE_EXPR
:
2125 tmp_string
= decode_constant_selective (TREE_OPERAND (val
, 0), all_decls
);
2126 if (tmp_string
->len
)
2127 APPEND (result
, tmp_string
->str
);
2129 tmp_string
= decode_constant_selective (TREE_OPERAND (val
, 1), all_decls
);
2130 if (tmp_string
->len
)
2132 MAYBE_NEWLINE (result
);
2133 APPEND (result
, tmp_string
->str
);
2141 tmp_string
= decode_constant_selective (TREE_OPERAND (val
, 0), all_decls
);
2142 if (tmp_string
->len
)
2143 APPEND (result
, tmp_string
->str
);
2157 val
= TREE_OPERAND (val
, 1);
2158 if (type
!= NULL
&& TREE_CODE (type
) == SET_TYPE
2159 && CH_BOOLS_TYPE_P (type
))
2160 /* It's a bitstring. */
2163 { /* It's some kind of tuple */
2164 if (type
!= NULL_TREE
)
2166 mode_string
= get_type_selective (type
, all_decls
);
2167 if (mode_string
->len
)
2168 APPEND (result
, mode_string
->str
);
2171 if (val
== NULL_TREE
2172 || TREE_CODE (val
) == ERROR_MARK
)
2174 else if (TREE_CODE (val
) != TREE_LIST
)
2180 tree lo_val
= TREE_PURPOSE (val
);
2181 tree hi_val
= TREE_VALUE (val
);
2182 MYSTRING
*val_string
;
2183 if (lo_val
!= NULL_TREE
)
2185 val_string
= decode_constant_selective (lo_val
, all_decls
);
2186 if (val_string
->len
)
2187 APPEND (result
, val_string
->str
);
2190 val_string
= decode_constant_selective (hi_val
, all_decls
);
2191 if (val_string
->len
)
2193 MAYBE_NEWLINE (result
);
2194 APPEND (result
, val_string
->str
);
2197 val
= TREE_CHAIN (val
);
2198 if (val
== NULL_TREE
)
2206 mode_string
= decode_constant_selective (TREE_OPERAND (init
, 0), all_decls
);
2207 if (mode_string
->len
)
2208 APPEND (result
, mode_string
->str
);
2213 error ("decode_constant_selective: mode and value mismatch");
2216 error ("decode_constant_selective: cannot decode this mode");
2222 /* Assuming DECL is an ALIAS_DECL, return its prefix rename clause. */
2225 decode_prefix_rename (decl
)
2228 MYSTRING
*result
= newstring ("");
2229 if (DECL_OLD_PREFIX (decl
) || DECL_NEW_PREFIX (decl
))
2231 APPEND (result
, "(");
2232 if (DECL_OLD_PREFIX (decl
))
2233 APPEND (result
, IDENTIFIER_POINTER (DECL_OLD_PREFIX (decl
)));
2234 APPEND (result
, "->");
2235 if (DECL_NEW_PREFIX (decl
))
2236 APPEND (result
, IDENTIFIER_POINTER (DECL_NEW_PREFIX (decl
)));
2237 APPEND (result
, ")!");
2239 if (DECL_POSTFIX_ALL (decl
))
2240 APPEND (result
, "ALL");
2242 APPEND (result
, IDENTIFIER_POINTER (DECL_POSTFIX (decl
)));
2250 MYSTRING
*result
= newstring ("");
2251 MYSTRING
*mode_string
;
2254 switch ((enum chill_tree_code
)TREE_CODE (decl
))
2258 APPEND (result
, "DCL ");
2259 APPEND (result
, IDENTIFIER_POINTER (DECL_NAME (decl
)));
2260 APPEND (result
, " ");
2261 mode_string
= get_type (TREE_TYPE (decl
));
2262 APPEND (result
, mode_string
->str
);
2264 if ((enum chill_tree_code
)TREE_CODE (decl
) == BASED_DECL
)
2266 APPEND (result
, " BASED (");
2267 APPEND (result
, IDENTIFIER_POINTER (DECL_ABSTRACT_ORIGIN (decl
)));
2268 APPEND (result
, ")");
2273 if (CH_DECL_SIGNAL (decl
))
2275 /* this is really a signal */
2276 tree fields
= TYPE_FIELDS (TREE_TYPE (decl
));
2277 tree signame
= DECL_NAME (decl
);
2280 APPEND (result
, "SIGNAL ");
2281 APPEND (result
, IDENTIFIER_POINTER (signame
));
2282 if (IDENTIFIER_SIGNAL_DATA (signame
))
2284 APPEND (result
, " = (");
2285 for ( ; fields
!= NULL_TREE
;
2286 fields
= TREE_CHAIN (fields
))
2288 MYSTRING
*mode_string
;
2290 mode_string
= get_type (TREE_TYPE (fields
));
2291 APPEND (result
, mode_string
->str
);
2293 if (TREE_CHAIN (fields
) != NULL_TREE
)
2294 APPEND (result
, ", ");
2296 APPEND (result
, ")");
2298 sigdest
= IDENTIFIER_SIGNAL_DEST (signame
);
2299 if (sigdest
!= NULL_TREE
)
2301 APPEND (result
, " TO ");
2302 APPEND (result
, IDENTIFIER_POINTER (DECL_NAME (sigdest
)));
2307 /* avoid defining a mode as itself */
2308 if (CH_NOVELTY (TREE_TYPE (decl
)) == decl
)
2309 APPEND (result
, "NEWMODE ");
2311 APPEND (result
, "SYNMODE ");
2312 APPEND (result
, IDENTIFIER_POINTER (DECL_NAME (decl
)));
2313 APPEND (result
, " = ");
2314 mode_string
= decode_mode (TREE_TYPE (decl
));
2315 APPEND (result
, mode_string
->str
);
2324 type
= TREE_TYPE (decl
);
2325 args
= TYPE_ARG_TYPES (type
);
2327 APPEND (result
, IDENTIFIER_POINTER (DECL_NAME (decl
)));
2329 if (CH_DECL_PROCESS (decl
))
2330 APPEND (result
, ": PROCESS (");
2332 APPEND (result
, ": PROC (");
2334 args
= TYPE_ARG_TYPES (type
);
2336 mode_string
= print_proc_tail (type
, args
, 1);
2337 APPEND (result
, mode_string
->str
);
2341 if (CH_DECL_GENERAL (decl
))
2342 APPEND (result
, " GENERAL");
2343 if (CH_DECL_SIMPLE (decl
))
2344 APPEND (result
, " SIMPLE");
2345 if (DECL_INLINE (decl
))
2346 APPEND (result
, " INLINE");
2347 if (CH_DECL_RECURSIVE (decl
))
2348 APPEND (result
, " RECURSIVE");
2349 APPEND (result
, " END");
2354 APPEND (result
, IDENTIFIER_POINTER (DECL_NAME (decl
)));
2355 APPEND (result
, " ");
2356 mode_string
= get_type (TREE_TYPE (decl
));
2357 APPEND (result
, mode_string
->str
);
2359 if (DECL_INITIAL (decl
) != NULL_TREE
)
2361 mode_string
= decode_layout (DECL_INITIAL (decl
));
2362 APPEND (result
, mode_string
->str
);
2366 if (is_forbidden (DECL_NAME (decl
), forbid
))
2367 APPEND (result
, " FORBID");
2372 if (DECL_INITIAL (decl
) == NULL_TREE
2373 || TREE_CODE (DECL_INITIAL (decl
)) == ERROR_MARK
)
2375 APPEND (result
, "SYN ");
2376 APPEND (result
, IDENTIFIER_POINTER (DECL_NAME (decl
)));
2377 APPEND (result
, " ");
2378 mode_string
= get_type (TREE_TYPE (decl
));
2379 APPEND (result
, mode_string
->str
);
2381 APPEND (result
, " = ");
2382 mode_string
= decode_constant (DECL_INITIAL (decl
));
2383 APPEND (result
, mode_string
->str
);
2388 /* If CH_DECL_GRANTED, decl was granted into this scope, and
2389 so wasn't in the source code. */
2390 if (!CH_DECL_GRANTED (decl
))
2392 static int restricted
= 0;
2394 if (DECL_SEIZEFILE (decl
) != use_seizefile_name
2395 && DECL_SEIZEFILE (decl
))
2397 use_seizefile_name
= DECL_SEIZEFILE (decl
);
2398 restricted
= use_seizefile_name
== NULL_TREE
? 0 : CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name
);
2400 grant_use_seizefile (IDENTIFIER_POINTER (use_seizefile_name
));
2401 mark_use_seizefile_written (use_seizefile_name
);
2405 APPEND (result
, "SEIZE ");
2406 mode_string
= decode_prefix_rename (decl
);
2407 APPEND (result
, mode_string
->str
);
2414 APPEND (result
, "----- not implemented ------");
2421 decode_decl_selective (decl
, all_decls
)
2425 MYSTRING
*result
= newstring ("");
2426 MYSTRING
*mode_string
;
2429 if (CH_ALREADY_GRANTED (decl
))
2433 CH_ALREADY_GRANTED (decl
) = 1;
2435 switch ((int)TREE_CODE (decl
))
2439 mode_string
= get_type_selective (TREE_TYPE (decl
), all_decls
);
2440 if (mode_string
->len
)
2441 APPEND (result
, mode_string
->str
);
2443 if ((enum chill_tree_code
)TREE_CODE (decl
) == BASED_DECL
)
2445 mode_string
= decode_mode_selective (DECL_ABSTRACT_ORIGIN (decl
), all_decls
);
2446 if (mode_string
->len
)
2447 PREPEND (result
, mode_string
->str
);
2453 if (CH_DECL_SIGNAL (decl
))
2455 /* this is really a signal */
2456 tree fields
= TYPE_FIELDS (TREE_TYPE (decl
));
2457 tree signame
= DECL_NAME (decl
);
2460 if (IDENTIFIER_SIGNAL_DATA (signame
))
2462 for ( ; fields
!= NULL_TREE
;
2463 fields
= TREE_CHAIN (fields
))
2465 MYSTRING
*mode_string
;
2467 mode_string
= get_type_selective (TREE_TYPE (fields
),
2469 if (mode_string
->len
)
2470 APPEND (result
, mode_string
->str
);
2474 sigdest
= IDENTIFIER_SIGNAL_DEST (signame
);
2475 if (sigdest
!= NULL_TREE
)
2477 mode_string
= decode_mode_selective (DECL_NAME (sigdest
), all_decls
);
2478 if (mode_string
->len
)
2480 MAYBE_NEWLINE (result
);
2481 APPEND (result
, mode_string
->str
);
2488 /* avoid defining a mode as itself */
2489 mode_string
= decode_mode_selective (TREE_TYPE (decl
), all_decls
);
2490 APPEND (result
, mode_string
->str
);
2499 type
= TREE_TYPE (decl
);
2500 args
= TYPE_ARG_TYPES (type
);
2502 args
= TYPE_ARG_TYPES (type
);
2504 mode_string
= print_proc_tail_selective (type
, args
, all_decls
);
2505 if (mode_string
->len
)
2506 APPEND (result
, mode_string
->str
);
2512 mode_string
= get_type_selective (TREE_TYPE (decl
), all_decls
);
2513 if (mode_string
->len
)
2514 APPEND (result
, mode_string
->str
);
2519 if (DECL_INITIAL (decl
) == NULL_TREE
2520 || TREE_CODE (DECL_INITIAL (decl
)) == ERROR_MARK
)
2522 mode_string
= get_type_selective (TREE_TYPE (decl
), all_decls
);
2523 if (mode_string
->len
)
2524 APPEND (result
, mode_string
->str
);
2526 mode_string
= decode_constant_selective (DECL_INITIAL (decl
), all_decls
);
2527 if (mode_string
->len
)
2529 MAYBE_NEWLINE (result
);
2530 APPEND (result
, mode_string
->str
);
2536 MAYBE_NEWLINE (result
);
2541 globalize_decl (decl
)
2544 if (!TREE_PUBLIC (decl
) && DECL_NAME (decl
) &&
2545 (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == FUNCTION_DECL
))
2547 extern FILE *asm_out_file
;
2548 extern char *first_global_object_name
;
2549 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2551 if (!first_global_object_name
)
2552 first_global_object_name
= name
+ (name
[0] == '*');
2553 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
2559 grant_one_decl (decl
)
2564 if (DECL_SOURCE_LINE (decl
) == 0)
2566 result
= decode_decl (decl
);
2569 APPEND (result
, ";\n");
2570 APPEND (gstring
, result
->str
);
2576 grant_one_decl_selective (decl
, all_decls
)
2583 tree d
= DECL_ABSTRACT_ORIGIN (decl
);
2585 if (CH_ALREADY_GRANTED (d
))
2589 result
= decode_decl (d
);
2597 APPEND (result
, ";\n");
2599 /* now process all undefined items in the decl */
2600 fixups
= decode_decl_selective (d
, all_decls
);
2603 PREPEND (result
, fixups
->str
);
2607 /* we have finished a decl */
2608 APPEND (selective_gstring
, result
->str
);
2613 compare_memory_file (fname
, buf
)
2620 /* check if we have something to write */
2621 if (!buf
|| !strlen (buf
))
2624 if ((fb
= fopen (fname
, "r")) == NULL
)
2627 while ((c
= getc (fb
)) != EOF
)
2636 return (*buf
? 1 : 0);
2644 /* We only write out the grant file if it has changed,
2645 to avoid changing its time-stamp and triggering an
2646 unnecessary 'make' action. Return if no change. */
2647 if (gstring
== NULL
|| !spec_module_generated
||
2648 !compare_memory_file (grant_file_name
, gstring
->str
))
2651 fb
= fopen (grant_file_name
, "w");
2653 pfatal_with_name (grant_file_name
);
2655 /* write file. Due to problems with record sizes on VAX/VMS
2656 write string to '\n' */
2658 /* do it this way for VMS, cause of problems with
2663 p1
= strchr (p
, '\n');
2666 fprintf (fb
, "%s", p
);
2671 /* faster way to write */
2672 if (write (fileno (fb
), gstring
->str
, gstring
->len
) < 0)
2674 int save_errno
= errno
;
2675 unlink (grant_file_name
);
2677 pfatal_with_name (grant_file_name
);
2684 /* handle grant statement */
2687 set_default_grant_file ()
2689 char *p
, *tmp
, *fname
;
2692 fname
= dump_base_name
; /* Probably invoked via gcc */
2694 { /* Probably invoked directly (not via gcc) */
2695 fname
= asm_file_name
;
2697 fname
= main_input_filename
? main_input_filename
: input_filename
;
2702 p
= strrchr (fname
, '.');
2705 tmp
= (char *) alloca (strlen (fname
) + 10);
2706 strcpy (tmp
, fname
);
2712 tmp
= (char *) alloca (i
+ 10);
2713 strncpy (tmp
, fname
, i
);
2716 strcat (tmp
, ".grt");
2717 default_grant_file
= build_string (strlen (tmp
), tmp
);
2719 grant_file_name
= TREE_STRING_POINTER (default_grant_file
);
2721 if (gstring
== NULL
)
2722 gstring
= newstring ("");
2723 if (selective_gstring
== NULL
)
2724 selective_gstring
= newstring ("");
2727 /* Make DECL visible under the name NAME in the (fake) outermost scope. */
2730 push_granted (name
, decl
)
2731 tree name ATTRIBUTE_UNUSED
, decl ATTRIBUTE_UNUSED
;
2734 IDENTIFIER_GRANTED_VALUE (name
) = decl
;
2735 granted_decls
= tree_cons (name
, decl
, granted_decls
);
2740 chill_grant (old_prefix
, new_prefix
, postfix
, forbid
)
2749 tree old_name
= old_prefix
== NULL_TREE
? postfix
2750 : get_identifier3 (IDENTIFIER_POINTER (old_prefix
),
2751 "!", IDENTIFIER_POINTER (postfix
));
2752 tree new_name
= new_prefix
== NULL_TREE
? postfix
2753 : get_identifier3 (IDENTIFIER_POINTER (new_prefix
),
2754 "!", IDENTIFIER_POINTER (postfix
));
2756 tree alias
= build_alias_decl (old_prefix
, new_prefix
, postfix
);
2757 CH_DECL_GRANTED (alias
) = 1;
2758 DECL_SEIZEFILE (alias
) = current_seizefile_name
;
2759 TREE_CHAIN (alias
) = current_module
->granted_decls
;
2760 current_module
->granted_decls
= alias
;
2763 warning ("FORBID is not yet implemented"); /* FIXME */
2767 /* flag GRANT ALL only once. Avoids search in case of GRANT ALL. */
2768 static int grant_all_seen
= 0;
2770 /* check if a decl is in the list of granted decls. */
2772 search_in_list (name
, granted_decls
)
2778 for (vars
= granted_decls
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
2779 if (DECL_SOURCE_LINE (vars
))
2781 if (DECL_POSTFIX_ALL (vars
))
2786 else if (name
== DECL_NAME (vars
))
2794 really_grant_this (decl
, granted_decls
)
2798 /* we never grant labels at module level */
2799 if ((enum chill_tree_code
)TREE_CODE (decl
) == LABEL_DECL
)
2805 switch ((enum chill_tree_code
)TREE_CODE (decl
))
2810 return search_in_list (DECL_NAME (decl
), granted_decls
);
2815 if (CH_DECL_SIGNAL (decl
))
2816 return search_in_list (DECL_NAME (decl
), granted_decls
);
2823 /* this nerver should happen */
2824 error_with_decl (decl
, "function \"really_grant_this\" called for `%s'.");
2828 /* Write a SPEC MODULE using the declarations in the list DECLS. */
2829 static int header_written
= 0;
2830 #define HEADER_TEMPLATE "--\n-- WARNING: this file was generated by\n\
2831 -- GNUCHILL version %s\n-- based on gcc version %s\n--\n"
2834 write_spec_module (decls
, granted_decls
)
2841 if (granted_decls
== NULL_TREE
)
2844 use_seizefile_name
= NULL_TREE
;
2846 if (!header_written
)
2848 hdr
= (char*) alloca (strlen (gnuchill_version
)
2849 + strlen (version_string
)
2850 + sizeof (HEADER_TEMPLATE
) /* includes \0 */);
2851 sprintf (hdr
, HEADER_TEMPLATE
, gnuchill_version
, version_string
);
2852 APPEND (gstring
, hdr
);
2855 APPEND (gstring
, IDENTIFIER_POINTER (current_module
->name
));
2856 APPEND (gstring
, ": SPEC MODULE\n");
2858 /* first of all we look for GRANT ALL specified */
2859 search_in_list (NULL_TREE
, granted_decls
);
2861 if (grant_all_seen
!= 0)
2863 /* write all identifiers to grant file */
2864 for (vars
= decls
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
2866 if (DECL_SOURCE_LINE (vars
))
2868 if (DECL_NAME (vars
))
2870 if ((TREE_CODE (vars
) != CONST_DECL
|| !CH_DECL_ENUM (vars
)) &&
2871 really_grant_this (vars
, granted_decls
))
2872 grant_one_decl (vars
);
2874 else if (DECL_POSTFIX_ALL (vars
))
2876 static int restricted
= 0;
2878 if (DECL_SEIZEFILE (vars
) != use_seizefile_name
2879 && DECL_SEIZEFILE (vars
))
2881 use_seizefile_name
= DECL_SEIZEFILE (vars
);
2882 restricted
= use_seizefile_name
== NULL_TREE
? 0 : CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name
);
2884 grant_use_seizefile (IDENTIFIER_POINTER (use_seizefile_name
));
2885 mark_use_seizefile_written (use_seizefile_name
);
2889 APPEND (gstring
, "SEIZE ALL;\n");
2897 seizefile_list
*wrk
, *x
;
2899 /* do a selective write to the grantfile. This will reduce the
2900 size of a grantfile and speed up compilation of
2901 modules depending on this grant file */
2903 if (selective_gstring
== 0)
2904 selective_gstring
= newstring ("");
2906 /* first of all process all SEIZE ALL's */
2907 for (vars
= decls
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
2909 if (DECL_SOURCE_LINE (vars
)
2910 && DECL_POSTFIX_ALL (vars
))
2911 grant_seized_identifier (vars
);
2914 /* now walk through granted decls */
2915 granted_decls
= nreverse (granted_decls
);
2916 for (vars
= granted_decls
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
2918 grant_one_decl_selective (vars
, decls
);
2920 granted_decls
= nreverse (granted_decls
);
2922 /* append all SEIZES */
2923 wrk
= selective_seizes
;
2927 APPEND (gstring
, wrk
->seizes
->str
);
2932 selective_seizes
= 0;
2934 /* append generated string to grant file */
2935 APPEND (gstring
, selective_gstring
->str
);
2936 FREE (selective_gstring
);
2937 selective_gstring
= NULL
;
2940 for (vars
= granted_decls
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
2941 if (DECL_SOURCE_LINE (vars
))
2943 MYSTRING
*mode_string
= decode_prefix_rename (vars
);
2944 APPEND (gstring
, "GRANT ");
2945 APPEND (gstring
, mode_string
->str
);
2947 APPEND (gstring
, ";\n");
2950 APPEND (gstring
, "END;\n");
2951 spec_module_generated
= 1;
2953 /* initialize this for next spec module */
2958 * after the dark comes, after all of the modules are at rest,
2959 * we tuck the compilation unit to bed... A story in pass 1
2960 * and a hug-and-a-kiss goodnight in pass 2.
2963 chill_finish_compile ()
2966 tree chill_init_function
;
2969 build_enum_tables ();
2971 /* We only need an initializer function for the source file if
2972 a) there's module-level code to be called, or
2973 b) tasking-related stuff to be initialized. */
2974 if (module_init_list
!= NULL_TREE
|| tasking_list
!= NULL_TREE
)
2976 extern tree initializer_type
;
2977 static tree chill_init_name
;
2979 /* declare the global initializer list */
2980 global_list
= do_decl (get_identifier ("_ch_init_list"),
2981 build_chill_pointer_type (initializer_type
), 1, 0,
2984 /* Now, we're building the function which is the *real*
2985 constructor - if there's any module-level code in this
2986 source file, the compiler puts the file's initializer entry
2987 onto the global initializer list, so each module's body code
2988 will eventually get called, after all of the processes have
2991 /* This is better done in pass 2 (when first_global_object_name
2992 may have been set), but that is too late.
2993 Perhaps rewrite this so nothing is done in pass 1. */
2996 extern char *first_global_object_name
;
2997 /* If we don't do this spoof, we get the name of the first
2998 tasking_code variable, and not the file name. */
2999 char *tmp
= first_global_object_name
;
3001 first_global_object_name
= NULL
;
3002 chill_init_name
= get_file_function_name ('I');
3003 first_global_object_name
= tmp
;
3004 /* strip off the file's extension, if any. */
3005 tmp
= strrchr (IDENTIFIER_POINTER (chill_init_name
), '.');
3010 start_chill_function (chill_init_name
, void_type_node
, NULL_TREE
,
3011 NULL_TREE
, NULL_TREE
);
3012 TREE_PUBLIC (current_function_decl
) = 1;
3013 chill_init_function
= current_function_decl
;
3015 /* For each module that we've compiled, that had module-level
3016 code to be called, add its entry to the global initializer
3023 for (module_init
= module_init_list
;
3024 module_init
!= NULL_TREE
;
3025 module_init
= TREE_CHAIN (module_init
))
3027 tree init_entry
= TREE_VALUE (module_init
);
3029 /* assign module_entry.next := _ch_init_list; */
3031 build_chill_modify_expr (
3032 build_component_ref (init_entry
,
3033 get_identifier ("__INIT_NEXT")),
3036 /* assign _ch_init_list := &module_entry; */
3038 build_chill_modify_expr (global_list
,
3039 build1 (ADDR_EXPR
, ptr_type_node
, init_entry
)));
3043 tasking_registry ();
3045 make_decl_rtl (current_function_decl
, NULL
, 1);
3047 finish_chill_function ();
3051 assemble_constructor (IDENTIFIER_POINTER (chill_init_name
));
3052 globalize_decl (chill_init_function
);
3055 /* ready now to link decls onto this list in pass 2. */
3056 module_init_list
= NULL_TREE
;
3057 tasking_list
= NULL_TREE
;