This is the mail archive of the gcc@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]

Proposed Patch for init_parse


Hi,

Attached is my proposed patch for the init_lex-->init_parse interface
change for egcs. It covers C, C++, fortran and (hopefully) ada (the
3.10p source from cs.nyu.edu:/pub/gnat).

The basic idea is to replace init_lex() with init_parse(char
*filename) and to add finish_parse(). init_parse opens the source file
(used to be done in toplev.c) and does whatever else init_lex used to
do. finish_parse closes the source file (if necessary). The definition
of FILE *finput is moved to whichever file contains init_parse.

1) This is all that was necessary for C and fortran. I built and
tested this patch on i686-pc-linux-gnulibc1.

2) C++ already had a function called init_parse which was called by
init_lex. This function was renamed to init_cpp_parse. I built and
tested this patch on i686-pc-linux-gnulibc1.

3) Ada does not appear to use finput as the source file, so I just
renamed init_lex to init_parse and added an empty finish_parse. The
attached patch to Ada includes Jim Wilson's patch which is already in
README.gnat. Let me know if I should supply a patch which assumes
Jim's patch is already there. I was unable to build and test this
patch because I don't have the ada compiler installed on my system.

Please let me know of any problems with these patches and let me know
if you want me to install them or if someone else does.

Dave
Index: c-lex.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-lex.c,v
retrieving revision 1.11
diff -c -r1.11 c-lex.c
*** c-lex.c	1998/04/01 23:18:04	1.11
--- c-lex.c	1998/04/02 22:50:25
***************
*** 47,52 ****
--- 47,55 ----
  cpp_reader parse_in;
  cpp_options parse_options;
  static enum cpp_token cpp_token;
+ #else
+ /* Stream for reading from the input file.  */
+ FILE *finput;
  #endif
  
  /* The elements of `ridpointers' are identifier nodes
***************
*** 183,194 ****
        wordlist[i].name = "oneway";   
  }
  
- #if USE_CPPLIB
  void
  init_parse (filename)
       char *filename;
  {
    init_lex ();
    yy_cur = "\n";
    yy_lim = yy_cur+1;
  
--- 186,215 ----
        wordlist[i].name = "oneway";   
  }
  
  void
  init_parse (filename)
       char *filename;
  {
+ #if !USE_CPPLIB
+   /* Open input file.  */
+   if (filename == 0 || !strcmp (filename, "-"))
+     {
+       finput = stdin;
+       filename = "stdin";
+     }
+   else
+     finput = fopen (filename, "r");
+   if (finput == 0)
+     pfatal_with_name (filename);
+ 
+ #ifdef IO_BUFFER_SIZE
+   setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
+ #endif
+ #endif /* !USE_CPPLIB */
+ 
    init_lex ();
+ 
+ #if USE_CPPLIB
    yy_cur = "\n";
    yy_lim = yy_cur+1;
  
***************
*** 199,212 ****
    parse_in.show_column = 1;
    if (! cpp_start_read (&parse_in, filename))
      abort ();
  }
  
  void
  finish_parse ()
  {
    cpp_finish (&parse_in);
! }
  #endif
  
  void
  init_lex ()
--- 220,237 ----
    parse_in.show_column = 1;
    if (! cpp_start_read (&parse_in, filename))
      abort ();
+ #endif
  }
  
  void
  finish_parse ()
  {
+ #if USE_CPPLIB
    cpp_finish (&parse_in);
! #else
!   fclose (finput);
  #endif
+ }
  
  void
  init_lex ()
Index: toplev.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/toplev.c,v
retrieving revision 1.49
diff -c -r1.49 toplev.c
*** toplev.c	1998/03/31 16:59:41	1.49
--- toplev.c	1998/04/02 22:50:40
***************
*** 128,134 ****
  extern int size_directive_output;
  extern tree last_assemble_variable_decl;
  
! extern void init_lex ();
  extern void init_decl_processing ();
  extern void init_obstacks ();
  extern void init_tree_codes ();
--- 128,135 ----
  extern int size_directive_output;
  extern tree last_assemble_variable_decl;
  
