mirror of git://gcc.gnu.org/git/gcc.git
godump.c (struct macro_hash_value): Define.
* godump.c (struct macro_hash_value): Define. (macro_hash_hashval): New static function. (macro_hash_eq, macro_hash_del): New static functions. (go_define): Use macro_hash_value to store values in macro_hash. Replace an old value on a redefinition. Don't print anything to go_dump_file. (go_undef): Delete the entry from the hash table. (go_output_typedef): For an enum, use macro_hash_value, and don't print anything to go_dump_file. (go_print_macro): New static function. (go_finish): Traverse macro_hash with go_print_macro. (dump_go_spec_init): Update macro_hash creation for macro_hash_value. From-SVN: r180762
This commit is contained in:
parent
1834883a34
commit
5743331e9d
|
@ -1,3 +1,19 @@
|
||||||
|
2011-11-01 Ian Lance Taylor <iant@google.com>
|
||||||
|
|
||||||
|
* godump.c (struct macro_hash_value): Define.
|
||||||
|
(macro_hash_hashval): New static function.
|
||||||
|
(macro_hash_eq, macro_hash_del): New static functions.
|
||||||
|
(go_define): Use macro_hash_value to store values in macro_hash.
|
||||||
|
Replace an old value on a redefinition. Don't print anything to
|
||||||
|
go_dump_file.
|
||||||
|
(go_undef): Delete the entry from the hash table.
|
||||||
|
(go_output_typedef): For an enum, use macro_hash_value, and don't
|
||||||
|
print anything to go_dump_file.
|
||||||
|
(go_print_macro): New static function.
|
||||||
|
(go_finish): Traverse macro_hash with go_print_macro.
|
||||||
|
(dump_go_spec_init): Update macro_hash creation for
|
||||||
|
macro_hash_value.
|
||||||
|
|
||||||
2011-11-02 Alan Modra <amodra@gmail.com>
|
2011-11-02 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
* config/rs6000/rs6000.c (rs6000_code_end): Declare ATTRIBUTE_UNUSED.
|
* config/rs6000/rs6000.c (rs6000_code_end): Declare ATTRIBUTE_UNUSED.
|
||||||
|
|
155
gcc/godump.c
155
gcc/godump.c
|
@ -62,7 +62,47 @@ static GTY(()) VEC(tree,gc) *queue;
|
||||||
|
|
||||||
static htab_t macro_hash;
|
static htab_t macro_hash;
|
||||||
|
|
||||||
/* For the hash tables. */
|
/* The type of a value in macro_hash. */
|
||||||
|
|
||||||
|
struct macro_hash_value
|
||||||
|
{
|
||||||
|
/* The name stored in the hash table. */
|
||||||
|
char *name;
|
||||||
|
/* The value of the macro. */
|
||||||
|
char *value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Calculate the hash value for an entry in the macro hash table. */
|
||||||
|
|
||||||
|
static hashval_t
|
||||||
|
macro_hash_hashval (const void *val)
|
||||||
|
{
|
||||||
|
const struct macro_hash_value *mhval = (const struct macro_hash_value *) val;
|
||||||
|
return htab_hash_string (mhval->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compare values in the macro hash table for equality. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
macro_hash_eq (const void *v1, const void *v2)
|
||||||
|
{
|
||||||
|
const struct macro_hash_value *mhv1 = (const struct macro_hash_value *) v1;
|
||||||
|
const struct macro_hash_value *mhv2 = (const struct macro_hash_value *) v2;
|
||||||
|
return strcmp (mhv1->name, mhv2->name) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free values deleted from the macro hash table. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
macro_hash_del (void *v)
|
||||||
|
{
|
||||||
|
struct macro_hash_value *mhv = (struct macro_hash_value *) v;
|
||||||
|
XDELETEVEC (mhv->name);
|
||||||
|
XDELETEVEC (mhv->value);
|
||||||
|
XDELETE (mhv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* For the string hash tables. */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
string_hash_eq (const void *y1, const void *y2)
|
string_hash_eq (const void *y1, const void *y2)
|
||||||
|
@ -77,10 +117,12 @@ go_define (unsigned int lineno, const char *buffer)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
const char *name_end;
|
const char *name_end;
|
||||||
|
size_t out_len;
|
||||||
char *out_buffer;
|
char *out_buffer;
|
||||||
char *q;
|
char *q;
|
||||||
bool saw_operand;
|
bool saw_operand;
|
||||||
bool need_operand;
|
bool need_operand;
|
||||||
|
struct macro_hash_value *mhval;
|
||||||
char *copy;
|
char *copy;
|
||||||
hashval_t hashval;
|
hashval_t hashval;
|
||||||
void **slot;
|
void **slot;
|
||||||
|
@ -105,17 +147,17 @@ go_define (unsigned int lineno, const char *buffer)
|
||||||
memcpy (copy, buffer, name_end - buffer);
|
memcpy (copy, buffer, name_end - buffer);
|
||||||
copy[name_end - buffer] = '\0';
|
copy[name_end - buffer] = '\0';
|
||||||
|
|
||||||
|
mhval = XNEW (struct macro_hash_value);
|
||||||
|
mhval->name = copy;
|
||||||
|
mhval->value = NULL;
|
||||||
|
|
||||||
hashval = htab_hash_string (copy);
|
hashval = htab_hash_string (copy);
|
||||||
slot = htab_find_slot_with_hash (macro_hash, copy, hashval, NO_INSERT);
|
slot = htab_find_slot_with_hash (macro_hash, mhval, hashval, NO_INSERT);
|
||||||
if (slot != NULL)
|
|
||||||
{
|
|
||||||
XDELETEVEC (copy);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* For simplicity, we force all names to be hidden by adding an
|
/* For simplicity, we force all names to be hidden by adding an
|
||||||
initial underscore, and let the user undo this as needed. */
|
initial underscore, and let the user undo this as needed. */
|
||||||
out_buffer = XNEWVEC (char, strlen (p) * 2 + 1);
|
out_len = strlen (p) * 2 + 1;
|
||||||
|
out_buffer = XNEWVEC (char, out_len);
|
||||||
q = out_buffer;
|
q = out_buffer;
|
||||||
saw_operand = false;
|
saw_operand = false;
|
||||||
need_operand = false;
|
need_operand = false;
|
||||||
|
@ -141,6 +183,7 @@ go_define (unsigned int lineno, const char *buffer)
|
||||||
don't worry about them. */
|
don't worry about them. */
|
||||||
const char *start;
|
const char *start;
|
||||||
char *n;
|
char *n;
|
||||||
|
struct macro_hash_value idval;
|
||||||
|
|
||||||
if (saw_operand)
|
if (saw_operand)
|
||||||
goto unknown;
|
goto unknown;
|
||||||
|
@ -151,8 +194,9 @@ go_define (unsigned int lineno, const char *buffer)
|
||||||
n = XALLOCAVEC (char, p - start + 1);
|
n = XALLOCAVEC (char, p - start + 1);
|
||||||
memcpy (n, start, p - start);
|
memcpy (n, start, p - start);
|
||||||
n[p - start] = '\0';
|
n[p - start] = '\0';
|
||||||
slot = htab_find_slot (macro_hash, n, NO_INSERT);
|
idval.name = n;
|
||||||
if (slot == NULL || *slot == NULL)
|
idval.value = NULL;
|
||||||
|
if (htab_find (macro_hash, &idval) == NULL)
|
||||||
{
|
{
|
||||||
/* This is a reference to a name which was not defined
|
/* This is a reference to a name which was not defined
|
||||||
as a macro. */
|
as a macro. */
|
||||||
|
@ -382,18 +426,30 @@ go_define (unsigned int lineno, const char *buffer)
|
||||||
if (need_operand)
|
if (need_operand)
|
||||||
goto unknown;
|
goto unknown;
|
||||||
|
|
||||||
|
gcc_assert ((size_t) (q - out_buffer) < out_len);
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
|
|
||||||
slot = htab_find_slot_with_hash (macro_hash, copy, hashval, INSERT);
|
mhval->value = out_buffer;
|
||||||
*slot = copy;
|
|
||||||
|
|
||||||
fprintf (go_dump_file, "const _%s = %s\n", copy, out_buffer);
|
if (slot == NULL)
|
||||||
|
{
|
||||||
|
slot = htab_find_slot_with_hash (macro_hash, mhval, hashval, INSERT);
|
||||||
|
gcc_assert (slot != NULL && *slot == NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (*slot != NULL)
|
||||||
|
macro_hash_del (*slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
*slot = mhval;
|
||||||
|
|
||||||
XDELETEVEC (out_buffer);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unknown:
|
unknown:
|
||||||
fprintf (go_dump_file, "// unknowndefine %s\n", buffer);
|
fprintf (go_dump_file, "// unknowndefine %s\n", buffer);
|
||||||
|
if (slot != NULL)
|
||||||
|
htab_clear_slot (macro_hash, slot);
|
||||||
XDELETEVEC (out_buffer);
|
XDELETEVEC (out_buffer);
|
||||||
XDELETEVEC (copy);
|
XDELETEVEC (copy);
|
||||||
}
|
}
|
||||||
|
@ -403,16 +459,16 @@ go_define (unsigned int lineno, const char *buffer)
|
||||||
static void
|
static void
|
||||||
go_undef (unsigned int lineno, const char *buffer)
|
go_undef (unsigned int lineno, const char *buffer)
|
||||||
{
|
{
|
||||||
|
struct macro_hash_value mhval;
|
||||||
void **slot;
|
void **slot;
|
||||||
|
|
||||||
real_debug_hooks->undef (lineno, buffer);
|
real_debug_hooks->undef (lineno, buffer);
|
||||||
|
|
||||||
slot = htab_find_slot (macro_hash, buffer, NO_INSERT);
|
mhval.name = CONST_CAST (char *, buffer);
|
||||||
if (slot == NULL)
|
mhval.value = NULL;
|
||||||
return;
|
slot = htab_find_slot (macro_hash, &mhval, NO_INSERT);
|
||||||
fprintf (go_dump_file, "// undef _%s\n", buffer);
|
if (slot != NULL)
|
||||||
/* We don't delete the slot from the hash table because that will
|
htab_clear_slot (macro_hash, slot);
|
||||||
cause a duplicate const definition. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A function or variable decl. */
|
/* A function or variable decl. */
|
||||||
|
@ -909,32 +965,37 @@ go_output_typedef (struct godump_container *container, tree decl)
|
||||||
element = TREE_CHAIN (element))
|
element = TREE_CHAIN (element))
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
struct macro_hash_value *mhval;
|
||||||
void **slot;
|
void **slot;
|
||||||
|
char buf[100];
|
||||||
|
|
||||||
name = IDENTIFIER_POINTER (TREE_PURPOSE (element));
|
name = IDENTIFIER_POINTER (TREE_PURPOSE (element));
|
||||||
|
|
||||||
/* Sometimes a name will be defined as both an enum constant
|
/* Sometimes a name will be defined as both an enum constant
|
||||||
and a macro. Avoid duplicate definition errors by
|
and a macro. Avoid duplicate definition errors by
|
||||||
treating enum constants as macros. */
|
treating enum constants as macros. */
|
||||||
slot = htab_find_slot (macro_hash, name, INSERT);
|
mhval = XNEW (struct macro_hash_value);
|
||||||
if (*slot == NULL)
|
mhval->name = xstrdup (name);
|
||||||
{
|
mhval->value = NULL;
|
||||||
*slot = CONST_CAST (char *, name);
|
slot = htab_find_slot (macro_hash, mhval, INSERT);
|
||||||
fprintf (go_dump_file, "const _%s = ", name);
|
if (*slot != NULL)
|
||||||
if (host_integerp (TREE_VALUE (element), 0))
|
macro_hash_del (*slot);
|
||||||
fprintf (go_dump_file, HOST_WIDE_INT_PRINT_DEC,
|
|
||||||
tree_low_cst (TREE_VALUE (element), 0));
|
if (host_integerp (TREE_VALUE (element), 0))
|
||||||
else if (host_integerp (TREE_VALUE (element), 1))
|
snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_DEC,
|
||||||
fprintf (go_dump_file, HOST_WIDE_INT_PRINT_UNSIGNED,
|
tree_low_cst (TREE_VALUE (element), 0));
|
||||||
((unsigned HOST_WIDE_INT)
|
else if (host_integerp (TREE_VALUE (element), 1))
|
||||||
tree_low_cst (TREE_VALUE (element), 1)));
|
snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_UNSIGNED,
|
||||||
else
|
((unsigned HOST_WIDE_INT)
|
||||||
fprintf (go_dump_file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
|
tree_low_cst (TREE_VALUE (element), 1)));
|
||||||
((unsigned HOST_WIDE_INT)
|
else
|
||||||
TREE_INT_CST_HIGH (TREE_VALUE (element))),
|
snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
|
||||||
TREE_INT_CST_LOW (TREE_VALUE (element)));
|
((unsigned HOST_WIDE_INT)
|
||||||
fprintf (go_dump_file, "\n");
|
TREE_INT_CST_HIGH (TREE_VALUE (element))),
|
||||||
}
|
TREE_INT_CST_LOW (TREE_VALUE (element)));
|
||||||
|
|
||||||
|
mhval->value = xstrdup (buf);
|
||||||
|
*slot = mhval;
|
||||||
}
|
}
|
||||||
pointer_set_insert (container->decls_seen, TREE_TYPE (decl));
|
pointer_set_insert (container->decls_seen, TREE_TYPE (decl));
|
||||||
if (TYPE_CANONICAL (TREE_TYPE (decl)) != NULL_TREE)
|
if (TYPE_CANONICAL (TREE_TYPE (decl)) != NULL_TREE)
|
||||||
|
@ -1039,6 +1100,17 @@ go_output_var (struct godump_container *container, tree decl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Output the final value of a preprocessor macro or enum constant.
|
||||||
|
This is called via htab_traverse_noresize. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
go_print_macro (void **slot, void *arg ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
struct macro_hash_value *mhval = (struct macro_hash_value *) *slot;
|
||||||
|
fprintf (go_dump_file, "const _%s = %s\n", mhval->name, mhval->value);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Build a hash table with the Go keywords. */
|
/* Build a hash table with the Go keywords. */
|
||||||
|
|
||||||
static const char * const keywords[] = {
|
static const char * const keywords[] = {
|
||||||
|
@ -1123,6 +1195,8 @@ go_finish (const char *filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
htab_traverse_noresize (macro_hash, go_print_macro, NULL);
|
||||||
|
|
||||||
/* To emit dummy definitions. */
|
/* To emit dummy definitions. */
|
||||||
pointer_set_traverse (container.pot_dummy_types, find_dummy_types,
|
pointer_set_traverse (container.pot_dummy_types, find_dummy_types,
|
||||||
(void *) &container);
|
(void *) &container);
|
||||||
|
@ -1163,7 +1237,8 @@ dump_go_spec_init (const char *filename, const struct gcc_debug_hooks *hooks)
|
||||||
go_debug_hooks.global_decl = go_global_decl;
|
go_debug_hooks.global_decl = go_global_decl;
|
||||||
go_debug_hooks.type_decl = go_type_decl;
|
go_debug_hooks.type_decl = go_type_decl;
|
||||||
|
|
||||||
macro_hash = htab_create (100, htab_hash_string, string_hash_eq, NULL);
|
macro_hash = htab_create (100, macro_hash_hashval, macro_hash_eq,
|
||||||
|
macro_hash_del);
|
||||||
|
|
||||||
return &go_debug_hooks;
|
return &go_debug_hooks;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue