2003-03-11 Aldy Hernandez <aldyh@redhat.com>
[official-gcc.git] / gcc / treelang / treetree.c
blobcc5455963fa91520e02e101d3e6ae71f6b6f1123
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 "parse.h"
78 extern int option_main;
79 extern char **file_names;
81 /* The front end language hooks (addresses of code for this front
82 end). Mostly just use the C routines. */
84 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
85 #define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion
86 #undef LANG_HOOKS_MARK_ADDRESSABLE
87 #define LANG_HOOKS_MARK_ADDRESSABLE c_mark_addressable
88 #undef LANG_HOOKS_SIGNED_TYPE
89 #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type
90 #undef LANG_HOOKS_UNSIGNED_TYPE
91 #define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type
92 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
93 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
94 #undef LANG_HOOKS_TYPE_FOR_MODE
95 #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
96 #undef LANG_HOOKS_TYPE_FOR_SIZE
97 #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size
98 #undef LANG_HOOKS_PARSE_FILE
99 #define LANG_HOOKS_PARSE_FILE treelang_parse_file
100 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
101 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE c_common_attribute_table
102 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
103 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE c_common_format_attribute_table
104 #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES
105 #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES c_insert_default_attributes
107 /* Hook routines and data unique to treelang. */
109 #undef LANG_HOOKS_INIT
110 #define LANG_HOOKS_INIT treelang_init
111 #undef LANG_HOOKS_NAME
112 #define LANG_HOOKS_NAME "GNU treelang"
113 #undef LANG_HOOKS_FINISH
114 #define LANG_HOOKS_FINISH treelang_finish
115 #undef LANG_HOOKS_DECODE_OPTION
116 #define LANG_HOOKS_DECODE_OPTION treelang_decode_option
117 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
119 /* Tree code type/name/code tables. */
121 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
123 const char tree_code_type[] = {
124 #include "tree.def"
127 #undef DEFTREECODE
129 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
131 const unsigned char tree_code_length[] = {
132 #include "tree.def"
135 #undef DEFTREECODE
137 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
139 const char *const tree_code_name[] = {
140 #include "tree.def"
141 "@@dummy"
143 #undef DEFTREECODE
145 /* Number of bits in int and char - accessed by front end. */
147 unsigned int tree_code_int_size = 0;
148 unsigned int tree_code_char_size = 0;
150 /* Return the tree stuff for this type TYPE_NUM. */
152 tree
153 tree_code_get_type (int type_num)
155 switch (type_num)
157 case SIGNED_CHAR:
158 return signed_char_type_node;
160 case UNSIGNED_CHAR:
161 return unsigned_char_type_node;
163 case SIGNED_INT:
164 return integer_type_node;
166 case UNSIGNED_INT:
167 return unsigned_type_node;
169 case VOID_TYPE:
170 return void_type_node;
172 default:
173 abort ();
177 /* Output the code for the start of an if statement. The test
178 expression is EXP (true if not zero), and the stmt occurred at line
179 LINENO in file FILENAME. */
181 void
182 tree_code_if_start (tree exp, const char* filename, int lineno)
184 tree cond_exp;
185 cond_exp = build (NE_EXPR,
186 TREE_TYPE (exp),
187 exp,
188 build1 (CONVERT_EXPR, TREE_TYPE (exp), integer_zero_node));
189 emit_line_note (filename, lineno); /* Output the line number information. */
190 expand_start_cond (cond_exp, /* Exit-able if nonzero. */ 0);
193 /* Output the code for the else of an if statement. The else occurred
194 at line LINENO in file FILENAME. */
196 void
197 tree_code_if_else (const char* filename, int lineno)
199 emit_line_note (filename, lineno); /* Output the line number information. */
200 expand_start_else ();
203 /* Output the code for the end_if an if statement. The end_if (final brace) occurred
204 at line LINENO in file FILENAME. */
206 void
207 tree_code_if_end (const char* filename, int lineno)
209 emit_line_note (filename, lineno); /* Output the line number information. */
210 expand_end_cond ();
213 /* Create a function. The prototype name is NAME, storage class is
214 STORAGE_CLASS, type of return variable is RET_TYPE, parameter lists
215 is PARMS, returns decl for this function. */
217 tree
218 tree_code_create_function_prototype (unsigned char* chars,
219 unsigned int storage_class,
220 unsigned int ret_type,
221 struct prod_token_parm_item* parms,
222 const char* filename,
223 int lineno)
226 tree id;
227 struct prod_token_parm_item* parm;
228 tree type_list = NULL_TREE;
229 tree type_node;
230 tree fn_type;
231 tree fn_decl;
233 /* Build the type. */
234 id = get_identifier ((const char*)chars);
235 for (parm = parms; parm; parm = parm->tp.par.next)
237 if (parm->category != parameter_category)
238 abort ();
239 type_node = get_type_for_numeric_type (parm->type);
240 type_list = tree_cons (NULL_TREE, type_node, type_list);
242 /* Last parm if void indicates fixed length list (as opposed to
243 printf style va_* list). */
244 type_list = tree_cons (NULL_TREE, void_type_node, type_list);
245 /* The back end needs them in reverse order. */
246 type_list = nreverse (type_list);
248 type_node = get_type_for_numeric_type (ret_type);
249 fn_type = build_function_type (type_node, type_list);
251 id = get_identifier ((const char*)chars);
252 fn_decl = build_decl (FUNCTION_DECL, id, fn_type);
254 DECL_CONTEXT (fn_decl) = NULL_TREE; /* Nested functions not supported here. */
255 DECL_SOURCE_FILE (fn_decl) = filename;
256 /* if (lineno > 1000000)
257 ; */ /* Probably the line # is rubbish because someone forgot to set
258 the line number - and unfortunately impossible line #s are used as
259 magic flags at various times. The longest known function for
260 example is about 550,000 lines (it was written in COBOL). */
261 DECL_SOURCE_LINE (fn_decl) = lineno;
263 TREE_USED (fn_decl) = 1;
265 /* Real name (optional). */
266 SET_DECL_ASSEMBLER_NAME (fn_decl, DECL_NAME (fn_decl));
268 TREE_PUBLIC (fn_decl) = 0;
269 DECL_EXTERNAL (fn_decl) = 0;
270 TREE_STATIC (fn_decl) = 0;
271 switch (storage_class)
273 case STATIC_STORAGE:
274 TREE_PUBLIC (fn_decl) = 0;
275 break;
277 case EXTERNAL_DEFINITION_STORAGE:
278 TREE_PUBLIC (fn_decl) = 1;
279 TREE_STATIC (fn_decl) = 0;
280 DECL_EXTERNAL (fn_decl) = 0;
281 break;
283 case EXTERNAL_REFERENCE_STORAGE:
284 TREE_PUBLIC (fn_decl) = 0;
285 DECL_EXTERNAL (fn_decl) = 1;
286 break;
289 case AUTOMATIC_STORAGE:
290 default:
291 abort ();
294 /* Process declaration of function defined elsewhere. */
295 rest_of_decl_compilation (fn_decl, NULL, 1, 0);
297 return fn_decl;
301 /* Output code for start of function; the decl of the function is in
302 PREV_SAVED (as created by tree_code_create_function_prototype),
303 the function is at line number LINENO in file FILENAME. The
304 parameter details are in the lists PARMS. Returns nothing. */
305 void
306 tree_code_create_function_initial (tree prev_saved,
307 const char* filename,
308 int lineno,
309 struct prod_token_parm_item* parms)
311 tree fn_decl;
312 tree param_decl;
313 tree next_param;
314 tree first_param;
315 tree parm_decl;
316 tree parm_list;
317 tree resultdecl;
318 struct prod_token_parm_item* this_parm;
319 struct prod_token_parm_item* parm;
321 fn_decl = prev_saved;
322 if (!fn_decl)
323 abort ();
325 /* Output message if not -quiet. */
326 announce_function (fn_decl);
328 /* This has something to do with forcing output also. */
329 pushdecl (fn_decl);
331 /* Set current function for error msgs etc. */
332 current_function_decl = fn_decl;
333 DECL_INITIAL (fn_decl) = error_mark_node;
335 DECL_SOURCE_FILE (fn_decl) = filename;
336 DECL_SOURCE_LINE (fn_decl) = lineno;
338 /* Prepare creation of rtl for a new function. */
340 resultdecl = DECL_RESULT (fn_decl) = build_decl (RESULT_DECL, NULL_TREE, TREE_TYPE (TREE_TYPE (fn_decl)));
341 DECL_CONTEXT (DECL_RESULT (fn_decl)) = fn_decl;
342 DECL_SOURCE_FILE (resultdecl) = filename;
343 DECL_SOURCE_LINE (resultdecl) = lineno;
344 /* Work out the size. ??? is this needed. */
345 layout_decl (DECL_RESULT (fn_decl), 0);
347 /* Make the argument variable decls. */
348 parm_list = NULL_TREE;
349 for (parm = parms; parm; parm = parm->tp.par.next)
351 parm_decl = build_decl (PARM_DECL, get_identifier
352 ((const char*) (parm->tp.par.variable_name)),
353 get_type_for_numeric_type (parm->type));
355 /* Some languages have different nominal and real types. */
356 DECL_ARG_TYPE (parm_decl) = TREE_TYPE (parm_decl);
357 if (!DECL_ARG_TYPE (parm_decl))
358 abort ();
359 if (!fn_decl)
360 abort ();
361 DECL_CONTEXT (parm_decl) = fn_decl;
362 DECL_SOURCE_FILE (parm_decl) = filename;
363 DECL_SOURCE_LINE (parm_decl) = lineno;
364 parm_list = chainon (parm_decl, parm_list);
367 /* Back into reverse order as the back end likes them. */
368 parm_list = nreverse (parm_list);
370 DECL_ARGUMENTS (fn_decl) = parm_list;
372 /* Save the decls for use when the args are referred to. */
373 for (param_decl = DECL_ARGUMENTS (fn_decl),
374 this_parm = parms;
375 param_decl;
376 param_decl = TREE_CHAIN (param_decl),
377 this_parm = this_parm->tp.par.next)
379 if (!this_parm)
380 abort (); /* Too few. */
381 *this_parm->tp.par.where_to_put_var_tree = param_decl;
383 if (this_parm)
384 abort (); /* Too many. */
386 /* Output the decl rtl (not the rtl for the function code). ???.
387 If the function is not defined in this file, when should you
388 execute this? */
389 make_decl_rtl (fn_decl, NULL);
391 /* Use filename/lineno from above. */
392 init_function_start (fn_decl, filename, lineno);
394 /* Create rtl for startup code of function, such as saving registers. */
396 expand_function_start (fn_decl, 0);
398 /* Function.c requires a push at the start of the function. that
399 looks like a bug to me but let's make it happy. */
401 (*lang_hooks.decls.pushlevel) (0);
403 /* Create rtl for the start of a new scope. */
405 expand_start_bindings (2);
407 /* Put the parameters into the symbol table. */
409 for (first_param = param_decl = nreverse (DECL_ARGUMENTS (fn_decl));
410 param_decl;
411 param_decl = next_param)
413 next_param = TREE_CHAIN (param_decl);
414 TREE_CHAIN (param_decl) = NULL;
415 /* layout_decl (param_decl, 0); Already done in build_decl tej 13/4/2002. */
416 pushdecl (param_decl);
417 if (DECL_CONTEXT (param_decl) != current_function_decl)
418 abort ();
421 /* Store back the PARM_DECL nodes. They appear in the right order. */
422 DECL_ARGUMENTS (fn_decl) = getdecls ();
424 /* Force it to be output, else may be solely inlined. */
425 TREE_ADDRESSABLE (fn_decl) = 1;
427 /* Stop -O3 from deleting it. */
428 TREE_USED (fn_decl) = 1;
430 /* Add a new level to the debugger symbol table. */
432 (*lang_hooks.decls.pushlevel) (0);
434 /* Create rtl for the start of a new scope. */
436 expand_start_bindings (0);
438 emit_line_note (filename, lineno); /* Output the line number information. */
441 /* Wrapup a function contained in file FILENAME, ending at line LINENO. */
442 void
443 tree_code_create_function_wrapup (const char* filename,
444 int lineno)
446 tree block;
447 tree fn_decl;
449 fn_decl = current_function_decl;
451 emit_line_note (filename, lineno); /* Output the line number information. */
453 /* Get completely built level from debugger symbol table. */
455 block = (*lang_hooks.decls.poplevel) (1, 0, 0);
457 /* Emit rtl for end of scope. */
459 expand_end_bindings (block, 0, 1);
461 /* Emit rtl for end of function. */
463 expand_function_end (filename, lineno, 0);
465 /* Pop the level. */
467 block = (*lang_hooks.decls.poplevel) (1, 0, 1);
469 /* And attach it to the function. */
471 DECL_INITIAL (fn_decl) = block;
473 /* Emit rtl for end of scope. */
475 expand_end_bindings (block, 0, 1);
477 /* Call optimization and convert optimized rtl to assembly code. */
479 rest_of_compilation (fn_decl);
481 /* We are not inside of any scope now. */
483 current_function_decl = NULL_TREE;
487 Create a variable.
489 The storage class is STORAGE_CLASS (eg LOCAL).
490 The name is CHARS/LENGTH.
491 The type is EXPRESSION_TYPE (eg UNSIGNED_TYPE).
492 The init tree is INIT.
495 tree
496 tree_code_create_variable (unsigned int storage_class,
497 unsigned char* chars,
498 unsigned int length,
499 unsigned int expression_type,
500 tree init,
501 const char* filename,
502 int lineno)
504 tree var_type;
505 tree var_id;
506 tree var_decl;
508 /* 1. Build the type. */
509 var_type = get_type_for_numeric_type (expression_type);
511 /* 2. Build the name. */
512 if (chars[length] != 0)
513 abort (); /* Should be null terminated. */
515 var_id = get_identifier ((const char*)chars);
517 /* 3. Build the decl and set up init. */
518 var_decl = build_decl (VAR_DECL, var_id, var_type);
520 /* 3a. Initialization. */
521 if (init)
522 DECL_INITIAL (var_decl) = build1 (CONVERT_EXPR, var_type, init);
523 else
524 DECL_INITIAL (var_decl) = NULL_TREE;
526 /* 4. Compute size etc. */
527 layout_decl (var_decl, 0);
529 if (TYPE_SIZE (var_type) == 0)
530 abort (); /* Did not calculate size. */
532 DECL_CONTEXT (var_decl) = current_function_decl;
534 DECL_SOURCE_FILE (var_decl) = filename;
535 DECL_SOURCE_LINE (var_decl) = lineno;
537 /* Set the storage mode and whether only visible in the same file. */
538 switch (storage_class)
540 case STATIC_STORAGE:
541 TREE_STATIC (var_decl) = 1;
542 TREE_PUBLIC (var_decl) = 0;
543 break;
545 case AUTOMATIC_STORAGE:
546 TREE_STATIC (var_decl) = 0;
547 TREE_PUBLIC (var_decl) = 0;
548 break;
550 case EXTERNAL_DEFINITION_STORAGE:
551 TREE_STATIC (var_decl) = 0;
552 TREE_PUBLIC (var_decl) = 1;
553 break;
555 case EXTERNAL_REFERENCE_STORAGE:
556 DECL_EXTERNAL (var_decl) = 1;
557 TREE_PUBLIC (var_decl) = 0;
558 break;
560 default:
561 abort ();
564 /* This should really only be set if the variable is used. */
565 TREE_USED (var_decl) = 1;
567 /* Expand declaration and initial value if any. */
569 if (TREE_STATIC (var_decl))
570 rest_of_decl_compilation (var_decl, 0, 0, 0);
571 else
573 expand_decl (var_decl);
574 if (DECL_INITIAL (var_decl))
575 expand_decl_init (var_decl);
578 return pushdecl (copy_node (var_decl));
583 /* Generate code for return statement. Type is in TYPE, expression
584 is in EXP if present. */
586 void
587 tree_code_generate_return (tree type, tree exp)
589 tree setret;
590 tree param;
592 for (param = DECL_ARGUMENTS (current_function_decl);
593 param;
594 param = TREE_CHAIN (param))
596 if (DECL_CONTEXT (param) != current_function_decl)
597 abort ();
600 if (exp)
602 setret = build (MODIFY_EXPR, type, DECL_RESULT (current_function_decl),
603 build1 (CONVERT_EXPR, type, exp));
604 TREE_SIDE_EFFECTS (setret) = 1;
605 TREE_USED (setret) = 1;
606 expand_expr_stmt (setret);
608 expand_return (DECL_RESULT (current_function_decl));
611 /* Output the code for this expression statement CODE. */
614 void
615 tree_code_output_expression_statement (tree code,
616 const char* filename, int lineno)
618 /* Output the line number information. */
619 emit_line_note (filename, lineno);
620 TREE_USED (code) = 1;
621 TREE_SIDE_EFFECTS (code) = 1;
622 expand_expr_stmt (code);
625 /* Return a tree for a constant integer value in the token TOK. No
626 size checking is done. */
628 tree
629 tree_code_get_integer_value (unsigned char* chars, unsigned int length)
631 long long int val = 0;
632 unsigned int ix;
633 unsigned int start = 0;
634 int negative = 1;
635 switch (chars[0])
637 case (unsigned char)'-':
638 negative = -1;
639 start = 1;
640 break;
642 case (unsigned char)'+':
643 start = 1;
644 break;
646 default:
647 break;
649 for (ix = start; ix < length; ix++)
650 val = val * 10 + chars[ix] - (unsigned char)'0';
651 val = val*negative;
652 return build_int_2 (val & 0xffffffff, (val >> 32) & 0xffffffff);
655 /* Return the tree for an expresssion, type EXP_TYPE (see treetree.h)
656 with tree type TYPE and with operands1 OP1, OP2 (maybe), OP3 (maybe). */
657 tree
658 tree_code_get_expression (unsigned int exp_type,
659 tree type, tree op1, tree op2, tree op3 ATTRIBUTE_UNUSED)
661 tree ret1;
662 int operator;
664 switch (exp_type)
666 case EXP_ASSIGN:
667 if (!op1 || !op2)
668 abort ();
669 operator = MODIFY_EXPR;
670 ret1 = build (operator, type,
671 op1,
672 build1 (CONVERT_EXPR, type, op2));
674 break;
676 case EXP_PLUS:
677 operator = PLUS_EXPR;
678 goto binary_expression;
680 case EXP_MINUS:
681 operator = MINUS_EXPR;
682 goto binary_expression;
684 case EXP_EQUALS:
685 operator = EQ_EXPR;
686 goto binary_expression;
688 /* Expand a binary expression. Ensure the operands are the right type. */
689 binary_expression:
690 if (!op1 || !op2)
691 abort ();
692 ret1 = build (operator, type,
693 build1 (CONVERT_EXPR, type, op1),
694 build1 (CONVERT_EXPR, type, op2));
695 break;
697 /* Reference to a variable. This is dead easy, just return the
698 decl for the variable. If the TYPE is different than the
699 variable type, convert it. */
700 case EXP_REFERENCE:
701 if (!op1)
702 abort ();
703 if (type == TREE_TYPE (op1))
704 ret1 = op1;
705 else
706 ret1 = build1 (CONVERT_EXPR, type, op1);
707 break;
709 case EXP_FUNCTION_INVOCATION:
710 if (!op1 || !op2)
711 abort ();
713 tree fun_ptr;
714 fun_ptr = build1 (ADDR_EXPR, build_pointer_type (type), op1);
715 ret1 = build (CALL_EXPR, type, fun_ptr, nreverse (op2));
717 break;
719 default:
720 abort ();
723 return ret1;
726 /* Init parameter list and return empty list. */
728 tree
729 tree_code_init_parameters (void)
731 return NULL_TREE;
734 /* Add a parameter EXP whose expression type is EXP_PROTO to list
735 LIST, returning the new list. */
737 tree
738 tree_code_add_parameter (tree list, tree proto_exp, tree exp)
740 tree new_exp;
741 new_exp = tree_cons (NULL_TREE,
742 build1 (CONVERT_EXPR, TREE_TYPE (proto_exp), exp),
743 NULL_TREE);
744 if (!list)
745 return new_exp;
746 return chainon (new_exp, list);
749 /* Get the tree type for this type whose number is NUMERIC_TYPE. */
751 tree
752 get_type_for_numeric_type (unsigned int numeric_type)
755 int size1;
756 int sign1;
757 switch (numeric_type)
759 case VOID_TYPE:
760 return void_type_node;
762 case SIGNED_INT:
763 size1 = tree_code_int_size;
764 sign1 = 1;
765 break;
767 case UNSIGNED_INT:
768 size1 = tree_code_int_size;
769 sign1 = 0;
770 break;
772 case SIGNED_CHAR:
773 size1 = tree_code_char_size;
774 sign1 = 1;
775 break;
777 case UNSIGNED_CHAR:
778 size1 = tree_code_char_size;
779 sign1 = 0;
780 break;
782 default:
783 abort ();
786 return tree_code_get_numeric_type (size1, sign1);
790 /* Return tree representing a numeric type of size SIZE1 bits and
791 signed if SIGN1 != 0. */
792 tree
793 tree_code_get_numeric_type (unsigned int size1, unsigned int sign1)
795 tree ret1;
796 if (size1 == tree_code_int_size)
798 if (sign1)
799 ret1 = integer_type_node;
800 else
801 ret1 = unsigned_type_node;
803 else
804 if (size1 == tree_code_char_size)
806 if (sign1)
807 ret1 = signed_char_type_node;
808 else
809 ret1 = unsigned_char_type_node;
811 else
812 abort ();
814 return ret1;
817 /* Garbage Collection. */
819 /* Callback to mark storage M as used always. */
821 void
822 tree_ggc_storage_always_used (void * m)
824 void **mm; /* Actually M is a pointer to a pointer to the memory. */
825 mm = (void**)m;
827 if (*mm)
828 ggc_mark (*mm);
831 /* Following from c-lang.c. */
833 /* Used by c-typeck.c (build_external_ref), but only for objc. */
835 tree
836 lookup_objc_ivar (tree id ATTRIBUTE_UNUSED)
838 return 0;
841 /* Dummy routines called from c code. Save copying c-decl.c, c-common.c etc. */
843 tree
844 objc_is_id (tree arg ATTRIBUTE_UNUSED)
846 return 0;
849 void
850 check_function_format (int *status ATTRIBUTE_UNUSED,
851 tree attrs ATTRIBUTE_UNUSED,
852 tree params ATTRIBUTE_UNUSED)
854 return;
857 /* Tell the c code we are not objective C. */
860 objc_comptypes (tree lhs ATTRIBUTE_UNUSED,
861 tree rhs ATTRIBUTE_UNUSED,
862 int reflexive ATTRIBUTE_UNUSED)
864 return 0;
867 /* Should not be called for treelang. */
869 tree
870 build_stmt VPARAMS ((enum tree_code code ATTRIBUTE_UNUSED, ...))
872 abort ();
875 /* Should not be called for treelang. */
877 tree
878 add_stmt (tree t ATTRIBUTE_UNUSED)
880 abort ();
883 /* Should not be called for treelang. */
885 tree
886 build_return_stmt (tree expr ATTRIBUTE_UNUSED)
888 abort ();
891 /* C warning, ignore. */
893 void
894 pedwarn_c99 VPARAMS ((const char *msgid ATTRIBUTE_UNUSED, ...))
896 return;
899 /* Should not be called for treelang. */
901 tree
902 build_case_label (tree low_value ATTRIBUTE_UNUSED,
903 tree high_value ATTRIBUTE_UNUSED,
904 tree label_decl ATTRIBUTE_UNUSED)
906 abort ();
909 /* Should not be called for treelang. */
911 void
912 emit_local_var (tree decl ATTRIBUTE_UNUSED)
914 abort ();
917 /* Should not be called for treelang. */
919 void
920 expand_stmt (tree t ATTRIBUTE_UNUSED)
922 abort ();
925 /* Should not be called for treelang. */
927 cpp_reader *
928 cpp_create_reader (enum c_lang lang ATTRIBUTE_UNUSED)
930 abort ();
933 /* Should not be called for treelang. */
935 void
936 init_c_lex (void)
938 abort ();
941 /* Should not be called for treelang. */
943 void init_pragma (void);
945 void
946 init_pragma ()
948 abort ();
951 /* Should not be called for treelang. */
954 cpp_finish (cpp_reader *pfile ATTRIBUTE_UNUSED, FILE *f ATTRIBUTE_UNUSED)
956 abort ();
959 /* Should not be called for treelang. */
961 unsigned int
962 cpp_errors (cpp_reader *pfile ATTRIBUTE_UNUSED)
964 abort ();
967 /* Dummy called by C. */
969 tree
970 handle_format_attribute (tree *node ATTRIBUTE_UNUSED,
971 tree name ATTRIBUTE_UNUSED,
972 tree args ATTRIBUTE_UNUSED,
973 int flags ATTRIBUTE_UNUSED,
974 bool *no_add_attrs ATTRIBUTE_UNUSED)
976 return NULL_TREE;
979 /* Should not be called for treelang. */
981 tree
982 handle_format_arg_attribute (tree *node ATTRIBUTE_UNUSED,
983 tree name ATTRIBUTE_UNUSED,
984 tree args ATTRIBUTE_UNUSED,
985 int flags ATTRIBUTE_UNUSED,
986 bool *no_add_attrs ATTRIBUTE_UNUSED)
988 abort ();
991 /* Should not be called for treelang. */
994 cpp_handle_option (cpp_reader *pfile ATTRIBUTE_UNUSED,
995 int argc ATTRIBUTE_UNUSED,
996 char **argv ATTRIBUTE_UNUSED)
998 abort ();
1001 /* Should not be called for treelang. */
1003 void
1004 cpp_assert (cpp_reader * cr ATTRIBUTE_UNUSED,
1005 const char *s ATTRIBUTE_UNUSED)
1007 abort ();
1010 /* Should not be called for treelang. */
1012 void
1013 set_Wformat (int setting ATTRIBUTE_UNUSED)
1015 abort ();
1018 /* Used for objective C. */
1020 void
1021 objc_check_decl (tree decl ATTRIBUTE_UNUSED);
1023 void
1024 objc_check_decl (tree decl ATTRIBUTE_UNUSED)
1026 abort ();
1029 /* Tell the c code we are not objective C. */
1031 tree
1032 objc_message_selector (void);
1034 tree
1035 objc_message_selector ()
1037 return 0;
1040 /* Should not be called for treelang. */
1042 void
1043 gen_aux_info_record (tree fndecl ATTRIBUTE_UNUSED,
1044 int is_definition ATTRIBUTE_UNUSED,
1045 int is_implicit ATTRIBUTE_UNUSED,
1046 int is_prototyped ATTRIBUTE_UNUSED)
1048 abort ();
1051 /* Should not be called for treelang, but it is. */
1053 void
1054 c_parse_init ()
1056 return;
1059 /* Should not be called for treelang. */
1061 void maybe_apply_pragma_weak (tree decl);
1063 void
1064 maybe_apply_pragma_weak (tree decl ATTRIBUTE_UNUSED)
1066 abort ();
1069 /* Should not be called for treelang. */
1071 void
1072 add_decl_stmt (tree decl ATTRIBUTE_UNUSED)
1074 abort ();
1077 /* Should not be called for treelang. */
1079 tree
1080 maybe_apply_renaming_pragma (tree decl, tree asmname);
1082 /* Should not be called for treelang. */
1084 tree
1085 maybe_apply_renaming_pragma (tree decl ATTRIBUTE_UNUSED, tree asmname ATTRIBUTE_UNUSED)
1087 abort ();
1090 /* Should not be called for treelang. */
1092 void
1093 begin_stmt_tree (tree *t ATTRIBUTE_UNUSED)
1095 abort ();
1098 /* Should not be called for treelang. */
1100 void
1101 finish_stmt_tree (tree *t ATTRIBUTE_UNUSED)
1103 abort ();
1106 /* Should not be called for treelang. */
1109 defer_fn (tree fn ATTRIBUTE_UNUSED)
1111 abort ();
1114 /* Should not be called for treelang. */
1116 cpp_options
1117 *cpp_get_options (cpp_reader * cr ATTRIBUTE_UNUSED)
1119 abort ();
1122 /* Should not be called for treelang. */
1124 void
1125 cpp_define (cpp_reader * cr ATTRIBUTE_UNUSED, const char * c ATTRIBUTE_UNUSED)
1127 abort ();
1130 /* Should not be called for treelang. */
1132 cpp_callbacks *
1133 cpp_get_callbacks (cpp_reader * cr ATTRIBUTE_UNUSED)
1135 abort ();
1138 /* Create the predefined scalar types of C,
1139 and some nodes representing standard constants (0, 1, (void *) 0).
1140 Initialize the global binding level.
1141 Make definitions for built-in primitive functions. */
1143 /* `unsigned long' is the standard type for sizeof.
1144 Note that stddef.h uses `unsigned long',
1145 and this must agree, even if long and int are the same size. */
1147 /* The reserved keyword table. */
1148 struct resword
1150 const char *word;
1151 ENUM_BITFIELD(rid) rid : 16;
1152 unsigned int disable : 16;
1155 static const struct resword reswords[] =
1157 { "_Bool", RID_BOOL, 0 },
1158 { "_Complex", RID_COMPLEX, 0 },
1159 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
1160 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
1161 { "__alignof", RID_ALIGNOF, 0 },
1162 { "__alignof__", RID_ALIGNOF, 0 },
1163 { "__asm", RID_ASM, 0 },
1164 { "__asm__", RID_ASM, 0 },
1165 { "__attribute", RID_ATTRIBUTE, 0 },
1166 { "__attribute__", RID_ATTRIBUTE, 0 },
1167 { "__bounded", RID_BOUNDED, 0 },
1168 { "__bounded__", RID_BOUNDED, 0 },
1169 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
1170 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
1171 { "__builtin_va_arg", RID_VA_ARG, 0 },
1172 { "__complex", RID_COMPLEX, 0 },
1173 { "__complex__", RID_COMPLEX, 0 },
1174 { "__const", RID_CONST, 0 },
1175 { "__const__", RID_CONST, 0 },
1176 { "__extension__", RID_EXTENSION, 0 },
1177 { "__func__", RID_C99_FUNCTION_NAME, 0 },
1178 { "__imag", RID_IMAGPART, 0 },
1179 { "__imag__", RID_IMAGPART, 0 },
1180 { "__inline", RID_INLINE, 0 },
1181 { "__inline__", RID_INLINE, 0 },
1182 { "__label__", RID_LABEL, 0 },
1183 { "__ptrbase", RID_PTRBASE, 0 },
1184 { "__ptrbase__", RID_PTRBASE, 0 },
1185 { "__ptrextent", RID_PTREXTENT, 0 },
1186 { "__ptrextent__", RID_PTREXTENT, 0 },
1187 { "__ptrvalue", RID_PTRVALUE, 0 },
1188 { "__ptrvalue__", RID_PTRVALUE, 0 },
1189 { "__real", RID_REALPART, 0 },
1190 { "__real__", RID_REALPART, 0 },
1191 { "__restrict", RID_RESTRICT, 0 },
1192 { "__restrict__", RID_RESTRICT, 0 },
1193 { "__signed", RID_SIGNED, 0 },
1194 { "__signed__", RID_SIGNED, 0 },
1195 { "__typeof", RID_TYPEOF, 0 },
1196 { "__typeof__", RID_TYPEOF, 0 },
1197 { "__unbounded", RID_UNBOUNDED, 0 },
1198 { "__unbounded__", RID_UNBOUNDED, 0 },
1199 { "__volatile", RID_VOLATILE, 0 },
1200 { "__volatile__", RID_VOLATILE, 0 },
1201 { "asm", RID_ASM, 0 },
1202 { "auto", RID_AUTO, 0 },
1203 { "break", RID_BREAK, 0 },
1204 { "case", RID_CASE, 0 },
1205 { "char", RID_CHAR, 0 },
1206 { "const", RID_CONST, 0 },
1207 { "continue", RID_CONTINUE, 0 },
1208 { "default", RID_DEFAULT, 0 },
1209 { "do", RID_DO, 0 },
1210 { "double", RID_DOUBLE, 0 },
1211 { "else", RID_ELSE, 0 },
1212 { "enum", RID_ENUM, 0 },
1213 { "extern", RID_EXTERN, 0 },
1214 { "float", RID_FLOAT, 0 },
1215 { "for", RID_FOR, 0 },
1216 { "goto", RID_GOTO, 0 },
1217 { "if", RID_IF, 0 },
1218 { "inline", RID_INLINE, 0 },
1219 { "int", RID_INT, 0 },
1220 { "long", RID_LONG, 0 },
1221 { "register", RID_REGISTER, 0 },
1222 { "restrict", RID_RESTRICT, 0 },
1223 { "return", RID_RETURN, 0 },
1224 { "short", RID_SHORT, 0 },
1225 { "signed", RID_SIGNED, 0 },
1226 { "sizeof", RID_SIZEOF, 0 },
1227 { "static", RID_STATIC, 0 },
1228 { "struct", RID_STRUCT, 0 },
1229 { "switch", RID_SWITCH, 0 },
1230 { "typedef", RID_TYPEDEF, 0 },
1231 { "typeof", RID_TYPEOF, 0 },
1232 { "union", RID_UNION, 0 },
1233 { "unsigned", RID_UNSIGNED, 0 },
1234 { "void", RID_VOID, 0 },
1235 { "volatile", RID_VOLATILE, 0 },
1236 { "while", RID_WHILE, 0 },
1238 #define N_reswords (sizeof reswords / sizeof (struct resword))
1240 /* Init enough to allow the C decl code to work, then clean up
1241 afterwards. */
1243 void
1244 treelang_init_decl_processing ()
1246 unsigned int i;
1247 tree id;
1249 ridpointers = (tree *) ggc_calloc ((int) RID_MAX, sizeof (tree));
1251 for (i = 0; i < N_reswords; i++)
1253 id = get_identifier (reswords[i].word);
1254 C_RID_CODE (id) = reswords[i].rid;
1255 C_IS_RESERVED_WORD (id) = 1;
1256 ridpointers [(int) reswords[i].rid] = id;
1259 c_init_decl_processing ();
1261 /* ix86_return_pops_args takes the type of these so need to patch
1262 their own type as themselves. */
1264 for (i = 0; i < itk_none; i++)
1266 if (integer_types[i])
1267 TREE_TYPE (integer_types [i]) = integer_types[i];
1270 /* Probably these ones too. */
1271 TREE_TYPE (float_type_node) = float_type_node;
1272 TREE_TYPE (double_type_node) = double_type_node;
1273 TREE_TYPE (long_double_type_node) = long_double_type_node;
1277 /* Save typing debug_tree all the time. Dump a tree T pretty and
1278 concise. */
1280 void dt (tree t);
1282 void
1283 dt (tree t)
1285 debug_tree (t);
1288 /* Get a stringpool entry for a string S of length L. This is needed
1289 because the GTY routines don't mark strings, forcing you to put
1290 them into stringpool, which is never freed. */
1292 const char*
1293 get_string (const char *s, size_t l)
1295 tree t;
1296 t = get_identifier_with_length (s, l);
1297 return IDENTIFIER_POINTER(t);