! extern void init_parse PVPROTO((char *));
! extern void finish_parse ();
  extern void init_decl_processing ();
  extern void init_obstacks ();
  extern void init_tree_codes ();
***************
*** 197,207 ****
  
  char *main_input_filename;
  
- #if !USE_CPPLIB
- /* Stream for reading from the input file.  */
- FILE *finput;
- #endif
- 
  /* Current line number in real source file.  */
  
  int lineno;
--- 198,203 ----
***************
*** 2261,2293 ****
    symout_time = 0;
    dump_time = 0;
  
- #if !USE_CPPLIB
-   /* Open input file.  */
- 
-   if (name == 0 || !strcmp (name, "-"))
-     {
-       finput = stdin;
-       name = "stdin";
-     }
-   else
-     finput = fopen (name, "r");
-   if (finput == 0)
-     pfatal_with_name (name);
- 
- #ifdef IO_BUFFER_SIZE
-   setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
- #endif
- #endif /* !USE_CPPLIB */
- 
    /* Initialize data in various passes.  */
  
    init_obstacks ();
    init_tree_codes ();
- #if USE_CPPLIB
    init_parse (name);
- #else
-   init_lex ();
- #endif
    init_rtl ();
    init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
  		  || debug_info_level == DINFO_LEVEL_VERBOSE
--- 2257,2267 ----
***************
*** 2808,2818 ****
       whether fclose returns an error, since the pages might still be on the
       buffer chain while the file is open.  */
  
- #if USE_CPPLIB
    finish_parse ();
! #else
!   fclose (finput);
! #endif
    if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
      fatal_io_error (asm_file_name);
  
--- 2782,2789 ----
       whether fclose returns an error, since the pages might still be on the
       buffer chain while the file is open.  */
  
    finish_parse ();
! 
    if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
      fatal_io_error (asm_file_name);
  
Index: cp/cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.49
diff -c -r1.49 cp-tree.h
*** cp-tree.h	1998/03/29 12:30:13	1.49
--- cp-tree.h	1998/04/02 22:50:47
***************
*** 2381,2389 ****
  #if 0
  extern void reinit_lang_specific		PROTO((void));
  #endif
- extern void init_lex				PROTO((void));
  extern void reinit_parse_for_function		PROTO((void));
- extern int *init_parse				PROTO((void));
  extern void print_parse_statistics		PROTO((void));
  extern void extract_interface_info		PROTO((void));
  extern void do_pending_inlines			PROTO((void));
--- 2381,2387 ----
Index: cp/lex.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/lex.c,v
retrieving revision 1.36
diff -c -r1.36 lex.c
*** lex.c	1998/03/31 13:25:26	1.36
--- lex.c	1998/04/02 22:50:51
***************
*** 108,113 ****
--- 108,116 ----
  struct obstack inline_text_obstack;
  char *inline_text_firstobj;
  
+ #if !USE_CPPLIB
+ FILE *finput;
+ #endif
  int end_of_file;
  
  /* Pending language change.
***************
*** 425,431 ****
  
  /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
     Stuck this hack in to get the files open correctly; this is called
!    in place of init_lex if we are an unexec'd binary.    */
  
  #if 0
  void
--- 428,434 ----
  
  /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
     Stuck this hack in to get the files open correctly; this is called
!    in place of init_parse if we are an unexec'd binary.    */
  
  #if 0
  void
***************
*** 436,449 ****
  }
  #endif
  
  void
! init_lex ()
  {
    extern int flag_no_gnu_keywords;
    extern int flag_operator_names;
  
    int i;
  
    /* Initialize the lookahead machinery.  */
    init_spew ();
  
--- 439,486 ----
  }
  #endif
  
+ static int *
+ init_cpp_parse ()
+ {
+ #ifdef GATHER_STATISTICS
+ #ifdef REDUCE_LENGTH
+   reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1));
+   bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1));
+   reduce_count += 1;
+   token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1));
+   bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1));
+   token_count += 1;
+ #endif
+ #endif
+   return token_count;
+ }
+ 
  void
