Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / treelang / tree1.c
blob1bd468988674bdf4c31567f28f5047eaa4688324
1 /*
3 TREELANG Compiler almost main (tree1)
4 Called by GCC's toplev.c
6 Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 In other words, you are welcome to use, share and improve this program.
24 You are forbidden to forbid anyone else to use, share and improve
25 what you give them. Help stamp out software-hoarding!
27 ---------------------------------------------------------------------------
29 Written by Tim Josling 1999, 2000, 2001, based in part on other
30 parts of the GCC compiler.
34 #include "config.h"
35 #include "system.h"
36 #include "coretypes.h"
37 #include "tm.h"
38 #include "flags.h"
39 #include "toplev.h"
41 #include "ggc.h"
42 #include "tree.h"
43 #include "diagnostic.h"
45 #include "treelang.h"
46 #include "treetree.h"
48 extern int yyparse (void);
50 /* Linked list of symbols - all must be unique in treelang. */
52 static GTY(()) struct prod_token_parm_item *symbol_table = NULL;
54 /* Language for usage for messages. */
56 const char *const language_string = "TREELANG - sample front end for GCC ";
58 /* Local prototypes. */
60 void version (void);
62 /* Global variables. */
64 extern struct cbl_tree_struct_parse_tree_top* parse_tree_top;
66 /*
67 Options.
70 /* Trace the parser. */
71 unsigned int option_parser_trace = 0;
73 /* Trace the lexical analysis. */
75 unsigned int option_lexer_trace = 0;
77 /* Warning levels. */
79 /* Local variables. */
81 unsigned char *in_fname = NULL; /* Input file name. */
83 /* This is 1 if we have output the version string. */
85 static int version_done = 0;
87 /* Variable nesting level. */
89 static unsigned int work_nesting_level = 0;
91 /* Process one switch - called by toplev.c. */
93 int
94 treelang_decode_option (num_options_left, first_option_left)
95 int num_options_left ATTRIBUTE_UNUSED;
96 char** first_option_left;
100 Process options - bear in mind I may get options that are really
101 meant for someone else (eg the main compiler) so I have to be very
102 permissive.
106 if (first_option_left[0][0] != '-')
107 return 0;
109 switch (first_option_left[0][1])
111 case '-':
112 if (!strcmp (first_option_left[0],"--help"))
114 if (!version_done)
116 fputs (language_string, stdout);
117 fputs (version_string, stdout);
118 fputs ("\n", stdout);
119 version_done = 1;
121 fprintf (stdout, "Usage: tree1 [switches] -o output input\n");
122 return 1;
124 case 'v':
125 if (!strcmp (first_option_left[0],"-v"))
127 if (!version_done)
129 fputs (language_string, stdout);
130 fputs (version_string, stdout);
131 fputs ("\n", stdout);
132 version_done = 1;
134 return 1;
136 case 'y':
137 if (!strcmp (first_option_left[0],"-y"))
139 option_lexer_trace = 1;
140 option_parser_trace = 1;
141 return 1;
143 case 'f':
144 if (!strcmp (first_option_left[0],"-fparser-trace"))
146 option_parser_trace = 1;
147 return 1;
149 if (!strcmp (first_option_left[0],"-flexer-trace"))
151 option_lexer_trace = 1;
152 return 1;
154 return 0;
156 case 'w':
157 if (!strcmp (first_option_left[0],"-w"))
159 /* Tolerate this option but ignore it - we always put out
160 all warnings. */
161 return 1;
163 return 0;
165 case 'W':
166 if (!strcmp (first_option_left[0],"-Wall"))
168 return 1;
170 return 0;
172 default:
173 return 0;
176 return 0;
180 /* Language dependent parser setup. */
182 const char*
183 treelang_init (const char* filename)
185 /* Set up the declarations needed for this front end. */
187 input_filename = "";
188 lineno = 0;
190 treelang_init_decl_processing ();
192 /* This error will not happen from GCC as it will always create a
193 fake input file. */
194 if (!filename || (filename[0] == ' ') || (!filename[0]))
196 if (!version_done)
198 fprintf (stderr, "No input file specified, try --help for help\n");
199 exit (1);
202 in_fname = NULL;
203 return NULL;
205 yyin = fopen (filename, "r");
206 if (!yyin)
208 fprintf (stderr, "Unable to open input file %s\n", filename);
209 exit (1);
211 input_filename = filename;
212 return (char*) (in_fname = (unsigned char*)filename);
215 /* Language dependent wrapup. */
217 void
218 treelang_finish (void)
220 fclose (yyin);
223 /* Parse a file. Debug flag doesn't seem to work. */
225 void
226 treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED)
228 treelang_debug ();
229 yyparse ();
232 /* Allocate SIZE bytes and clear them. */
234 void *
235 my_malloc (size_t size)
237 void *mem;
238 mem = ggc_alloc (size);
239 if (!mem)
241 fprintf (stderr, "\nOut of memory\n");
242 abort ();
244 memset (mem, 0, size);
245 return mem;
248 /* Look up a name in PROD->SYMBOL_TABLE_NAME in the symbol table;
249 return the symbol table entry from the symbol table if found there,
250 else 0. */
252 struct prod_token_parm_item*
253 lookup_tree_name (struct prod_token_parm_item *prod)
255 struct prod_token_parm_item *this;
256 struct prod_token_parm_item *this_tok;
257 struct prod_token_parm_item *tok;
258 tok = SYMBOL_TABLE_NAME (prod);
259 for (this = symbol_table; this; this = this->tp.pro.next)
261 this_tok = this->tp.pro.main_token;
262 if (tok->tp.tok.length != this_tok->tp.tok.length)
263 continue;
264 if (memcmp (tok->tp.tok.chars, this_tok->tp.tok.chars, this_tok->tp.tok.length))
265 continue;
266 if (option_parser_trace)
267 fprintf (stderr, "Found symbol %s (%i:%i) as %i \n", tok->tp.tok.chars,
268 tok->tp.tok.lineno, tok->tp.tok.charno, NUMERIC_TYPE (this));
269 return this;
271 if (option_parser_trace)
272 fprintf (stderr, "Not found symbol %s (%i:%i) as %i \n", tok->tp.tok.chars,
273 tok->tp.tok.lineno, tok->tp.tok.charno, tok->type);
274 return NULL;
277 /* Insert name PROD into the symbol table. Return 1 if duplicate, 0 if OK. */
280 insert_tree_name (struct prod_token_parm_item *prod)
282 struct prod_token_parm_item *tok;
283 tok = SYMBOL_TABLE_NAME (prod);
284 if (lookup_tree_name (prod))
286 fprintf (stderr, "%s:%i:%i duplicate name %s\n", in_fname, tok->tp.tok.lineno,
287 tok->tp.tok.charno, tok->tp.tok.chars);
288 errorcount++;
289 return 1;
291 prod->tp.pro.next = symbol_table;
292 NESTING_LEVEL (prod) = work_nesting_level;
293 symbol_table = prod;
294 return 0;
297 /* Create a struct productions of type TYPE, main token MAIN_TOK. */
299 struct prod_token_parm_item *
300 make_production (int type, struct prod_token_parm_item *main_tok)
302 struct prod_token_parm_item *prod;
303 prod = my_malloc (sizeof (struct prod_token_parm_item));
304 prod->category = production_category;
305 prod->type = type;
306 prod->tp.pro.main_token = main_tok;
307 return prod;
311 /* New garbage collection regime see gty.texi. */
312 #include "gt-treelang-tree1.h"
313 /*#include "gt-treelang-treelang.h"*/
314 #include "gtype-treelang.h"