1995-04-03 21:28:01 +02:00
|
|
|
/* Code to maintain a C++ template repository.
|
|
|
|
Copyright (C) 1995 Free Software Foundation, Inc.
|
|
|
|
Contributed by Jason Merrill (jason@cygnus.com)
|
|
|
|
|
|
|
|
This file is part of GNU CC.
|
|
|
|
|
|
|
|
GNU CC 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 version.
|
|
|
|
|
|
|
|
GNU CC is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or 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 GNU CC; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
|
|
|
|
|
/* My strategy here is as follows:
|
|
|
|
|
|
|
|
Everything should be emitted in a translation unit where it is used.
|
|
|
|
The results of the automatic process should be easily reproducible with
|
1995-04-04 19:51:34 +02:00
|
|
|
explicit code. */
|
1995-04-03 21:28:01 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
1995-04-04 19:51:34 +02:00
|
|
|
#include "config.h"
|
1995-04-03 21:28:01 +02:00
|
|
|
#include "tree.h"
|
|
|
|
#include "cp-tree.h"
|
|
|
|
#include "input.h"
|
1995-04-09 13:41:24 +02:00
|
|
|
#include "obstack.h"
|
1995-04-03 21:28:01 +02:00
|
|
|
|
|
|
|
extern char * rindex ();
|
1995-04-04 19:51:34 +02:00
|
|
|
extern char * getenv ();
|
1995-04-03 21:28:01 +02:00
|
|
|
|
|
|
|
static tree pending_repo;
|
1995-04-09 13:41:24 +02:00
|
|
|
static tree original_repo;
|
1995-04-03 21:28:01 +02:00
|
|
|
static char repo_name[1024];
|
|
|
|
static FILE *repo_file;
|
|
|
|
|
|
|
|
extern int flag_use_repository;
|
|
|
|
extern int errorcount, sorrycount;
|
|
|
|
|
|
|
|
#define IDENTIFIER_REPO_USED(NODE) (TREE_LANG_FLAG_3 (NODE))
|
|
|
|
#define IDENTIFIER_REPO_CHOSEN(NODE) (TREE_LANG_FLAG_4 (NODE))
|
|
|
|
|
|
|
|
/* Record the flags used to compile this translation unit. */
|
|
|
|
|
|
|
|
void
|
|
|
|
repo_compile_flags (argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this template has not been seen before, add a note to the repository
|
|
|
|
saying where the declaration was. This may be used to find the
|
|
|
|
definition at link time. */
|
|
|
|
|
|
|
|
void
|
|
|
|
repo_template_declared (t)
|
|
|
|
tree t;
|
|
|
|
{}
|
|
|
|
|
|
|
|
/* Note where the definition of a template lives so that instantiations can
|
|
|
|
be generated later. */
|
|
|
|
|
|
|
|
void
|
|
|
|
repo_template_defined (t)
|
|
|
|
tree t;
|
|
|
|
{}
|
|
|
|
|
|
|
|
/* Note where the definition of a class lives to that template
|
|
|
|
instantiations can use it. */
|
|
|
|
|
|
|
|
void
|
|
|
|
repo_class_defined (t)
|
|
|
|
tree t;
|
|
|
|
{}
|
|
|
|
|
1995-04-18 21:23:38 +02:00
|
|
|
tree
|
|
|
|
repo_get_id (t)
|
|
|
|
tree t;
|
|
|
|
{
|
|
|
|
if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
|
|
|
|
{
|
|
|
|
t = TYPE_BINFO_VTABLE (t);
|
|
|
|
if (t == NULL_TREE)
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
return DECL_ASSEMBLER_NAME (t);
|
|
|
|
}
|
|
|
|
|
1995-04-03 21:28:01 +02:00
|
|
|
/* Note that a template has been used. If we can see the definition, offer
|
|
|
|
to emit it. */
|
|
|
|
|
|
|
|
void
|
|
|
|
repo_template_used (t)
|
|
|
|
tree t;
|
|
|
|
{
|
|
|
|
tree id;
|
|
|
|
|
|
|
|
if (! flag_use_repository)
|
|
|
|
return;
|
|
|
|
|
1995-04-18 21:23:38 +02:00
|
|
|
id = repo_get_id (t);
|
|
|
|
if (id == NULL_TREE)
|
|
|
|
return;
|
|
|
|
|
1995-04-03 21:28:01 +02:00
|
|
|
if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
|
|
|
|
{
|
|
|
|
if (IDENTIFIER_REPO_CHOSEN (id))
|
|
|
|
mark_class_instantiated (t, 0);
|
|
|
|
}
|
|
|
|
else if (TREE_CODE_CLASS (TREE_CODE (t)) == 'd')
|
|
|
|
{
|
|
|
|
if (IDENTIFIER_REPO_CHOSEN (id))
|
|
|
|
mark_function_instantiated (t, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
my_friendly_abort (1);
|
|
|
|
|
|
|
|
if (! IDENTIFIER_REPO_USED (id))
|
|
|
|
{
|
|
|
|
IDENTIFIER_REPO_USED (id) = 1;
|
1995-04-09 13:41:24 +02:00
|
|
|
pending_repo = perm_tree_cons (NULL_TREE, id, pending_repo);
|
1995-04-03 21:28:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that the vtable for a class has been used, and offer to emit it. */
|
|
|
|
|
|
|
|
void
|
|
|
|
repo_vtable_used (t)
|
|
|
|
tree t;
|
|
|
|
{
|
|
|
|
if (! flag_use_repository)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pending_repo = perm_tree_cons (NULL_TREE, t, pending_repo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that an inline with external linkage has been used, and offer to
|
|
|
|
emit it. */
|
|
|
|
|
|
|
|
void
|
|
|
|
repo_inline_used (fn)
|
|
|
|
tree fn;
|
|
|
|
{
|
|
|
|
if (! flag_use_repository)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Member functions of polymorphic classes go with their vtables. */
|
|
|
|
if (DECL_FUNCTION_MEMBER_P (fn) && TYPE_VIRTUAL_P (DECL_CLASS_CONTEXT (fn)))
|
|
|
|
{
|
|
|
|
repo_vtable_used (DECL_CLASS_CONTEXT (fn));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pending_repo = perm_tree_cons (NULL_TREE, fn, pending_repo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that a particular typeinfo node has been used, and offer to
|
|
|
|
emit it. */
|
|
|
|
|
|
|
|
void
|
|
|
|
repo_tinfo_used (ti)
|
|
|
|
tree ti;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1995-04-18 21:23:38 +02:00
|
|
|
void
|
|
|
|
repo_template_instantiated (t, extern_p)
|
|
|
|
tree t;
|
|
|
|
int extern_p;
|
|
|
|
{
|
|
|
|
if (! extern_p)
|
|
|
|
{
|
|
|
|
tree id = repo_get_id (t);
|
|
|
|
if (id)
|
|
|
|
IDENTIFIER_REPO_CHOSEN (id) = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-04 19:51:34 +02:00
|
|
|
static char *
|
|
|
|
save_string (s, len)
|
|
|
|
char *s;
|
|
|
|
int len;
|
|
|
|
{
|
1995-04-09 13:41:24 +02:00
|
|
|
extern struct obstack temporary_obstack;
|
|
|
|
return obstack_copy0 (&temporary_obstack, s, len);
|
1995-04-04 19:51:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_base_filename (filename)
|
|
|
|
char *filename;
|
|
|
|
{
|
|
|
|
char *p = getenv ("COLLECT_GCC_OPTIONS");
|
|
|
|
char *output = 0;
|
|
|
|
int compiling = 0;
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
char *q = p;
|
|
|
|
while (*q && *q != ' ') q++;
|
|
|
|
if (*p == '-' && p[1] == 'o')
|
|
|
|
{
|
|
|
|
p += 2;
|
|
|
|
if (p == q)
|
|
|
|
{
|
|
|
|
p++; q++;
|
|
|
|
if (*q)
|
|
|
|
while (*q && *q != ' ') q++;
|
|
|
|
}
|
|
|
|
|
|
|
|
output = save_string (p, q - p);
|
|
|
|
}
|
|
|
|
else if (*p == '-' && p[1] == 'c')
|
|
|
|
compiling = 1;
|
|
|
|
if (*q) q++;
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compiling && output)
|
|
|
|
return output;
|
|
|
|
|
1995-04-09 13:41:24 +02:00
|
|
|
if (p && ! compiling)
|
|
|
|
{
|
|
|
|
warning ("-frepo must be used with -c");
|
|
|
|
flag_use_repository = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = rindex (filename, '/');
|
|
|
|
if (p)
|
|
|
|
return p+1;
|
|
|
|
else
|
|
|
|
return filename;
|
1995-04-04 19:51:34 +02:00
|
|
|
}
|
|
|
|
|
1995-04-03 21:28:01 +02:00
|
|
|
static void
|
|
|
|
open_repo_file (filename)
|
|
|
|
char *filename;
|
|
|
|
{
|
|
|
|
register char *p, *q;
|
1995-04-04 19:51:34 +02:00
|
|
|
char *file = get_base_filename (filename);
|
1995-04-09 13:41:24 +02:00
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = rindex (file, '/');
|
1995-04-03 21:28:01 +02:00
|
|
|
if (s == NULL)
|
|
|
|
s = file;
|
|
|
|
else
|
|
|
|
++s;
|
|
|
|
|
|
|
|
for (p = repo_name, q = file; q < s; )
|
|
|
|
*p++ = *q++;
|
1995-04-09 13:41:24 +02:00
|
|
|
/* *p++ = '.'; */
|
1995-04-04 19:51:34 +02:00
|
|
|
if ((s = rindex (q, '.')) == NULL)
|
|
|
|
strcpy (p, q);
|
|
|
|
else
|
|
|
|
for (; q < s;)
|
|
|
|
*p++ = *q++;
|
1995-04-09 13:41:24 +02:00
|
|
|
strcat (p, ".rpo");
|
1995-04-03 21:28:01 +02:00
|
|
|
|
|
|
|
repo_file = fopen (repo_name, "r");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_repo (filename)
|
|
|
|
char *filename;
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
if (! flag_use_repository)
|
|
|
|
return;
|
|
|
|
|
1995-04-09 13:41:24 +02:00
|
|
|
open_repo_file (filename);
|
1995-04-03 21:28:01 +02:00
|
|
|
|
|
|
|
if (repo_file == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (fgets (buf, 1024, repo_file))
|
|
|
|
{
|
|
|
|
switch (buf[0])
|
|
|
|
{
|
|
|
|
case 'A':
|
1995-04-04 19:51:34 +02:00
|
|
|
case 'G':
|
1995-04-03 21:28:01 +02:00
|
|
|
case 'M':
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
case 'O':
|
|
|
|
{
|
1995-04-09 13:41:24 +02:00
|
|
|
char *q;
|
1995-04-18 21:23:38 +02:00
|
|
|
tree id, orig;
|
1995-04-09 13:41:24 +02:00
|
|
|
|
|
|
|
for (q = &buf[2]; *q && *q != ' ' && *q != '\n'; ++q) ;
|
|
|
|
q = save_string (&buf[2], q - &buf[2]);
|
|
|
|
id = get_identifier (q);
|
|
|
|
|
1995-04-03 21:28:01 +02:00
|
|
|
if (buf[0] == 'C')
|
1995-04-18 21:23:38 +02:00
|
|
|
{
|
|
|
|
IDENTIFIER_REPO_CHOSEN (id) = 1;
|
|
|
|
orig = integer_one_node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
orig = NULL_TREE;
|
|
|
|
|
|
|
|
original_repo = perm_tree_cons (orig, id, original_repo);
|
1995-04-03 21:28:01 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error ("mysterious repository information in %s", repo_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reopen_repo_file_for_write ()
|
|
|
|
{
|
|
|
|
if (repo_file)
|
|
|
|
fclose (repo_file);
|
|
|
|
repo_file = fopen (repo_name, "w");
|
|
|
|
|
|
|
|
if (repo_file == 0)
|
|
|
|
{
|
1995-04-04 19:51:34 +02:00
|
|
|
error ("can't create repository information file `%s'", repo_name);
|
1995-04-03 21:28:01 +02:00
|
|
|
flag_use_repository = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit any pending repos. */
|
|
|
|
|
|
|
|
void
|
|
|
|
finish_repo ()
|
|
|
|
{
|
|
|
|
tree t;
|
1995-04-04 19:51:34 +02:00
|
|
|
char *p;
|
1995-04-09 13:41:24 +02:00
|
|
|
int repo_changed = 0;
|
1995-04-03 21:28:01 +02:00
|
|
|
|
|
|
|
if (! flag_use_repository)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Do we have to write out a new info file? */
|
|
|
|
|
1995-04-18 21:23:38 +02:00
|
|
|
/* Are there any old templates that aren't used any longer or that are
|
|
|
|
newly chosen? */
|
1995-04-09 13:41:24 +02:00
|
|
|
|
|
|
|
for (t = original_repo; t; t = TREE_CHAIN (t))
|
|
|
|
{
|
1995-04-18 21:23:38 +02:00
|
|
|
if (! IDENTIFIER_REPO_USED (TREE_VALUE (t))
|
|
|
|
|| (! TREE_PURPOSE (t) && IDENTIFIER_REPO_CHOSEN (TREE_VALUE (t))))
|
1995-04-09 13:41:24 +02:00
|
|
|
{
|
|
|
|
repo_changed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
IDENTIFIER_REPO_USED (TREE_VALUE (t)) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Are there any templates that are newly used? */
|
|
|
|
|
|
|
|
if (! repo_changed)
|
|
|
|
for (t = pending_repo; t; t = TREE_CHAIN (t))
|
|
|
|
{
|
|
|
|
if (IDENTIFIER_REPO_USED (TREE_VALUE (t)))
|
|
|
|
{
|
|
|
|
repo_changed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-03 21:28:01 +02:00
|
|
|
if (! repo_changed || errorcount || sorrycount)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
reopen_repo_file_for_write ();
|
|
|
|
|
|
|
|
if (repo_file == 0)
|
|
|
|
goto out;
|
|
|
|
|
1995-04-04 19:51:34 +02:00
|
|
|
fprintf (repo_file, "M %s\n", main_input_filename);
|
|
|
|
|
|
|
|
p = getenv ("COLLECT_GCC");
|
|
|
|
if (p != 0)
|
|
|
|
fprintf (repo_file, "G %s\n", p);
|
|
|
|
|
|
|
|
p = getenv ("COLLECT_GCC_OPTIONS");
|
|
|
|
if (p != 0)
|
|
|
|
fprintf (repo_file, "A %s\n", p);
|
|
|
|
|
1995-04-03 21:28:01 +02:00
|
|
|
for (t = pending_repo; t; t = TREE_CHAIN (t))
|
|
|
|
{
|
|
|
|
tree val = TREE_VALUE (t);
|
1995-04-09 13:41:24 +02:00
|
|
|
char type = IDENTIFIER_REPO_CHOSEN (val) ? 'C' : 'O';
|
1995-04-03 21:28:01 +02:00
|
|
|
|
1995-04-09 13:41:24 +02:00
|
|
|
fprintf (repo_file, "%c %s ", type, IDENTIFIER_POINTER (val));
|
|
|
|
ASM_OUTPUT_LABELREF (repo_file, IDENTIFIER_POINTER (val));
|
|
|
|
putc ('\n', repo_file);
|
1995-04-03 21:28:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (repo_file)
|
|
|
|
fclose (repo_file);
|
|
|
|
}
|