! init_parse (filename)
!      char *filename;
  {
    extern int flag_no_gnu_keywords;
    extern int flag_operator_names;
  
    int i;
  
+ #if !USE_CPPLIB
+   /* Open input file.  */
+   if (filename == 0 || !strcmp (filename, "-"))
+     {
+       finput = stdin;
+       filename = "stdin";
+     }
+   else
+     finput = fopen (filename, "r");
+   if (finput == 0)
+     pfatal_with_name (filename);
+ 
+ #ifdef IO_BUFFER_SIZE
+   setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
+ #endif
+ #endif /* !USE_CPPLIB */
+ 
    /* Initialize the lookahead machinery.  */
    init_spew ();
  
***************
*** 851,861 ****
        UNSET_RESERVED_WORD ("xor_eq");
      }
  
!   token_count = init_parse ();
    interface_unknown = 1;
  }
  
  void
  reinit_parse_for_function ()
  {
    current_base_init_list = NULL_TREE;
--- 888,908 ----
        UNSET_RESERVED_WORD ("xor_eq");
      }
  
!   token_count = init_cpp_parse ();
    interface_unknown = 1;
  }
  
  void
+ finish_parse ()
+ {
+ #if USE_CPPLIB
+   cpp_finish (&parse_in);
+ #else
+   fclose (finput);
+ #endif
+ }
+ 
+ void
  reinit_parse_for_function ()
  {
    current_base_init_list = NULL_TREE;
***************
*** 921,942 ****
  #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
  #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
  #endif
- 
- int *
- init_parse ()
- {
- #ifdef GATHER_STATISTICS
- #ifdef REDUCE_LENGTH
-   reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1));
-   bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1));
-   reduce_count += 1;
-   token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1));
-   bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1));
-   token_count += 1;
- #endif
- #endif
-   return token_count;
- }
  
  #ifdef GATHER_STATISTICS
  #ifdef REDUCE_LENGTH
--- 968,973 ----
Index: cp/spew.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/spew.c,v
retrieving revision 1.10
diff -c -r1.10 spew.c
*** spew.c	1998/03/31 13:25:41	1.10
--- spew.c	1998/04/02 22:50:52
***************
*** 69,75 ****
  static int debug_yychar ();
  #endif
  
! /* Initialize token_obstack. Called once, from init_lex.  */
  
  void
  init_spew ()
--- 69,75 ----
  static int debug_yychar ();
  #endif
  
! /* Initialize token_obstack. Called once, from init_parse.  */
  
  void
  init_spew ()
Index: f/com.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/f/com.c,v
retrieving revision 1.21
diff -c -r1.21 com.c
*** com.c	1998/03/28 00:35:33	1.21
--- com.c	1998/04/02 22:51:07
***************
*** 238,243 ****
--- 238,246 ----
  
  char *language_string = "GNU F77";
  
+ /* Stream for reading from the input file.  */
+ FILE *finput;
+ 
  /* These definitions parallel those in c-decl.c so that code from that
     module can be used pretty much as is.  Much of these defs aren't
     otherwise used, i.e. by g77 code per se, except some of them are used
***************
*** 14812,14823 ****
  }
  
  void
! init_lex ()
  {
  #if BUILT_FOR_270
    extern void (*print_error_function) (char *);
  #endif
  
    /* Make identifier nodes long enough for the language-specific slots.  */
    set_identifier_size (sizeof (struct lang_identifier));
    decl_printable_name = lang_printable_name;
--- 14815,14842 ----
  }
  
  void
! init_parse (filename)
!      char *filename;
  {
  #if BUILT_FOR_270
    extern void (*print_error_function) (char *);
  #endif
  
+   /* Open input file.  */
+   if (filename == 0 || !strcmp (filename, "-"))
+     {
+       finput = stdin;
+       filename = "stdin";
+     }
+   else
+     finput = fopen (filename, "r");
+   if (finput == 0)
+     pfatal_with_name (filename);
+ 
+ #ifdef IO_BUFFER_SIZE
+   setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
+ #endif
+ 
    /* Make identifier nodes long enough for the language-specific slots.  */
    set_identifier_size (sizeof (struct lang_identifier));
    decl_printable_name = lang_printable_name;
***************
*** 14827,14832 ****
--- 14846,14857 ----
  }
  
  void
