X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fgenextract.c;h=c414891bb6bfa6788696cd5c97488e89c85fa1c4;hb=f96d34f19f87467b4ca672d423857405c2913bc6;hp=1fd684228cf4323d2fdb969f188b66a614e6ce74;hpb=0a1039d0a6d67e2b6c303ceb4079deead1e6b108;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/genextract.c b/gcc/genextract.c index 1fd684228cf..c414891bb6b 100644 --- a/gcc/genextract.c +++ b/gcc/genextract.c @@ -1,13 +1,13 @@ /* Generate code from machine description to extract operands from insn as rtl. Copyright (C) 1987, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2003, - 2004, 2005 + 2004, 2005, 2007, 2008 Free Software Foundation, Inc. This file is part of GCC. GCC 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 +Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY @@ -16,9 +16,8 @@ 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ +along with GCC; see the file COPYING3. If not see +. */ #include "bconfig.h" @@ -29,6 +28,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA #include "errors.h" #include "gensupport.h" #include "vec.h" +#include "vecprim.h" /* This structure contains all the information needed to describe one set of extractions methods. Each method may be used by more than @@ -69,11 +69,7 @@ static struct code_ptr *peepholes; /* This structure is used by gen_insn and walk_rtx to accumulate the data that will be used to produce an extractions structure. */ -DEF_VEC_I(int); -DEF_VEC_I(char); DEF_VEC_P(locstr); -DEF_VEC_ALLOC_I(int,heap); -DEF_VEC_ALLOC_I(char,heap); DEF_VEC_ALLOC_P(locstr,heap); struct accum_extract @@ -84,9 +80,10 @@ struct accum_extract VEC(char,heap) *pathstr; }; +int line_no; + /* Forward declarations. */ static void walk_rtx (rtx, struct accum_extract *); -static void record_insn_name (int, const char *); static void gen_insn (rtx insn, int insn_code_number) @@ -157,7 +154,7 @@ gen_insn (rtx insn, int insn_code_number) /* Otherwise, make a new extraction method. We stash the arrays after the extraction structure in memory. */ - p = xmalloc (sizeof (struct extraction) + p = XNEWVAR (struct extraction, sizeof (struct extraction) + op_count*sizeof (char *) + dup_count*sizeof (char *) + dup_count*sizeof (int)); @@ -188,18 +185,23 @@ gen_insn (rtx insn, int insn_code_number) exist and be NULL, or not yet exist within the vector. In the latter case the vector is enlarged as appropriate. */ static void -VEC_safe_set_locstr (VEC(locstr,heap) *v, unsigned int ix, char *str) +VEC_safe_set_locstr (VEC(locstr,heap) **vp, unsigned int ix, char *str) { - if (ix < VEC_length (locstr, v)) + if (ix < VEC_length (locstr, *vp)) { - gcc_assert (VEC_index (locstr, v, ix) == 0); - VEC_replace (locstr, v, ix, str); + if (VEC_index (locstr, *vp, ix)) + { + message_with_line (line_no, "repeated operand number %d", ix); + have_error = 1; + } + else + VEC_replace (locstr, *vp, ix, str); } else { - while (ix > VEC_length (locstr, v)) - VEC_safe_push (locstr,heap, v, 0); - VEC_safe_push (locstr,heap, v, str); + while (ix > VEC_length (locstr, *vp)) + VEC_safe_push (locstr, heap, *vp, 0); + VEC_safe_push (locstr, heap, *vp, str); } } @@ -209,7 +211,7 @@ static char * VEC_char_to_string (VEC(char,heap) *v) { size_t n = VEC_length (char, v); - char *s = xmalloc (n + 1); + char *s = XNEWVEC (char, n + 1); memcpy (s, VEC_address (char, v), n); s[n] = '\0'; return s; @@ -236,13 +238,13 @@ walk_rtx (rtx x, struct accum_extract *acc) case MATCH_OPERAND: case MATCH_SCRATCH: - VEC_safe_set_locstr (acc->oplocs, XINT (x, 0), + VEC_safe_set_locstr (&acc->oplocs, XINT (x, 0), VEC_char_to_string (acc->pathstr)); break; case MATCH_OPERATOR: case MATCH_PARALLEL: - VEC_safe_set_locstr (acc->oplocs, XINT (x, 0), + VEC_safe_set_locstr (&acc->oplocs, XINT (x, 0), VEC_char_to_string (acc->pathstr)); base = (code == MATCH_OPERATOR ? '0' : 'a'); @@ -404,7 +406,6 @@ main (int argc, char **argv) struct code_ptr *link; const char *name; int insn_code_number; - int line_no; progname = "genextract"; @@ -416,14 +417,11 @@ main (int argc, char **argv) while ((desc = read_md_rtx (&line_no, &insn_code_number)) != NULL) { if (GET_CODE (desc) == DEFINE_INSN) - { - record_insn_name (insn_code_number, XSTR (desc, 0)); - gen_insn (desc, insn_code_number); - } + gen_insn (desc, insn_code_number); else if (GET_CODE (desc) == DEFINE_PEEPHOLE) { - struct code_ptr *link = xmalloc (sizeof (struct code_ptr)); + struct code_ptr *link = XNEW (struct code_ptr); link->insn_code = insn_code_number; link->next = peepholes; @@ -431,6 +429,9 @@ main (int argc, char **argv) } } + if (have_error) + return FATAL_EXIT_CODE; + print_header (); /* Write out code to handle peepholes and the insn_codes that it should @@ -493,49 +494,3 @@ main (int argc, char **argv) fflush (stdout); return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); } - -/* Define this so we can link with print-rtl.o to get debug_rtx function. */ - -/* Holds an array of names indexed by insn_code_number. */ -static char **insn_name_ptr = 0; -static int insn_name_ptr_size = 0; - -const char * -get_insn_name (int code ATTRIBUTE_UNUSED) -{ - if (code < insn_name_ptr_size) - return insn_name_ptr[code]; - else - return NULL; -} - -static void -record_insn_name (int code, const char *name) -{ - static const char *last_real_name = "insn"; - static int last_real_code = 0; - char *new; - - if (insn_name_ptr_size <= code) - { - int new_size; - new_size = (insn_name_ptr_size ? insn_name_ptr_size * 2 : 512); - insn_name_ptr = xrealloc (insn_name_ptr, sizeof(char *) * new_size); - memset (insn_name_ptr + insn_name_ptr_size, 0, - sizeof(char *) * (new_size - insn_name_ptr_size)); - insn_name_ptr_size = new_size; - } - - if (!name || name[0] == '\0') - { - new = xmalloc (strlen (last_real_name) + 10); - sprintf (new, "%s+%d", last_real_name, code - last_real_code); - } - else - { - last_real_name = new = xstrdup (name); - last_real_code = code; - } - - insn_name_ptr[code] = new; -}