From a30d35c1d7649a749990c64e328854dfa47d6d5b Mon Sep 17 00:00:00 2001 From: timjosling Date: Sat, 1 Mar 2003 02:05:37 +0000 Subject: [PATCH] Treelang fixes. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63604 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/treelang/ChangeLog | 5 +++++ gcc/testsuite/treelang/treetests.exp | 2 +- gcc/treelang/ChangeLog | 37 ++++++++++++++++++++++++++++++++++++ gcc/treelang/Make-lang.in | 3 ++- gcc/treelang/lex.l | 6 +++--- gcc/treelang/parse.y | 22 +++++++++++++++++++-- gcc/treelang/tree1.c | 31 ++++++++++++++++++++++++++++-- gcc/treelang/treelang.h | 3 ++- gcc/treelang/treetree.c | 24 +++++++++++++++++------ gcc/treelang/treetree.h | 6 +++--- 10 files changed, 120 insertions(+), 19 deletions(-) diff --git a/gcc/testsuite/treelang/ChangeLog b/gcc/testsuite/treelang/ChangeLog index 09a69046ad4..ca767d024fc 100644 --- a/gcc/testsuite/treelang/ChangeLog +++ b/gcc/testsuite/treelang/ChangeLog @@ -1,3 +1,8 @@ +2003-02-25 Tim Josling + + * treetests.exp (run3): set options to force aggressive GC, to + ensure GC is all set up correct, + 2002-05-07 Tim Josling * Makefile.in: Fix copyright diff --git a/gcc/testsuite/treelang/treetests.exp b/gcc/testsuite/treelang/treetests.exp index e5c2a85989f..42ceb242d46 100644 --- a/gcc/testsuite/treelang/treetests.exp +++ b/gcc/testsuite/treelang/treetests.exp @@ -301,7 +301,7 @@ if {${check_rc} == 1} { # #set X "x" set X "" - run3 "${sourcedir}" "${testdir}" " -g -O3 " 01 01 0 3 0 1 0 +run3 "${sourcedir}" "${testdir}" " -g -O3 --param ggc-min-heapsize=0 --param ggc-min-expand=0 " 01 01 0 3 0 1 0 set X "" } diff --git a/gcc/treelang/ChangeLog b/gcc/treelang/ChangeLog index edcc18af688..40a9b32388a 100644 --- a/gcc/treelang/ChangeLog +++ b/gcc/treelang/ChangeLog @@ -1,3 +1,40 @@ +2003-02-24 Tim Josling + + * parse.y (my_yylex): New - ensure lexer time is charged to + TV_LEX. + (yylex): redefine as invocation of my_yylex which then calls + flex-generated yylex. + (timevar.h): include. + +2003-02-23 Tim Josling + + Fix garbage collection, add more error checking, force GC always. + + * Make-lang.in (treelang/tree1.o): Depend on treelang/treetree.h + (treelang/treetree.o): Depend on treelang/parse.h + + * lex.l: include "treetree.h" + + * lex.l (update_yylval): Allocate string using get_string so GC + works. + + * parse.y (function_prototype): Set category correctly so GC works. + (function): Set category in search so checking works. + (function_invocation): Ditto. + (variable_ref): Ditto. + + * tree1.c (lookup_tree_name): Call sanity_check for passed + production and associated token and for symbol table entries. + + * tree1.c (sanity_check): New, basic check that struct is valid. + + * treelang.h: Prototype for sanity_check. + +2003-01-27 Tim Josling + + * treetree.c (treelang_init_decl_processing): Change memory + allocation to use GC. + 2003-02-04 Joseph S. Myers * treelang.texi: Update to GFDL 1.2. diff --git a/gcc/treelang/Make-lang.in b/gcc/treelang/Make-lang.in index 6ac2c076aee..71c7851bf7b 100644 --- a/gcc/treelang/Make-lang.in +++ b/gcc/treelang/Make-lang.in @@ -94,12 +94,13 @@ tree1$(exeext): treelang/tree1.o treelang/treetree.o treelang/lex.o treelang/par treelang/tree1.o: treelang/tree1.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ flags.h toplev.h $(GGC_H) $(TREE_H) diagnostic.h treelang/treelang.h \ + treelang/treetree.h \ treelang/treetree.h gt-treelang-tree1.h gtype-treelang.h treelang/treetree.o: treelang/treetree.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) $(TREE_H) flags.h output.h $(C_TREE_H) $(RTL_H) $(GGC_H) toplev.h \ varray.h $(LANGHOOKS_DEF_H) langhooks.h treelang/treelang.h \ - treelang/treetree.h + treelang/treetree.h treelang/parse.h treelang/parse.o: treelang/parse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) diagnostic.h treelang/treelang.h treelang/treetree.h diff --git a/gcc/treelang/lex.l b/gcc/treelang/lex.l index 4ce755bff98..869138c410b 100644 --- a/gcc/treelang/lex.l +++ b/gcc/treelang/lex.l @@ -4,7 +4,7 @@ --------------------------------------------------------------------- - Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002 + Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it @@ -44,6 +44,7 @@ /* Token defs. */ #include "treelang.h" #include "parse.h" +#include "treetree.h" extern int option_lexer_trace; @@ -257,8 +258,7 @@ update_yylval (int a) tok->tp.tok.length = yyleng; /* Have to copy yytext as it is just a ptr into the buffer at the moment. */ - tok->tp.tok.chars = my_malloc (yyleng + 1); - memcpy (tok->tp.tok.chars, yytext, yyleng); + tok->tp.tok.chars = (unsigned char*) get_string (yytext, yyleng); } /* Trace the value LEXRET and the position and token details being diff --git a/gcc/treelang/parse.y b/gcc/treelang/parse.y index 1f8cf221d61..d1954e2c516 100644 --- a/gcc/treelang/parse.y +++ b/gcc/treelang/parse.y @@ -5,7 +5,7 @@ --------------------------------------------------------------------- - Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -47,6 +47,7 @@ #include "coretypes.h" #include "tm.h" #include "diagnostic.h" +#include "timevar.h" #include "treelang.h" #include "treetree.h" @@ -55,13 +56,26 @@ #define YYPRINT(file, type, value) print_token (file, type, value) #define YYERROR_VERBOSE YES +/* My yylex routine used to intercept calls to flex generated code, to + record lex time. */ +int yylex (void); +static inline int my_yylex(void); +/* Call lex, but ensure time is charged to TV_LEX. */ +static inline int my_yylex () +{ + int res; + timevar_push (TV_LEX); + res = yylex (); + timevar_pop (TV_LEX); + return res; +} +#define yylex my_yylex extern int option_parser_trace; /* Local prototypes. */ static void yyerror (const char *error_message); -int yylex (void); int yyparse (void); void print_token (FILE * file, unsigned int type ATTRIBUTE_UNUSED, YYSTYPE value); static struct prod_token_parm_item *reverse_prod_list (struct prod_token_parm_item *old_first); @@ -287,6 +301,7 @@ storage typename NAME LEFT_PARENTHESIS parameters RIGHT_PARENTHESIS SEMICOLON { if (!this_parm_var->tp.pro.main_token) abort (); this_parms->tp.par.variable_name = this_parm_var->tp.pro.main_token->tp.tok.chars; + this_parms->category = parameter_category; this_parms->type = NUMERIC_TYPE (( (struct prod_token_parm_item*)EXPRESSION_TYPE (this_parm_var))); if (last_parms) { @@ -318,6 +333,7 @@ NAME LEFT_BRACE { struct prod_token_parm_item *this_parm; tok = $1; SYMBOL_TABLE_NAME ((&search_prod)) = tok; + search_prod.category = token_category; current_function = proto = lookup_tree_name (&search_prod); if (!proto) { @@ -690,6 +706,7 @@ NAME LEFT_PARENTHESIS expressions_with_commas RIGHT_PARENTHESIS { SYMBOL_TABLE_NAME (prod) = tok; PARAMETERS (prod) = reverse_prod_list ($3); SYMBOL_TABLE_NAME ((&search_prod)) = tok; + search_prod.category = token_category; proto = lookup_tree_name (&search_prod); if (!proto) { @@ -768,6 +785,7 @@ NAME { tok = $1; SYMBOL_TABLE_NAME ((&search_prod)) = tok; + search_prod.category = token_category; symbol_table_entry = lookup_tree_name (&search_prod); if (!symbol_table_entry) { diff --git a/gcc/treelang/tree1.c b/gcc/treelang/tree1.c index 1bd46898867..20913bafd78 100644 --- a/gcc/treelang/tree1.c +++ b/gcc/treelang/tree1.c @@ -3,7 +3,7 @@ TREELANG Compiler almost main (tree1) Called by GCC's toplev.c - Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -187,6 +187,8 @@ treelang_init (const char* filename) input_filename = ""; lineno = 0; + /* Init decls etc. */ + treelang_init_decl_processing (); /* This error will not happen from GCC as it will always create a @@ -229,7 +231,8 @@ treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED) yyparse (); } -/* Allocate SIZE bytes and clear them. */ +/* Allocate SIZE bytes and clear them. Not to be used for strings + which must go in stringpool. */ void * my_malloc (size_t size) @@ -255,10 +258,17 @@ lookup_tree_name (struct prod_token_parm_item *prod) struct prod_token_parm_item *this; struct prod_token_parm_item *this_tok; struct prod_token_parm_item *tok; + + sanity_check (prod); + tok = SYMBOL_TABLE_NAME (prod); + sanity_check (tok); + for (this = symbol_table; this; this = this->tp.pro.next) { + sanity_check (this); this_tok = this->tp.pro.main_token; + sanity_check (this_tok); if (tok->tp.tok.length != this_tok->tp.tok.length) continue; if (memcmp (tok->tp.tok.chars, this_tok->tp.tok.chars, this_tok->tp.tok.length)) @@ -281,6 +291,7 @@ insert_tree_name (struct prod_token_parm_item *prod) { struct prod_token_parm_item *tok; tok = SYMBOL_TABLE_NAME (prod); + sanity_check (prod); if (lookup_tree_name (prod)) { fprintf (stderr, "%s:%i:%i duplicate name %s\n", in_fname, tok->tp.tok.lineno, @@ -307,6 +318,22 @@ make_production (int type, struct prod_token_parm_item *main_tok) return prod; } +/* Abort if ITEM is not a valid structure, based on 'category'. */ + +void +sanity_check (struct prod_token_parm_item *item) +{ + switch (item->category) + { + case token_category: + case production_category: + case parameter_category: + break; + + default: + abort (); + } +} /* New garbage collection regime see gty.texi. */ #include "gt-treelang-tree1.h" diff --git a/gcc/treelang/treelang.h b/gcc/treelang/treelang.h index f42a2e2e2e9..6258c0e88ec 100644 --- a/gcc/treelang/treelang.h +++ b/gcc/treelang/treelang.h @@ -2,7 +2,7 @@ TREELANG Compiler common definitions (treelang.h) - Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -150,3 +150,4 @@ void mark_production_used (struct prod_token_parm_item *pp); void mark_token_used (struct prod_token_parm_item *tt); void treelang_debug (void); +void sanity_check (struct prod_token_parm_item *item); diff --git a/gcc/treelang/treetree.c b/gcc/treelang/treetree.c index f489fdf8b1a..4bf1276b4cd 100644 --- a/gcc/treelang/treetree.c +++ b/gcc/treelang/treetree.c @@ -6,8 +6,8 @@ If you want a working example of how to write a front end to GCC, you are in the right place. - Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2001, 2002, 2003, Free Software Foundation, Inc. This code is based on toy.c written by Richard Kenner. @@ -73,6 +73,7 @@ #include "treelang.h" #include "treetree.h" +#include "parse.h" extern int option_main; extern char **file_names; @@ -233,6 +234,8 @@ tree_code_create_function_prototype (unsigned char* chars, id = get_identifier ((const char*)chars); for (parm = parms; parm; parm = parm->tp.par.next) { + if (parm->category != parameter_category) + abort (); type_node = get_type_for_numeric_type (parm->type); type_list = tree_cons (NULL_TREE, type_node, type_list); } @@ -1243,10 +1246,7 @@ treelang_init_decl_processing () unsigned int i; tree id; - /* It is not necessary to register ridpointers as a GC root, because - all the trees it points to are permanently interned in the - get_identifier hash anyway. */ - ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree)); + ridpointers = (tree *) ggc_calloc ((int) RID_MAX, sizeof (tree)); for (i = 0; i < N_reswords; i++) { @@ -1284,3 +1284,15 @@ dt (tree t) { debug_tree (t); } + +/* Get a stringpool entry for a string S of length L. This is needed + because the GTY routines don't mark strings, forcing you to put + them into stringpool, which is never freed. */ + +const char* +get_string (const char *s, size_t l) +{ + tree t; + t = get_identifier_with_length (s, l); + return IDENTIFIER_POINTER(t); +} diff --git a/gcc/treelang/treetree.h b/gcc/treelang/treetree.h index e394ebae8e0..111cf128183 100644 --- a/gcc/treelang/treetree.h +++ b/gcc/treelang/treetree.h @@ -3,7 +3,7 @@ TREELANG Compiler definitions for interfacing to treetree.c (compiler back end interface). - Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -63,11 +63,11 @@ void tree_code_if_end (unsigned char* filename, int lineno); tree tree_code_get_type (int type_num); void treelang_init_decl_processing (void); void treelang_finish (void); -const char * treelang_init (const char* filename); +const char *treelang_init (const char* filename); int treelang_decode_option (int, char **); void treelang_parse_file (int debug_flag); void push_var_level (void); void pop_var_level (void); - +const char* get_string (const char *s, size_t l); -- 2.11.0