OSDN Git Service

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