8sa1-gcc/gcc/genextract.c
Kaveh R. Ghazi d6f4ec5199 Warning fixes:
* Makefile.in (c-lang.o): Depend on c-tree.h, c-lex.h and toplev.h.
	(c-lex.o): Depend on output.h.
	(c-common.o): Likewise.
	(stmt.o): Likewise.
	(calls.o): Likewise.
	(integrate.o): Depend on toplev.h.
	(regclass.o): Depend on output.h.
	(final.o): Depend on reload.h.
	* c-common.c: Include output.h.
	(check_format_info): Remove unused variable `integral_format'.
	* c-decl.c (print_lang_decl): Mark parameters `file', `node' and
	`indent' with ATTRIBUTE_UNUSED.
	(print_lang_type): Likewise.
	(maybe_build_cleanup): Likewise for parameter `decl'.
	(copy_lang_decl): Likewise for parameter `node'.
	* c-lang.c: Include c-tree.h, c-lex.h and toplev.h.
	(lang_print_xnode): Mark parameters `file', `node' and `indent'
 	with ATTRIBUTE_UNUSED.
	(lookup_interface): Likewise for parameter `arg'.
	(is_class_name): Likewise.
	(maybe_objc_check_decl): Likewise for parameter `decl'.
	(maybe_objc_comptypes): Likewise for parameters `lhs', `rhs' and
	`reflexive'.
	(maybe_objc_method_name): Likewise for parameter `decl'.
	(build_objc_string): Likewise for parameters `len' and `str'.
	* c-lex.c: Include output.h.
	* c-lex.h (position_after_white_space): Correct typo in prototype.
	* c-tree.h (finish_file, c_expand_start_cond, c_expand_start_else,
 	c_expand_end_cond, init_iterators): Add prototypes.
	* caller-save.c (set_reg_live): Mark parameters `reg' and `setter'
	with ATTRIBUTE_UNUSED.
	* calls.c: Include output.h.
	* cccp.c (pipe_closed): Mark parameter `signo' with
 	ATTRIBUTE_UNUSED.
	* combine.c: Move inclusion of expr.h to after insn-config.h.
	* iris6.h (ASM_IDENTIFY_GCC, ASM_IDENTIFY_LANGUAGE): Don't define
	as empty, rather define as ((void)0).
	* sparc.c (sparc_check_64): Add braces around ambiguous `else'.
	Add parentheses around assignment used as truth value.
	* cplus-dem.c (squangle_mop_up): Change return type to void.
	(internal_cplus_demangle): Remove unused parameter `options'.
	All callers changed.
	(cplus_demangle_opname): Remove function wide variable `int i' and
 	replace with `size_t i' at each location where it is used.
	(cplus_demangle_opname): change type of `i' from int to size_t.
	* cppexp.c (right_shift): Mark parameter `pfile' with
	ATTRIBUTE_UNUSED.
	* cpphash.c (cpp_lookup): Likewise.
	(cpp_hash_cleanup): Likewise.
	* cpplib.c (parse_name): Add a prototype and make it static.
	(null_underflow): Mark parameter `pfile' with ATTRIBUTE_UNUSED.
	(null_cleanup): Likewise for parameters `pbuf' and `pfile'.
	(macro_cleanup): Likewise for parameter `pfile'.
	(file_cleanup): Likewise.
	* cpplib.h (cpp_reader_init, cpp_options_init, cpp_start_read,
 	cpp_read_check_assertion, skip_rest_of_line): Add prototypes.
	* crtstuff.c (force_to_data, __CTOR_LIST__, force_to_data,
	__DTOR_END__, __FRAME_END__): Mark with ATTRIBUTE_UNUSED.
	* cse.c (cse_check_loop_start): Mark parameter `set' with
 	ATTRIBUTE_UNUSED.
	* dbxout.c (flag_minimal_debug, have_used_extensions,
	source_label_number): Move inside macro wrapper check against
	defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO).
	* dwarf2out.c (gen_entry_point_die): Hide prototype and definition.
	* except.h (doing_eh): Provide prototype.
	* expr.c: Move inclusion of expr.h to after insn-config.h.
	* final.c: Include reload.h.
	(shorten_branches): Cast the first argument of bzero to char *.
	* fix-header.c (cpp_print_containing_files): Mark parameter
 	`pfile' with ATTRIBUTE_UNUSED.
	(cpp_fatal): Likewise.
	* flow.c (find_basic_blocks_1): Cast the first argument of bzero
	to char *.
	* genattrtab.c (make_length_attrs): Change the type of variable
	`i' from int to size_t.
	(zero_fn): Mark parameter `exp' with ATTRIBUTE_UNUSED.
	(one_fn): Likewise.
	* genextract.c (main): When generating insn-extract.c, mark
	variable `junk' with ATTRIBUTE_UNUSED.
	* gengenrtl.c (gencode): When generating genrtl.c, cast the first
	argument of bzero to char*.
	* integrate.c: Include toplev.h.
	* libgcc2.c: Wrap `struct exception_table' and
	`find_exception_handler' in macro DWARF2_UNWIND_INFO.
	* objc/Make-lang.in (objc-act.o): Depend on toplev.h.
	* objc/objc-act.c: Include toplev.h.
	(lang_print_xnode): Mark parameters `file', `node' and `indent'
	with ATTRIBUTE_UNUSED.
	(finish_protocol): Likewise for parameter `protocol'.
	* output.h (declare_weak): Add prototype.
	(decode_reg_name): Don't wrap with TREE_CODE macro.
	(assemble_alias): Add prototype.
	* regclass.c: Include output.h.
	* reload.h (reloads_conflict): Add prototype.
	* rtl.h (print_rtl_single, mark_elimiation, reg_class_subset_p,
	output_func_start_profiler): Add prototypes.
	* rtlanal.c (reg_set_p_1): Mark parameters `x' and `pat' with
 	ATTRIBUTE_UNUSED.
	* scan-decls.c: Include scan.h.
	* scan.h (recognized_function, recognized_extern): Add prototypes.
	* stmt.c: Include output.h.
	* toplev.c (error_for_asm, warning_for_asm): Remove prototypes.
	(output_lang_identify): Hide prototype and definition.
	(float_signal): Mark parameter `signo' with ATTRIBUTE_UNUSED.
	(pipe_closed): Likewise.
	* toplev.h (count_error, strip_off_ending, error_for_asm,
 	warning_for_asm): Add prototypes.

From-SVN: r19712
1998-05-13 12:40:39 +00:00

572 lines
13 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Generate code from machine description to extract operands from insn as rtl.
Copyright (C) 1987, 91, 92, 93, 97, 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "hconfig.h"
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "system.h"
#include "rtl.h"
#include "obstack.h"
#include "insn-config.h"
static struct obstack obstack;
struct obstack *rtl_obstack = &obstack;
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
/* Names for patterns. Need to allow linking with print-rtl. */
char **insn_name_ptr;
/* This structure contains all the information needed to describe one
set of extractions methods. Each method may be used by more than
one pattern if the operands are in the same place.
The string for each operand describes that path to the operand and
contains `0' through `9' when going into an expression and `a' through
`z' when going into a vector. We assume here that only the first operand
of an rtl expression is a vector. genrecog.c makes the same assumption
(and uses the same representation) and it is currently true. */
struct extraction
{
int op_count;
char *oplocs[MAX_RECOG_OPERANDS];
int dup_count;
char *duplocs[MAX_DUP_OPERANDS];
int dupnums[MAX_DUP_OPERANDS];
struct code_ptr *insns;
struct extraction *next;
};
/* Holds a single insn code that use an extraction method. */
struct code_ptr
{
int insn_code;
struct code_ptr *next;
};
static struct extraction *extractions;
/* Number instruction patterns handled, starting at 0 for first one. */
static int insn_code_number;
/* Records the large operand number in this insn. */
static int op_count;
/* Records the location of any operands using the string format described
above. */
static char *oplocs[MAX_RECOG_OPERANDS];
/* Number the occurrences of MATCH_DUP in each instruction,
starting at 0 for the first occurrence. */
static int dup_count;
/* Records the location of any MATCH_DUP operands. */
static char *duplocs[MAX_DUP_OPERANDS];
/* Record the operand number of any MATCH_DUPs. */
static int dupnums[MAX_DUP_OPERANDS];
/* Record the list of insn_codes for peepholes. */
static struct code_ptr *peepholes;
static void gen_insn PROTO ((rtx));
static void walk_rtx PROTO ((rtx, char *));
static void print_path PROTO ((char *));
char *xmalloc PROTO ((unsigned));
char *xrealloc PROTO ((char *, unsigned));
static void fatal PVPROTO ((char *, ...)) ATTRIBUTE_PRINTF_1;
static char *copystr PROTO ((char *));
static void mybzero ();
void fancy_abort PROTO ((void));
static void
gen_insn (insn)
rtx insn;
{
register int i;
register struct extraction *p;
register struct code_ptr *link;
op_count = 0;
dup_count = 0;
/* No operands seen so far in this pattern. */
mybzero (oplocs, sizeof oplocs);
/* Walk the insn's pattern, remembering at all times the path
down to the walking point. */
if (XVECLEN (insn, 1) == 1)
walk_rtx (XVECEXP (insn, 1, 0), "");
else
for (i = XVECLEN (insn, 1) - 1; i >= 0; i--)
{
char *path = (char *) alloca (2);
path[0] = 'a' + i;
path[1] = 0;
walk_rtx (XVECEXP (insn, 1, i), path);
}
link = (struct code_ptr *) xmalloc (sizeof (struct code_ptr));
link->insn_code = insn_code_number;
/* See if we find something that already had this extraction method. */
for (p = extractions; p; p = p->next)
{
if (p->op_count != op_count || p->dup_count != dup_count)
continue;
for (i = 0; i < op_count; i++)
if (p->oplocs[i] != oplocs[i]
&& ! (p->oplocs[i] != 0 && oplocs[i] != 0
&& ! strcmp (p->oplocs[i], oplocs[i])))
break;
if (i != op_count)
continue;
for (i = 0; i < dup_count; i++)
if (p->dupnums[i] != dupnums[i]
|| strcmp (p->duplocs[i], duplocs[i]))
break;
if (i != dup_count)
continue;
/* This extraction is the same as ours. Just link us in. */
link->next = p->insns;
p->insns = link;
return;
}
/* Otherwise, make a new extraction method. */
p = (struct extraction *) xmalloc (sizeof (struct extraction));
p->op_count = op_count;
p->dup_count = dup_count;
p->next = extractions;
extractions = p;
p->insns = link;
link->next = 0;
for (i = 0; i < op_count; i++)
p->oplocs[i] = oplocs[i];
for (i = 0; i < dup_count; i++)
p->dupnums[i] = dupnums[i], p->duplocs[i] = duplocs[i];
}
static void
walk_rtx (x, path)
rtx x;
char *path;
{
register RTX_CODE code;
register int i;
register int len;
register char *fmt;
int depth = strlen (path);
char *newpath;
if (x == 0)
return;
code = GET_CODE (x);
switch (code)
{
case PC:
case CC0:
case CONST_INT:
case SYMBOL_REF:
return;
case MATCH_OPERAND:
case MATCH_SCRATCH:
oplocs[XINT (x, 0)] = copystr (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
break;
case MATCH_DUP:
case MATCH_PAR_DUP:
duplocs[dup_count] = copystr (path);
dupnums[dup_count] = XINT (x, 0);
dup_count++;
break;
case MATCH_OP_DUP:
duplocs[dup_count] = copystr (path);
dupnums[dup_count] = XINT (x, 0);
dup_count++;
newpath = (char *) alloca (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
for (i = XVECLEN (x, 1) - 1; i >= 0; i--)
{
newpath[depth] = '0' + i;
walk_rtx (XVECEXP (x, 1, i), newpath);
}
return;
case MATCH_OPERATOR:
oplocs[XINT (x, 0)] = copystr (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
newpath = (char *) alloca (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
for (i = XVECLEN (x, 2) - 1; i >= 0; i--)
{
newpath[depth] = '0' + i;
walk_rtx (XVECEXP (x, 2, i), newpath);
}
return;
case MATCH_PARALLEL:
oplocs[XINT (x, 0)] = copystr (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
newpath = (char *) alloca (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
for (i = XVECLEN (x, 2) - 1; i >= 0; i--)
{
newpath[depth] = 'a' + i;
walk_rtx (XVECEXP (x, 2, i), newpath);
}
return;
case ADDRESS:
walk_rtx (XEXP (x, 0), path);
return;
default:
break;
}
newpath = (char *) alloca (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
fmt = GET_RTX_FORMAT (code);
len = GET_RTX_LENGTH (code);
for (i = 0; i < len; i++)
{
if (fmt[i] == 'e' || fmt[i] == 'u')
{
newpath[depth] = '0' + i;
walk_rtx (XEXP (x, i), newpath);
}
else if (fmt[i] == 'E')
{
int j;
for (j = XVECLEN (x, i) - 1; j >= 0; j--)
{
newpath[depth] = 'a' + j;
walk_rtx (XVECEXP (x, i, j), newpath);
}
}
}
}
/* Given a PATH, representing a path down the instruction's
pattern from the root to a certain point, output code to
evaluate to the rtx at that point. */
static void
print_path (path)
char *path;
{
register int len = strlen (path);
register int i;
/* We first write out the operations (XEXP or XVECEXP) in reverse
order, then write "insn", then the indices in forward order. */
for (i = len - 1; i >=0 ; i--)
{
if (path[i] >= 'a' && path[i] <= 'z')
printf ("XVECEXP (");
else if (path[i] >= '0' && path[i] <= '9')
printf ("XEXP (");
else
abort ();
}
printf ("pat");
for (i = 0; i < len; i++)
{
if (path[i] >= 'a' && path[i] <= 'z')
printf (", 0, %d)", path[i] - 'a');
else if (path[i] >= '0' && path[i] <= '9')
printf (", %d)", path[i] - '0');
else
abort ();
}
}
char *
xmalloc (size)
unsigned size;
{
register char *val = (char *) malloc (size);
if (val == 0)
fatal ("virtual memory exhausted");
return val;
}
char *
xrealloc (ptr, size)
char *ptr;
unsigned size;
{
char *result = (char *) realloc (ptr, size);
if (!result)
fatal ("virtual memory exhausted");
return result;
}
static void
fatal VPROTO ((char *format, ...))
{
#ifndef __STDC__
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef __STDC__
format = va_arg (ap, char *);
#endif
fprintf (stderr, "genextract: ");
vfprintf (stderr, format, ap);
va_end (ap);
fprintf (stderr, "\n");
exit (FATAL_EXIT_CODE);
}
/* More 'friendly' abort that prints the line and file.
config.h can #define abort fancy_abort if you like that sort of thing. */
void
fancy_abort ()
{
fatal ("Internal gcc abort.");
}
static char *
copystr (s1)
char *s1;
{
register char *tem;
if (s1 == 0)
return 0;
tem = (char *) xmalloc (strlen (s1) + 1);
strcpy (tem, s1);
return tem;
}
static void
mybzero (b, length)
register char *b;
register unsigned length;
{
while (length-- > 0)
*b++ = 0;
}
int
main (argc, argv)
int argc;
char **argv;
{
rtx desc;
FILE *infile;
register int c, i;
struct extraction *p;
struct code_ptr *link;
obstack_init (rtl_obstack);
if (argc <= 1)
fatal ("No input file name.");
infile = fopen (argv[1], "r");
if (infile == 0)
{
perror (argv[1]);
exit (FATAL_EXIT_CODE);
}
init_rtl ();
/* Assign sequential codes to all entries in the machine description
in parallel with the tables in insn-output.c. */
insn_code_number = 0;
printf ("/* Generated automatically by the program `genextract'\n\
from the machine description file `md'. */\n\n");
printf ("#include \"config.h\"\n");
printf ("#include \"system.h\"\n");
printf ("#include \"rtl.h\"\n\n");
/* This variable exists only so it can be the "location"
of any missing operand whose numbers are skipped by a given pattern. */
printf ("static rtx junk ATTRIBUTE_UNUSED;\n");
printf ("extern rtx recog_operand[];\n");
printf ("extern rtx *recog_operand_loc[];\n");
printf ("extern rtx *recog_dup_loc[];\n");
printf ("extern char recog_dup_num[];\n");
printf ("void\ninsn_extract (insn)\n");
printf (" rtx insn;\n");
printf ("{\n");
printf (" register rtx *ro = recog_operand;\n");
printf (" register rtx **ro_loc = recog_operand_loc;\n");
printf (" rtx pat = PATTERN (insn);\n");
printf (" int i;\n\n");
printf (" switch (INSN_CODE (insn))\n");
printf (" {\n");
printf (" case -1:\n");
printf (" fatal_insn_not_found (insn);\n\n");
/* Read the machine description. */
while (1)
{
c = read_skip_spaces (infile);
if (c == EOF)
break;
ungetc (c, infile);
desc = read_rtx (infile);
if (GET_CODE (desc) == DEFINE_INSN)
{
gen_insn (desc);
++insn_code_number;
}
else if (GET_CODE (desc) == DEFINE_PEEPHOLE)
{
struct code_ptr *link
= (struct code_ptr *) xmalloc (sizeof (struct code_ptr));
link->insn_code = insn_code_number;
link->next = peepholes;
peepholes = link;
++insn_code_number;
}
else if (GET_CODE (desc) == DEFINE_EXPAND
|| GET_CODE (desc) == DEFINE_SPLIT)
++insn_code_number;
}
/* Write out code to handle peepholes and the insn_codes that it should
be called for. */
if (peepholes)
{
for (link = peepholes; link; link = link->next)
printf (" case %d:\n", link->insn_code);
/* The vector in the insn says how many operands it has.
And all it contains are operands. In fact, the vector was
created just for the sake of this function. */
printf (" for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)\n");
printf (" ro[i] = XVECEXP (pat, 0, i);\n");
printf (" break;\n\n");
}
/* Write out all the ways to extract insn operands. */
for (p = extractions; p; p = p->next)
{
for (link = p->insns; link; link = link->next)
printf (" case %d:\n", link->insn_code);
for (i = 0; i < p->op_count; i++)
{
if (p->oplocs[i] == 0)
{
printf (" ro[%d] = const0_rtx;\n", i);
printf (" ro_loc[%d] = &junk;\n", i);
}
else
{
printf (" ro[%d] = *(ro_loc[%d] = &", i, i);
print_path (p->oplocs[i]);
printf (");\n");
}
}
for (i = 0; i < p->dup_count; i++)
{
printf (" recog_dup_loc[%d] = &", i);
print_path (p->duplocs[i]);
printf (";\n");
printf (" recog_dup_num[%d] = %d;\n", i, p->dupnums[i]);
}
printf (" break;\n\n");
}
/* This should never be reached. Note that we would also reach this abort
if we tried to extract something whose INSN_CODE was a DEFINE_EXPAND or
DEFINE_SPLIT, but that is correct. */
printf (" default:\n abort ();\n");
printf (" }\n}\n");
fflush (stdout);
exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
/* NOTREACHED */
return 0;
}