Commit a269d6c8 by Richard Sandiford Committed by Richard Sandiford

read-rtl.c (string_obstack): New file-scope variable.

	* read-rtl.c (string_obstack): New file-scope variable.
	(read_string, read_quoted_string, read_braced_string)
	(read_escape): Remove obstack parameter and use string_obstack instead.
	(read_rtx): Remove function-local rtl_obstack and initialize
	string_obstack instead.  Update call to read_string.

From-SVN: r86402
parent 9fc3b39a
2004-08-23 Richard Sandiford <rsandifo@redhat.com>
* read-rtl.c (string_obstack): New file-scope variable.
(read_string, read_quoted_string, read_braced_string)
(read_escape): Remove obstack parameter and use string_obstack instead.
(read_rtx): Remove function-local rtl_obstack and initialize
string_obstack instead. Update call to read_string.
2004-08-22 Andrew Pinski <apinski@apple.com> 2004-08-22 Andrew Pinski <apinski@apple.com>
PR c/15262 PR c/15262
......
...@@ -34,15 +34,18 @@ static void fatal_with_file_and_line (FILE *, const char *, ...) ...@@ -34,15 +34,18 @@ static void fatal_with_file_and_line (FILE *, const char *, ...)
ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN; ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN;
static void fatal_expected_char (FILE *, int, int) ATTRIBUTE_NORETURN; static void fatal_expected_char (FILE *, int, int) ATTRIBUTE_NORETURN;
static void read_name (char *, FILE *); static void read_name (char *, FILE *);
static char *read_string (struct obstack *, FILE *, int); static char *read_string (FILE *, int);
static char *read_quoted_string (struct obstack *, FILE *); static char *read_quoted_string (FILE *);
static char *read_braced_string (struct obstack *, FILE *); static char *read_braced_string (FILE *);
static void read_escape (struct obstack *, FILE *); static void read_escape (FILE *);
static hashval_t def_hash (const void *); static hashval_t def_hash (const void *);
static int def_name_eq_p (const void *, const void *); static int def_name_eq_p (const void *, const void *);
static void read_constants (FILE *infile, char *tmp_char); static void read_constants (FILE *infile, char *tmp_char);
static void validate_const_int (FILE *, const char *); static void validate_const_int (FILE *, const char *);
/* Obstack used for allocating RTL strings. */
static struct obstack string_obstack;
/* Subroutines of read_rtx. */ /* Subroutines of read_rtx. */
/* The current line number for the file. */ /* The current line number for the file. */
...@@ -203,7 +206,7 @@ read_name (char *str, FILE *infile) ...@@ -203,7 +206,7 @@ read_name (char *str, FILE *infile)
/* Subroutine of the string readers. Handles backslash escapes. /* Subroutine of the string readers. Handles backslash escapes.
Caller has read the backslash, but not placed it into the obstack. */ Caller has read the backslash, but not placed it into the obstack. */
static void static void
read_escape (struct obstack *ob, FILE *infile) read_escape (FILE *infile)
{ {
int c = getc (infile); int c = getc (infile);
...@@ -232,31 +235,31 @@ read_escape (struct obstack *ob, FILE *infile) ...@@ -232,31 +235,31 @@ read_escape (struct obstack *ob, FILE *infile)
case 'a': case 'b': case 'f': case 'n': case 'r': case 't': case 'v': case 'a': case 'b': case 'f': case 'n': case 'r': case 't': case 'v':
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '0': case '1': case '2': case '3': case '4': case '5': case '6':
case '7': case 'x': case '7': case 'x':
obstack_1grow (ob, '\\'); obstack_1grow (&string_obstack, '\\');
break; break;
/* \; makes stuff for a C string constant containing /* \; makes stuff for a C string constant containing
newline and tab. */ newline and tab. */
case ';': case ';':
obstack_grow (ob, "\\n\\t", 4); obstack_grow (&string_obstack, "\\n\\t", 4);
return; return;
/* pass anything else through, but issue a warning. */ /* pass anything else through, but issue a warning. */
default: default:
fprintf (stderr, "%s:%d: warning: unrecognized escape \\%c\n", fprintf (stderr, "%s:%d: warning: unrecognized escape \\%c\n",
read_rtx_filename, read_rtx_lineno, c); read_rtx_filename, read_rtx_lineno, c);
obstack_1grow (ob, '\\'); obstack_1grow (&string_obstack, '\\');
break; break;
} }
obstack_1grow (ob, c); obstack_1grow (&string_obstack, c);
} }
/* Read a double-quoted string onto the obstack. Caller has scanned /* Read a double-quoted string onto the obstack. Caller has scanned
the leading quote. */ the leading quote. */
static char * static char *
read_quoted_string (struct obstack *ob, FILE *infile) read_quoted_string (FILE *infile)
{ {
int c; int c;
...@@ -267,30 +270,30 @@ read_quoted_string (struct obstack *ob, FILE *infile) ...@@ -267,30 +270,30 @@ read_quoted_string (struct obstack *ob, FILE *infile)
read_rtx_lineno++; read_rtx_lineno++;
else if (c == '\\') else if (c == '\\')
{ {
read_escape (ob, infile); read_escape (infile);
continue; continue;
} }
else if (c == '"') else if (c == '"')
break; break;
obstack_1grow (ob, c); obstack_1grow (&string_obstack, c);
} }
obstack_1grow (ob, 0); obstack_1grow (&string_obstack, 0);
return (char *) obstack_finish (ob); return (char *) obstack_finish (&string_obstack);
} }
/* Read a braced string (a la Tcl) onto the obstack. Caller has /* Read a braced string (a la Tcl) onto the string obstack. Caller
scanned the leading brace. Note that unlike quoted strings, has scanned the leading brace. Note that unlike quoted strings,
the outermost braces _are_ included in the string constant. */ the outermost braces _are_ included in the string constant. */
static char * static char *
read_braced_string (struct obstack *ob, FILE *infile) read_braced_string (FILE *infile)
{ {
int c; int c;
int brace_depth = 1; /* caller-processed */ int brace_depth = 1; /* caller-processed */
unsigned long starting_read_rtx_lineno = read_rtx_lineno; unsigned long starting_read_rtx_lineno = read_rtx_lineno;
obstack_1grow (ob, '{'); obstack_1grow (&string_obstack, '{');
while (brace_depth) while (brace_depth)
{ {
c = getc (infile); /* Read the string */ c = getc (infile); /* Read the string */
...@@ -303,7 +306,7 @@ read_braced_string (struct obstack *ob, FILE *infile) ...@@ -303,7 +306,7 @@ read_braced_string (struct obstack *ob, FILE *infile)
brace_depth--; brace_depth--;
else if (c == '\\') else if (c == '\\')
{ {
read_escape (ob, infile); read_escape (infile);
continue; continue;
} }
else if (c == EOF) else if (c == EOF)
...@@ -311,11 +314,11 @@ read_braced_string (struct obstack *ob, FILE *infile) ...@@ -311,11 +314,11 @@ read_braced_string (struct obstack *ob, FILE *infile)
(infile, "missing closing } for opening brace on line %lu", (infile, "missing closing } for opening brace on line %lu",
starting_read_rtx_lineno); starting_read_rtx_lineno);
obstack_1grow (ob, c); obstack_1grow (&string_obstack, c);
} }
obstack_1grow (ob, 0); obstack_1grow (&string_obstack, 0);
return (char *) obstack_finish (ob); return (char *) obstack_finish (&string_obstack);
} }
/* Read some kind of string constant. This is the high-level routine /* Read some kind of string constant. This is the high-level routine
...@@ -323,7 +326,7 @@ read_braced_string (struct obstack *ob, FILE *infile) ...@@ -323,7 +326,7 @@ read_braced_string (struct obstack *ob, FILE *infile)
and dispatch to the appropriate string constant reader. */ and dispatch to the appropriate string constant reader. */
static char * static char *
read_string (struct obstack *ob, FILE *infile, int star_if_braced) read_string (FILE *infile, int star_if_braced)
{ {
char *stringbuf; char *stringbuf;
int saw_paren = 0; int saw_paren = 0;
...@@ -337,12 +340,12 @@ read_string (struct obstack *ob, FILE *infile, int star_if_braced) ...@@ -337,12 +340,12 @@ read_string (struct obstack *ob, FILE *infile, int star_if_braced)
} }
if (c == '"') if (c == '"')
stringbuf = read_quoted_string (ob, infile); stringbuf = read_quoted_string (infile);
else if (c == '{') else if (c == '{')
{ {
if (star_if_braced) if (star_if_braced)
obstack_1grow (ob, '*'); obstack_1grow (&string_obstack, '*');
stringbuf = read_braced_string (ob, infile); stringbuf = read_braced_string (infile);
} }
else else
fatal_with_file_and_line (infile, "expected `\"' or `{', found `%c'", c); fatal_with_file_and_line (infile, "expected `\"' or `{', found `%c'", c);
...@@ -521,8 +524,6 @@ read_rtx (FILE *infile) ...@@ -521,8 +524,6 @@ read_rtx (FILE *infile)
int tmp_int; int tmp_int;
HOST_WIDE_INT tmp_wide; HOST_WIDE_INT tmp_wide;
/* Obstack used for allocating RTL objects. */
static struct obstack rtl_obstack;
static int initialized; static int initialized;
/* Linked list structure for making RTXs: */ /* Linked list structure for making RTXs: */
...@@ -532,10 +533,11 @@ read_rtx (FILE *infile) ...@@ -532,10 +533,11 @@ read_rtx (FILE *infile)
rtx value; /* Value of this node. */ rtx value; /* Value of this node. */
}; };
if (!initialized) { if (!initialized)
obstack_init (&rtl_obstack); {
initialized = 1; obstack_init (&string_obstack);
} initialized = 1;
}
again: again:
c = read_skip_spaces (infile); /* Should be open paren. */ c = read_skip_spaces (infile); /* Should be open paren. */
...@@ -676,7 +678,7 @@ again: ...@@ -676,7 +678,7 @@ again:
written with a brace block instead of a string constant. */ written with a brace block instead of a string constant. */
star_if_braced = (format_ptr[-1] == 'T'); star_if_braced = (format_ptr[-1] == 'T');
stringbuf = read_string (&rtl_obstack, infile, star_if_braced); stringbuf = read_string (infile, star_if_braced);
/* For insn patterns, we want to provide a default name /* For insn patterns, we want to provide a default name
based on the file and line, like "*foo.md:12", if the based on the file and line, like "*foo.md:12", if the
...@@ -693,11 +695,11 @@ again: ...@@ -693,11 +695,11 @@ again:
for (slash = fn; *slash; slash ++) for (slash = fn; *slash; slash ++)
if (*slash == '/' || *slash == '\\' || *slash == ':') if (*slash == '/' || *slash == '\\' || *slash == ':')
fn = slash + 1; fn = slash + 1;
obstack_1grow (&rtl_obstack, '*'); obstack_1grow (&string_obstack, '*');
obstack_grow (&rtl_obstack, fn, strlen (fn)); obstack_grow (&string_obstack, fn, strlen (fn));
sprintf (line_name, ":%d", read_rtx_lineno); sprintf (line_name, ":%d", read_rtx_lineno);
obstack_grow (&rtl_obstack, line_name, strlen (line_name)+1); obstack_grow (&string_obstack, line_name, strlen (line_name)+1);
stringbuf = (char *) obstack_finish (&rtl_obstack); stringbuf = (char *) obstack_finish (&string_obstack);
} }
if (star_if_braced) if (star_if_braced)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment