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, 2003, 2004
7 Free Software Foundation, Inc.
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
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.
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.
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!
28 ---------------------------------------------------------------------------
30 Written by Tim Josling 1999, 2000, 2001, based in part on other
31 parts of the GCC compiler.
37 #include "coretypes.h"
46 #include "diagnostic.h"
53 extern int yyparse (void);
55 /* Linked list of symbols - all must be unique in treelang. */
57 static GTY(()) struct prod_token_parm_item *symbol_table = NULL;
59 /* Language for usage for messages. */
61 const char *const language_string = "TREELANG - sample front end for GCC ";
63 /* Local prototypes. */
67 /* Global variables. */
69 extern struct cbl_tree_struct_parse_tree_top* parse_tree_top;
75 /* Trace the parser. */
76 unsigned int option_parser_trace = 0;
78 /* Trace the lexical analysis. */
80 unsigned int option_lexer_trace = 0;
84 /* Local variables. */
86 /* This is 1 if we have output the version string. */
88 static int version_done = 0;
90 /* Variable nesting level. */
92 static unsigned int work_nesting_level = 0;
94 /* Prepare to handle switches. */
96 treelang_init_options (unsigned int argc ATTRIBUTE_UNUSED,
97 const char **argv ATTRIBUTE_UNUSED)
102 /* Process a switch - called by opts.c. */
104 treelang_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED,
107 enum opt_code code = (enum opt_code) scode;
117 fputs (language_string, stdout);
118 fputs (version_string, stdout);
119 fputs ("\n", stdout);
125 option_lexer_trace = 1;
126 option_parser_trace = 1;
129 case OPT_fparser_trace:
130 option_parser_trace = value;
133 case OPT_flexer_trace:
134 option_lexer_trace = value;
141 /* Language dependent parser setup. */
146 input_filename = main_input_filename;
149 /* Init decls etc. */
151 treelang_init_decl_processing ();
153 /* This error will not happen from GCC as it will always create a
155 if (!input_filename || input_filename[0] == ' ' || !input_filename[0])
159 fprintf (stderr, "No input file specified, try --help for help\n");
166 yyin = fopen (input_filename, "r");
169 fprintf (stderr, "Unable to open input file %s\n", input_filename);
176 /* Language dependent wrapup. */
179 treelang_finish (void)
184 /* Parse a file. Debug flag doesn't seem to work. */
187 treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED)
191 cgraph_finalize_compilation_unit ();
195 /* Allocate SIZE bytes and clear them. Not to be used for strings
196 which must go in stringpool. */
199 my_malloc (size_t size)
202 mem = ggc_alloc (size);
205 fprintf (stderr, "\nOut of memory\n");
208 memset (mem, 0, size);
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,
216 struct prod_token_parm_item*
217 lookup_tree_name (struct prod_token_parm_item *prod)
219 struct prod_token_parm_item *this;
220 struct prod_token_parm_item *this_tok;
221 struct prod_token_parm_item *tok;
225 tok = SYMBOL_TABLE_NAME (prod);
228 for (this = symbol_table; this; this = this->tp.pro.next)
231 this_tok = this->tp.pro.main_token;
232 sanity_check (this_tok);
233 if (tok->tp.tok.length != this_tok->tp.tok.length)
235 if (memcmp (tok->tp.tok.chars, this_tok->tp.tok.chars, this_tok->tp.tok.length))
237 if (option_parser_trace)
238 fprintf (stderr, "Found symbol %s (%i:%i) as %i \n",
240 tok->tp.tok.location.line, tok->tp.tok.charno,
241 NUMERIC_TYPE (this));
244 if (option_parser_trace)
245 fprintf (stderr, "Not found symbol %s (%i:%i) as %i \n",
247 tok->tp.tok.location.line, tok->tp.tok.charno, tok->type);
251 /* Insert name PROD into the symbol table. Return 1 if duplicate, 0 if OK. */
254 insert_tree_name (struct prod_token_parm_item *prod)
256 struct prod_token_parm_item *tok;
257 tok = SYMBOL_TABLE_NAME (prod);
259 if (lookup_tree_name (prod))
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);
267 prod->tp.pro.next = symbol_table;
268 NESTING_LEVEL (prod) = work_nesting_level;
273 /* Create a struct productions of type TYPE, main token MAIN_TOK. */
275 struct prod_token_parm_item *
276 make_production (int type, struct prod_token_parm_item *main_tok)
278 struct prod_token_parm_item *prod;
279 prod = my_malloc (sizeof (struct prod_token_parm_item));
280 prod->category = production_category;
282 prod->tp.pro.main_token = main_tok;
286 /* Abort if ITEM is not a valid structure, based on 'category'. */
289 sanity_check (struct prod_token_parm_item *item)
291 switch (item->category)
294 case production_category:
295 case parameter_category:
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"