/* An output file, suitable for definitions, that can see declarations
made in INPUT_FILE and is linked into every language that uses
- INPUT_FILE. */
+ 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. */
+/* 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;
+/* The plugin input files and their number; in that case only
+ corresponding gt-<plugin>.h are generated in the current
+ directory. */
+static char** plugin_files;
+static int nb_plugin_files;
+
/* The output header file that is included into pretty much every
source file. */
static outf_p header_file;
int c;
bool atbol = true;
num_lang_dirs = 0;
- num_gt_files = 0;
+ num_gt_files = plugin_files ? nb_plugin_files : 0;
while ((c = getc (list)) != EOF)
{
n++;
/* Update the global counts now that we know accurately how many
things there are. (We do not bother resizing the arrays down.) */
num_lang_dirs = langno;
+ /* Add the plugin files if provided. */
+ if (plugin_files)
+ {
+ int i;
+ for (i = 0; i < nb_plugin_files; i++)
+ gt_files[nfiles++] = plugin_files[i];
+ }
num_gt_files = nfiles;
}
{
outf_p f = get_output_file_with_visibility (NULL);
int i;
+ if (!f)
+ return;
oprintf (f, "\n/* Used to implement the RTX_NEXT macro. */\n");
oprintf (f, "EXPORTED_CONST unsigned char rtx_next[NUM_RTX_CODE] = {\n");
create_file (const char *name, const char *oname)
{
static const char *const hdr[] = {
- " Copyright (C) 2004, 2007 Free Software Foundation, Inc.\n",
+ " Copyright (C) 2004, 2007, 2009 Free Software Foundation, Inc.\n",
"\n",
"This file is part of GCC.\n",
"\n",
outf_p f;
size_t i;
+ gcc_assert (name != NULL);
+ gcc_assert (oname != NULL);
f = XCNEW (struct outf);
f->next = output_files;
f->name = oname;
size_t slength;
va_list ap;
+ /* In plugin mode, the O could be a NULL pointer, so avoid crashing
+ in that case. */
+ if (!o)
+ return;
+
va_start (ap, format);
slength = vasprintf (&s, format, ap);
if (s == NULL || (int)slength < 0)
{
size_t i;
+ if (nb_plugin_files > 0 && plugin_files)
+ return;
+
header_file = create_file ("GCC", "gtype-desc.h");
base_files = XNEWVEC (outf_p, num_lang_dirs);
if (input_file == NULL)
input_file = "system.h";
+ /* In plugin mode, return NULL unless the input_file is one of the
+ plugin_files. */
+ if (plugin_files && nb_plugin_files > 0)
+ {
+ int ix= -1, i;
+ for (i = 0; i < nb_plugin_files && ix < 0; i++)
+ if (strcmp (input_file, plugin_files[i]) == 0)
+ ix = i;
+ if (ix < 0)
+ return NULL;
+ }
+
/* Determine the output file name. */
basename = get_file_basename (input_file);
/* If not, create it. */
r = create_file (for_name, output_name);
+ gcc_assert (r && r->name);
return r;
}
const char *
get_output_file_name (const char *input_file)
{
- return get_output_file_with_visibility (input_file)->name;
+ outf_p o = get_output_file_with_visibility (input_file);
+ if (o)
+ return o->name;
+ return NULL;
}
/* Copy the output to its final destination,
memset (&d, 0, sizeof (d));
d.of = get_output_file_with_visibility (fn);
-
d.process_field = write_types_local_process_field;
d.opt = s->u.s.opt;
d.line = &s->u.s.line;
{
type_p s;
+ if (!header_file)
+ return;
oprintf (header_file, "\n/* Local pointer-walking routines. */\n");
for (s = structures; s; s = s->next)
if (s->gc_used == GC_POINTED_TO
{
type_p s;
+ if (!header_file)
+ return;
oprintf (header_file, "\n/* Enumeration of types known. */\n");
oprintf (header_file, "enum gt_types_enum {\n");
for (s = structures; s; s = s->next)
put_mangled_filename (outf_p f, const char *fn)
{
const char *name = get_output_file_name (fn);
+ if (!f || !name)
+ return;
for (; *name != 0; name++)
if (ISALNUM (*name))
oprintf (f, "%c", *name);
oprintf (fli2->f, "};\n\n");
}
- for (fli2 = flp; fli2; fli2 = fli2->next)
+ for (fli2 = flp; fli2 && base_files; fli2 = fli2->next)
if (fli2->started_p)
{
lang_bitmap bitmap = get_lang_bitmap (fli2->name);
{
size_t fnum;
- for (fnum = 0; fnum < num_lang_dirs; fnum++)
+ for (fnum = 0; base_files && fnum < num_lang_dirs; fnum++)
oprintf (base_files [fnum],
"EXPORTED_CONST struct %s * const %s[] = {\n",
tname, name);
fli2->started_p = 0;
- for (fnum = 0; bitmap != 0; fnum++, bitmap >>= 1)
+ for (fnum = 0; base_files && bitmap != 0; fnum++, bitmap >>= 1)
if (bitmap & 1)
{
oprintf (base_files[fnum], " gt_%s_", pfx);
{
size_t fnum;
- for (fnum = 0; fnum < num_lang_dirs; fnum++)
+ for (fnum = 0; base_files && fnum < num_lang_dirs; fnum++)
{
oprintf (base_files[fnum], " NULL\n");
oprintf (base_files[fnum], "};\n");
v->name, o->name);
for (fli = flp; fli; fli = fli->next)
- if (fli->f == f)
+ if (fli->f == f && f)
break;
if (fli == NULL)
{
fli->next = flp;
fli->started_p = 0;
fli->name = v->line.file;
+ gcc_assert(fli->name);
flp = fli;
oprintf (f, "\n/* GC roots. */\n\n");
{
size_t i;
static struct fileloc pos = { this_file, 0 };
-
+ char* inputlist = 0;
/* fatal uses this */
progname = "gengtype";
- if (argc != 3)
- fatal ("usage: gengtype srcdir input-list");
+ if (argc >= 5 && !strcmp (argv[1], "-p"))
+ {
+ srcdir = argv[2];
+ inputlist = argv[3];
+ plugin_files = argv+4;
+ nb_plugin_files = argc-4;
+ }
+ else if (argc == 3)
+ {
+ srcdir = argv[1];
+ inputlist = argv[2];
+ }
+ else
+ fatal ("usage: gengtype [-p] srcdir input-list [file1 file2 ... fileN]");
- srcdir = argv[1];
srcdir_len = strlen (srcdir);
- read_input_list (argv[2]);
+ read_input_list (inputlist);
if (hit_error)
return 1;