stl_bvector.h (swap(_Bit_reference,_Bit_reference)): Move/rename...
[official-gcc.git] / gcc / treelang / treetree.c
blob2cb57ff32376b3990edca57a3ff2c6cee504b1e0
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, 1999, 2000,
10 2001, 2002 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 /* Standard/OS headers. */
59 #include <stdlib.h>
60 #include <unistd.h>
61 #include "safe-ctype.h"
62 #include <errno.h>
63 #include <stdarg.h>
64 #include <limits.h>
65 #include <string.h>
67 #include <fcntl.h>
68 #include <getopt.h>
69 #include <stdio.h>
71 /* GCC headers. */
73 #include "ansidecl.h"
74 #include "config.h"
75 #include "system.h"
76 #include "tree.h"
77 #include "flags.h"
78 #include "output.h"
79 #include "c-tree.h"
80 #include "rtl.h"
81 #include "tm_p.h"
82 #include "ggc.h"
83 #include "toplev.h"
84 #include "varray.h"
85 #include "langhooks-def.h"
86 #include "langhooks.h"
88 #include "treetree.h"
90 extern int option_main;
91 extern char **file_names;
93 /* Flags etc required by c code. */
95 int warn_format = 0;
96 int warn_format_y2k = 0;
97 int warn_format_extra_args = 0;
98 int warn_format_nonliteral = 0;
99 int warn_format_security = 0;
100 int warn_format_zero_length = 0;
103 /* The front end language hooks (addresses of code for this front
104 end). Mostly just use the C routines. */
106 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
107 #define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion
108 #undef LANG_HOOKS_MARK_ADDRESSABLE
109 #define LANG_HOOKS_MARK_ADDRESSABLE c_mark_addressable
110 #undef LANG_HOOKS_SIGNED_TYPE
111 #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type
112 #undef LANG_HOOKS_UNSIGNED_TYPE
113 #define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type
114 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
115 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
116 #undef LANG_HOOKS_TYPE_FOR_MODE
117 #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
118 #undef LANG_HOOKS_TYPE_FOR_SIZE
119 #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size
120 #undef LANG_HOOKS_PARSE_FILE
121 #define LANG_HOOKS_PARSE_FILE treelang_parse_file
123 /* Hook routines and data unique to treelang. */
125 #undef LANG_HOOKS_INIT
126 #define LANG_HOOKS_INIT treelang_init
127 #undef LANG_HOOKS_NAME
128 #define LANG_HOOKS_NAME "GNU treelang"
129 #undef LANG_HOOKS_FINISH
130 #define LANG_HOOKS_FINISH treelang_finish
131 #undef LANG_HOOKS_DECODE_OPTION
132 #define LANG_HOOKS_DECODE_OPTION treelang_decode_option
133 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
135 /* Tree code type/name/code tables. */
137 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
139 const char tree_code_type[] = {
140 #include "tree.def"
143 #undef DEFTREECODE
145 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
147 const unsigned char tree_code_length[] = {
148 #include "tree.def"
151 #undef DEFTREECODE
153 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
155 const char *const tree_code_name[] = {
156 #include "tree.def"
157 "@@dummy"
159 #undef DEFTREECODE
161 /* Number of bits in int and char - accessed by front end. */
163 unsigned int tree_code_int_size = 0;
164 unsigned int tree_code_char_size = 0;
166 /* In this case there is very little to keep between functions - we
167 keep the symbol table only and the things that hang off that - see
168 tree1.c. Garbage collection is only invoked when we call
169 rest_of_compilation at the end of a function. */
171 #define ADDROOT(where) ggc_add_root (&where, 1, /* Unused size. */ sizeof (void*), \
172 tree_ggc_storage_always_used);
174 /* Return the tree stuff for this type TYPE_NUM. */
176 tree
177 tree_code_get_type (int type_num)
179 switch (type_num)
181 case SIGNED_CHAR:
182 return signed_char_type_node;
184 case UNSIGNED_CHAR:
185 return unsigned_char_type_node;
187 case SIGNED_INT:
188 return integer_type_node;
190 case UNSIGNED_INT:
191 return unsigned_type_node;
193 case VOID_TYPE:
194 return void_type_node;
196 default:
197 abort ();
201 /* Output the code for the start of an if statement. The test
202 expression is EXP (true if not zero), and the stmt occurred at line
203 LINENO in file FILENAME. */
205 void
206 tree_code_if_start (tree exp, unsigned char* filename, int lineno)
208 tree cond_exp;
209 cond_exp = build (NE_EXPR,
210 TREE_TYPE (exp),
211 exp,
212 build1 (CONVERT_EXPR, TREE_TYPE (exp), integer_zero_node));
213 emit_line_note ((const char *)filename, lineno); /* Output the line number information. */
214 expand_start_cond (cond_exp, /* Exit-able if non zero. */ 0);
217 /* Output the code for the else of an if statement. The else occurred
218 at line LINENO in file FILENAME. */
220 void
221 tree_code_if_else (unsigned char* filename, int lineno)
223 emit_line_note ((const char *)filename, lineno); /* Output the line number information. */
224 expand_start_else ();
227 /* Output the code for the end_if an if statement. The end_if (final brace) occurred
228 at line LINENO in file FILENAME. */
230 void
231 tree_code_if_end (unsigned char* filename, int lineno)
233 emit_line_note ((const char *)filename, lineno); /* Output the line number information. */
234 expand_end_cond ();
237 /* Create a function. The prototype name is NAME, storage class is
238 STORAGE_CLASS, type of return variable is RET_TYPE, parameter lists
239 is PARMS, returns decl for this function. */
241 tree
242 tree_code_create_function_prototype (unsigned char* chars,
243 unsigned int storage_class,
244 unsigned int ret_type,
245 struct tree_parameter_list* parms,
246 unsigned char* filename,
247 int lineno)
250 tree id;
251 struct tree_parameter_list* parm;
252 tree type_list = NULL_TREE;
253 tree type_node;
254 tree fn_type;
255 tree fn_decl;
257 /* Build the type. */
258 id = get_identifier ((const char*)chars);
259 for (parm = parms; parm; parm = parm->next)
261 type_node = get_type_for_numeric_type (parm->type);
262 type_list = tree_cons (NULL_TREE, type_node, type_list);
264 /* Last parm if null indicates fixed length list (as opposed to
265 printf style va_* list). */
266 type_list = tree_cons (NULL_TREE, void_type_node, type_list);
267 /* The back end needs them in reverse order. */
268 type_list = nreverse (type_list);
270 type_node = get_type_for_numeric_type (ret_type);
271 fn_type = build_function_type (type_node, type_list);
273 id = get_identifier ((const char*)chars);
274 fn_decl = build_decl (FUNCTION_DECL, id, fn_type);
276 DECL_CONTEXT (fn_decl) = NULL_TREE; /* Nested functions not supported here. */
277 DECL_SOURCE_FILE (fn_decl) = (const char *)filename;
278 /* if (lineno > 1000000)
279 ; */ /* Probably the line # is rubbish because someone forgot to set
280 the line number - and unfortunately impossible line #s are used as
281 magic flags at various times. The longest known function for
282 example is about 550,000 lines (it was written in COBOL). */
283 DECL_SOURCE_LINE (fn_decl) = lineno;
285 TREE_USED (fn_decl) = 1;
287 /* Real name (optional). */
288 SET_DECL_ASSEMBLER_NAME (fn_decl, DECL_NAME (fn_decl));
290 TREE_PUBLIC (fn_decl) = 0;
291 DECL_EXTERNAL (fn_decl) = 0;
292 TREE_STATIC (fn_decl) = 0;
293 switch (storage_class)
295 case STATIC_STORAGE:
296 TREE_PUBLIC (fn_decl) = 0;
297 break;
299 case EXTERNAL_DEFINITION_STORAGE:
300 TREE_PUBLIC (fn_decl) = 1;
301 TREE_STATIC (fn_decl) = 0;
302 DECL_EXTERNAL (fn_decl) = 0;
303 break;
305 case EXTERNAL_REFERENCE_STORAGE:
306 TREE_PUBLIC (fn_decl) = 0;
307 DECL_EXTERNAL (fn_decl) = 1;
308 break;
311 case AUTOMATIC_STORAGE:
312 default:
313 abort ();
316 /* Process declaration of function defined elsewhere. */
317 rest_of_decl_compilation (fn_decl, NULL, 1, 0);
319 return fn_decl;
323 /* Output code for start of function; the decl of the function is in
324 PREV_SAVED (as created by tree_code_create_function_prototype),
325 the function is at line number LINENO in file FILENAME. The
326 parameter details are in the lists PARMS. Returns nothing. */
327 void
328 tree_code_create_function_initial (tree prev_saved,
329 unsigned char* filename,
330 int lineno,
331 struct tree_parameter_list* parms)
333 tree fn_decl;
334 tree param_decl;
335 tree next_param;
336 tree first_param;
337 tree parm_decl;
338 tree parm_list;
339 tree resultdecl;
340 struct tree_parameter_list* this_parm;
341 struct tree_parameter_list* parm;
343 fn_decl = prev_saved;
344 if (!fn_decl)
345 abort ();
347 /* Output message if not -quiet. */
348 announce_function (fn_decl);
350 /* This has something to do with forcing output also. */
351 pushdecl (fn_decl);
353 /* Set current function for error msgs etc. */
354 current_function_decl = fn_decl;
355 DECL_INITIAL (fn_decl) = error_mark_node;
357 DECL_SOURCE_FILE (fn_decl) = (const char *)filename;
358 DECL_SOURCE_LINE (fn_decl) = lineno;
360 /* Prepare creation of rtl for a new function. */
362 resultdecl = DECL_RESULT (fn_decl) = build_decl (RESULT_DECL, NULL_TREE, TREE_TYPE (TREE_TYPE (fn_decl)));
363 DECL_CONTEXT (DECL_RESULT (fn_decl)) = fn_decl;
364 DECL_SOURCE_FILE (resultdecl) = (const char *)filename;
365 DECL_SOURCE_LINE (resultdecl) = lineno;
366 /* Work out the size. ??? is this needed. */
367 layout_decl (DECL_RESULT (fn_decl), 0);
369 /* Make the argument variable decls. */
370 parm_list = NULL_TREE;
371 for (parm = parms; parm; parm = parm->next)
373 parm_decl = build_decl (PARM_DECL, get_identifier ((const char*) (parm->variable_name)),
374 get_type_for_numeric_type (parm->type));
376 /* Some languages have different nominal and real types. */
377 DECL_ARG_TYPE (parm_decl) = TREE_TYPE (parm_decl);
378 if (!DECL_ARG_TYPE (parm_decl))
379 abort ();
380 if (!fn_decl)
381 abort ();
382 DECL_CONTEXT (parm_decl) = fn_decl;
383 DECL_SOURCE_FILE (parm_decl) = (const char *)filename;
384 DECL_SOURCE_LINE (parm_decl) = lineno;
385 parm_list = chainon (parm_decl, parm_list);
388 /* Back into reverse order as the back end likes them. */
389 parm_list = nreverse (parm_list);
391 DECL_ARGUMENTS (fn_decl) = parm_list;
393 /* Save the decls for use when the args are referred to. */
394 for (param_decl = DECL_ARGUMENTS (fn_decl),
395 this_parm = parms;
396 param_decl;
397 param_decl = TREE_CHAIN (param_decl),
398 this_parm = this_parm->next)
400 if (!this_parm)
401 abort (); /* Too few. */
402 *this_parm->where_to_put_var_tree = param_decl;
404 if (this_parm)
405 abort (); /* Too many. */
407 /* Output the decl rtl (not the rtl for the function code). ???.
408 If the function is not defined in this file, when should you
409 execute this? */
410 make_decl_rtl (fn_decl, NULL);
412 /* Use filename/lineno from above. */
413 init_function_start (fn_decl, (const char *)filename, lineno);
415 /* Create rtl for startup code of function, such as saving registers. */
417 expand_function_start (fn_decl, 0);
419 /* Function.c requires a push at the start of the function. that
420 looks like a bug to me but let's make it happy. */
422 (*lang_hooks.decls.pushlevel) (0);
424 /* Create rtl for the start of a new scope. */
426 expand_start_bindings (2);
428 /* Put the parameters into the symbol table. */
430 for (first_param = param_decl = nreverse (DECL_ARGUMENTS (fn_decl));
431 param_decl;
432 param_decl = next_param)
434 next_param = TREE_CHAIN (param_decl);
435 TREE_CHAIN (param_decl) = NULL;
436 /* layout_decl (param_decl, 0); Already done in build_decl tej 13/4/2002. */
437 pushdecl (param_decl);
438 if (DECL_CONTEXT (param_decl) != current_function_decl)
439 abort ();
442 /* Store back the PARM_DECL nodes. They appear in the right order. */
443 DECL_ARGUMENTS (fn_decl) = getdecls ();
445 /* Force it to be output, else may be solely inlined. */
446 TREE_ADDRESSABLE (fn_decl) = 1;
448 /* Stop -O3 from deleting it. */
449 TREE_USED (fn_decl) = 1;
451 /* Add a new level to the debugger symbol table. */
453 (*lang_hooks.decls.pushlevel) (0);
455 /* Create rtl for the start of a new scope. */
457 expand_start_bindings (0);
459 emit_line_note ((const char *)filename, lineno); /* Output the line number information. */
462 /* Wrapup a function contained in file FILENAME, ending at line LINENO. */
463 void
464 tree_code_create_function_wrapup (unsigned char* filename,
465 int lineno)
467 tree block;
468 tree fn_decl;
470 fn_decl = current_function_decl;
472 emit_line_note ((const char *)filename, lineno); /* Output the line number information. */
474 /* Get completely built level from debugger symbol table. */
476 block = (*lang_hooks.decls.poplevel) (1, 0, 0);
478 /* Emit rtl for end of scope. */
480 expand_end_bindings (block, 0, 1);
482 /* Emit rtl for end of function. */
484 expand_function_end ((const char *)filename, lineno, 0);
486 /* Pop the level. */
488 block = (*lang_hooks.decls.poplevel) (1, 0, 1);
490 /* And attach it to the function. */
492 DECL_INITIAL (fn_decl) = block;
494 /* Emit rtl for end of scope. */
496 expand_end_bindings (block, 0, 1);
498 /* Call optimization and convert optimized rtl to assembly code. */
500 rest_of_compilation (fn_decl);
502 /* We are not inside of any scope now. */
504 current_function_decl = NULL_TREE;
508 Create a variable.
510 The storage class is STORAGE_CLASS (eg LOCAL).
511 The name is CHARS/LENGTH.
512 The type is EXPRESSION_TYPE (eg UNSIGNED_TYPE).
513 The init tree is INIT.
516 tree
517 tree_code_create_variable (unsigned int storage_class,
518 unsigned char* chars,
519 unsigned int length,
520 unsigned int expression_type,
521 tree init,
522 unsigned char* filename,
523 int lineno)
525 tree var_type;
526 tree var_id;
527 tree var_decl;
529 /* 1. Build the type. */
530 var_type = get_type_for_numeric_type (expression_type);
532 /* 2. Build the name. */
533 if (chars[length] != 0)
534 abort (); /* Should be null terminated. */
536 var_id = get_identifier ((const char*)chars);
538 /* 3. Build the decl and set up init. */
539 var_decl = build_decl (VAR_DECL, var_id, var_type);
541 /* 3a. Initialization. */
542 if (init)
543 DECL_INITIAL (var_decl) = build1 (CONVERT_EXPR, var_type, init);
544 else
545 DECL_INITIAL (var_decl) = NULL_TREE;
547 /* 4. Compute size etc. */
548 layout_decl (var_decl, 0);
550 if (TYPE_SIZE (var_type) == 0)
551 abort (); /* Did not calculate size. */
553 DECL_CONTEXT (var_decl) = current_function_decl;
555 DECL_SOURCE_FILE (var_decl) = (const char *)filename;
556 DECL_SOURCE_LINE (var_decl) = lineno;
558 /* Set the storage mode and whether only visible in the same file. */
559 switch (storage_class)
561 case STATIC_STORAGE:
562 TREE_STATIC (var_decl) = 1;
563 TREE_PUBLIC (var_decl) = 0;
564 break;
566 case AUTOMATIC_STORAGE:
567 TREE_STATIC (var_decl) = 0;
568 TREE_PUBLIC (var_decl) = 0;
569 break;
571 case EXTERNAL_DEFINITION_STORAGE:
572 TREE_STATIC (var_decl) = 0;
573 TREE_PUBLIC (var_decl) = 1;
574 break;
576 case EXTERNAL_REFERENCE_STORAGE:
577 DECL_EXTERNAL (var_decl) = 1;
578 TREE_PUBLIC (var_decl) = 0;
579 break;
581 default:
582 abort ();
585 /* This should really only be set if the variable is used. */
586 TREE_USED (var_decl) = 1;
588 /* Expand declaration and initial value if any. */
590 if (TREE_STATIC (var_decl))
591 rest_of_decl_compilation (var_decl, 0, 0, 0);
592 else
594 expand_decl (var_decl);
595 if (DECL_INITIAL (var_decl))
596 expand_decl_init (var_decl);
599 return pushdecl (copy_node (var_decl));
604 /* Generate code for return statement. Type is in TYPE, expression
605 is in EXP if present. */
607 void
608 tree_code_generate_return (tree type, tree exp)
610 tree setret;
611 tree param;
613 for (param = DECL_ARGUMENTS (current_function_decl);
614 param;
615 param = TREE_CHAIN (param))
617 if (DECL_CONTEXT (param) != current_function_decl)
618 abort ();
621 if (exp)
623 setret = build (MODIFY_EXPR, type, DECL_RESULT (current_function_decl),
624 build1 (CONVERT_EXPR, type, exp));
625 TREE_SIDE_EFFECTS (setret) = 1;
626 TREE_USED (setret) = 1;
627 expand_expr_stmt (setret);
629 expand_return (DECL_RESULT (current_function_decl));
632 /* Output the code for this expression statement CODE. */
635 void
636 tree_code_output_expression_statement (tree code,
637 unsigned char* filename, int lineno)
639 /* Output the line number information. */
640 emit_line_note ((const char *)filename, lineno);
641 TREE_USED (code) = 1;
642 TREE_SIDE_EFFECTS (code) = 1;
643 expand_expr_stmt (code);
646 /* Return a tree for a constant integer value in the token TOK. No
647 size checking is done. */
649 tree
650 tree_code_get_integer_value (unsigned char* chars, unsigned int length)
652 long long int val = 0;
653 unsigned int ix;
654 unsigned int start = 0;
655 int negative = 1;
656 switch (chars[0])
658 case (unsigned char)'-':
659 negative = -1;
660 start = 1;
661 break;
663 case (unsigned char)'+':
664 start = 1;
665 break;
667 default:
668 break;
670 for (ix = start; ix < length; ix++)
671 val = val * 10 + chars[ix] - (unsigned char)'0';
672 val = val*negative;
673 return build_int_2 (val & 0xffffffff, (val >> 32) & 0xffffffff);
676 /* Return the tree for an expresssion, type EXP_TYPE (see treetree.h)
677 with tree type TYPE and with operands1 OP1, OP2 (maybe), OP3 (maybe). */
678 tree
679 tree_code_get_expression (unsigned int exp_type,
680 tree type, tree op1, tree op2, tree op3 ATTRIBUTE_UNUSED)
682 tree ret1;
683 int operator;
685 switch (exp_type)
687 case EXP_ASSIGN:
688 if (!op1 || !op2)
689 abort ();
690 operator = MODIFY_EXPR;
691 ret1 = build (operator, type,
692 op1,
693 build1 (CONVERT_EXPR, type, op2));
695 break;
697 case EXP_PLUS:
698 operator = PLUS_EXPR;
699 goto binary_expression;
701 case EXP_MINUS:
702 operator = MINUS_EXPR;
703 goto binary_expression;
705 case EXP_EQUALS:
706 operator = EQ_EXPR;
707 goto binary_expression;
709 /* Expand a binary expression. Ensure the operands are the right type. */
710 binary_expression:
711 if (!op1 || !op2)
712 abort ();
713 ret1 = build (operator, type,
714 build1 (CONVERT_EXPR, type, op1),
715 build1 (CONVERT_EXPR, type, op2));
716 break;
718 /* Reference to a variable. This is dead easy, just return the
719 decl for the variable. If the TYPE is different than the
720 variable type, convert it. */
721 case EXP_REFERENCE:
722 if (!op1)
723 abort ();
724 if (type == TREE_TYPE (op1))
725 ret1 = op1;
726 else
727 ret1 = build1 (CONVERT_EXPR, type, op1);
728 break;
730 case EXP_FUNCTION_INVOCATION:
731 if (!op1 || !op2)
732 abort ();
734 tree fun_ptr;
735 fun_ptr = build1 (ADDR_EXPR, build_pointer_type (type), op1);
736 ret1 = build (CALL_EXPR, type, fun_ptr, nreverse (op2));
738 break;
740 default:
741 abort ();
744 return ret1;
747 /* Init parameter list and return empty list. */
749 tree
750 tree_code_init_parameters (void)
752 return NULL_TREE;
755 /* Add a parameter EXP whose expression type is EXP_PROTO to list
756 LIST, returning the new list. */
758 tree
759 tree_code_add_parameter (tree list, tree proto_exp, tree exp)
761 tree new_exp;
762 new_exp = tree_cons (NULL_TREE,
763 build1 (CONVERT_EXPR, TREE_TYPE (proto_exp), exp),
764 NULL_TREE);
765 if (!list)
766 return new_exp;
767 return chainon (new_exp, list);
770 /* Get the tree type for this type whose number is NUMERIC_TYPE. */
772 tree
773 get_type_for_numeric_type (unsigned int numeric_type)
776 int size1;
777 int sign1;
778 switch (numeric_type)
780 case VOID_TYPE:
781 return void_type_node;
783 case SIGNED_INT:
784 size1 = tree_code_int_size;
785 sign1 = 1;
786 break;
788 case UNSIGNED_INT:
789 size1 = tree_code_int_size;
790 sign1 = 0;
791 break;
793 case SIGNED_CHAR:
794 size1 = tree_code_char_size;
795 sign1 = 1;
796 break;
798 case UNSIGNED_CHAR:
799 size1 = tree_code_char_size;
800 sign1 = 0;
801 break;
803 default:
804 abort ();
807 return tree_code_get_numeric_type (size1, sign1);
811 /* Return tree representing a numeric type of size SIZE1 bits and
812 signed if SIGN1 != 0. */
813 tree
814 tree_code_get_numeric_type (unsigned int size1, unsigned int sign1)
816 tree ret1;
817 if (size1 == tree_code_int_size)
819 if (sign1)
820 ret1 = integer_type_node;
821 else
822 ret1 = unsigned_type_node;
824 else
825 if (size1 == tree_code_char_size)
827 if (sign1)
828 ret1 = signed_char_type_node;
829 else
830 ret1 = unsigned_char_type_node;
832 else
833 abort ();
835 return ret1;
838 /* Garbage Collection. */
840 /* Callback to mark storage M as used always. */
842 void
843 tree_ggc_storage_always_used (void * m)
845 void **mm; /* Actually M is a pointer to a pointer to the memory. */
846 mm = (void**)m;
848 if (*mm)
849 ggc_mark (*mm);
852 /* Following from c-lang.c. */
854 /* Tell the c code we are not objective C. */
857 maybe_objc_comptypes (tree lhs ATTRIBUTE_UNUSED,
858 tree rhs ATTRIBUTE_UNUSED,
859 int reflexive ATTRIBUTE_UNUSED)
861 return -1;
864 /* Used by c-typeck.c (build_external_ref), but only for objc. */
866 tree
867 lookup_objc_ivar (tree id ATTRIBUTE_UNUSED)
869 return 0;
872 /* Dummy routines called from c code. Save copying c-decl.c, c-common.c etc. */
874 void
875 check_function_format (int *status ATTRIBUTE_UNUSED,
876 tree attrs ATTRIBUTE_UNUSED,
877 tree params ATTRIBUTE_UNUSED)
879 return;
882 /* Tell the c code we are not objective C. */
884 tree
885 maybe_building_objc_message_expr ()
887 return 0;
890 /* Should not be called for treelang. */
892 tree
893 build_stmt VPARAMS ((enum tree_code code ATTRIBUTE_UNUSED, ...))
895 abort ();
898 /* Should not be called for treelang. */
900 tree
901 add_stmt (tree t ATTRIBUTE_UNUSED)
903 abort ();
906 /* Should not be called for treelang. */
908 tree
909 build_return_stmt (tree expr ATTRIBUTE_UNUSED)
911 abort ();
914 /* C warning, ignore. */
916 void
917 pedwarn_c99 VPARAMS ((const char *msgid ATTRIBUTE_UNUSED, ...))
919 return;
922 /* Should not be called for treelang. */
924 tree
925 build_case_label (tree low_value ATTRIBUTE_UNUSED,
926 tree high_value ATTRIBUTE_UNUSED,
927 tree label_decl ATTRIBUTE_UNUSED)
929 abort ();
932 /* Should not be called for treelang. */
934 void
935 emit_local_var (tree decl ATTRIBUTE_UNUSED)
937 abort ();
940 /* Should not be called for treelang. */
942 void
943 expand_stmt (tree t ATTRIBUTE_UNUSED)
945 abort ();
948 /* Should not be called for treelang. */
950 cpp_reader *
951 cpp_create_reader (enum c_lang lang ATTRIBUTE_UNUSED)
953 abort ();
956 /* Should not be called for treelang. */
958 void
959 cpp_post_options (cpp_reader *pfile ATTRIBUTE_UNUSED)
961 abort ();
964 /* Should not be called for treelang. */
966 void
967 cpp_preprocess_file (cpp_reader *pfile ATTRIBUTE_UNUSED)
969 abort ();
972 /* Should not be called for treelang. */
974 const char *
975 init_c_lex (const char *filename ATTRIBUTE_UNUSED)
977 abort ();
980 /* Should not be called for treelang. */
982 void init_pragma (void);
984 void
985 init_pragma ()
987 abort ();
990 /* Should not be called for treelang. */
992 void
993 cpp_finish (cpp_reader *pfile ATTRIBUTE_UNUSED)
995 abort ();
998 /* Should not be called for treelang. */
1000 unsigned int
1001 cpp_errors (cpp_reader *pfile ATTRIBUTE_UNUSED)
1003 abort ();
1006 /* Should not be called for treelang. */
1008 tree
1009 handle_format_attribute (tree *node ATTRIBUTE_UNUSED,
1010 tree name ATTRIBUTE_UNUSED,
1011 tree args ATTRIBUTE_UNUSED,
1012 int flags ATTRIBUTE_UNUSED,
1013 bool *no_add_attrs ATTRIBUTE_UNUSED)
1015 abort ();
1018 /* Should not be called for treelang. */
1020 tree
1021 handle_format_arg_attribute (tree *node ATTRIBUTE_UNUSED,
1022 tree name ATTRIBUTE_UNUSED,
1023 tree args ATTRIBUTE_UNUSED,
1024 int flags ATTRIBUTE_UNUSED,
1025 bool *no_add_attrs ATTRIBUTE_UNUSED)
1027 abort ();
1030 /* Should not be called for treelang. */
1033 cpp_handle_option (cpp_reader *pfile ATTRIBUTE_UNUSED,
1034 int argc ATTRIBUTE_UNUSED,
1035 char **argv ATTRIBUTE_UNUSED,
1036 int ignore ATTRIBUTE_UNUSED)
1038 abort ();
1041 /* Should not be called for treelang. */
1043 void
1044 set_Wformat (int setting ATTRIBUTE_UNUSED)
1046 abort ();
1049 /* Should not be called for treelang. */
1051 void
1052 maybe_objc_check_decl (tree decl ATTRIBUTE_UNUSED)
1054 abort ();
1057 /* Should not be called for treelang. */
1059 void
1060 gen_aux_info_record (tree fndecl ATTRIBUTE_UNUSED,
1061 int is_definition ATTRIBUTE_UNUSED,
1062 int is_implicit ATTRIBUTE_UNUSED,
1063 int is_prototyped ATTRIBUTE_UNUSED)
1065 abort ();
1068 /* Should not be called for treelang, but it is. */
1070 void
1071 c_parse_init ()
1073 return;
1076 /* Should not be called for treelang. */
1078 void maybe_apply_pragma_weak (tree decl);
1080 void
1081 maybe_apply_pragma_weak (tree decl ATTRIBUTE_UNUSED)
1083 abort ();
1086 /* Should not be called for treelang. */
1088 void
1089 add_decl_stmt (tree decl ATTRIBUTE_UNUSED)
1091 abort ();
1094 /* Should not be called for treelang. */
1096 tree
1097 maybe_apply_renaming_pragma (tree decl, tree asmname);
1099 /* Should not be called for treelang. */
1101 tree
1102 maybe_apply_renaming_pragma (tree decl ATTRIBUTE_UNUSED, tree asmname ATTRIBUTE_UNUSED)
1104 abort ();
1107 /* Should not be called for treelang. */
1109 void
1110 begin_stmt_tree (tree *t ATTRIBUTE_UNUSED)
1112 abort ();
1115 /* Should not be called for treelang. */
1117 void
1118 finish_stmt_tree (tree *t ATTRIBUTE_UNUSED)
1120 abort ();
1123 /* Should not be called for treelang. */
1126 defer_fn (tree fn ATTRIBUTE_UNUSED)
1128 abort ();
1131 /* Should not be called for treelang. */
1133 cpp_options
1134 *cpp_get_options (cpp_reader * cr ATTRIBUTE_UNUSED)
1136 abort ();
1139 /* Should not be called for treelang. */
1141 void
1142 cpp_define (cpp_reader * cr ATTRIBUTE_UNUSED, const char * c ATTRIBUTE_UNUSED)
1144 abort ();
1147 /* Should not be called for treelang. */
1149 cpp_callbacks *
1150 cpp_get_callbacks (cpp_reader * cr ATTRIBUTE_UNUSED)
1152 abort ();
1155 /* Create the predefined scalar types of C,
1156 and some nodes representing standard constants (0, 1, (void *) 0).
1157 Initialize the global binding level.
1158 Make definitions for built-in primitive functions. */
1160 /* `unsigned long' is the standard type for sizeof.
1161 Note that stddef.h uses `unsigned long',
1162 and this must agree, even if long and int are the same size. */
1164 /* This variable keeps a table for types for each precision so that we
1165 only allocate each of them once. Signed and unsigned types are
1166 kept separate. */
1168 tree integer_types[itk_none] = { NULL_TREE};
1170 /* The reserved keyword table. */
1171 struct resword
1173 const char *word;
1174 ENUM_BITFIELD(rid) rid : 16;
1175 unsigned int disable : 16;
1178 static const struct resword reswords[] =
1180 { "_Bool", RID_BOOL, 0 },
1181 { "_Complex", RID_COMPLEX, 0 },
1182 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
1183 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
1184 { "__alignof", RID_ALIGNOF, 0 },
1185 { "__alignof__", RID_ALIGNOF, 0 },
1186 { "__asm", RID_ASM, 0 },
1187 { "__asm__", RID_ASM, 0 },
1188 { "__attribute", RID_ATTRIBUTE, 0 },
1189 { "__attribute__", RID_ATTRIBUTE, 0 },
1190 { "__bounded", RID_BOUNDED, 0 },
1191 { "__bounded__", RID_BOUNDED, 0 },
1192 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
1193 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
1194 { "__builtin_va_arg", RID_VA_ARG, 0 },
1195 { "__complex", RID_COMPLEX, 0 },
1196 { "__complex__", RID_COMPLEX, 0 },
1197 { "__const", RID_CONST, 0 },
1198 { "__const__", RID_CONST, 0 },
1199 { "__extension__", RID_EXTENSION, 0 },
1200 { "__func__", RID_C99_FUNCTION_NAME, 0 },
1201 { "__imag", RID_IMAGPART, 0 },
1202 { "__imag__", RID_IMAGPART, 0 },
1203 { "__inline", RID_INLINE, 0 },
1204 { "__inline__", RID_INLINE, 0 },
1205 { "__label__", RID_LABEL, 0 },
1206 { "__ptrbase", RID_PTRBASE, 0 },
1207 { "__ptrbase__", RID_PTRBASE, 0 },
1208 { "__ptrextent", RID_PTREXTENT, 0 },
1209 { "__ptrextent__", RID_PTREXTENT, 0 },
1210 { "__ptrvalue", RID_PTRVALUE, 0 },
1211 { "__ptrvalue__", RID_PTRVALUE, 0 },
1212 { "__real", RID_REALPART, 0 },
1213 { "__real__", RID_REALPART, 0 },
1214 { "__restrict", RID_RESTRICT, 0 },
1215 { "__restrict__", RID_RESTRICT, 0 },
1216 { "__signed", RID_SIGNED, 0 },
1217 { "__signed__", RID_SIGNED, 0 },
1218 { "__typeof", RID_TYPEOF, 0 },
1219 { "__typeof__", RID_TYPEOF, 0 },
1220 { "__unbounded", RID_UNBOUNDED, 0 },
1221 { "__unbounded__", RID_UNBOUNDED, 0 },
1222 { "__volatile", RID_VOLATILE, 0 },
1223 { "__volatile__", RID_VOLATILE, 0 },
1224 { "asm", RID_ASM, 0 },
1225 { "auto", RID_AUTO, 0 },
1226 { "break", RID_BREAK, 0 },
1227 { "case", RID_CASE, 0 },
1228 { "char", RID_CHAR, 0 },
1229 { "const", RID_CONST, 0 },
1230 { "continue", RID_CONTINUE, 0 },
1231 { "default", RID_DEFAULT, 0 },
1232 { "do", RID_DO, 0 },
1233 { "double", RID_DOUBLE, 0 },
1234 { "else", RID_ELSE, 0 },
1235 { "enum", RID_ENUM, 0 },
1236 { "extern", RID_EXTERN, 0 },
1237 { "float", RID_FLOAT, 0 },
1238 { "for", RID_FOR, 0 },
1239 { "goto", RID_GOTO, 0 },
1240 { "if", RID_IF, 0 },
1241 { "inline", RID_INLINE, 0 },
1242 { "int", RID_INT, 0 },
1243 { "long", RID_LONG, 0 },
1244 { "register", RID_REGISTER, 0 },
1245 { "restrict", RID_RESTRICT, 0 },
1246 { "return", RID_RETURN, 0 },
1247 { "short", RID_SHORT, 0 },
1248 { "signed", RID_SIGNED, 0 },
1249 { "sizeof", RID_SIZEOF, 0 },
1250 { "static", RID_STATIC, 0 },
1251 { "struct", RID_STRUCT, 0 },
1252 { "switch", RID_SWITCH, 0 },
1253 { "typedef", RID_TYPEDEF, 0 },
1254 { "typeof", RID_TYPEOF, 0 },
1255 { "union", RID_UNION, 0 },
1256 { "unsigned", RID_UNSIGNED, 0 },
1257 { "void", RID_VOID, 0 },
1258 { "volatile", RID_VOLATILE, 0 },
1259 { "while", RID_WHILE, 0 },
1261 #define N_reswords (sizeof reswords / sizeof (struct resword))
1263 /* Init enough to allow the C decl code to work, then clean up
1264 afterwards. */
1266 void
1267 treelang_init_decl_processing ()
1269 unsigned int i;
1270 tree id;
1272 /* It is not necessary to register ridpointers as a GC root, because
1273 all the trees it points to are permanently interned in the
1274 get_identifier hash anyway. */
1275 ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
1277 for (i = 0; i < N_reswords; i++)
1279 id = get_identifier (reswords[i].word);
1280 C_RID_CODE (id) = reswords[i].rid;
1281 C_IS_RESERVED_WORD (id) = 1;
1282 ridpointers [(int) reswords[i].rid] = id;
1285 c_init_decl_processing ();
1287 /* ix86_return_pops_args takes the type of these so need to patch
1288 their own type as themselves. */
1290 for (i = 0; i < itk_none; i++)
1292 if (integer_types[i])
1293 TREE_TYPE (integer_types [i]) = integer_types[i];
1296 /* Probably these ones too. */
1297 TREE_TYPE (float_type_node) = float_type_node;
1298 TREE_TYPE (double_type_node) = double_type_node;
1299 TREE_TYPE (long_double_type_node) = long_double_type_node;
1303 /* Save typing debug_tree all the time. Dump a tree T pretty and
1304 concise. */
1306 void dt (tree t);
1308 void
1309 dt (tree t)
1311 debug_tree (t);