#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "ggc.h"
#include "tree.h"
#include "symtab.h"
#include "cpplib.h"
const char empty_string[] = "";
const char digit_vector[] = {
'0', 0, '1', 0, '2', 0, '3', 0, '4', 0,
'5', 0, '6', 0, '7', 0, '8', 0, '9', 0
};
struct ht *ident_hash;
static struct obstack string_stack;
static hashnode alloc_node (hash_table *);
static int mark_ident (struct cpp_reader *, hashnode, const void *);
static void *
stringpool_ggc_alloc (size_t x)
{
return ggc_alloc (x);
}
void
init_stringpool (void)
{
ident_hash = ht_create (14);
ident_hash->alloc_node = alloc_node;
ident_hash->alloc_subobject = stringpool_ggc_alloc;
gcc_obstack_init (&string_stack);
}
static hashnode
alloc_node (hash_table *table ATTRIBUTE_UNUSED)
{
return GCC_IDENT_TO_HT_IDENT (make_node (IDENTIFIER_NODE));
}
const char *
ggc_alloc_string (const char *contents, int length)
{
if (length == -1)
length = strlen (contents);
if (length == 0)
return empty_string;
if (length == 1 && ISDIGIT (contents[0]))
return digit_string (contents[0] - '0');
obstack_grow0 (&string_stack, contents, length);
return XOBFINISH (&string_stack, const char *);
}
#undef get_identifier
tree
get_identifier (const char *text)
{
hashnode ht_node = ht_lookup (ident_hash,
(const unsigned char *) text,
strlen (text), HT_ALLOC);
return HT_IDENT_TO_GCC_IDENT (ht_node);
}
tree
get_identifier_with_length (const char *text, size_t length)
{
hashnode ht_node = ht_lookup (ident_hash,
(const unsigned char *) text,
length, HT_ALLOC);
return HT_IDENT_TO_GCC_IDENT (ht_node);
}
tree
maybe_get_identifier (const char *text)
{
hashnode ht_node;
ht_node = ht_lookup (ident_hash, (const unsigned char *) text,
strlen (text), HT_NO_INSERT);
if (ht_node)
return HT_IDENT_TO_GCC_IDENT (ht_node);
return NULL_TREE;
}
void
stringpool_statistics (void)
{
ht_dump_statistics (ident_hash);
}
static int
mark_ident (struct cpp_reader *pfile ATTRIBUTE_UNUSED, hashnode h,
const void *v ATTRIBUTE_UNUSED)
{
gt_ggc_m_9tree_node (HT_IDENT_TO_GCC_IDENT (h));
return 1;
}
void
ggc_mark_stringpool (void)
{
ht_forall (ident_hash, mark_ident, NULL);
}
void
gt_ggc_m_S (void *x ATTRIBUTE_UNUSED)
{
}
void
gt_pch_p_S (void *obj ATTRIBUTE_UNUSED, void *x ATTRIBUTE_UNUSED,
gt_pointer_operator op ATTRIBUTE_UNUSED,
void *cookie ATTRIBUTE_UNUSED)
{
}
void
gt_pch_n_S (const void *x)
{
gt_pch_note_object ((void *)x, (void *)x, >_pch_p_S,
gt_types_enum_last);
}
struct string_pool_data GTY(())
{
struct ht_identifier * *
GTY((length ("%h.nslots"),
nested_ptr (union tree_node, "%h ? GCC_IDENT_TO_HT_IDENT (%h) : NULL",
"%h ? HT_IDENT_TO_GCC_IDENT (%h) : NULL")))
entries;
unsigned int nslots;
unsigned int nelements;
};
static GTY(()) struct string_pool_data * spd;
void
gt_pch_save_stringpool (void)
{
spd = ggc_alloc (sizeof (*spd));
spd->nslots = ident_hash->nslots;
spd->nelements = ident_hash->nelements;
spd->entries = ggc_alloc (sizeof (spd->entries[0]) * spd->nslots);
memcpy (spd->entries, ident_hash->entries,
spd->nslots * sizeof (spd->entries[0]));
}
void
gt_pch_fixup_stringpool (void)
{
}
void
gt_pch_restore_stringpool (void)
{
ht_load (ident_hash, spd->entries, spd->nslots, spd->nelements, false);
spd = NULL;
}
#include "gt-stringpool.h"