This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

treelang fixes for GC and timevar


This patch fixes two bugs in treelang garbage collection and adds some error
checking. It also has a fix to ensure that lexer time is accounted correctly
(display from -Q option).

I also changed the treelang test suite script so that maximal garbage
collection is forced to ensure any GC bugs get found ASAP in future.

I will apply in a few days assuming noone finds any fault with the patch.

Tests: bootstrap C/C++/COBOL/Treelang and run treelang test suite on gnu/linux
Red hat 7.3 Intel PIII/1024mhz.

Tim Josling

*** gcc/gcc/treelang/ChangeLog  4 Feb 2003 01:27:51 -0000       1.24
--- gcc/gcc/treelang/ChangeLog  25 Feb 2003 08:08:59 -0000
***************
*** 1,3 ****
--- 1,40 ----
+ 2003-02-24  Tim Josling  <tej at melbpc dot org dot au>
+ 
+       * 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  <tej at melbpc dot org dot au>
+ 
+         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  <tej at melbpc dot org dot au>
+ 
+       * treetree.c (treelang_init_decl_processing): Change memory
+       allocation to use GC.
+ 
diff -c -r1.2 ChangeLog
*** gcc/gcc/testsuite/treelang/ChangeLog        6 May 2002 21:57:47
-0000       1.2
--- gcc/gcc/testsuite/treelang/ChangeLog        25 Feb 2003 08:08:58 -0000
***************
*** 1,3 ****
--- 1,8 ----
+ 2003-02-25  Tim Josling  <tej at melbpc dot org dot au>
+ 
+       * treetests.exp (run3): set options to force aggressive GC, to
+       ensure GC is all set up correct,
+ 
  2002-05-07  Tim Josling  <tej at melbpc dot org dot au>
? gcc/gcc/testsuite/treelang/a01gcci01.s
Index: gcc/gcc/testsuite/treelang/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/treelang/ChangeLog,v
retrieving revision 1.2
diff -c -r1.2 ChangeLog
*** gcc/gcc/testsuite/treelang/ChangeLog	6 May 2002 21:57:47 -0000	1.2
--- gcc/gcc/testsuite/treelang/ChangeLog	25 Feb 2003 08:08:58 -0000
***************
*** 1,3 ****
--- 1,8 ----
+ 2003-02-25  Tim Josling  <tej at melbpc dot org dot au>
+ 
+ 	* treetests.exp (run3): set options to force aggressive GC, to
+ 	ensure GC is all set up correct,
+ 
  2002-05-07  Tim Josling  <tej at melbpc dot org dot au>
  
  	* Makefile.in: Fix copyright
Index: gcc/gcc/testsuite/treelang/treetests.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/treelang/treetests.exp,v
retrieving revision 1.2
diff -c -r1.2 treetests.exp
*** gcc/gcc/testsuite/treelang/treetests.exp	6 May 2002 21:57:48 -0000	1.2
--- gcc/gcc/testsuite/treelang/treetests.exp	25 Feb 2003 08:08:59 -0000
***************
*** 301,307 ****
  #
  #set X "x"
  set X ""
!     run3 "${sourcedir}" "${testdir}" " -g -O3 " 01 01 0 3 0 1 0
  set X ""
  }
  
--- 301,307 ----
  #
  #set X "x"
  set X ""
! run3 "${sourcedir}" "${testdir}" " -g -O3 --param ggc-min-heapsize=0 --param ggc-min-expand=0 " 01 01 0 3 0 1 0
  set X ""
  }
  
Index: gcc/gcc/treelang/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/ChangeLog,v
retrieving revision 1.24
diff -c -r1.24 ChangeLog
*** gcc/gcc/treelang/ChangeLog	4 Feb 2003 01:27:51 -0000	1.24
--- gcc/gcc/treelang/ChangeLog	25 Feb 2003 08:08:59 -0000
***************
*** 1,3 ****
--- 1,40 ----
+ 2003-02-24  Tim Josling  <tej at melbpc dot org dot au>
+ 
+ 	* 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  <tej at melbpc dot org dot au>
+ 
+         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  <tej at melbpc dot org dot au>
+ 
+ 	* treetree.c (treelang_init_decl_processing): Change memory
+ 	allocation to use GC.
+ 
  2003-02-04  Joseph S. Myers  <jsm at polyomino dot org dot uk>
  
  	* treelang.texi: Update to GFDL 1.2.
Index: gcc/gcc/treelang/Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/Make-lang.in,v
retrieving revision 1.12
diff -c -r1.12 Make-lang.in
*** gcc/gcc/treelang/Make-lang.in	26 Jan 2003 10:17:17 -0000	1.12
--- gcc/gcc/treelang/Make-lang.in	25 Feb 2003 08:09:00 -0000
***************
*** 94,105 ****
  
  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 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/parse.o: treelang/parse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
    $(TM_H) diagnostic.h treelang/treelang.h treelang/treetree.h
--- 94,106 ----
  
  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/parse.h
  
  treelang/parse.o: treelang/parse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
    $(TM_H) diagnostic.h treelang/treelang.h treelang/treetree.h
Index: gcc/gcc/treelang/lex.l
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/lex.l,v
retrieving revision 1.4
diff -c -r1.4 lex.l
*** gcc/gcc/treelang/lex.l	16 Dec 2002 18:22:44 -0000	1.4
--- gcc/gcc/treelang/lex.l	25 Feb 2003 08:09:02 -0000
***************
*** 4,10 ****
  
     ---------------------------------------------------------------------
  
!    Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002
     Free Software Foundation, Inc.
     
     This program is free software; you can redistribute it and/or modify it 
