From: Richard Henderson Date: Mon, 20 May 2002 01:17:14 +0000 (-0700) Subject: gensupport.c (init_include_reader): Merge into ... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=174cc7d12781fcced14be9b0af9ab7e1b9120206;p=gcc.git gensupport.c (init_include_reader): Merge into ... * gensupport.c (init_include_reader): Merge into ... (process_include): ... here. Simplify composite path creation. Plug memory leaks. Fix file/line number tracking. Do not process_define_cond_exec. Return void. (process_rtx): Don't check process_include return value. From-SVN: r53643 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0aedfaae3c4..50bb057c89f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2002-05-19 Richard Henderson + + * gensupport.c (init_include_reader): Merge into ... + (process_include): ... here. Simplify composite path creation. + Plug memory leaks. Fix file/line number tracking. Do not + process_define_cond_exec. Return void. + (process_rtx): Don't check process_include return value. + 2002-05-20 Zdenek Dvorak * basic_block.h (struct basic_block_def): Added prev_bb and next_bb diff --git a/gcc/gensupport.c b/gcc/gensupport.c index e6292d9981f..8b52eaecab8 100644 --- a/gcc/gensupport.c +++ b/gcc/gensupport.c @@ -97,9 +97,8 @@ static const char *alter_output_for_insn PARAMS ((struct queue_elem *, int, int)); static void process_one_cond_exec PARAMS ((struct queue_elem *)); static void process_define_cond_exec PARAMS ((void)); -static int process_include PARAMS ((rtx, int)); +static void process_include PARAMS ((rtx, int)); static char *save_string PARAMS ((const char *, int)); -static int init_include_reader PARAMS ((FILE *)); void message_with_line VPARAMS ((int lineno, const char *msg, ...)) @@ -179,142 +178,81 @@ remove_constraints (part) } } -/* The entry point for initializing the reader. */ - -static int -init_include_reader (inf) - FILE *inf; -{ - int c; - - errors = 0; - - /* Read the entire file. */ - while (1) - { - rtx desc; - int lineno; - - c = read_skip_spaces (inf); - if (c == EOF) - break; - - ungetc (c, inf); - lineno = read_rtx_lineno; - desc = read_rtx (inf); - process_rtx (desc, lineno); - } - fclose (inf); - - /* Process define_cond_exec patterns. */ - if (define_cond_exec_queue != NULL) - process_define_cond_exec (); - - return errors ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE; -} - /* Process an include file assuming that it lives in gcc/config/{target}/ - if the include looks line (include "file" ) */ -static int + if the include looks line (include "file"). */ + +static void process_include (desc, lineno) rtx desc; int lineno; { const char *filename = XSTR (desc, 0); - char *pathname = NULL; + const char *old_filename; + int old_lineno; + char *pathname; FILE *input_file; - char *fname = NULL; - struct file_name_list *stackp; - int flen; - stackp = first_dir_md_include; - - /* If specified file name is absolute, just open it. */ - if (IS_ABSOLUTE_PATHNAME (filename) || !stackp) + /* If specified file name is absolute, skip the include stack. */ + if (! IS_ABSOLUTE_PATHNAME (filename)) { - if (base_dir) - { - pathname = xmalloc (strlen (base_dir) + strlen (filename) + 1); - pathname = strcpy (pathname, base_dir); - strcat (pathname, filename); - strcat (pathname, "\0"); - } - else - { - pathname = xstrdup (filename); - } - read_rtx_filename = pathname; - input_file = fopen (pathname, "r"); + struct file_name_list *stackp; - if (input_file == 0) + /* Search directory path, trying to open the file. */ + for (stackp = first_dir_md_include; stackp; stackp = stackp->next) { - perror (pathname); - return FATAL_EXIT_CODE; + static const char sep[2] = { DIR_SEPARATOR, '\0' }; + + pathname = concat (stackp->fname, sep, filename, NULL); + input_file = fopen (pathname, "r"); + if (input_file != NULL) + goto success; + free (pathname); } } - else if (stackp) - { - - flen = strlen (filename); - - fname = (char *) xmalloc (max_include_len + flen + 2); - /* + 2 above for slash and terminating null. */ + if (base_dir) + pathname = concat (base_dir, filename, NULL); + else + pathname = xstrdup (filename); + input_file = fopen (pathname, "r"); + if (input_file == NULL) + { + free (pathname); + message_with_line (lineno, "include file `%s' not found", filename); + errors = 1; + return; + } + success: - /* Search directory path, trying to open the file. - Copy each filename tried into FNAME. */ + /* Save old cursor; setup new for the new file. Note that "lineno" the + argument to this function is the beginning of the include statement, + while read_rtx_lineno has already been advanced. */ + old_filename = read_rtx_filename; + old_lineno = read_rtx_lineno; + read_rtx_filename = pathname; + read_rtx_lineno = 1; - for (; stackp; stackp = stackp->next) - { - if (stackp->fname) - { - strcpy (fname, stackp->fname); - strcat (fname, "/"); - fname[strlen (fname) + flen] = 0; - } - else - { - fname[0] = 0; - } - strncat (fname, (const char *) filename, flen); - read_rtx_filename = fname; - input_file = fopen (fname, "r"); - if (input_file != NULL) - break; - } - if (stackp == NULL) - { - if (strchr (fname, '/') == NULL || strchr (fname, '\\' ) || base_dir) - { - if (base_dir) - { - pathname = - xmalloc (strlen (base_dir) + strlen (filename) + 1); - pathname = strcpy (pathname, base_dir); - strcat (pathname, filename); - strcat (pathname, "\0"); - } - else - pathname = xstrdup (filename); - } - read_rtx_filename = pathname; - input_file = fopen (pathname, "r"); + /* Read the entire file. */ + while (1) + { + rtx desc; + int c; - if (input_file == 0) - { - perror (filename); - return FATAL_EXIT_CODE; - } - } + c = read_skip_spaces (input_file); + if (c == EOF) + break; + ungetc (c, input_file); + lineno = read_rtx_lineno; + desc = read_rtx (input_file); + process_rtx (desc, lineno); } - if (init_include_reader (input_file) == FATAL_EXIT_CODE) - message_with_line (lineno, "read errors found in include file %s\n", pathname); + read_rtx_filename = old_filename; + read_rtx_lineno = old_lineno; - if (fname) - free (fname); - return SUCCESS_EXIT_CODE; + fclose (input_file); + free (pathname); } /* Process a top level rtx in some way, queueing as appropriate. */ @@ -339,12 +277,7 @@ process_rtx (desc, lineno) break; case INCLUDE: - if (process_include (desc, lineno) == FATAL_EXIT_CODE) - { - const char *filename = XSTR (desc, 0); - message_with_line (lineno, "include file at %s not found\n", - filename); - } + process_include (desc, lineno); break; case DEFINE_INSN_AND_SPLIT: