OSDN Git Service

Make unsafe vector float optimizations dependent on -ffast-math.
[pf3gnuchains/gcc-fork.git] / gcc / treelang / tree1.c
1   /* 
2
3     TREELANG Compiler almost main (tree1)
4     Called by GCC's toplev.c
5
6     Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003, 2004
7     Free Software Foundation, Inc.
8
9     This program is free software; you can redistribute it and/or modify it
10     under the terms of the GNU General Public License as published by the
11     Free Software Foundation; either version 2, or (at your option) any
12     later version.
13
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, 59 Temple Place - Suite 330,
22     Boston, MA 02111-1307, USA.
23
24     In other words, you are welcome to use, share and improve this program.
25     You are forbidden to forbid anyone else to use, share and improve
26     what you give them.   Help stamp out software-hoarding!  
27
28     ---------------------------------------------------------------------------
29
30     Written by Tim Josling 1999, 2000, 2001, based in part on other
31     parts of the GCC compiler.
32
33 */
34
35 #include "config.h"
36 #include "system.h"
37 #include "coretypes.h"
38 #include "tm.h"
39 #include "flags.h"
40 #include "toplev.h"
41 #include "version.h"
42
43 #include "ggc.h"
44 #include "tree.h"
45 #include "cgraph.h"
46 #include "diagnostic.h"
47
48 #include "treelang.h"
49 #include "treetree.h"
50 #include "opts.h"
51 #include "options.h"
52
53 extern int yyparse (void);
54
55 /* Linked list of symbols - all must be unique in treelang.  */
56
57 static GTY(()) struct prod_token_parm_item *symbol_table = NULL;
58
59 /* Language for usage for messages.  */
60
61 const char *const language_string = "TREELANG - sample front end for GCC ";
62
63 /* Local prototypes.  */
64
65 void version (void);
66
67 /* Global variables.  */
68
69 extern struct cbl_tree_struct_parse_tree_top* parse_tree_top;
70
71 /* 
72    Options. 
73 */
74
75 /* Trace the parser.  */
76 unsigned int option_parser_trace = 0;
77
78 /* Trace the lexical analysis.  */
79
80 unsigned int option_lexer_trace = 0;
81
82 /* Warning levels.  */
83
84 /* Local variables.  */
85
86 /* This is 1 if we have output the version string.  */
87
88 static int version_done = 0;
89
90 /* Variable nesting level.  */
91
92 static unsigned int work_nesting_level = 0;
93
94 /* Prepare to handle switches.  */
95 unsigned int
96 treelang_init_options (unsigned int argc ATTRIBUTE_UNUSED,
97                        const char **argv ATTRIBUTE_UNUSED)
98 {
99   return CL_Treelang;
100 }
101
102 /* Process a switch - called by opts.c.  */
103 int
104 treelang_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED,
105                         int value)
106 {
107   enum opt_code code = (enum opt_code) scode;
108
109   switch (code)
110     {
111     default:
112       abort();
113
114     case OPT_v:
115       if (!version_done)
116         {
117           fputs (language_string, stdout);
118           fputs (version_string, stdout);
119           fputs ("\n", stdout);
120           version_done = 1;
121         }
122       break;
123
124     case OPT_y:
125       option_lexer_trace = 1;
126       option_parser_trace = 1;
127       break;
128
129     case OPT_fparser_trace:
130       option_parser_trace = value;
131       break;
132
133     case OPT_flexer_trace:
134       option_lexer_trace = value;
135       break;
136     }
137
138   return 1;
139 }
140
141 /* Language dependent parser setup.  */
142
143 bool
144 treelang_init (void)
145 {
146   input_filename = main_input_filename;
147   input_line = 1;
148
149   /* Init decls etc.  */
150
151   treelang_init_decl_processing ();
152
153   /* This error will not happen from GCC as it will always create a
154      fake input file.  */
155   if (!input_filename || input_filename[0] == ' ' || !input_filename[0]) 
156     {
157       if (!version_done)
158         {
159           fprintf (stderr, "No input file specified, try --help for help\n");
160           exit (1);
161         }
162
163       return false;
164     }
165
166   yyin = fopen (input_filename, "r");
167   if (!yyin)
168     {
169       fprintf (stderr, "Unable to open input file %s\n", input_filename);
170       exit (1);
171     }
172
173   return true;
174 }
175
176 /* Language dependent wrapup.  */
177
178 void 
179 treelang_finish (void)
180 {
181   fclose (yyin);
182 }
183
184 /* Parse a file.  Debug flag doesn't seem to work. */
185
186 void
187 treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED)
188 {
189   treelang_debug ();
190   yyparse ();
191   cgraph_finalize_compilation_unit ();
192   cgraph_optimize ();
193 }
194
195 /* Allocate SIZE bytes and clear them.  Not to be used for strings
196    which must go in stringpool.  */
197
198 void *
199 my_malloc (size_t size)
200 {
201   void *mem;
202   mem = ggc_alloc (size);
203   if (!mem)
204     {
205       fprintf (stderr, "\nOut of memory\n");
206       abort ();
207     }
208   memset (mem, 0, size);
209   return mem;
210 }
211
212 /* Look up a name in PROD->SYMBOL_TABLE_NAME in the symbol table;
213    return the symbol table entry from the symbol table if found there,
214    else 0.  */
215
216 struct prod_token_parm_item*
217 lookup_tree_name (struct prod_token_parm_item *prod)
218 {
219   struct prod_token_parm_item *this;
220   struct prod_token_parm_item *this_tok;
221   struct prod_token_parm_item *tok;
222
223   sanity_check (prod);
224   
225   tok = SYMBOL_TABLE_NAME (prod);
226   sanity_check (tok);
227   
228   for (this = symbol_table; this; this = this->tp.pro.next)
229     {
230       sanity_check (this);
231       this_tok = this->tp.pro.main_token;
232       sanity_check (this_tok);
233       if (tok->tp.tok.length != this_tok->tp.tok.length) 
234         continue;
235       if (memcmp (tok->tp.tok.chars, this_tok->tp.tok.chars, this_tok->tp.tok.length))
236         continue;
237       if (option_parser_trace)
238         fprintf (stderr, "Found symbol %s (%i:%i) as %i \n",
239                  tok->tp.tok.chars, 
240                  tok->tp.tok.location.line, tok->tp.tok.charno,
241                  NUMERIC_TYPE (this));
242       return this;
243     }
244   if (option_parser_trace)
245     fprintf (stderr, "Not found symbol %s (%i:%i) as %i \n",
246              tok->tp.tok.chars, 
247              tok->tp.tok.location.line, tok->tp.tok.charno, tok->type);
248   return NULL;
249 }
250
251 /* Insert name PROD into the symbol table.  Return 1 if duplicate, 0 if OK.  */
252
253 int
254 insert_tree_name (struct prod_token_parm_item *prod)
255 {
256   struct prod_token_parm_item *tok;
257   tok = SYMBOL_TABLE_NAME (prod);
258   sanity_check (prod);
259   if (lookup_tree_name (prod))
260     {
261       fprintf (stderr, "%s:%i:%i duplicate name %s\n",
262                tok->tp.tok.location.file, tok->tp.tok.location.line, 
263                tok->tp.tok.charno, tok->tp.tok.chars);
264       errorcount++;
265       return 1;
266     }
267   prod->tp.pro.next = symbol_table;
268   NESTING_LEVEL (prod) = work_nesting_level;
269   symbol_table = prod;
270   return 0;
271 }
272
273 /* Create a struct productions of type TYPE, main token MAIN_TOK.  */
274
275 struct prod_token_parm_item *
276 make_production (int type, struct prod_token_parm_item *main_tok)
277 {
278   struct prod_token_parm_item *prod;
279   prod = my_malloc (sizeof (struct prod_token_parm_item));
280   prod->category = production_category;
281   prod->type = type;
282   prod->tp.pro.main_token = main_tok;
283   return prod;
284
285
286 /* Abort if ITEM is not a valid structure, based on 'category'.  */
287
288 void
289 sanity_check (struct prod_token_parm_item *item)
290 {
291   switch (item->category)
292     {
293     case   token_category:
294     case production_category:
295     case parameter_category:
296       break;
297       
298     default:
299       abort ();
300     }
301 }  
302
303 /* New garbage collection regime see gty.texi.  */
304 #include "gt-treelang-tree1.h"
305 /*#include "gt-treelang-treelang.h"*/
306 #include "gtype-treelang.h"