--- 4,10 ----
  
     ---------------------------------------------------------------------
  
!    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,49 ****
--- 44,50 ----
  /* Token defs.  */
  #include "treelang.h"
  #include "parse.h"
+ #include "treetree.h"
  
  extern int option_lexer_trace;
  
***************
*** 257,264 ****
    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);
  }
  
  /* Trace the value LEXRET and the position and token details being
--- 258,264 ----
    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 = (unsigned char*) get_string (yytext, yyleng);
  }
  
  /* Trace the value LEXRET and the position and token details being
Index: gcc/gcc/treelang/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/parse.y,v
retrieving revision 1.4
diff -c -r1.4 parse.y
*** gcc/gcc/treelang/parse.y	16 Dec 2002 18:22:44 -0000	1.4
--- gcc/gcc/treelang/parse.y	25 Feb 2003 08:09:07 -0000
***************
*** 5,11 ****
  
       ---------------------------------------------------------------------
  
!      Copyright (C) 1999, 2000, 2001, 2002 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
--- 5,11 ----
  
       ---------------------------------------------------------------------
  
!      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,52 ****
--- 47,53 ----
  #include "coretypes.h"
  #include "tm.h"
  #include "diagnostic.h"
+ #include "timevar.h"
  
  #include "treelang.h"
  #include "treetree.h"
***************
*** 55,67 ****
  #define YYPRINT(file, type, value) print_token (file, type, value) 
  #define YYERROR_VERBOSE YES
  
  
  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);
--- 56,81 ----
  #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 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,292 ****
--- 301,307 ----
        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,323 ****
--- 333,339 ----
    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,695 ****
--- 706,712 ----
    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,773 ****
--- 785,791 ----
  
    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)
      {
Index: gcc/gcc/treelang/tree1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/tree1.c,v
retrieving revision 1.3
diff -c -r1.3 tree1.c
*** gcc/gcc/treelang/tree1.c	16 Dec 2002 18:22:44 -0000	1.3
--- gcc/gcc/treelang/tree1.c	25 Feb 2003 08:09:07 -0000
***************
*** 3,9 ****
      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.
  
      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
--- 3,9 ----
      TREELANG Compiler almost main (tree1)
      Called by GCC's toplev.c
  
!     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,192 ****
--- 187,194 ----
    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,235 ****
    yyparse ();
  }
  
! /* Allocate SIZE bytes and clear them.  */
  
  void *
  my_malloc (size_t size)
--- 231,238 ----
    yyparse ();
  }
  
! /* Allocate SIZE bytes and clear them.  Not to be used for strings
!    which must go in stringpool.  */
  
  void *
  my_malloc (size_t size)
***************
*** 255,264 ****
--- 258,274 ----
    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,286 ****
--- 291,297 ----
  {
    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,312 ****
--- 318,339 ----
    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"
Index: gcc/gcc/treelang/treelang.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/treelang.h,v
retrieving revision 1.2
diff -c -r1.2 treelang.h
*** gcc/gcc/treelang/treelang.h	10 Jun 2002 00:56:49 -0000	1.2
--- gcc/gcc/treelang/treelang.h	25 Feb 2003 08:09:07 -0000
***************
*** 2,8 ****
  
      TREELANG Compiler common definitions (treelang.h)
  
!     Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002 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
--- 2,8 ----
  
      TREELANG Compiler common definitions (treelang.h)
  
!     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,152 ****
--- 150,153 ----
  void mark_token_used (struct prod_token_parm_item *tt);
  void treelang_debug (void);
  
+ void sanity_check (struct prod_token_parm_item *item);
Index: gcc/gcc/treelang/treetree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/treetree.c,v
retrieving revision 1.13
diff -c -r1.13 treetree.c
*** gcc/gcc/treelang/treetree.c	16 Dec 2002 18:22:44 -0000	1.13
--- gcc/gcc/treelang/treetree.c	25 Feb 2003 08:09:09 -0000
***************
*** 6,13 ****
      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.
  
      This code is based on toy.c written by Richard Kenner. 
      
--- 6,13 ----
      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, 2003, Free Software Foundation, Inc.
  
      This code is based on toy.c written by Richard Kenner. 
      
***************
*** 73,78 ****
--- 73,79 ----
  
  #include "treelang.h"
  #include "treetree.h"
+ #include "parse.h"
  
  extern int option_main;
  extern char **file_names;
***************
*** 233,238 ****
--- 234,241 ----
    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,1252 ****
    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));
    
    for (i = 0; i < N_reswords; i++)
      {
--- 1246,1252 ----
    unsigned int i;
    tree id;
  
!   ridpointers = (tree *) ggc_calloc ((int) RID_MAX, sizeof (tree));
    
    for (i = 0; i < N_reswords; i++)
      {
***************
*** 1283,1286 ****
--- 1283,1298 ----
  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);
  }
Index: gcc/gcc/treelang/treetree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/treetree.h,v
retrieving revision 1.2
diff -c -r1.2 treetree.h
*** gcc/gcc/treelang/treetree.h	10 Jun 2002 00:56:49 -0000	1.2
--- gcc/gcc/treelang/treetree.h	25 Feb 2003 08:09:09 -0000
***************
*** 3,9 ****
      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.
  
      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
--- 3,9 ----
      TREELANG Compiler definitions for interfacing to treetree.c
      (compiler back end interface).
  
!     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,73 ****
  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);
  int treelang_decode_option (int, char **);
  void treelang_parse_file (int debug_flag);
  void push_var_level (void);
  void pop_var_level (void);
! 
  
  
--- 63,73 ----
  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);
  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);
  
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]