From patchwork Tue Nov 16 14:02:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 71400 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 9FCDDB713A for ; Wed, 17 Nov 2010 01:02:50 +1100 (EST) Received: (qmail 10622 invoked by alias); 16 Nov 2010 14:02:47 -0000 Received: (qmail 10607 invoked by uid 22791); 16 Nov 2010 14:02:46 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Nov 2010 14:02:40 +0000 Received: (qmail 22521 invoked from network); 16 Nov 2010 14:02:38 -0000 Received: from unknown (HELO codesourcery.com) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 16 Nov 2010 14:02:38 -0000 Date: Tue, 16 Nov 2010 09:02:36 -0500 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: [PATCH] use VEC a bit more in the driver Message-ID: <20101116140236.GD24469@nightcrawler> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Following on to Joseph's patch here: http://gcc.gnu.org/ml/gcc-patches/2010-11/msg01635.html the patch below converts a few more manually allocated arrays to VECs. Tested on x86_64-unknown-linux-gnu. OK to commit? -Nathan * gcc.c (char_p): Define. Define a VEC of it. (n_linker_options, n_assembler_options, n_preprocessor_options): Delete. (linker_options, assembler_options, preprocessor_options): Convert to a VEC. (add_preprocessor_option): Adjust. (add_assembler_option): Adjust. (add_linker_option): Adjust. (do_specs_vec): New function. (do_spec_1): Call it. Adjust for new types. diff --git a/gcc/gcc.c b/gcc/gcc.c index 58f7a31..fb98171 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -983,23 +983,24 @@ static const struct compiler default_compilers[] = static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1; +typedef char *char_p; /* For DEF_VEC_P. */ +DEF_VEC_P(char_p); +DEF_VEC_ALLOC_P(char_p,heap); + /* A vector of options to give to the linker. These options are accumulated by %x, and substituted into the linker command with %X. */ -static int n_linker_options; -static char **linker_options; +static VEC(char_p,heap) *linker_options; /* A vector of options to give to the assembler. These options are accumulated by -Wa, and substituted into the assembler command with %Y. */ -static int n_assembler_options; -static char **assembler_options; +static VEC(char_p,heap) *assembler_options; /* A vector of options to give to the preprocessor. These options are accumulated by -Wp, and substituted into the preprocessor command with %Z. */ -static int n_preprocessor_options; -static char **preprocessor_options; +static VEC(char_p,heap) *preprocessor_options; static char * skip_whitespace (char *p) @@ -2975,43 +2976,20 @@ display_help (void) static void add_preprocessor_option (const char *option, int len) { - n_preprocessor_options++; - - if (! preprocessor_options) - preprocessor_options = XNEWVEC (char *, n_preprocessor_options); - else - preprocessor_options = XRESIZEVEC (char *, preprocessor_options, - n_preprocessor_options); - - preprocessor_options [n_preprocessor_options - 1] = - save_string (option, len); + VEC_safe_push (char_p, heap, preprocessor_options, + save_string (option, len)); } static void add_assembler_option (const char *option, int len) { - n_assembler_options++; - - if (! assembler_options) - assembler_options = XNEWVEC (char *, n_assembler_options); - else - assembler_options = XRESIZEVEC (char *, assembler_options, - n_assembler_options); - - assembler_options [n_assembler_options - 1] = save_string (option, len); + VEC_safe_push (char_p, heap, assembler_options, save_string (option, len)); } static void add_linker_option (const char *option, int len) { - n_linker_options++; - - if (! linker_options) - linker_options = XNEWVEC (char *, n_linker_options); - else - linker_options = XRESIZEVEC (char *, linker_options, n_linker_options); - - linker_options [n_linker_options - 1] = save_string (option, len); + VEC_safe_push (char_p, heap, linker_options, save_string (option, len)); } /* Allocate space for an input file in infiles. */ @@ -4404,6 +4382,22 @@ compile_input_file_p (struct infile *infile) return false; } +/* Process each member of VEC as a spec. */ + +static void +do_specs_vec (VEC(char_p,heap) *vec) +{ + unsigned ix; + char *opt; + + FOR_EACH_VEC_ELT (char_p, vec, ix, opt) + { + do_spec_1 (opt, 1, NULL); + /* Make each accumulated option a separate argument. */ + do_spec_1 (" ", 0, NULL); + } +} + /* Process the sub-spec SPEC as a portion of a larger spec. This is like processing a whole spec except that we do not initialize at the beginning and we do not supply a @@ -4965,6 +4959,8 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) { const char *p1 = p; char *string; + char *opt; + unsigned ix; /* Skip past the option value and make a copy. */ if (*p != '{') @@ -4974,8 +4970,8 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) string = save_string (p1 + 1, p - p1 - 2); /* See if we already recorded this option. */ - for (i = 0; i < n_linker_options; i++) - if (! strcmp (string, linker_options[i])) + FOR_EACH_VEC_ELT (char_p, linker_options, ix, opt) + if (! strcmp (string, opt)) { free (string); return 0; @@ -4988,32 +4984,17 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) /* Dump out the options accumulated previously using %x. */ case 'X': - for (i = 0; i < n_linker_options; i++) - { - do_spec_1 (linker_options[i], 1, NULL); - /* Make each accumulated option a separate argument. */ - do_spec_1 (" ", 0, NULL); - } + do_specs_vec (linker_options); break; /* Dump out the options accumulated previously using -Wa,. */ case 'Y': - for (i = 0; i < n_assembler_options; i++) - { - do_spec_1 (assembler_options[i], 1, NULL); - /* Make each accumulated option a separate argument. */ - do_spec_1 (" ", 0, NULL); - } + do_specs_vec (assembler_options); break; /* Dump out the options accumulated previously using -Wp,. */ case 'Z': - for (i = 0; i < n_preprocessor_options; i++) - { - do_spec_1 (preprocessor_options[i], 1, NULL); - /* Make each accumulated option a separate argument. */ - do_spec_1 (" ", 0, NULL); - } + do_specs_vec (preprocessor_options); break; /* Here are digits and numbers that just process