From patchwork Tue Jun 22 14:40:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jeremie.salvucci@free.fr X-Patchwork-Id: 56520 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 028ABB6F16 for ; Wed, 23 Jun 2010 00:41:16 +1000 (EST) Received: (qmail 29347 invoked by alias); 22 Jun 2010 14:41:03 -0000 Received: (qmail 29007 invoked by uid 22791); 22 Jun 2010 14:40:56 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, TW_CP, TW_RG, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from smtp5-g21.free.fr (HELO smtp5-g21.free.fr) (212.27.42.5) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Jun 2010 14:40:46 +0000 Received: from zimbra30-e5.priv.proxad.net (zimbra30-e5.priv.proxad.net [172.20.243.180]) by smtp5-g21.free.fr (Postfix) with ESMTP id 39993D48185; Tue, 22 Jun 2010 16:40:38 +0200 (CEST) Date: Tue, 22 Jun 2010 16:40:37 +0200 (CEST) From: jeremie.salvucci@free.fr To: bonzini@gnu.org Cc: basile@starynkevitch.net, gcc-patches@gcc.gnu.org, laurynas.biveinis@gmail.com Message-ID: <1912594726.385401277217637011.JavaMail.root@zimbra30-e5.priv.proxad.net> In-Reply-To: <1303636010.385301277217587410.JavaMail.root@zimbra30-e5.priv.proxad.net> Subject: Re: [Trunk] patch for GNU-friendly gengtype MIME-Version: 1.0 X-Authenticated-User: jeremie.salvucci@free.fr 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 With Basile, we decided to not use version.o in build/. as Laurynas suggested we print usage and version on stdout. gcc/Changelog entry : 2010-06-22 Jeremie Salvucci Basile Starynkevitch * Makefile.in (gengtype.o): Pass version information strings as -DGENGTYPE_* preprocessor flags. * gengtype.c: Include getopt.h. (do_dump): Added static variable moved from main. (inputlist): Ditto. (plugin_output_filename): Ditto. (gengtype_long_options): New variable. (print_usage): Added function. (bug_report_url, version_string, pkgversion_string): Added variable. (print_version): Added function. (parse_program_options): Added new function. (main): Changed program invocation convention. Call parse_program_options. Removed old argument parsing. Attached the patch to trunk revision 161188. Ok for trunk ? Index: gcc/gengtype.c =================================================================== --- gcc/gengtype.c (revision 161188) +++ gcc/gengtype.c (working copy) @@ -21,9 +21,11 @@ #include "bconfig.h" #include "system.h" #include "gengtype.h" +#include "getopt.h" #include "errors.h" /* for fatal */ #include "double-int.h" #include "hashtab.h" +#include "version.h" /* for version_string & pkgversion_string */ /* Data types, macros, etc. used only in this file. */ @@ -145,10 +147,12 @@ /* The list of output files. */ static outf_p output_files; -/* The plugin input files and their number; in that case only - a single file is produced. */ +/* The plugin input files and their number; in that case only a single + file is produced. Each element of plugin_files should have an all + zero lang_bitmap. */ static char** plugin_files; static size_t nb_plugin_files; + /* the generated plugin output name & file */ static outf_p plugin_output; @@ -162,6 +166,10 @@ /* Length of srcdir name. */ static size_t srcdir_len = 0; +static int do_dump = 0; +static char* inputlist = NULL; +static char* plugin_output_filename = NULL; + static outf_p create_file (const char *, const char *); static const char * get_file_basename (const char *); @@ -4158,54 +4166,129 @@ } +/* Option specification for getopt_long. */ +static const struct option gengtype_long_options[] = +{ + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, + { "dump", no_argument, NULL, 'd' }, + { "plugin", required_argument, NULL, 'P' }, + { "srcdir", required_argument, NULL, 'S' }, + { "inputs", required_argument, NULL, 'I' }, + { NULL, no_argument, NULL, 0 }, +}; + + +static void +print_usage (void) +{ + printf ("Usage: %s\n", progname); + printf ("\t -h | --help \t# Give this help.\n"); + printf ("\t -v | --version \t# Give version information.\n"); + printf ("\t -d | --dump \t# Dump state for debugging.\n"); + printf ("\t -P | --plugin \t# Generate for a plugin.\n"); + printf ("\t -S | --srcdir \t# Specify the GCC source directory.\n"); + printf ("\t -I | --inputs \t# Specify the file with source files list.\n"); +} + + +/* This is the location of the online document giving instructions for + reporting bugs. If you distribute a modified version of GCC, + please configure with --with-bugurl pointing to a document giving + instructions for reporting bugs to you, not us. (You are of course + welcome to forward us bugs reported to you, if you determine that + they are not bugs in your modifications.) */ +const char bug_report_url[] = GENGTYPE_BUGURL; +/* The complete version string, assembled from several pieces. + GENGTYPE_BASEVER, GENGTYPE_DATESTAMP, GENGTYPE_DEVPHASE, and + GENGTYPE_REVISION are defined by the Makefile. */ + +const char version_string[] = GENGTYPE_BASEVER GENGTYPE_DATESTAMP GENGTYPE_DEVPHASE GENGTYPE_REVISION; +const char pkgversion_string[] = GENGTYPE_PKGVERSION; + +static void +print_version (void) +{ + /* Since we cannot depend upon version.o, we have to duplicate + version information here. */ + printf ("%s %s%s\n", progname, pkgversion_string, version_string); + printf ("Report bugs: %s\n", bug_report_url); +} + + +/* Parse the program options using getopt_long... */ +static void +parse_program_options (int argc, char**argv) +{ + int opt = -1; + while ((opt = getopt_long (argc, argv, "hvdP:S:I:", + gengtype_long_options, NULL)) >= 0) + { + switch (opt) + { + case 'h': /* --help */ + print_usage (); + break; + case 'v': /* --version */ + print_version (); + break; + case 'd': /* --dump */ + do_dump = 1; + break; + case 'P': /* --plugin */ + if (optarg) + plugin_output_filename = optarg; + else + fatal ("missing plugin output file name"); + break; + case 'S': /* --srcdir */ + if (optarg) + srcdir = optarg; + else + fatal ("missing source directory"); + srcdir_len = strlen (srcdir); + break; + case 'I': /* --inputs */ + if (optarg) + inputlist = optarg; + else + fatal ("missing input list"); + break; + default: + fprintf (stderr, "%s: unknown flag '%c'\n", progname, opt); + print_usage (); + fatal ("unexpected flag"); + } + }; + if (plugin_output_filename) + { + /* In plugin mode we require some input files. */ + int i = 0; + if (optind >= argc) + fatal("no source files given in plugin mode"); + nb_plugin_files = argc - optind; + for (i = 0; i < (int) nb_plugin_files; i++) + { + /* Place an all zero lang_bitmap before the plugin file + name. */ + char *name = argv[i + optind]; + int len = strlen(name) + 1 + sizeof (lang_bitmap); + plugin_files[i] = XCNEWVEC (char, len) + sizeof (lang_bitmap); + strcpy (plugin_files[i], name); + } + } +} + int main (int argc, char **argv) { size_t i; static struct fileloc pos = { this_file, 0 }; - char* inputlist = 0; - int do_dump = 0; outf_p output_header; - char* plugin_output_filename = NULL; /* fatal uses this */ - progname = "gengtype"; + progname = (argc > 0) ? argv[0] : "gengtype"; + parse_program_options (argc, argv); - if (argc >= 2 && !strcmp (argv[1], "-d")) - { - do_dump = 1; - argv = &argv[1]; - argc--; - } - - if (argc >= 6 && !strcmp (argv[1], "-P")) - { - plugin_output_filename = argv[2]; - plugin_output = create_file ("GCC", plugin_output_filename); - srcdir = argv[3]; - inputlist = argv[4]; - nb_plugin_files = argc - 5; - plugin_files = XCNEWVEC (char *, nb_plugin_files); - for (i = 0; i < nb_plugin_files; i++) - { - /* Place an all zero lang_bitmap before the plugin file - name. */ - char *name = argv[i + 5]; - int len = strlen(name) + 1 + sizeof (lang_bitmap); - plugin_files[i] = XCNEWVEC (char, len) + sizeof (lang_bitmap); - strcpy (plugin_files[i], name); - } - } - else if (argc == 3) - { - srcdir = argv[1]; - inputlist = argv[2]; - } - else - fatal ("usage: gengtype [-d] [-P pluginout.h] srcdir input-list " - "[file1 file2 ... fileN]"); - - srcdir_len = strlen (srcdir); - read_input_list (inputlist); if (hit_error) return 1; Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 161188) +++ gcc/Makefile.in (working copy) @@ -3745,7 +3745,7 @@ s-gtype: build/gengtype$(build_exeext) $(filter-out [%], $(GTFILES)) \ gtyp-input.list - $(RUN_GEN) build/gengtype$(build_exeext) $(srcdir) gtyp-input.list + $(RUN_GEN) build/gengtype$(build_exeext) -S $(srcdir) -I gtyp-input.list $(STAMP) s-gtype generated_files = config.h tm.h $(TM_P_H) $(TM_H) multilib.h \ @@ -3831,8 +3831,17 @@ build/gengtype-lex.o : gengtype-lex.c gengtype.h $(BCONFIG_H) $(SYSTEM_H) build/gengtype-parse.o : gengtype-parse.c gengtype.h $(BCONFIG_H) \ $(SYSTEM_H) + +# gengtype cannot depend of version.o, otherwise a circular make +# dependency appears. build/gengtype.o : gengtype.c $(BCONFIG_H) $(SYSTEM_H) gengtype.h \ - rtl.def insn-notes.def errors.h double-int.h $(HASHTAB_H) + rtl.def insn-notes.def errors.h double-int.h $(HASHTAB_H) \ + $(REVISION) $(DATESTAMP) $(BASEVER) + $(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \ + -DGENGTYPE_BASEVER=$(BASEVER_s) -DGENGTYPE_DATESTAMP=$(DATESTAMP_s) \ + -DGENGTYPE_REVISION=$(REVISION_s) \ + -DGENGTYPE_DEVPHASE=$(DEVPHASE_s) -DGENGTYPE_PKGVERSION=$(PKGVERSION_s) \ + -DGENGTYPE_BUGURL=$(BUGURL_s) -c $(srcdir)/gengtype.c $(OUTPUT_OPTION) build/genmddeps.o: genmddeps.c $(BCONFIG_H) $(SYSTEM_H) coretypes.h \ errors.h $(READ_MD_H) build/genmodes.o : genmodes.c $(BCONFIG_H) $(SYSTEM_H) errors.h \