+ finish_parse ()
+ {
+   fclose (finput);
+ }
+ 
+ void
  insert_block (block)
       tree block;
  {
***************
*** 14870,14877 ****
  void
  lang_init ()
  {
-   extern FILE *finput;		/* Don't pollute com.h with this. */
- 
    /* If the file is output from cpp, it should contain a first line
       `# 1 "real-filename"', and the current design of gcc (toplev.c
       in particular and the way it sets up information relied on by
--- 14895,14900 ----
diff -c ada/a-gtran3.c /home/brolley/comp/egcs/tmp/ada/a-gtran3.c
*** ada/a-gtran3.c	Mon Mar 30 16:29:04 1998
--- /home/brolley/comp/egcs/tmp/ada/a-gtran3.c	Thu Apr  2 17:16:15 1998
***************
*** 3329,3334 ****
--- 3329,3341 ----
       isn't changing.  Likewise, clear the alignment if it isn't being
       changed.  Then return if we aren't doing anything.  */
  
+     if (size != 0
+ 	&& TYPE_MODE (TREE_TYPE (size)) != TYPE_MODE (TREE_TYPE (orig_size)))
+       {
+ 	size = convert (sizetype, size);
+ 	orig_size = convert (sizetype, orig_size);
+       }
+  
    if (size != 0
        && (operand_equal_p (size, orig_size, 0)
  	  || (TREE_CODE (orig_size) == INTEGER_CST
diff -c ada/a-misc.c /home/brolley/comp/egcs/tmp/ada/a-misc.c
*** ada/a-misc.c	Mon Mar 30 16:29:05 1998
--- /home/brolley/comp/egcs/tmp/ada/a-misc.c	Thu Apr  2 17:36:19 1998
***************
*** 70,77 ****
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  
! char *gnat_tree_code_type[] = {
!   "x",
  #include "a-tree.def"
  };
  #undef DEFTREECODE
--- 70,77 ----
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  
! char gnat_tree_code_type[] = {
!   'x',
  #include "a-tree.def"
  };
  #undef DEFTREECODE
***************
*** 254,259 ****
--- 254,268 ----
  print_lang_statistics ()
  {}
  
+ void
+ lang_print_xnode (file, node, indent)
+      FILE *file;
+      tree node;
+      int indent;
+ {
+ }
+  
+ 
  /* integrate_decl_tree calls this function, but since we don't use the
     DECL_LANG_SPECIFIC field, this is a no-op.  */
  
***************
*** 603,622 ****
     it, but it's where g++ does it.  */
  
  void
! init_lex ()
  {
    lang_expand_expr = gnat_expand_expr;
  
-   tree_code_type
-     = (char **) realloc (tree_code_type,
- 			 sizeof (char *) * LAST_GNAT_TREE_CODE);
-   tree_code_length
-     = (int *) realloc (tree_code_length,
- 		       sizeof (int) * LAST_GNAT_TREE_CODE);
-   tree_code_name
-     = (char **) realloc (tree_code_name,
- 			 sizeof (char *) * LAST_GNAT_TREE_CODE);
- 
    bcopy ((char *) gnat_tree_code_type,
  	 (char *) (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE),
  	 ((LAST_GNAT_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE)
--- 612,622 ----
     it, but it's where g++ does it.  */
  
  void
! init_parse (filename)
!      char *filename
  {
    lang_expand_expr = gnat_expand_expr;
  
    bcopy ((char *) gnat_tree_code_type,
  	 (char *) (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE),
  	 ((LAST_GNAT_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE)
***************
*** 629,636 ****
  
    bcopy ((char *) gnat_tree_code_name,
  	 (char *) (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE),
! 	 ((LAST_GNAT_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE)
! 	  * sizeof (char *)));
  }
  
  /* Sets some debug flags for the parsed. It does nothing here.  */
--- 629,640 ----
  
    bcopy ((char *) gnat_tree_code_name,
  	 (char *) (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE),
! 	 LAST_GNAT_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE);
! }
! 
! void
! finish_parse ()
! {
  }
  
  /* Sets some debug flags for the parsed. It does nothing here.  */
diff -c ada/a-tree.def /home/brolley/comp/egcs/tmp/ada/a-tree.def
*** ada/a-tree.def	Mon Mar 30 16:29:09 1998
--- /home/brolley/comp/egcs/tmp/ada/a-tree.def	Thu Apr  2 17:20:38 1998
***************
*** 31,69 ****
     The only field used if TREE_COMPLEXITY, which contains the GNAT node
     number.  */
  
! DEFTREECODE (TRANSFORM_EXPR, "transform_expr", "e", 0)
  
  /* Perform an unchecked conversion between the input and the output. 
     if TREE_ADDRESSABLE is set, it means this is in an LHS; in that case,
     we can only use techniques, such as pointer punning, that leave the
     expression a "name".  */
  
! DEFTREECODE (UNCHECKED_CONVERT_EXPR, "unchecked_convert_expr", "1", 1)
  
  /* A type that is an unconstrained array itself.  This node is never passed
     to GCC. TREE_TYPE is the type of the fat pointer and TYPE_OBJECT_RECORD_TYPE
     is the type of a record containing the template and data.  */
  
! DEFTREECODE (UNCONSTRAINED_ARRAY_TYPE, "unconstrained_array_type", "t", 0)
  
  /* A reference to an unconstrained array.  This node only exists as an
     intermediate node during the translation of a GNAT tree to a GCC tree;
     it is never passed to GCC.  The only field used is operand 0, which
     is the fat pointer object.  */
  
! DEFTREECODE (UNCONSTRAINED_ARRAY_REF, "unconstrained_array_ref", "r", 1)
  
  /* An expression that returns an RTL suitable for its type.  Operand 0
     is an expression to be evaluated for side effects only.  */
  
! DEFTREECODE (NULL_EXPR, "null_expr", "e", 1)
  
  /* An expression that emits a USE for its single operand.  */
  
! DEFTREECODE (USE_EXPR, "use_expr", "e", 1)
  
  /* An expression that is treated as a conversion while generating code, but is
     used to prevent infinite recursion when conversions of biased types are
     involved.  */
  
! DEFTREECODE (GNAT_NOP_EXPR, "gnat_nop_expr", "1", 1)
--- 31,69 ----
     The only field used if TREE_COMPLEXITY, which contains the GNAT node
     number.  */
  
! DEFTREECODE (TRANSFORM_EXPR, "transform_expr", 'e', 0)
  
  /* Perform an unchecked conversion between the input and the output. 
     if TREE_ADDRESSABLE is set, it means this is in an LHS; in that case,
     we can only use techniques, such as pointer punning, that leave the
     expression a "name".  */
  
! DEFTREECODE (UNCHECKED_CONVERT_EXPR, "unchecked_convert_expr", '1', 1)
  
  /* A type that is an unconstrained array itself.  This node is never passed
     to GCC. TREE_TYPE is the type of the fat pointer and TYPE_OBJECT_RECORD_TYPE
     is the type of a record containing the template and data.  */
  
! DEFTREECODE (UNCONSTRAINED_ARRAY_TYPE, "unconstrained_array_type", 't', 0)
  
  /* A reference to an unconstrained array.  This node only exists as an
     intermediate node during the translation of a GNAT tree to a GCC tree;
     it is never passed to GCC.  The only field used is operand 0, which
     is the fat pointer object.  */
  
! DEFTREECODE (UNCONSTRAINED_ARRAY_REF, "unconstrained_array_ref", 'r', 1)
  
  /* An expression that returns an RTL suitable for its type.  Operand 0
     is an expression to be evaluated for side effects only.  */
  
! DEFTREECODE (NULL_EXPR, "null_expr", 'e', 1)
  
  /* An expression that emits a USE for its single operand.  */
  
! DEFTREECODE (USE_EXPR, "use_expr", 'e', 1)
  
  /* An expression that is treated as a conversion while generating code, but is
     used to prevent infinite recursion when conversions of biased types are
     involved.  */
  
! DEFTREECODE (GNAT_NOP_EXPR, "gnat_nop_expr", '1', 1)

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