From patchwork Mon Oct 4 19:47:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Basile Starynkevitch X-Patchwork-Id: 66735 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 CEC6BB70D0 for ; Tue, 5 Oct 2010 06:49:12 +1100 (EST) Received: (qmail 16067 invoked by alias); 4 Oct 2010 19:49:10 -0000 Received: (qmail 16014 invoked by uid 22791); 4 Oct 2010 19:49:06 -0000 X-SWARE-Spam-Status: No, hits=0.9 required=5.0 tests=AWL, BAYES_40, RCVD_IN_JMF_BL, TW_CP, TW_GT, TW_RG X-Spam-Check-By: sourceware.org Received: from smtp-151-monday.nerim.net (HELO maiev.nerim.net) (194.79.134.151) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Oct 2010 19:48:55 +0000 Received: from hector.lesours (ours.starynkevitch.net [213.41.244.95]) by maiev.nerim.net (Postfix) with ESMTPS id 453C02E012; Mon, 4 Oct 2010 21:48:52 +0200 (CEST) Received: from glinka.lesours ([192.168.0.1] helo=glinka) by hector.lesours with smtp (Exim 4.72) (envelope-from ) id 1P2r1n-0005fV-8v; Mon, 04 Oct 2010 21:48:51 +0200 Date: Mon, 4 Oct 2010 21:47:23 +0200 From: Basile Starynkevitch To: Laurynas Biveinis Cc: Diego Novillo , Jakub Jelinek , gcc-patches@gcc.gnu.org Subject: Ping! gengtype plugin improvement last2round - patch 1 [declprog] Message-Id: <20101004214723.5c5b72a2.basile@starynkevitch.net> In-Reply-To: References: <20100923195519.8eeaba90.basile@starynkevitch.net> <20100923180841.GH1269@tyan-ft48-01.lab.bos.redhat.com> <20100924065252.99509bd6.basile@starynkevitch.net> <20100924193729.391a15f1.basile@starynkevitch.net> <20100924202518.42420b16.basile@starynkevitch.net> Mime-Version: 1.0 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 I am pinging once again http://gcc.gnu.org/ml/gcc-patches/2010-09/msg01964.html taking into account http://gcc.gnu.org/ml/gcc-patches/2010-09/msg02086.html Attached patch is against trunk r164957. The changes w.r.t. http://gcc.gnu.org/ml/gcc-patches/2010-09/msg01964.html are purely cosmetic, to please Laurynas, by taking his remarks into account. If the reviewer prefer the patch from http://gcc.gnu.org/ml/gcc-patches/2010-09/msg01964.html please tell The gcc/ChangeLog entry is the same as in http://gcc.gnu.org/ml/gcc-patches/2010-09/msg01964.html: #### gcc/ChangeLog entry 2010-10-04 Jeremie Salvucci Basile Starynkevitch * gengtype.c: Include getopt.h and version.h. (lang_bitmap, struct outf, outf_p) (get_output_file_with_visibility, oprintf): Definitions moved to gengtype.h (output_files, header_file, srcdir, srcdir_len, this_file) (do_dump): No more static variables. (do_debug): New. (dbgprint_count_type_at): Added new function. (gengtype_long_options): New. (print_usage, print_version, parse_program_options): New. (main): Call parse_program_options, and removed old option handling code. Added some debug output. * gengtype.h: Updated copyright year. (lang_bitmap, struct outf, outf_p, header_file, oprintf) (get_output_file_with_visibility, srcdir, srcdir_len, do_dump): Moved from gengtype.c to here. (do_debug, read_state_filename, write_state_filename): New variables. (DBGPRINTF, DBGPRINT_COUNT_TYPE): New macros. * Makefile.in: (REVISION): Always defined. (version.o): Removed ifdef REVISION_c. (s-gtype): Pass arguments to build/gengtype program. (build/version.o): Added building rule. (build/gengtype$(build_exeext)): Added build/version.o. ################################################################ Ok for trunk? With what changes? Cheers. PS. I am beginning to lose hope getting this patch series into 4.6! I can't understand who is interested in OK-ing them (Laurynas' status don't permit it, he is a plain write after approval maintainer like me, not a reviewer). In case some reviewer want to meet me on sunday october 24th before the GCC Summit, I am arriving at Ottawa on saturday evening. Index: gcc/gengtype.c =================================================================== --- gcc/gengtype.c (revision 164957) +++ gcc/gengtype.c (working copy) @@ -20,10 +20,12 @@ #include "bconfig.h" #include "system.h" -#include "gengtype.h" #include "errors.h" /* for fatal */ +#include "getopt.h" #include "double-int.h" +#include "version.h" /* for version_string & pkgversion_string. */ #include "hashtab.h" +#include "gengtype.h" /* Data types, macros, etc. used only in this file. */ @@ -40,7 +42,6 @@ enum typekind TYPE_PARAM_STRUCT }; -typedef unsigned lang_bitmap; /* A way to pass data through to the output end. */ struct options @@ -117,55 +118,50 @@ struct type }; #define UNION_P(x) \ - ((x)->kind == TYPE_UNION || \ - ((x)->kind == TYPE_LANG_STRUCT \ - && (x)->u.s.lang_struct->kind == TYPE_UNION)) + ((x)->kind == TYPE_UNION || \ + ((x)->kind == TYPE_LANG_STRUCT \ + && (x)->u.s.lang_struct->kind == TYPE_UNION)) #define UNION_OR_STRUCT_P(x) \ - ((x)->kind == TYPE_UNION \ - || (x)->kind == TYPE_STRUCT \ - || (x)->kind == TYPE_LANG_STRUCT) + ((x)->kind == TYPE_UNION \ + || (x)->kind == TYPE_STRUCT \ + || (x)->kind == TYPE_LANG_STRUCT) -/* Structure representing an output file. */ -struct outf -{ - struct outf *next; - const char *name; - size_t buflength; - size_t bufused; - char *buf; -}; -typedef struct outf *outf_p; -/* An output file, suitable for definitions, that can see declarations - made in INPUT_FILE and is linked into every language that uses - INPUT_FILE. May return NULL in plugin mode. */ -extern outf_p get_output_file_with_visibility (const char *input_file); + const char *get_output_file_name (const char *); -/* Print, like fprintf, to O. No-op if O is NULL. */ -static void -oprintf (outf_p o, const char *S, ...) - ATTRIBUTE_PRINTF_2; /* The list of output files. */ -static outf_p output_files; +outf_p output_files; +/* The output header file that is included into pretty much every + source file. */ +outf_p header_file; + + +/* The name of the file containing the list of input files. */ +static char *inputlist; + /* The plugin input files and their number; in that case only a single file is produced. */ static char **plugin_files; static size_t nb_plugin_files; -/* the generated plugin output name & file */ + +/* The generated plugin output file and name. */ static outf_p plugin_output; +static char *plugin_output_filename; -/* The output header file that is included into pretty much every - source file. */ -static outf_p header_file; +/* Our source directory and its length. */ +const char *srcdir; +size_t srcdir_len; -/* Source directory. */ -static const char *srcdir; +/* Variables used for reading and writing the state. */ +const char *read_state_filename; +const char *write_state_filename; -/* Length of srcdir name. */ -static size_t srcdir_len = 0; +/* Variables to help debugging. */ +int do_dump; +int do_debug; static outf_p create_file (const char *, const char *); @@ -225,10 +221,12 @@ xasprintf (const char *format, ...) static const char **gt_files; static size_t num_gt_files; -/* A number of places use the name of this file for a location for - things that we can't rely on the source to define. Make sure we - can still use pointer comparison on filenames. */ -static const char this_file[] = __FILE__; +/* A number of places use the name of this "gengtype.h" file for a + location for things that we can't rely on the source to define. + Make sure we can still use pointer comparison on filenames. */ +const char this_file[] = __FILE__; +/* The "system.h" file is likewise specially useful. */ +const char system_h_file[] = "system.h"; /* Vector of per-language directories. */ static const char **lang_dir_names; @@ -254,9 +252,13 @@ static lang_bitmap get_lang_bitmap (const char *gtfile) { - if (gtfile == this_file) - /* Things defined in this file are universal. */ - return (((lang_bitmap) 1) << num_lang_dirs) - 1; + if (gtfile == this_file || gtfile == system_h_file) + { + /* Things defined in this "gengtype.c" file or in "system.h" are + universal (and there is no space for their lang_bitmap before + their file names). */ + return (((lang_bitmap) 1) << num_lang_dirs) - 1; + } else { lang_bitmap n = 0; @@ -280,6 +282,65 @@ set_lang_bitmap (char *gtfile, lang_bitmap n) } } + +#if ENABLE_CHECKING +/* Utility debugging function, printing the various type counts within + a list of types. Called thru the DBGPRINT_COUNT_TYPE macro. */ +void +dbgprint_count_type_at (const char *fil, int lin, const char *msg, type_p t) +{ + int nb_types = 0, nb_scalar = 0, nb_string = 0; + int nb_struct = 0, nb_union = 0, nb_array = 0, nb_pointer = 0; + int nb_lang_struct = 0, nb_param_struct = 0; + type_p p = NULL; + for (p = t; p; p = p->next) + { + nb_types++; + switch (p->kind) + { + case TYPE_SCALAR: + nb_scalar++; + break; + case TYPE_STRING: + nb_string++; + break; + case TYPE_STRUCT: + nb_struct++; + break; + case TYPE_UNION: + nb_union++; + break; + case TYPE_POINTER: + nb_pointer++; + break; + case TYPE_ARRAY: + nb_array++; + break; + case TYPE_LANG_STRUCT: + nb_lang_struct++; + break; + case TYPE_PARAM_STRUCT: + nb_param_struct++; + break; + default: + gcc_unreachable (); + } + } + fprintf (stderr, "\n" "%s:%d: %s: @@%%@@ %d types ::\n", + lbasename (fil), lin, msg, nb_types); + if (nb_scalar > 0 || nb_string > 0) + fprintf (stderr, "@@%%@@ %d scalars, %d strings\n", nb_scalar, nb_string); + if (nb_struct > 0 || nb_union > 0) + fprintf (stderr, "@@%%@@ %d structs, %d unions\n", nb_struct, nb_union); + if (nb_pointer > 0 || nb_array > 0) + fprintf (stderr, "@@%%@@ %d pointers, %d arrays\n", nb_pointer, nb_array); + if (nb_lang_struct > 0 || nb_param_struct > 0) + fprintf (stderr, "@@%%@@ %d lang_structs, %d param_structs\n", + nb_lang_struct, nb_param_struct); + fprintf (stderr, "\n"); +} +#endif /* ENABLE_CHECKING */ + /* Scan the input file, LIST, and determine how much space we need to store strings in. Also, count the number of language directories and files. The numbers returned are overestimates as they does not @@ -864,7 +925,7 @@ create_field_at (pair_p next, type_p type, const c /* Create a fake field with the given type and name. NEXT is the next field in the chain. */ #define create_field(next,type,name) \ - create_field_all(next,type,name, 0, this_file, __LINE__) + create_field_all(next,type,name, 0, this_file, __LINE__) /* Like create_field, but the field is only valid when condition COND is true. */ @@ -893,7 +954,7 @@ create_optional_field_ (pair_p next, type_p type, } #define create_optional_field(next,type,name,cond) \ - create_optional_field_(next,type,name,cond,__LINE__) + create_optional_field_(next,type,name,cond,__LINE__) /* Reverse a linked list of 'struct pair's in place. */ pair_p @@ -3230,13 +3291,13 @@ write_field_root (outf_p f, pair_p v, type_p type, /* Write out to F the table entry and any marker routines needed to mark NAME as TYPE. V can be one of three values: - - null, if NAME is too complex to represent using a single - count and stride. In this case, it is an error for NAME to - contain any gc-ed data. + - null, if NAME is too complex to represent using a single + count and stride. In this case, it is an error for NAME to + contain any gc-ed data. - - the outermost array that contains NAME, if NAME is part of an array. + - the outermost array that contains NAME, if NAME is part of an array. - - the C variable that contains NAME, if NAME is not part of an array. + - the C variable that contains NAME, if NAME is not part of an array. LINE is the line of the C source that declares the root variable. HAS_LENGTH is nonzero iff V was a variable-length array. IF_MARKED @@ -3732,7 +3793,7 @@ note_def_vec (const char *type_name, bool is_scala we had expanded the macros in vec.h: typedef struct VEC__ { - VEC__base base; + VEC__base base; } VEC__; */ void @@ -4223,100 +4284,264 @@ dump_everything (void) } + +/* 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'}, + {"debug", no_argument, NULL, 'D'}, + {"plugin", required_argument, NULL, 'P'}, + {"srcdir", required_argument, NULL, 'S'}, + {"inputs", required_argument, NULL, 'I'}, + {"read-state", required_argument, NULL, 'r'}, + {"write-state", required_argument, NULL, 'w'}, + /* Terminating NULL placeholder. */ + {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 -D | --debug " + " \t# Give debug output to debug %s itself.\n", progname); + 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 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"); + printf ("\t -w | --write-state " " \t# Write a state file.\n"); + printf ("\t -r | --read-state " " \t# Read a state file.\n"); +} + +static void +print_version (void) +{ + 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:w:r:D", + 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 'D': /* --debug */ + do_debug = 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; + case 'r': /* --read-state */ + if (optarg) + read_state_filename = optarg; + else + fatal ("missing read state file"); + DBGPRINTF ("read state %s\n", optarg); + break; + case 'w': /* --write-state */ + DBGPRINTF ("write state %s\n", optarg); + if (optarg) + write_state_filename = optarg; + else + fatal ("missing write state file"); + 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++) + { + char *name = argv[i + optind]; + 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; + static struct fileloc pos = { NULL, 0 }; outf_p output_header; - char *plugin_output_filename = NULL; - /* fatal uses this */ - progname = "gengtype"; - if (argc >= 2 && !strcmp (argv[1], "-d")) + /* Mandatory common initializations. */ + progname = "gengtype"; /* For fatal and messages. */ + /* Set the scalar_is_char union number for predefined scalar types. */ + scalar_nonchar.u.scalar_is_char = FALSE; + scalar_char.u.scalar_is_char = TRUE; + + parse_program_options (argc, argv); + +#if ENABLE_CHECKING + if (do_debug) { - do_dump = 1; - argv = &argv[1]; - argc--; + time_t now = (time_t) 0; + time (&now); + DBGPRINTF ("gengtype started pid %d at %s", + (int) getpid (), ctime (&now)); } +#endif /* ENABLE_CHECKING */ - if (argc >= 6 && !strcmp (argv[1], "-P")) + /* Parse the input list and the input files. */ + DBGPRINTF ("inputlist %s", inputlist); + if (read_state_filename) { - 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++) + fatal ("read state %s not implemented yet", read_state_filename); + /* TODO: implement read state. */ + } + else if (inputlist) + { + /* These types are set up with #define or else outside of where + we can see them. We should initialize them before calling + read_input_list. */ + pos.file = this_file; + pos.line = __LINE__ + 1; + do_scalar_typedef ("CUMULATIVE_ARGS", &pos); + pos.line++; + do_scalar_typedef ("REAL_VALUE_TYPE", &pos); + pos.line++; + do_scalar_typedef ("FIXED_VALUE_TYPE", &pos); + pos.line++; + do_scalar_typedef ("double_int", &pos); + pos.line++; + do_scalar_typedef ("uint64_t", &pos); + pos.line++; + do_scalar_typedef ("uint8", &pos); + pos.line++; + do_scalar_typedef ("jword", &pos); + pos.line++; + do_scalar_typedef ("JCF_u2", &pos); + pos.line++; + do_scalar_typedef ("void", &pos); + pos.line++; + do_typedef ("PTR", create_pointer (resolve_typedef ("void", &pos)), + &pos); + read_input_list (inputlist); + for (i = 0; i < num_gt_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); + parse_file (gt_files[i]); + DBGPRINTF ("parsed file #%d %s", (int) i, gt_files[i]); } + DBGPRINT_COUNT_TYPE ("structures after parsing", structures); + DBGPRINT_COUNT_TYPE ("param_structs after parsing", param_structs); + } - 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); + fatal ("either an input list or a read state file should be given"); if (hit_error) return 1; - scalar_char.u.scalar_is_char = true; - scalar_nonchar.u.scalar_is_char = false; - gen_rtx_next (); - /* These types are set up with #define or else outside of where - we can see them. */ - pos.line = __LINE__ + 1; - do_scalar_typedef ("CUMULATIVE_ARGS", &pos); - pos.line++; - do_scalar_typedef ("REAL_VALUE_TYPE", &pos); - pos.line++; - do_scalar_typedef ("FIXED_VALUE_TYPE", &pos); - pos.line++; - do_scalar_typedef ("double_int", &pos); - pos.line++; - do_scalar_typedef ("uint64_t", &pos); - pos.line++; - do_scalar_typedef ("uint8", &pos); - pos.line++; - do_scalar_typedef ("jword", &pos); - pos.line++; - do_scalar_typedef ("JCF_u2", &pos); - pos.line++; - do_scalar_typedef ("void", &pos); - pos.line++; - do_typedef ("PTR", create_pointer (resolve_typedef ("void", &pos)), &pos); + if (plugin_output_filename) + { + size_t ix = 0; + /* In plugin mode, we should have read a state file, and have + given at least one plugin file. */ + if (!read_state_filename) + fatal ("No read state given in plugin mode for %s", + plugin_output_filename); - for (i = 0; i < num_gt_files; i++) - parse_file (gt_files[i]); + if (nb_plugin_files <= 0 || !plugin_files) + fatal ("No plugin files given in plugin mode for %s", + plugin_output_filename); + /* Parse our plugin files. */ + for (ix = 0; ix < nb_plugin_files; ix++) + parse_file (plugin_files[ix]); + + if (hit_error) + return 1; + + plugin_output = create_file ("GCC", plugin_output_filename); + DBGPRINTF ("created plugin_output %p named %s", + (void *) plugin_output, plugin_output->name); + } + else + { /* No plugin files, we are in normal mode. */ + if (!srcdir) + fatal ("gengtype needs a source directory in normal mode"); + } if (hit_error) return 1; + gen_rtx_next (); + + /* The call to set_gc_used may indirectly call find_param_structure + hence enlarge the param_structs list of types. */ set_gc_used (variables); + /* We should write the state here, but it is not yet implemented. */ + if (write_state_filename) + { + fatal ("write state %s in not yet implemented", write_state_filename); + /* TODO: implement write state. */ + } + + open_base_files (); + write_enum_defn (structures, param_structs); write_typed_alloc_defns (structures, typedefs); output_header = plugin_output ? plugin_output : header_file; + DBGPRINT_COUNT_TYPE ("structures before write_types outputheader", + structures); + DBGPRINT_COUNT_TYPE ("param_structs before write_types outputheader", + param_structs); + write_types (output_header, structures, param_structs, &ggc_wtd); if (plugin_files == NULL) { + DBGPRINT_COUNT_TYPE ("structures before write_types headerfil", + structures); + DBGPRINT_COUNT_TYPE ("param_structs before write_types headerfil", + param_structs); write_types (header_file, structures, param_structs, &pch_wtd); write_local (header_file, structures, param_structs); } @@ -4328,12 +4553,7 @@ main (int argc, char **argv) if (do_dump) dump_everything (); - if (plugin_files) - { - for (i = 0; i < nb_plugin_files; i++) - free (plugin_files[i] - sizeof (lang_bitmap)); - free (plugin_files); - } + /* Don't bother about free-ing any input or plugin file, etc. */ if (hit_error) return 1; Index: gcc/gengtype.h =================================================================== --- gcc/gengtype.h (revision 164957) +++ gcc/gengtype.h (working copy) @@ -1,5 +1,6 @@ /* Process source files and output type information. - Copyright (C) 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2007, 2008, 2010 + Free Software Foundation, Inc. This file is part of GCC. @@ -20,6 +21,10 @@ #ifndef GCC_GENGTYPE_H #define GCC_GENGTYPE_H +/* Sets of accepted source languages like C, C++, Ada... are + represented by a bitmap. */ +typedef unsigned lang_bitmap; + /* A file position, mostly for error messages. The FILE element may be compared using pointer equality. */ struct fileloc @@ -38,14 +43,50 @@ typedef struct options *options_p; extern int lexer_toplevel_done; extern struct fileloc lexer_line; +/* Structure representing an output file. */ +struct outf +{ + struct outf *next; + const char *name; + size_t buflength; + size_t bufused; + char *buf; +}; +typedef struct outf *outf_p; + +/* The list of output files. */ +extern outf_p output_files; + +/* The output header file that is included into pretty much every + source file. */ +extern outf_p header_file; + +/* Print, like fprintf, to O. No-op if O is NULL. */ +void +oprintf (outf_p o, const char *S, ...) + ATTRIBUTE_PRINTF_2; + +/* An output file, suitable for definitions, that can see declarations + made in INPUT_FILE and is linked into every language that uses + INPUT_FILE. May return NULL in plugin mode. */ +extern outf_p get_output_file_with_visibility (const char *input_file); + +/* Source directory. */ +extern const char *srcdir; /* (-S) program argument. */ + +/* Length of srcdir name. */ +extern size_t srcdir_len; + +/* Variable used for reading and writing the state. */ +extern const char *read_state_filename; /* (-r) program argument. */ +extern const char *write_state_filename; /* (-w) program argument. */ + /* Print an error message. */ extern void error_at_line (const struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2; /* Like asprintf, but calls fatal() on out of memory. */ -extern char * -xasprintf (const char *, ...) - ATTRIBUTE_PRINTF_1; +extern char *xasprintf (const char *, ...) ATTRIBUTE_PRINTF_1; /* Constructor routines for types. */ extern void do_typedef (const char *s, type_p t, struct fileloc *pos); @@ -117,4 +158,28 @@ enum a meaningful value to be printed. */ FIRST_TOKEN_WITH_VALUE = PARAM_IS }; + + +/* For debugging purposes we provide two flags. */ + +/* Dump everything to understand gengtype's state. Might be useful to + gengtype users. */ +extern int do_dump; /* (-d) program argument. */ + +/* Trace the execution by many DBGPRINTF (with the position inside + gengtype source code). Only useful to debug gengtype itself. */ +extern int do_debug; /* (-D) program argument. */ + +#if ENABLE_CHECKING +#define DBGPRINTF(Fmt,...) do {if (do_debug) \ + fprintf (stderr, "%s:%d: " Fmt "\n", \ + lbasename (__FILE__),__LINE__, ##__VA_ARGS__);} while (0) +void dbgprint_count_type_at (const char *, int, const char *, type_p); +#define DBGPRINT_COUNT_TYPE(Msg,Ty) do {if (do_debug) \ + dbgprint_count_type_at (__FILE__, __LINE__, Msg, Ty);}while (0) +#else +#define DBGPRINTF(Fmt,...) do {/*nodbgrintf*/} while (0) +#define DBGPRINT_COUNT_TYPE(Msg,Ty) do{/*nodbgprint_count_type*/}while (0) +#endif /*ENABLE_CHECKING */ + #endif Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 164957) +++ gcc/Makefile.in (working copy) @@ -837,6 +837,7 @@ DATESTAMP_c := $(shell cat $(DATESTAMP)) ifeq (,$(wildcard $(REVISION))) REVISION_c := +REVISION := else REVISION_c := $(shell cat $(REVISION)) endif @@ -2245,11 +2246,7 @@ gcc-options.o: options.c $(CONFIG_H) $(SYSTEM_H) c dumpvers: dumpvers.c -ifdef REVISION_c version.o: version.c version.h $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE) -else -version.o: version.c version.h $(DATESTAMP) $(BASEVER) $(DEVPHASE) -endif $(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \ -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \ -DREVISION=$(REVISION_s) \ @@ -3802,7 +3799,7 @@ s-gtyp-input: Makefile 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 \ @@ -3822,6 +3819,16 @@ build/%.o : # dependencies provided by explicit r $(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \ -o $@ $< +## build/version.o is compiled by the $(COMPILER_FOR_BUILD) but needs +## several C macro definitions, just like version.o +build/version.o: version.c version.h \ + $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE) + $(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \ + -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \ + -DREVISION=$(REVISION_s) \ + -DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \ + -DBUGURL=$(BUGURL_s) -o $@ $< + # Header dependencies for the programs that generate source code. # These are library modules... build/errors.o : errors.c $(BCONFIG_H) $(SYSTEM_H) errors.h @@ -3931,7 +3938,8 @@ genprog = $(genprogerr) check checksum condmd build/genautomata$(build_exeext) : BUILD_LIBS += -lm # These programs are not linked with the MD reader. -build/gengtype$(build_exeext) : build/gengtype-lex.o build/gengtype-parse.o +build/gengtype$(build_exeext) : build/gengtype-lex.o build/gengtype-parse.o \ + build/version.o # Rule for the generator programs: $(genprog:%=build/gen%$(build_exeext)): build/gen%$(build_exeext): build/gen%.o $(BUILD_LIBDEPS)