rtl.h (emit_line_note): Take a location_t.
[gcc.git] / gcc / treelang / treetree.c
1 /*
2
3 TREELANG Compiler back end interface (treetree.c)
4 Called by the parser.
5
6 If you want a working example of how to write a front end to GCC,
7 you are in the right place.
8
9 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
10 1999, 2000, 2001, 2002, 2003, Free Software Foundation, Inc.
11
12 This code is based on toy.c written by Richard Kenner.
13
14 It was later modified by Jonathan Bartlett whose changes have all
15 been removed (by Tim Josling).
16
17 Various bits and pieces were cloned from the GCC main tree, as
18 GCC evolved, for COBOLForGCC, by Tim Josling.
19
20 It was adapted to TREELANG by Tim Josling 2001.
21
22 ---------------------------------------------------------------------------
23
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.
28
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.
33
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.
38
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!
42
43 ---------------------------------------------------------------------------
44
45 */
46
47 /*
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. */
53
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. */
56
57 /* GCC headers. */
58
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"
73
74 #include "treelang.h"
75 #include "treetree.h"
76 #include "opts.h"
77
78 extern int option_main;
79 extern char **file_names;
80
81 /* The front end language hooks (addresses of code for this front
82 end). Mostly just use the C routines. */
83
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
106
107 /* Hook routines and data unique to treelang. */
108
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_INIT_OPTIONS
116 #define LANG_HOOKS_INIT_OPTIONS treelang_init_options
117 #undef LANG_HOOKS_HANDLE_OPTION
118 #define LANG_HOOKS_HANDLE_OPTION treelang_handle_option
119 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
120
121 /* Tree code type/name/code tables. */
122
123 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
124
125 const char tree_code_type[] = {
126 #include "tree.def"
127 'x'
128 };
129 #undef DEFTREECODE
130
131 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
132
133 const unsigned char tree_code_length[] = {
134 #include "tree.def"
135 0
136 };
137 #undef DEFTREECODE
138
139 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
140
141 const char *const tree_code_name[] = {
142 #include "tree.def"
143 "@@dummy"
144 };
145 #undef DEFTREECODE
146
147 /* Number of bits in int and char - accessed by front end. */
148
149 unsigned int tree_code_int_size = SIZEOF_INT * HOST_BITS_PER_CHAR;
150
151 unsigned int tree_code_char_size = HOST_BITS_PER_CHAR;
152
153 /* Return the tree stuff for this type TYPE_NUM. */
154
155 tree
156 tree_code_get_type (int type_num)
157 {
158 switch (type_num)
159 {
160 case SIGNED_CHAR:
161 return signed_char_type_node;
162
163 case UNSIGNED_CHAR:
164 return unsigned_char_type_node;
165
166 case SIGNED_INT:
167 return integer_type_node;
168
169 case UNSIGNED_INT:
170 return unsigned_type_node;
171
172 case VOID_TYPE:
173 return void_type_node;
174
175 default:
176 abort ();
177 }
178 }
179
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. */
183
184 void
185 tree_code_if_start (tree exp, location_t loc)
186 {
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); /* Output the line number information. */
193 expand_start_cond (cond_exp, /* Exit-able if nonzero. */ 0);
194 }
195
196 /* Output the code for the else of an if statement. The else occurred
197 at line LINENO in file FILENAME. */
198
199 void
200 tree_code_if_else (location_t loc)
201 {
202 emit_line_note (loc); /* Output the line number information. */
203 expand_start_else ();
204 }
205
206 /* Output the code for the end_if an if statement. The end_if (final brace) occurred
207 at line LINENO in file FILENAME. */
208
209 void
210 tree_code_if_end (location_t loc)
211 {
212 emit_line_note (loc); /* Output the line number information. */
213 expand_end_cond ();
214 }
215
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. */
219
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)
226 {
227
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;
234
235 /* Build the type. */
236 id = get_identifier ((const char*)chars);
237 for (parm = parms; parm; parm = parm->tp.par.next)
238 {
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);
243 }
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);
249
250 type_node = get_type_for_numeric_type (ret_type);
251 fn_type = build_function_type (type_node, type_list);
252
253 id = get_identifier ((const char*)chars);
254 fn_decl = build_decl (FUNCTION_DECL, id, fn_type);
255
256 DECL_CONTEXT (fn_decl) = NULL_TREE; /* Nested functions not supported here. */
257 DECL_SOURCE_LOCATION (fn_decl) = loc;
258
259 TREE_USED (fn_decl) = 1;
260
261 /* Real name (optional). */
262 SET_DECL_ASSEMBLER_NAME (fn_decl, DECL_NAME (fn_decl));
263
264 TREE_PUBLIC (fn_decl) = 0;
265 DECL_EXTERNAL (fn_decl) = 0;
266 TREE_STATIC (fn_decl) = 0;
267 switch (storage_class)
268 {
269 case STATIC_STORAGE:
270 TREE_PUBLIC (fn_decl) = 0;
271 break;
272
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;
278
279 case EXTERNAL_REFERENCE_STORAGE:
280 TREE_PUBLIC (fn_decl) = 0;
281 DECL_EXTERNAL (fn_decl) = 1;
282 break;
283
284
285 case AUTOMATIC_STORAGE:
286 default:
287 abort ();
288 }
289
290 /* Process declaration of function defined elsewhere. */
291 rest_of_decl_compilation (fn_decl, NULL, 1, 0);
292
293 return fn_decl;
294 }
295
296
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)
305 {
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;
315
316 fn_decl = prev_saved;
317 if (!fn_decl)
318 abort ();
319
320 /* Output message if not -quiet. */
321 announce_function (fn_decl);
322
323 /* This has something to do with forcing output also. */
324 pushdecl (fn_decl);
325
326 /* Set current function for error msgs etc. */
327 current_function_decl = fn_decl;
328 DECL_INITIAL (fn_decl) = error_mark_node;
329
330 DECL_SOURCE_LOCATION (fn_decl) = loc;
331
332 /* Prepare creation of rtl for a new function. */
333
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;
338
339 /* Work out the size. ??? is this needed. */
340 layout_decl (DECL_RESULT (fn_decl), 0);
341
342 /* Make the argument variable decls. */
343 parm_list = NULL_TREE;
344 for (parm = parms; parm; parm = parm->tp.par.next)
345 {
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));
349
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);
359 }
360
361 /* Back into reverse order as the back end likes them. */
362 parm_list = nreverse (parm_list);
363
364 DECL_ARGUMENTS (fn_decl) = parm_list;
365
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)
372 {
373 if (!this_parm)
374 abort (); /* Too few. */
375 *this_parm->tp.par.where_to_put_var_tree = param_decl;
376 }
377 if (this_parm)
378 abort (); /* Too many. */
379
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);
384
385 init_function_start (fn_decl);
386
387 /* Create rtl for startup code of function, such as saving registers. */
388
389 expand_function_start (fn_decl, 0);
390
391 /* Function.c requires a push at the start of the function. that
392 looks like a bug to me but let's make it happy. */
393
394 (*lang_hooks.decls.pushlevel) (0);
395
396 /* Create rtl for the start of a new scope. */
397
398 expand_start_bindings (2);
399
400 /* Put the parameters into the symbol table. */
401
402 for (first_param = param_decl = nreverse (DECL_ARGUMENTS (fn_decl));
403 param_decl;
404 param_decl = next_param)
405 {
406 next_param = TREE_CHAIN (param_decl);
407 TREE_CHAIN (param_decl) = NULL;
408 /* layout_decl (param_decl, 0); Already done in build_decl tej 13/4/2002. */
409 pushdecl (param_decl);
410 if (DECL_CONTEXT (param_decl) != current_function_decl)
411 abort ();
412 }
413
414 /* Store back the PARM_DECL nodes. They appear in the right order. */
415 DECL_ARGUMENTS (fn_decl) = getdecls ();
416
417 /* Force it to be output, else may be solely inlined. */
418 TREE_ADDRESSABLE (fn_decl) = 1;
419
420 /* Stop -O3 from deleting it. */
421 TREE_USED (fn_decl) = 1;
422
423 /* Add a new level to the debugger symbol table. */
424
425 (*lang_hooks.decls.pushlevel) (0);
426
427 /* Create rtl for the start of a new scope. */
428
429 expand_start_bindings (0);
430
431 emit_line_note (loc); /* Output the line number information. */
432 }
433
434 /* Wrapup a function contained in file FILENAME, ending at line LINENO. */
435 void
436 tree_code_create_function_wrapup (location_t loc)
437 {
438 tree block;
439 tree fn_decl;
440
441 fn_decl = current_function_decl;
442
443 emit_line_note (loc); /* Output the line number information. */
444
445 /* Get completely built level from debugger symbol table. */
446
447 block = (*lang_hooks.decls.poplevel) (1, 0, 0);
448
449 /* Emit rtl for end of scope. */
450
451 expand_end_bindings (block, 0, 1);
452
453 /* Emit rtl for end of function. */
454
455 expand_function_end ();
456
457 /* Pop the level. */
458
459 block = (*lang_hooks.decls.poplevel) (1, 0, 1);
460
461 /* And attach it to the function. */
462
463 DECL_INITIAL (fn_decl) = block;
464
465 /* Emit rtl for end of scope. */
466
467 expand_end_bindings (block, 0, 1);
468
469 /* Call optimization and convert optimized rtl to assembly code. */
470
471 rest_of_compilation (fn_decl);
472
473 /* We are not inside of any scope now. */
474
475 current_function_decl = NULL_TREE;
476 }
477
478 /*
479 Create a variable.
480
481 The storage class is STORAGE_CLASS (eg LOCAL).
482 The name is CHARS/LENGTH.
483 The type is EXPRESSION_TYPE (eg UNSIGNED_TYPE).
484 The init tree is INIT.
485 */
486
487 tree
488 tree_code_create_variable (unsigned int storage_class,
489 unsigned char* chars,
490 unsigned int length,
491 unsigned int expression_type,
492 tree init,
493 location_t loc)
494 {
495 tree var_type;
496 tree var_id;
497 tree var_decl;
498
499 /* 1. Build the type. */
500 var_type = get_type_for_numeric_type (expression_type);
501
502 /* 2. Build the name. */
503 if (chars[length] != 0)
504 abort (); /* Should be null terminated. */
505
506 var_id = get_identifier ((const char*)chars);
507
508 /* 3. Build the decl and set up init. */
509 var_decl = build_decl (VAR_DECL, var_id, var_type);
510
511 /* 3a. Initialization. */
512 if (init)
513 DECL_INITIAL (var_decl) = build1 (CONVERT_EXPR, var_type, init);
514 else
515 DECL_INITIAL (var_decl) = NULL_TREE;
516
517 /* 4. Compute size etc. */
518 layout_decl (var_decl, 0);
519
520 if (TYPE_SIZE (var_type) == 0)
521 abort (); /* Did not calculate size. */
522
523 DECL_CONTEXT (var_decl) = current_function_decl;
524
525 DECL_SOURCE_LOCATION (var_decl) = loc;
526
527 /* Set the storage mode and whether only visible in the same file. */
528 switch (storage_class)
529 {
530 case STATIC_STORAGE:
531 TREE_STATIC (var_decl) = 1;
532 TREE_PUBLIC (var_decl) = 0;
533 break;
534
535 case AUTOMATIC_STORAGE:
536 TREE_STATIC (var_decl) = 0;
537 TREE_PUBLIC (var_decl) = 0;
538 break;
539
540 case EXTERNAL_DEFINITION_STORAGE:
541 TREE_STATIC (var_decl) = 0;
542 TREE_PUBLIC (var_decl) = 1;
543 break;
544
545 case EXTERNAL_REFERENCE_STORAGE:
546 DECL_EXTERNAL (var_decl) = 1;
547 TREE_PUBLIC (var_decl) = 0;
548 break;
549
550 default:
551 abort ();
552 }
553
554 /* This should really only be set if the variable is used. */
555 TREE_USED (var_decl) = 1;
556
557 /* Expand declaration and initial value if any. */
558
559 if (TREE_STATIC (var_decl))
560 rest_of_decl_compilation (var_decl, 0, 0, 0);
561 else
562 {
563 expand_decl (var_decl);
564 if (DECL_INITIAL (var_decl))
565 expand_decl_init (var_decl);
566 }
567
568 return pushdecl (copy_node (var_decl));
569
570 }
571
572
573 /* Generate code for return statement. Type is in TYPE, expression
574 is in EXP if present. */
575
576 void
577 tree_code_generate_return (tree type, tree exp)
578 {
579 tree setret;
580 tree param;
581
582 for (param = DECL_ARGUMENTS (current_function_decl);
583 param;
584 param = TREE_CHAIN (param))
585 {
586 if (DECL_CONTEXT (param) != current_function_decl)
587 abort ();
588 }
589
590 if (exp)
591 {
592 setret = build (MODIFY_EXPR, type, DECL_RESULT (current_function_decl),
593 build1 (CONVERT_EXPR, type, exp));
594 TREE_SIDE_EFFECTS (setret) = 1;
595 TREE_USED (setret) = 1;
596 expand_expr_stmt (setret);
597 }
598 expand_return (DECL_RESULT (current_function_decl));
599 }
600
601 /* Output the code for this expression statement CODE. */
602
603
604 void
605 tree_code_output_expression_statement (tree code, location_t loc)
606 {
607 /* Output the line number information. */
608 emit_line_note (loc);
609 TREE_USED (code) = 1;
610 TREE_SIDE_EFFECTS (code) = 1;
611 expand_expr_stmt (code);
612 }
613
614 /* Return a tree for a constant integer value in the token TOK. No
615 size checking is done. */
616
617 tree
618 tree_code_get_integer_value (unsigned char* chars, unsigned int length)
619 {
620 long long int val = 0;
621 unsigned int ix;
622 unsigned int start = 0;
623 int negative = 1;
624 switch (chars[0])
625 {
626 case (unsigned char)'-':
627 negative = -1;
628 start = 1;
629 break;
630
631 case (unsigned char)'+':
632 start = 1;
633 break;
634
635 default:
636 break;
637 }
638 for (ix = start; ix < length; ix++)
639 val = val * 10 + chars[ix] - (unsigned char)'0';
640 val = val*negative;
641 return build_int_2 (val & 0xffffffff, (val >> 32) & 0xffffffff);
642 }
643
644 /* Return the tree for an expresssion, type EXP_TYPE (see treetree.h)
645 with tree type TYPE and with operands1 OP1, OP2 (maybe), OP3 (maybe). */
646 tree
647 tree_code_get_expression (unsigned int exp_type,
648 tree type, tree op1, tree op2, tree op3 ATTRIBUTE_UNUSED)
649 {
650 tree ret1;
651 int operator;
652
653 switch (exp_type)
654 {
655 case EXP_ASSIGN:
656 if (!op1 || !op2)
657 abort ();
658 operator = MODIFY_EXPR;
659 ret1 = build (operator, type,
660 op1,
661 build1 (CONVERT_EXPR, type, op2));
662
663 break;
664
665 case EXP_PLUS:
666 operator = PLUS_EXPR;
667 goto binary_expression;
668
669 case EXP_MINUS:
670 operator = MINUS_EXPR;
671 goto binary_expression;
672
673 case EXP_EQUALS:
674 operator = EQ_EXPR;
675 goto binary_expression;
676
677 /* Expand a binary expression. Ensure the operands are the right type. */
678 binary_expression:
679 if (!op1 || !op2)
680 abort ();
681 ret1 = build (operator, type,
682 build1 (CONVERT_EXPR, type, op1),
683 build1 (CONVERT_EXPR, type, op2));
684 break;
685
686 /* Reference to a variable. This is dead easy, just return the
687 decl for the variable. If the TYPE is different than the
688 variable type, convert it. */
689 case EXP_REFERENCE:
690 if (!op1)
691 abort ();
692 if (type == TREE_TYPE (op1))
693 ret1 = op1;
694 else
695 ret1 = build1 (CONVERT_EXPR, type, op1);
696 break;
697
698 case EXP_FUNCTION_INVOCATION:
699 if (!op1 || !op2)
700 abort ();
701 {
702 tree fun_ptr;
703 fun_ptr = build1 (ADDR_EXPR, build_pointer_type (type), op1);
704 ret1 = build (CALL_EXPR, type, fun_ptr, nreverse (op2));
705 }
706 break;
707
708 default:
709 abort ();
710 }
711
712 return ret1;
713 }
714
715 /* Init parameter list and return empty list. */
716
717 tree
718 tree_code_init_parameters (void)
719 {
720 return NULL_TREE;
721 }
722
723 /* Add a parameter EXP whose expression type is EXP_PROTO to list
724 LIST, returning the new list. */
725
726 tree
727 tree_code_add_parameter (tree list, tree proto_exp, tree exp)
728 {
729 tree new_exp;
730 new_exp = tree_cons (NULL_TREE,
731 build1 (CONVERT_EXPR, TREE_TYPE (proto_exp), exp),
732 NULL_TREE);
733 if (!list)
734 return new_exp;
735 return chainon (new_exp, list);
736 }
737
738 /* Get the tree type for this type whose number is NUMERIC_TYPE. */
739
740 tree
741 get_type_for_numeric_type (unsigned int numeric_type)
742 {
743
744 int size1;
745 int sign1;
746 switch (numeric_type)
747 {
748 case VOID_TYPE:
749 return void_type_node;
750
751 case SIGNED_INT:
752 size1 = tree_code_int_size;
753 sign1 = 1;
754 break;
755
756 case UNSIGNED_INT:
757 size1 = tree_code_int_size;
758 sign1 = 0;
759 break;
760
761 case SIGNED_CHAR:
762 size1 = tree_code_char_size;
763 sign1 = 1;
764 break;
765
766 case UNSIGNED_CHAR:
767 size1 = tree_code_char_size;
768 sign1 = 0;
769 break;
770
771 default:
772 abort ();
773 }
774
775 return tree_code_get_numeric_type (size1, sign1);
776
777 }
778
779 /* Return tree representing a numeric type of size SIZE1 bits and
780 signed if SIGN1 != 0. */
781 tree
782 tree_code_get_numeric_type (unsigned int size1, unsigned int sign1)
783 {
784 tree ret1;
785 if (!size1)
786 abort ();
787 if (size1 == tree_code_int_size)
788 {
789 if (sign1)
790 ret1 = integer_type_node;
791 else
792 ret1 = unsigned_type_node;
793 }
794 else
795 if (size1 == tree_code_char_size)
796 {
797 if (sign1)
798 ret1 = signed_char_type_node;
799 else
800 ret1 = unsigned_char_type_node;
801 }
802 else
803 abort ();
804
805 return ret1;
806 }
807
808 /* Garbage Collection. */
809
810 /* Callback to mark storage M as used always. */
811
812 void
813 tree_ggc_storage_always_used (void * m)
814 {
815 void **mm; /* Actually M is a pointer to a pointer to the memory. */
816 mm = (void**)m;
817
818 if (*mm)
819 ggc_mark (*mm);
820 }
821
822 /* Following from c-lang.c. */
823
824 /* Used by c-typeck.c (build_external_ref), but only for objc. */
825
826 tree
827 lookup_objc_ivar (tree id ATTRIBUTE_UNUSED)
828 {
829 return 0;
830 }
831
832 /* Dummy routines called from c code. Save copying c-decl.c, c-common.c etc. */
833
834 tree
835 objc_is_id (tree arg ATTRIBUTE_UNUSED)
836 {
837 return 0;
838 }
839
840 void
841 check_function_format (int *status ATTRIBUTE_UNUSED,
842 tree attrs ATTRIBUTE_UNUSED,
843 tree params ATTRIBUTE_UNUSED)
844 {
845 return;
846 }
847
848 /* Tell the c code we are not objective C. */
849
850 int
851 objc_comptypes (tree lhs ATTRIBUTE_UNUSED,
852 tree rhs ATTRIBUTE_UNUSED,
853 int reflexive ATTRIBUTE_UNUSED)
854 {
855 return 0;
856 }
857
858 /* Should not be called for treelang. Needed by RS6000 backend. */
859
860 int c_lex (tree *value);
861
862 int
863 c_lex (tree *value ATTRIBUTE_UNUSED)
864 {
865 abort ();
866 }
867
868 /* Should not be called for treelang. */
869
870 tree
871 build_stmt (enum tree_code code ATTRIBUTE_UNUSED, ...)
872 {
873 abort ();
874 }
875
876 /* Should not be called for treelang. */
877
878 tree
879 add_stmt (tree t ATTRIBUTE_UNUSED)
880 {
881 abort ();
882 }
883
884 /* Should not be called for treelang. */
885
886 tree
887 build_return_stmt (tree expr ATTRIBUTE_UNUSED)
888 {
889 abort ();
890 }
891
892 /* C warning, ignore. */
893
894 void
895 pedwarn_c99 (const char *msgid ATTRIBUTE_UNUSED, ...)
896 {
897 return;
898 }
899
900 /* Should not be called for treelang. */
901
902 tree
903 build_case_label (tree low_value ATTRIBUTE_UNUSED,
904 tree high_value ATTRIBUTE_UNUSED,
905 tree label_decl ATTRIBUTE_UNUSED)
906 {
907 abort ();
908 }
909
910 /* Should not be called for treelang. */
911
912 void
913 emit_local_var (tree decl ATTRIBUTE_UNUSED)
914 {
915 abort ();
916 }
917
918 /* Should not be called for treelang. */
919
920 void
921 expand_stmt (tree t ATTRIBUTE_UNUSED)
922 {
923 abort ();
924 }
925
926 /* Should not be called for treelang. */
927
928 cpp_reader *
929 cpp_create_reader (enum c_lang lang ATTRIBUTE_UNUSED,
930 struct ht *table ATTRIBUTE_UNUSED)
931 {
932 abort ();
933 }
934
935 /* Should not be called for treelang. */
936
937 void
938 init_c_lex (void)
939 {
940 abort ();
941 }
942
943 /* Should not be called for treelang. */
944
945 void init_pragma (void);
946
947 void
948 init_pragma ()
949 {
950 abort ();
951 }
952
953 /* Should not be called for treelang. */
954
955 int
956 cpp_finish (cpp_reader *pfile ATTRIBUTE_UNUSED, FILE *f ATTRIBUTE_UNUSED)
957 {
958 abort ();
959 }
960
961 /* Should not be called for treelang. */
962
963 unsigned int
964 cpp_errors (cpp_reader *pfile ATTRIBUTE_UNUSED)
965 {
966 abort ();
967 }
968
969 /* Dummy called by C. */
970
971 tree
972 handle_format_attribute (tree *node ATTRIBUTE_UNUSED,
973 tree name ATTRIBUTE_UNUSED,
974 tree args ATTRIBUTE_UNUSED,
975 int flags ATTRIBUTE_UNUSED,
976 bool *no_add_attrs ATTRIBUTE_UNUSED)
977 {
978 return NULL_TREE;
979 }
980
981 /* Should not be called for treelang. */
982
983 tree
984 handle_format_arg_attribute (tree *node ATTRIBUTE_UNUSED,
985 tree name ATTRIBUTE_UNUSED,
986 tree args ATTRIBUTE_UNUSED,
987 int flags ATTRIBUTE_UNUSED,
988 bool *no_add_attrs ATTRIBUTE_UNUSED)
989 {
990 abort ();
991 }
992
993 /* Should not be called for treelang. */
994
995 void
996 cpp_assert (cpp_reader * cr ATTRIBUTE_UNUSED,
997 const char *s ATTRIBUTE_UNUSED)
998 {
999 abort ();
1000 }
1001
1002 /* Should not be called for treelang. */
1003
1004 void
1005 set_Wformat (int setting ATTRIBUTE_UNUSED)
1006 {
1007 abort ();
1008 }
1009
1010 /* Used for objective C. */
1011
1012 void
1013 objc_check_decl (tree decl ATTRIBUTE_UNUSED);
1014
1015 void
1016 objc_check_decl (tree decl ATTRIBUTE_UNUSED)
1017 {
1018 abort ();
1019 }
1020
1021 /* Tell the c code we are not objective C. */
1022
1023 tree
1024 objc_message_selector (void);
1025
1026 tree
1027 objc_message_selector ()
1028 {
1029 return 0;
1030 }
1031
1032 /* Should not be called for treelang. */
1033
1034 void
1035 gen_aux_info_record (tree fndecl ATTRIBUTE_UNUSED,
1036 int is_definition ATTRIBUTE_UNUSED,
1037 int is_implicit ATTRIBUTE_UNUSED,
1038 int is_prototyped ATTRIBUTE_UNUSED)
1039 {
1040 abort ();
1041 }
1042
1043 /* Should not be called for treelang, but it is. */
1044
1045 void
1046 c_parse_init ()
1047 {
1048 return;
1049 }
1050
1051 /* Should not be called for treelang. */
1052
1053 void maybe_apply_pragma_weak (tree decl);
1054
1055 void
1056 maybe_apply_pragma_weak (tree decl ATTRIBUTE_UNUSED)
1057 {
1058 abort ();
1059 }
1060
1061 /* Should not be called for treelang. */
1062
1063 void
1064 add_decl_stmt (tree decl ATTRIBUTE_UNUSED)
1065 {
1066 abort ();
1067 }
1068
1069 /* Should not be called for treelang. */
1070
1071 tree
1072 maybe_apply_renaming_pragma (tree decl, tree asmname);
1073
1074 /* Should not be called for treelang. */
1075
1076 tree
1077 maybe_apply_renaming_pragma (tree decl ATTRIBUTE_UNUSED, tree asmname ATTRIBUTE_UNUSED)
1078 {
1079 abort ();
1080 }
1081
1082 /* Should not be called for treelang. */
1083
1084 void
1085 begin_stmt_tree (tree *t ATTRIBUTE_UNUSED)
1086 {
1087 abort ();
1088 }
1089
1090 /* Should not be called for treelang. */
1091
1092 void
1093 finish_stmt_tree (tree *t ATTRIBUTE_UNUSED)
1094 {
1095 abort ();
1096 }
1097
1098 /* Should not be called for treelang. */
1099
1100 int
1101 defer_fn (tree fn ATTRIBUTE_UNUSED)
1102 {
1103 abort ();
1104 }
1105
1106 /* Should not be called for treelang. */
1107
1108 cpp_options
1109 *cpp_get_options (cpp_reader * cr ATTRIBUTE_UNUSED)
1110 {
1111 abort ();
1112 }
1113
1114 /* Should not be called for treelang. */
1115
1116 void
1117 cpp_define (cpp_reader * cr ATTRIBUTE_UNUSED, const char * c ATTRIBUTE_UNUSED)
1118 {
1119 abort ();
1120 }
1121
1122 /* Should not be called for treelang. */
1123
1124 cpp_callbacks *
1125 cpp_get_callbacks (cpp_reader * cr ATTRIBUTE_UNUSED)
1126 {
1127 abort ();
1128 }
1129
1130 /* Create the predefined scalar types of C,
1131 and some nodes representing standard constants (0, 1, (void *) 0).
1132 Initialize the global binding level.
1133 Make definitions for built-in primitive functions. */
1134
1135 /* `unsigned long' is the standard type for sizeof.
1136 Note that stddef.h uses `unsigned long',
1137 and this must agree, even if long and int are the same size. */
1138
1139 /* The reserved keyword table. */
1140 struct resword
1141 {
1142 const char *word;
1143 ENUM_BITFIELD(rid) rid : 16;
1144 unsigned int disable : 16;
1145 };
1146
1147 static const struct resword reswords[] =
1148 {
1149 { "_Bool", RID_BOOL, 0 },
1150 { "_Complex", RID_COMPLEX, 0 },
1151 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
1152 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
1153 { "__alignof", RID_ALIGNOF, 0 },
1154 { "__alignof__", RID_ALIGNOF, 0 },
1155 { "__asm", RID_ASM, 0 },
1156 { "__asm__", RID_ASM, 0 },
1157 { "__attribute", RID_ATTRIBUTE, 0 },
1158 { "__attribute__", RID_ATTRIBUTE, 0 },
1159 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
1160 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
1161 { "__builtin_va_arg", RID_VA_ARG, 0 },
1162 { "__complex", RID_COMPLEX, 0 },
1163 { "__complex__", RID_COMPLEX, 0 },
1164 { "__const", RID_CONST, 0 },
1165 { "__const__", RID_CONST, 0 },
1166 { "__extension__", RID_EXTENSION, 0 },
1167 { "__func__", RID_C99_FUNCTION_NAME, 0 },
1168 { "__imag", RID_IMAGPART, 0 },
1169 { "__imag__", RID_IMAGPART, 0 },
1170 { "__inline", RID_INLINE, 0 },
1171 { "__inline__", RID_INLINE, 0 },
1172 { "__label__", RID_LABEL, 0 },
1173 { "__ptrbase", RID_PTRBASE, 0 },
1174 { "__ptrbase__", RID_PTRBASE, 0 },
1175 { "__ptrextent", RID_PTREXTENT, 0 },
1176 { "__ptrextent__", RID_PTREXTENT, 0 },
1177 { "__ptrvalue", RID_PTRVALUE, 0 },
1178 { "__ptrvalue__", RID_PTRVALUE, 0 },
1179 { "__real", RID_REALPART, 0 },
1180 { "__real__", RID_REALPART, 0 },
1181 { "__restrict", RID_RESTRICT, 0 },
1182 { "__restrict__", RID_RESTRICT, 0 },
1183 { "__signed", RID_SIGNED, 0 },
1184 { "__signed__", RID_SIGNED, 0 },
1185 { "__typeof", RID_TYPEOF, 0 },
1186 { "__typeof__", RID_TYPEOF, 0 },
1187 { "__volatile", RID_VOLATILE, 0 },
1188 { "__volatile__", RID_VOLATILE, 0 },
1189 { "asm", RID_ASM, 0 },
1190 { "auto", RID_AUTO, 0 },
1191 { "break", RID_BREAK, 0 },
1192 { "case", RID_CASE, 0 },
1193 { "char", RID_CHAR, 0 },
1194 { "const", RID_CONST, 0 },
1195 { "continue", RID_CONTINUE, 0 },
1196 { "default", RID_DEFAULT, 0 },
1197 { "do", RID_DO, 0 },
1198 { "double", RID_DOUBLE, 0 },
1199 { "else", RID_ELSE, 0 },
1200 { "enum", RID_ENUM, 0 },
1201 { "extern", RID_EXTERN, 0 },
1202 { "float", RID_FLOAT, 0 },
1203 { "for", RID_FOR, 0 },
1204 { "goto", RID_GOTO, 0 },
1205 { "if", RID_IF, 0 },
1206 { "inline", RID_INLINE, 0 },
1207 { "int", RID_INT, 0 },
1208 { "long", RID_LONG, 0 },
1209 { "register", RID_REGISTER, 0 },
1210 { "restrict", RID_RESTRICT, 0 },
1211 { "return", RID_RETURN, 0 },
1212 { "short", RID_SHORT, 0 },
1213 { "signed", RID_SIGNED, 0 },
1214 { "sizeof", RID_SIZEOF, 0 },
1215 { "static", RID_STATIC, 0 },
1216 { "struct", RID_STRUCT, 0 },
1217 { "switch", RID_SWITCH, 0 },
1218 { "typedef", RID_TYPEDEF, 0 },
1219 { "typeof", RID_TYPEOF, 0 },
1220 { "union", RID_UNION, 0 },
1221 { "unsigned", RID_UNSIGNED, 0 },
1222 { "void", RID_VOID, 0 },
1223 { "volatile", RID_VOLATILE, 0 },
1224 { "while", RID_WHILE, 0 },
1225 };
1226 #define N_reswords (sizeof reswords / sizeof (struct resword))
1227
1228 /* Init enough to allow the C decl code to work, then clean up
1229 afterwards. */
1230
1231 void
1232 treelang_init_decl_processing ()
1233 {
1234 unsigned int i;
1235 tree id;
1236
1237 ridpointers = (tree *) ggc_calloc ((int) RID_MAX, sizeof (tree));
1238
1239 for (i = 0; i < N_reswords; i++)
1240 {
1241 id = get_identifier (reswords[i].word);
1242 C_RID_CODE (id) = reswords[i].rid;
1243 C_IS_RESERVED_WORD (id) = 1;
1244 ridpointers [(int) reswords[i].rid] = id;
1245 }
1246
1247 c_init_decl_processing ();
1248
1249 /* ix86_return_pops_args takes the type of these so need to patch
1250 their own type as themselves. */
1251
1252 for (i = 0; i < itk_none; i++)
1253 {
1254 if (integer_types[i])
1255 TREE_TYPE (integer_types [i]) = integer_types[i];
1256 }
1257
1258 /* Probably these ones too. */
1259 TREE_TYPE (float_type_node) = float_type_node;
1260 TREE_TYPE (double_type_node) = double_type_node;
1261 TREE_TYPE (long_double_type_node) = long_double_type_node;
1262
1263 }
1264
1265 /* Save typing debug_tree all the time. Dump a tree T pretty and
1266 concise. */
1267
1268 void dt (tree t);
1269
1270 void
1271 dt (tree t)
1272 {
1273 debug_tree (t);
1274 }
1275
1276 /* Get a stringpool entry for a string S of length L. This is needed
1277 because the GTY routines don't mark strings, forcing you to put
1278 them into stringpool, which is never freed. */
1279
1280 const char*
1281 get_string (const char *s, size_t l)
1282 {
1283 tree t;
1284 t = get_identifier_with_length (s, l);
1285 return IDENTIFIER_POINTER(t);
1286 }
1287