OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [treelang/] [tree1.c] - Blame information for rev 844

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.