Improve support for arm-wince-pe target:
[official-gcc.git] / gcc / treelang / treetree.c
blobca50df4f82064f2f0b915f413c96eae4991e23ba
1 /*
3 TREELANG Compiler back end interface (treetree.c)
4 Called by the parser.
6 If you want a working example of how to write a front end to GCC,
7 you are in the right place.
9 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
10 1999, 2000, 2001, 2002, 2003, Free Software Foundation, Inc.
12 This code is based on toy.c written by Richard Kenner.
14 It was later modified by Jonathan Bartlett whose changes have all
15 been removed (by Tim Josling).
17 Various bits and pieces were cloned from the GCC main tree, as
18 GCC evolved, for COBOLForGCC, by Tim Josling.
20 It was adapted to TREELANG by Tim Josling 2001.
22 ---------------------------------------------------------------------------
24 This program is free software; you can redistribute it and/or modify it
25 under the terms of the GNU General Public License as published by the
26 Free Software Foundation; either version 2, or (at your option) any
27 later version.
29 This program is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 GNU General Public License for more details.
34 You should have received a copy of the GNU General Public License
35 along with this program; if not, write to the Free Software
36 Foundation, 59 Temple Place - Suite 330,
37 Boston, MA 02111-1307, USA.
39 In other words, you are welcome to use, share and improve this program.
40 You are forbidden to forbid anyone else to use, share and improve
41 what you give them. Help stamp out software-hoarding!
43 ---------------------------------------------------------------------------
48 Assumption: garbage collection is never called implicitly. It will
49 not be called 'at any time' when short of memory. It will only be
50 called explicitly at the end of each function. This removes the
51 need for a *lot* of bother to ensure everything is in the mark trees
52 at all times. */
54 /* Note it is OK to use GCC extensions such as long long in a compiler front end.
55 This is because the GCC front ends are built using GCC. */
57 /* GCC headers. */
59 #include "config.h"
60 #include "system.h"
61 #include "coretypes.h"
62 #include "tm.h"
63 #include "tree.h"
64 #include "flags.h"
65 #include "output.h"
66 #include "c-tree.h"
67 #include "rtl.h"
68 #include "ggc.h"
69 #include "toplev.h"
70 #include "varray.h"
71 #include "langhooks-def.h"
72 #include "langhooks.h"
74 #include "treelang.h"
75 #include "treetree.h"
76 #include "opts.h"
78 const unsigned int cl_options_count;
79 const struct cl_option cl_options[1];
80 extern int option_main;
81 extern char **file_names;
83 /* The front end language hooks (addresses of code for this front
84 end). Mostly just use the C routines. */
86 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
87 #define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion
88 #undef LANG_HOOKS_MARK_ADDRESSABLE
89 #define LANG_HOOKS_MARK_ADDRESSABLE c_mark_addressable
90 #undef LANG_HOOKS_SIGNED_TYPE
91 #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type
92 #undef LANG_HOOKS_UNSIGNED_TYPE
93 #define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type
94 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
95 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
96 #undef LANG_HOOKS_TYPE_FOR_MODE
97 #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
98 #undef LANG_HOOKS_TYPE_FOR_SIZE
99 #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size
100 #undef LANG_HOOKS_PARSE_FILE
101 #define LANG_HOOKS_PARSE_FILE treelang_parse_file
102 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
103 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE c_common_attribute_table
104 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
105 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE c_common_format_attribute_table
106 #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES
107 #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES c_insert_default_attributes
109 /* Hook routines and data unique to treelang. */
111 #undef LANG_HOOKS_INIT
112 #define LANG_HOOKS_INIT treelang_init
113 #undef LANG_HOOKS_NAME
114 #define LANG_HOOKS_NAME "GNU treelang"
115 #undef LANG_HOOKS_FINISH
116 #define LANG_HOOKS_FINISH treelang_finish
117 #undef LANG_HOOKS_DECODE_OPTION
118 #define LANG_HOOKS_DECODE_OPTION treelang_decode_option
119 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
121 /* Tree code type/name/code tables. */
123 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
125 const char tree_code_type[] = {
126 #include "tree.def"
129 #undef DEFTREECODE
131 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
133 const unsigned char tree_code_length[] = {
134 #include "tree.def"
137 #undef DEFTREECODE
139 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
141 const char *const tree_code_name[] = {
142 #include "tree.def"
143 "@@dummy"
145 #undef DEFTREECODE
147 /* Number of bits in int and char - accessed by front end. */
149 unsigned int tree_code_int_size = SIZEOF_INT * HOST_BITS_PER_CHAR;
151 unsigned int tree_code_char_size = HOST_BITS_PER_CHAR;
153 /* Return the tree stuff for this type TYPE_NUM. */
155 tree
156 tree_code_get_type (int type_num)
158 switch (type_num)
160 case SIGNED_CHAR:
161 return signed_char_type_node;
163 case UNSIGNED_CHAR:
164 return unsigned_char_type_node;
166 case SIGNED_INT:
167 return integer_type_node;
169 case UNSIGNED_INT:
170 return unsigned_type_node;
172 case VOID_TYPE:
173 return void_type_node;
175 default:
176 abort ();
180 /* Output the code for the start of an if statement. The test
181 expression is EXP (true if not zero), and the stmt occurred at line
182 LINENO in file FILENAME. */
184 void
185 tree_code_if_start (tree exp, location_t loc)
187 tree cond_exp;
188 cond_exp = build (NE_EXPR,
189 TREE_TYPE (exp),
190 exp,
191 build1 (CONVERT_EXPR, TREE_TYPE (exp), integer_zero_node));
192 emit_line_note (loc.file, loc.line); /* Output the line number information. */
193 expand_start_cond (cond_exp, /* Exit-able if nonzero. */ 0);
196 /* Output the code for the else of an if statement. The else occurred
197 at line LINENO in file FILENAME. */
199 void
200 tree_code_if_else (location_t loc)
202 emit_line_note (loc.file, loc.line); /* Output the line number information. */
203 expand_start_else ();
206 /* Output the code for the end_if an if statement. The end_if (final brace) occurred
207 at line LINENO in file FILENAME. */
209 void
210 tree_code_if_end (location_t loc)
212 emit_line_note (loc.file, loc.line); /* Output the line number information. */
213 expand_end_cond ();
216 /* Create a function. The prototype name is NAME, storage class is
217 STORAGE_CLASS, type of return variable is RET_TYPE, parameter lists
218 is PARMS, returns decl for this function. */
220 tree
221 tree_code_create_function_prototype (unsigned char* chars,
222 unsigned int storage_class,
223 unsigned int ret_type,
224 struct prod_token_parm_item* parms,
225 location_t loc)
228 tree id;
229 struct prod_token_parm_item* parm;
230 tree type_list = NULL_TREE;
231 tree type_node;
232 tree fn_type;
233 tree fn_decl;
235 /* Build the type. */
236 id = get_identifier ((const char*)chars);
237 for (parm = parms; parm; parm = parm->tp.par.next)
239 if (parm->category != parameter_category)
240 abort ();
241 type_node = get_type_for_numeric_type (parm->type);
242 type_list = tree_cons (NULL_TREE, type_node, type_list);
244 /* Last parm if void indicates fixed length list (as opposed to
245 printf style va_* list). */
246 type_list = tree_cons (NULL_TREE, void_type_node, type_list);
247 /* The back end needs them in reverse order. */
248 type_list = nreverse (type_list);
250 type_node = get_type_for_numeric_type (ret_type);
251 fn_type = build_function_type (type_node, type_list);
253 id = get_identifier ((const char*)chars);
254 fn_decl = build_decl (FUNCTION_DECL, id, fn_type);
256 DECL_CONTEXT (fn_decl) = NULL_TREE; /* Nested functions not supported here. */
257 DECL_SOURCE_LOCATION (fn_decl) = loc;
259 TREE_USED (fn_decl) = 1;
261 /* Real name (optional). */
262 SET_DECL_ASSEMBLER_NAME (fn_decl, DECL_NAME (fn_decl));
264 TREE_PUBLIC (fn_decl) = 0;
265 DECL_EXTERNAL (fn_decl) = 0;
266 TREE_STATIC (fn_decl) = 0;
267 switch (storage_class)
269 case STATIC_STORAGE:
270 TREE_PUBLIC (fn_decl) = 0;
271 break;
273 case EXTERNAL_DEFINITION_STORAGE:
274 TREE_PUBLIC (fn_decl) = 1;
275 TREE_STATIC (fn_decl) = 0;
276 DECL_EXTERNAL (fn_decl) = 0;
277 break;
279 case EXTERNAL_REFERENCE_STORAGE:
280 TREE_PUBLIC (fn_decl) = 0;
281 DECL_EXTERNAL (fn_decl) = 1;
282 break;
285 case AUTOMATIC_STORAGE:
286 default:
287 abort ();
290 /* Process declaration of function defined elsewhere. */
291 rest_of_decl_compilation (fn_decl, NULL, 1, 0);
293 return fn_decl;
297 /* Output code for start of function; the decl of the function is in
298 PREV_SAVED (as created by tree_code_create_function_prototype),
299 the function is at line number LINENO in file FILENAME. The
300 parameter details are in the lists PARMS. Returns nothing. */
301 void
302 tree_code_create_function_initial (tree prev_saved,
303 location_t loc,
304 struct prod_token_parm_item* parms)
306 tree fn_decl;
307 tree param_decl;
308 tree next_param;
309 tree first_param;
310 tree parm_decl;
311 tree parm_list;
312 tree resultdecl;
313 struct prod_token_parm_item* this_parm;
314 struct prod_token_parm_item* parm;
316 fn_decl = prev_saved;
317 if (!fn_decl)
318 abort ();
320 /* Output message if not -quiet. */
321 announce_function (fn_decl);
323 /* This has something to do with forcing output also. */
324 pushdecl (fn_decl);
326 /* Set current function for error msgs etc. */
327 current_function_decl = fn_decl;
328 DECL_INITIAL (fn_decl) = error_mark_node;
330 DECL_SOURCE_LOCATION (fn_decl) = loc;
332 /* Prepare creation of rtl for a new function. */
334 resultdecl = DECL_RESULT (fn_decl)
335 = build_decl (RESULT_DECL, NULL_TREE, TREE_TYPE (TREE_TYPE (fn_decl)));
336 DECL_CONTEXT (DECL_RESULT (fn_decl)) = fn_decl;
337 DECL_SOURCE_LOCATION (resultdecl) = loc;
339 /* Work out the size. ??? is this needed. */
340 layout_decl (DECL_RESULT (fn_decl), 0);
342 /* Make the argument variable decls. */
343 parm_list = NULL_TREE;
344 for (parm = parms; parm; parm = parm->tp.par.next)
346 parm_decl = build_decl (PARM_DECL, get_identifier
347 ((const char*) (parm->tp.par.variable_name)),
348 get_type_for_numeric_type (parm->type));
350 /* Some languages have different nominal and real types. */
351 DECL_ARG_TYPE (parm_decl) = TREE_TYPE (parm_decl);
352 if (!DECL_ARG_TYPE (parm_decl))
353 abort ();
354 if (!fn_decl)
355 abort ();
356 DECL_CONTEXT (parm_decl) = fn_decl;
357 DECL_SOURCE_LOCATION (parm_decl) = loc;
358 parm_list = chainon (parm_decl, parm_list);
361 /* Back into reverse order as the back end likes them. */
362 parm_list = nreverse (parm_list);
364 DECL_ARGUMENTS (fn_decl) = parm_list;
366 /* Save the decls for use when the args are referred to. */
367 for (param_decl = DECL_ARGUMENTS (fn_decl),
368 this_parm = parms;
369 param_decl;
370 param_decl = TREE_CHAIN (param_decl),
371 this_parm = this_parm->tp.par.next)
373 if (!this_parm)
374 abort (); /* Too few. */
375 *this_parm->tp.par.where_to_put_var_tree = param_decl;
377 if (this_parm)
378 abort (); /* Too many. */
380 /* Output the decl rtl (not the rtl for the function code). ???.
381 If the function is not defined in this file, when should you
382 execute this? */
383 make_decl_rtl (fn_decl, NULL);
385 /* Use filename/lineno from above. */
386 init_function_start (fn_decl, loc.file, loc.line);
388 /* Create rtl for startup code of function, such as saving registers. */
390 expand_function_start (fn_decl, 0);
392 /* Function.c requires a push at the start of the function. that
393 looks like a bug to me but let's make it happy. */
395 (*lang_hooks.decls.pushlevel) (0);
397 /* Create rtl for the start of a new scope. */
399 expand_start_bindings (2);
401 /* Put the parameters into the symbol table. */
403 for (first_param = param_decl = nreverse (DECL_ARGUMENTS (fn_decl));
404 param_decl;
405 param_decl = next_param)
407 next_param = TREE_CHAIN (param_decl);
408 TREE_CHAIN (param_decl) = NULL;
409 /* layout_decl (param_decl, 0); Already done in build_decl tej 13/4/2002. */
410 pushdecl (param_decl);
411 if (DECL_CONTEXT (param_decl) != current_function_decl)
412 abort ();
415 /* Store back the PARM_DECL nodes. They appear in the right order. */
416 DECL_ARGUMENTS (fn_decl) = getdecls ();
418 /* Force it to be output, else may be solely inlined. */
419 TREE_ADDRESSABLE (fn_decl) = 1;
421 /* Stop -O3 from deleting it. */
422 TREE_USED (fn_decl) = 1;
424 /* Add a new level to the debugger symbol table. */
426 (*lang_hooks.decls.pushlevel) (0);
428 /* Create rtl for the start of a new scope. */
430 expand_start_bindings (0);
432 emit_line_note (loc.file, loc.line); /* Output the line number information. */
435 /* Wrapup a function contained in file FILENAME, ending at line LINENO. */
436 void
437 tree_code_create_function_wrapup (location_t loc)
439 tree block;
440 tree fn_decl;
442 fn_decl = current_function_decl;
444 emit_line_note (loc.file, loc.line); /* Output the line number information. */
446 /* Get completely built level from debugger symbol table. */
448 block = (*lang_hooks.decls.poplevel) (1, 0, 0);
450 /* Emit rtl for end of scope. */
452 expand_end_bindings (block, 0, 1);
454 /* Emit rtl for end of function. */
456 expand_function_end (loc.file, loc.line, 0);
458 /* Pop the level. */
460 block = (*lang_hooks.decls.poplevel) (1, 0, 1);
462 /* And attach it to the function. */
464 DECL_INITIAL (fn_decl) = block;
466 /* Emit rtl for end of scope. */
468 expand_end_bindings (block, 0, 1);
470 /* Call optimization and convert optimized rtl to assembly code. */
472 rest_of_compilation (fn_decl);
474 /* We are not inside of any scope now. */
476 current_function_decl = NULL_TREE;
480 Create a variable.
482 The storage class is STORAGE_CLASS (eg LOCAL).
483 The name is CHARS/LENGTH.
484 The type is EXPRESSION_TYPE (eg UNSIGNED_TYPE).
485 The init tree is INIT.
488 tree
489 tree_code_create_variable (unsigned int storage_class,
490 unsigned char* chars,
491 unsigned int length,
492 unsigned int expression_type,
493 tree init,
494 location_t loc)
496 tree var_type;
497 tree var_id;
498 tree var_decl;
500 /* 1. Build the type. */
501 var_type = get_type_for_numeric_type (expression_type);
503 /* 2. Build the name. */
504 if (chars[length] != 0)
505 abort (); /* Should be null terminated. */
507 var_id = get_identifier ((const char*)chars);
509 /* 3. Build the decl and set up init. */
510 var_decl = build_decl (VAR_DECL, var_id, var_type);
512 /* 3a. Initialization. */
513 if (init)
514 DECL_INITIAL (var_decl) = build1 (CONVERT_EXPR, var_type, init);
515 else
516 DECL_INITIAL (var_decl) = NULL_TREE;
518 /* 4. Compute size etc. */
519 layout_decl (var_decl, 0);
521 if (TYPE_SIZE (var_type) == 0)
522 abort (); /* Did not calculate size. */
524 DECL_CONTEXT (var_decl) = current_function_decl;
526 DECL_SOURCE_LOCATION (var_decl) = loc;
528 /* Set the storage mode and whether only visible in the same file. */
529 switch (storage_class)
531 case STATIC_STORAGE:
532 TREE_STATIC (var_decl) = 1;
533 TREE_PUBLIC (var_decl) = 0;
534 break;
536 case AUTOMATIC_STORAGE:
537 TREE_STATIC (var_decl) = 0;
538 TREE_PUBLIC (var_decl) = 0;
539 break;
541 case EXTERNAL_DEFINITION_STORAGE:
542 TREE_STATIC (var_decl) = 0;
543 TREE_PUBLIC (var_decl) = 1;
544 break;
546 case EXTERNAL_REFERENCE_STORAGE:
547 DECL_EXTERNAL (var_decl) = 1;
548 TREE_PUBLIC (var_decl) = 0;
549 break;
551 default:
552 abort ();
555 /* This should really only be set if the variable is used. */
556 TREE_USED (var_decl) = 1;
558 /* Expand declaration and initial value if any. */
560 if (TREE_STATIC (var_decl))
561 rest_of_decl_compilation (var_decl, 0, 0, 0);
562 else
564 expand_decl (var_decl);
565 if (DECL_INITIAL (var_decl))
566 expand_decl_init (var_decl);
569 return pushdecl (copy_node (var_decl));
574 /* Generate code for return statement. Type is in TYPE, expression
575 is in EXP if present. */
577 void
578 tree_code_generate_return (tree type, tree exp)
580 tree setret;
581 tree param;
583 for (param = DECL_ARGUMENTS (current_function_decl);
584 param;
585 param = TREE_CHAIN (param))
587 if (DECL_CONTEXT (param) != current_function_decl)
588 abort ();
591 if (exp)
593 setret = build (MODIFY_EXPR, type, DECL_RESULT (current_function_decl),
594 build1 (CONVERT_EXPR, type, exp));
595 TREE_SIDE_EFFECTS (setret) = 1;
596 TREE_USED (setret) = 1;
597 expand_expr_stmt (setret);
599 expand_return (DECL_RESULT (current_function_decl));
602 /* Output the code for this expression statement CODE. */
605 void
606 tree_code_output_expression_statement (tree code,
607 location_t loc)
609 /* Output the line number information. */
610 emit_line_note (loc.file, loc.line);
611 TREE_USED (code) = 1;
612 TREE_SIDE_EFFECTS (code) = 1;
613 expand_expr_stmt (code);
616 /* Return a tree for a constant integer value in the token TOK. No
617 size checking is done. */
619 tree
620 tree_code_get_integer_value (unsigned char* chars, unsigned int length)
622 long long int val = 0;
623 unsigned int ix;
624 unsigned int start = 0;
625 int negative = 1;
626 switch (chars[0])
628 case (unsigned char)'-':
629 negative = -1;
630 start = 1;
631 break;
633 case (unsigned char)'+':
634 start = 1;
635 break;
637 default:
638 break;
640 for (ix = start; ix < length; ix++)
641 val = val * 10 + chars[ix] - (unsigned char)'0';
642 val = val*negative;
643 return build_int_2 (val & 0xffffffff, (val >> 32) & 0xffffffff);
646 /* Return the tree for an expresssion, type EXP_TYPE (see treetree.h)
647 with tree type TYPE and with operands1 OP1, OP2 (maybe), OP3 (maybe). */
648 tree
649 tree_code_get_expression (unsigned int exp_type,
650 tree type, tree op1, tree op2, tree op3 ATTRIBUTE_UNUSED)
652 tree ret1;
653 int operator;
655 switch (exp_type)
657 case EXP_ASSIGN:
658 if (!op1 || !op2)
659 abort ();
660 operator = MODIFY_EXPR;
661 ret1 = build (operator, type,
662 op1,
663 build1 (CONVERT_EXPR, type, op2));
665 break;
667 case EXP_PLUS:
668 operator = PLUS_EXPR;
669 goto binary_expression;
671 case EXP_MINUS:
672 operator = MINUS_EXPR;
673 goto binary_expression;
675 case EXP_EQUALS:
676 operator = EQ_EXPR;
677 goto binary_expression;
679 /* Expand a binary expression. Ensure the operands are the right type. */
680 binary_expression:
681 if (!op1 || !op2)
682 abort ();
683 ret1 = build (operator, type,
684 build1 (CONVERT_EXPR, type, op1),
685 build1 (CONVERT_EXPR, type, op2));
686 break;
688 /* Reference to a variable. This is dead easy, just return the
689 decl for the variable. If the TYPE is different than the
690 variable type, convert it. */
691 case EXP_REFERENCE:
692 if (!op1)
693 abort ();
694 if (type == TREE_TYPE (op1))
695 ret1 = op1;
696 else
697 ret1 = build1 (CONVERT_EXPR, type, op1);
698 break;
700 case EXP_FUNCTION_INVOCATION:
701 if (!op1 || !op2)
702 abort ();
704 tree fun_ptr;
705 fun_ptr = build1 (ADDR_EXPR, build_pointer_type (type), op1);
706 ret1 = build (CALL_EXPR, type, fun_ptr, nreverse (op2));
708 break;
710 default:
711 abort ();
714 return ret1;
717 /* Init parameter list and return empty list. */
719 tree
720 tree_code_init_parameters (void)
722 return NULL_TREE;
725 /* Add a parameter EXP whose expression type is EXP_PROTO to list
726 LIST, returning the new list. */
728 tree
729 tree_code_add_parameter (tree list, tree proto_exp, tree exp)
731 tree new_exp;
732 new_exp = tree_cons (NULL_TREE,
733 build1 (CONVERT_EXPR, TREE_TYPE (proto_exp), exp),
734 NULL_TREE);
735 if (!list)
736 return new_exp;
737 return chainon (new_exp, list);
740 /* Get the tree type for this type whose number is NUMERIC_TYPE. */
742 tree
743 get_type_for_numeric_type (unsigned int numeric_type)
746 int size1;
747 int sign1;
748 switch (numeric_type)
750 case VOID_TYPE:
751 return void_type_node;
753 case SIGNED_INT:
754 size1 = tree_code_int_size;
755 sign1 = 1;
756 break;
758 case UNSIGNED_INT:
759 size1 = tree_code_int_size;
760 sign1 = 0;
761 break;
763 case SIGNED_CHAR:
764 size1 = tree_code_char_size;
765 sign1 = 1;
766 break;
768 case UNSIGNED_CHAR:
769 size1 = tree_code_char_size;
770 sign1 = 0;
771 break;
773 default:
774 abort ();
777 return tree_code_get_numeric_type (size1, sign1);
781 /* Return tree representing a numeric type of size SIZE1 bits and
782 signed if SIGN1 != 0. */
783 tree
784 tree_code_get_numeric_type (unsigned int size1, unsigned int sign1)
786 tree ret1;
787 if (!size1)
788 abort ();
789 if (size1 == tree_code_int_size)
791 if (sign1)
792 ret1 = integer_type_node;
793 else
794 ret1 = unsigned_type_node;
796 else
797 if (size1 == tree_code_char_size)
799 if (sign1)
800 ret1 = signed_char_type_node;
801 else
802 ret1 = unsigned_char_type_node;
804 else
805 abort ();
807 return ret1;
810 /* Garbage Collection. */
812 /* Callback to mark storage M as used always. */
814 void
815 tree_ggc_storage_always_used (void * m)
817 void **mm; /* Actually M is a pointer to a pointer to the memory. */
818 mm = (void**)m;
820 if (*mm)
821 ggc_mark (*mm);
824 /* Following from c-lang.c. */
826 /* Used by c-typeck.c (build_external_ref), but only for objc. */
828 tree
829 lookup_objc_ivar (tree id ATTRIBUTE_UNUSED)
831 return 0;
834 /* Dummy routines called from c code. Save copying c-decl.c, c-common.c etc. */
836 tree
837 objc_is_id (tree arg ATTRIBUTE_UNUSED)
839 return 0;
842 void
843 check_function_format (int *status ATTRIBUTE_UNUSED,
844 tree attrs ATTRIBUTE_UNUSED,
845 tree params ATTRIBUTE_UNUSED)
847 return;
850 /* Tell the c code we are not objective C. */
853 objc_comptypes (tree lhs ATTRIBUTE_UNUSED,
854 tree rhs ATTRIBUTE_UNUSED,
855 int reflexive ATTRIBUTE_UNUSED)
857 return 0;
860 /* Should not be called for treelang. Needed by RS6000 backend. */
862 int c_lex (tree *value);
865 c_lex (tree *value ATTRIBUTE_UNUSED)
867 abort ();
870 /* Should not be called for treelang. */
872 tree
873 build_stmt VPARAMS ((enum tree_code code ATTRIBUTE_UNUSED, ...))
875 abort ();
878 /* Should not be called for treelang. */
880 tree
881 add_stmt (tree t ATTRIBUTE_UNUSED)
883 abort ();
886 /* Should not be called for treelang. */
888 tree
889 build_return_stmt (tree expr ATTRIBUTE_UNUSED)
891 abort ();
894 /* C warning, ignore. */
896 void
897 pedwarn_c99 VPARAMS ((const char *msgid ATTRIBUTE_UNUSED, ...))
899 return;
902 /* Should not be called for treelang. */
904 tree
905 build_case_label (tree low_value ATTRIBUTE_UNUSED,
906 tree high_value ATTRIBUTE_UNUSED,
907 tree label_decl ATTRIBUTE_UNUSED)
909 abort ();
912 /* Should not be called for treelang. */
914 void
915 emit_local_var (tree decl ATTRIBUTE_UNUSED)
917 abort ();
920 /* Should not be called for treelang. */
922 void
923 expand_stmt (tree t ATTRIBUTE_UNUSED)
925 abort ();
928 /* Should not be called for treelang. */
930 cpp_reader *
931 cpp_create_reader (enum c_lang lang ATTRIBUTE_UNUSED,
932 struct ht *table ATTRIBUTE_UNUSED)
934 abort ();
937 /* Should not be called for treelang. */
939 void
940 init_c_lex (void)
942 abort ();
945 /* Should not be called for treelang. */
947 void init_pragma (void);
949 void
950 init_pragma ()
952 abort ();
955 /* Should not be called for treelang. */
958 cpp_finish (cpp_reader *pfile ATTRIBUTE_UNUSED, FILE *f ATTRIBUTE_UNUSED)
960 abort ();
963 /* Should not be called for treelang. */
965 unsigned int
966 cpp_errors (cpp_reader *pfile ATTRIBUTE_UNUSED)
968 abort ();
971 /* Dummy called by C. */
973 tree
974 handle_format_attribute (tree *node ATTRIBUTE_UNUSED,
975 tree name ATTRIBUTE_UNUSED,
976 tree args ATTRIBUTE_UNUSED,
977 int flags ATTRIBUTE_UNUSED,
978 bool *no_add_attrs ATTRIBUTE_UNUSED)
980 return NULL_TREE;
983 /* Should not be called for treelang. */
985 tree
986 handle_format_arg_attribute (tree *node ATTRIBUTE_UNUSED,
987 tree name ATTRIBUTE_UNUSED,
988 tree args ATTRIBUTE_UNUSED,
989 int flags ATTRIBUTE_UNUSED,
990 bool *no_add_attrs ATTRIBUTE_UNUSED)
992 abort ();
995 /* Should not be called for treelang. */
997 void
998 cpp_assert (cpp_reader * cr ATTRIBUTE_UNUSED,
999 const char *s ATTRIBUTE_UNUSED)
1001 abort ();
1004 /* Should not be called for treelang. */
1006 void
1007 set_Wformat (int setting ATTRIBUTE_UNUSED)
1009 abort ();
1012 /* Used for objective C. */
1014 void
1015 objc_check_decl (tree decl ATTRIBUTE_UNUSED);
1017 void
1018 objc_check_decl (tree decl ATTRIBUTE_UNUSED)
1020 abort ();
1023 /* Tell the c code we are not objective C. */
1025 tree
1026 objc_message_selector (void);
1028 tree
1029 objc_message_selector ()
1031 return 0;
1034 /* Should not be called for treelang. */
1036 void
1037 gen_aux_info_record (tree fndecl ATTRIBUTE_UNUSED,
1038 int is_definition ATTRIBUTE_UNUSED,
1039 int is_implicit ATTRIBUTE_UNUSED,
1040 int is_prototyped ATTRIBUTE_UNUSED)
1042 abort ();
1045 /* Should not be called for treelang, but it is. */
1047 void
1048 c_parse_init ()
1050 return;
1053 /* Should not be called for treelang. */
1055 void maybe_apply_pragma_weak (tree decl);
1057 void
1058 maybe_apply_pragma_weak (tree decl ATTRIBUTE_UNUSED)
1060 abort ();
1063 /* Should not be called for treelang. */
1065 void
1066 add_decl_stmt (tree decl ATTRIBUTE_UNUSED)
1068 abort ();
1071 /* Should not be called for treelang. */
1073 tree
1074 maybe_apply_renaming_pragma (tree decl, tree asmname);
1076 /* Should not be called for treelang. */
1078 tree
1079 maybe_apply_renaming_pragma (tree decl ATTRIBUTE_UNUSED, tree asmname ATTRIBUTE_UNUSED)
1081 abort ();
1084 /* Should not be called for treelang. */
1086 void
1087 begin_stmt_tree (tree *t ATTRIBUTE_UNUSED)
1089 abort ();
1092 /* Should not be called for treelang. */
1094 void
1095 finish_stmt_tree (tree *t ATTRIBUTE_UNUSED)
1097 abort ();
1100 /* Should not be called for treelang. */
1103 defer_fn (tree fn ATTRIBUTE_UNUSED)
1105 abort ();
1108 /* Should not be called for treelang. */
1110 cpp_options
1111 *cpp_get_options (cpp_reader * cr ATTRIBUTE_UNUSED)
1113 abort ();
1116 /* Should not be called for treelang. */
1118 void
1119 cpp_define (cpp_reader * cr ATTRIBUTE_UNUSED, const char * c ATTRIBUTE_UNUSED)
1121 abort ();
1124 /* Should not be called for treelang. */
1126 cpp_callbacks *
1127 cpp_get_callbacks (cpp_reader * cr ATTRIBUTE_UNUSED)
1129 abort ();
1132 /* Create the predefined scalar types of C,
1133 and some nodes representing standard constants (0, 1, (void *) 0).
1134 Initialize the global binding level.
1135 Make definitions for built-in primitive functions. */
1137 /* `unsigned long' is the standard type for sizeof.
1138 Note that stddef.h uses `unsigned long',
1139 and this must agree, even if long and int are the same size. */
1141 /* The reserved keyword table. */
1142 struct resword
1144 const char *word;
1145 ENUM_BITFIELD(rid) rid : 16;
1146 unsigned int disable : 16;
1149 static const struct resword reswords[] =
1151 { "_Bool", RID_BOOL, 0 },
1152 { "_Complex", RID_COMPLEX, 0 },
1153 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
1154 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
1155 { "__alignof", RID_ALIGNOF, 0 },
1156 { "__alignof__", RID_ALIGNOF, 0 },
1157 { "__asm", RID_ASM, 0 },
1158 { "__asm__", RID_ASM, 0 },
1159 { "__attribute", RID_ATTRIBUTE, 0 },
1160 { "__attribute__", RID_ATTRIBUTE, 0 },
1161 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
1162 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
1163 { "__builtin_va_arg", RID_VA_ARG, 0 },
1164 { "__complex", RID_COMPLEX, 0 },
1165 { "__complex__", RID_COMPLEX, 0 },
1166 { "__const", RID_CONST, 0 },
1167 { "__const__", RID_CONST, 0 },
1168 { "__extension__", RID_EXTENSION, 0 },
1169 { "__func__", RID_C99_FUNCTION_NAME, 0 },
1170 { "__imag", RID_IMAGPART, 0 },
1171 { "__imag__", RID_IMAGPART, 0 },
1172 { "__inline", RID_INLINE, 0 },
1173 { "__inline__", RID_INLINE, 0 },
1174 { "__label__", RID_LABEL, 0 },
1175 { "__ptrbase", RID_PTRBASE, 0 },
1176 { "__ptrbase__", RID_PTRBASE, 0 },
1177 { "__ptrextent", RID_PTREXTENT, 0 },
1178 { "__ptrextent__", RID_PTREXTENT, 0 },
1179 { "__ptrvalue", RID_PTRVALUE, 0 },
1180 { "__ptrvalue__", RID_PTRVALUE, 0 },
1181 { "__real", RID_REALPART, 0 },
1182 { "__real__", RID_REALPART, 0 },
1183 { "__restrict", RID_RESTRICT, 0 },
1184 { "__restrict__", RID_RESTRICT, 0 },
1185 { "__signed", RID_SIGNED, 0 },
1186 { "__signed__", RID_SIGNED, 0 },
1187 { "__typeof", RID_TYPEOF, 0 },
1188 { "__typeof__", RID_TYPEOF, 0 },
1189 { "__volatile", RID_VOLATILE, 0 },
1190 { "__volatile__", RID_VOLATILE, 0 },
1191 { "asm", RID_ASM, 0 },
1192 { "auto", RID_AUTO, 0 },
1193 { "break", RID_BREAK, 0 },
1194 { "case", RID_CASE, 0 },
1195 { "char", RID_CHAR, 0 },
1196 { "const", RID_CONST, 0 },
1197 { "continue", RID_CONTINUE, 0 },
1198 { "default", RID_DEFAULT, 0 },
1199 { "do", RID_DO, 0 },
1200 { "double", RID_DOUBLE, 0 },
1201 { "else", RID_ELSE, 0 },
1202 { "enum", RID_ENUM, 0 },
1203 { "extern", RID_EXTERN, 0 },
1204 { "float", RID_FLOAT, 0 },
1205 { "for", RID_FOR, 0 },
1206 { "goto", RID_GOTO, 0 },
1207 { "if", RID_IF, 0 },
1208 { "inline", RID_INLINE, 0 },
1209 { "int", RID_INT, 0 },
1210 { "long", RID_LONG, 0 },
1211 { "register", RID_REGISTER, 0 },
1212 { "restrict", RID_RESTRICT, 0 },
1213 { "return", RID_RETURN, 0 },
1214 { "short", RID_SHORT, 0 },
1215 { "signed", RID_SIGNED, 0 },
1216 { "sizeof", RID_SIZEOF, 0 },
1217 { "static", RID_STATIC, 0 },
1218 { "struct", RID_STRUCT, 0 },
1219 { "switch", RID_SWITCH, 0 },
1220 { "typedef", RID_TYPEDEF, 0 },
1221 { "typeof", RID_TYPEOF, 0 },
1222 { "union", RID_UNION, 0 },
1223 { "unsigned", RID_UNSIGNED, 0 },
1224 { "void", RID_VOID, 0 },
1225 { "volatile", RID_VOLATILE, 0 },
1226 { "while", RID_WHILE, 0 },
1228 #define N_reswords (sizeof reswords / sizeof (struct resword))
1230 /* Init enough to allow the C decl code to work, then clean up
1231 afterwards. */
1233 void
1234 treelang_init_decl_processing ()
1236 unsigned int i;
1237 tree id;
1239 ridpointers = (tree *) ggc_calloc ((int) RID_MAX, sizeof (tree));
1241 for (i = 0; i < N_reswords; i++)
1243 id = get_identifier (reswords[i].word);
1244 C_RID_CODE (id) = reswords[i].rid;
1245 C_IS_RESERVED_WORD (id) = 1;
1246 ridpointers [(int) reswords[i].rid] = id;
1249 c_init_decl_processing ();
1251 /* ix86_return_pops_args takes the type of these so need to patch
1252 their own type as themselves. */
1254 for (i = 0; i < itk_none; i++)
1256 if (integer_types[i])
1257 TREE_TYPE (integer_types [i]) = integer_types[i];
1260 /* Probably these ones too. */
1261 TREE_TYPE (float_type_node) = float_type_node;
1262 TREE_TYPE (double_type_node) = double_type_node;
1263 TREE_TYPE (long_double_type_node) = long_double_type_node;
1267 /* Save typing debug_tree all the time. Dump a tree T pretty and
1268 concise. */
1270 void dt (tree t);
1272 void
1273 dt (tree t)
1275 debug_tree (t);
1278 /* Get a stringpool entry for a string S of length L. This is needed
1279 because the GTY routines don't mark strings, forcing you to put
1280 them into stringpool, which is never freed. */
1282 const char*
1283 get_string (const char *s, size_t l)
1285 tree t;
1286 t = get_identifier_with_length (s, l);
1287 return IDENTIFIER_POINTER(t);