00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "config.h"
00031 #include "system.h"
00032 #include "coretypes.h"
00033 #include "tm.h"
00034 #include "ggc.h"
00035 #include "tree.h"
00036 #include "symtab.h"
00037 #include "cpplib.h"
00038
00039
00040 const char empty_string[] = "";
00041
00042
00043
00044 const char digit_vector[] = {
00045 '0', 0, '1', 0, '2', 0, '3', 0, '4', 0,
00046 '5', 0, '6', 0, '7', 0, '8', 0, '9', 0
00047 };
00048
00049 struct ht *ident_hash;
00050 static struct obstack string_stack;
00051
00052 static hashnode alloc_node (hash_table *);
00053 static int mark_ident (struct cpp_reader *, hashnode, const void *);
00054
00055 static void *
00056 stringpool_ggc_alloc (size_t x)
00057 {
00058 return ggc_alloc (x);
00059 }
00060
00061
00062 void
00063 init_stringpool (void)
00064 {
00065
00066 ident_hash = ht_create (14);
00067 ident_hash->alloc_node = alloc_node;
00068 ident_hash->alloc_subobject = stringpool_ggc_alloc;
00069 gcc_obstack_init (&string_stack);
00070 }
00071
00072
00073 static hashnode
00074 alloc_node (hash_table *table ATTRIBUTE_UNUSED)
00075 {
00076 return GCC_IDENT_TO_HT_IDENT (make_node (IDENTIFIER_NODE));
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 const char *
00086 ggc_alloc_string (const char *contents, int length)
00087 {
00088 if (length == -1)
00089 length = strlen (contents);
00090
00091 if (length == 0)
00092 return empty_string;
00093 if (length == 1 && ISDIGIT (contents[0]))
00094 return digit_string (contents[0] - '0');
00095
00096 obstack_grow0 (&string_stack, contents, length);
00097 return obstack_finish (&string_stack);
00098 }
00099
00100
00101
00102
00103
00104 #undef get_identifier
00105
00106 tree
00107 get_identifier (const char *text)
00108 {
00109 hashnode ht_node = ht_lookup (ident_hash,
00110 (const unsigned char *) text,
00111 strlen (text), HT_ALLOC);
00112
00113
00114 return HT_IDENT_TO_GCC_IDENT (ht_node);
00115 }
00116
00117
00118
00119
00120 tree
00121 get_identifier_with_length (const char *text, size_t length)
00122 {
00123 hashnode ht_node = ht_lookup (ident_hash,
00124 (const unsigned char *) text,
00125 length, HT_ALLOC);
00126
00127
00128 return HT_IDENT_TO_GCC_IDENT (ht_node);
00129 }
00130
00131
00132
00133
00134
00135 tree
00136 maybe_get_identifier (const char *text)
00137 {
00138 hashnode ht_node;
00139
00140 ht_node = ht_lookup (ident_hash, (const unsigned char *) text,
00141 strlen (text), HT_NO_INSERT);
00142 if (ht_node)
00143 return HT_IDENT_TO_GCC_IDENT (ht_node);
00144
00145 return NULL_TREE;
00146 }
00147
00148
00149
00150 void
00151 stringpool_statistics (void)
00152 {
00153 ht_dump_statistics (ident_hash);
00154 }
00155
00156
00157
00158 static int
00159 mark_ident (struct cpp_reader *pfile ATTRIBUTE_UNUSED, hashnode h,
00160 const void *v ATTRIBUTE_UNUSED)
00161 {
00162 gt_ggc_m_9tree_node (HT_IDENT_TO_GCC_IDENT (h));
00163 return 1;
00164 }
00165
00166
00167
00168
00169
00170 void
00171 ggc_mark_stringpool (void)
00172 {
00173 ht_forall (ident_hash, mark_ident, NULL);
00174 }
00175
00176
00177
00178
00179
00180 void
00181 gt_ggc_m_S (void *x ATTRIBUTE_UNUSED)
00182 {
00183 }
00184
00185
00186
00187
00188 void
00189 gt_pch_p_S (void *obj ATTRIBUTE_UNUSED, void *x ATTRIBUTE_UNUSED,
00190 gt_pointer_operator op ATTRIBUTE_UNUSED,
00191 void *cookie ATTRIBUTE_UNUSED)
00192 {
00193 }
00194
00195
00196
00197 void
00198 gt_pch_n_S (const void *x)
00199 {
00200 gt_pch_note_object ((void *)x, (void *)x, >_pch_p_S);
00201 }
00202
00203
00204
00205
00206
00207
00208 struct string_pool_data GTY(())
00209 {
00210 struct ht_identifier * *
00211 GTY((length ("%h.nslots"),
00212 nested_ptr (union tree_node, "%h ? GCC_IDENT_TO_HT_IDENT (%h) : NULL",
00213 "%h ? HT_IDENT_TO_GCC_IDENT (%h) : NULL")))
00214 entries;
00215 unsigned int nslots;
00216 unsigned int nelements;
00217 };
00218
00219 static GTY(()) struct string_pool_data * spd;
00220
00221
00222
00223 void
00224 gt_pch_save_stringpool (void)
00225 {
00226 spd = ggc_alloc (sizeof (*spd));
00227 spd->nslots = ident_hash->nslots;
00228 spd->nelements = ident_hash->nelements;
00229 spd->entries = ggc_alloc (sizeof (spd->entries[0]) * spd->nslots);
00230 memcpy (spd->entries, ident_hash->entries,
00231 spd->nslots * sizeof (spd->entries[0]));
00232 }
00233
00234
00235
00236
00237 void
00238 gt_pch_fixup_stringpool (void)
00239 {
00240 }
00241
00242
00243
00244
00245 void
00246 gt_pch_restore_stringpool (void)
00247 {
00248 ht_load (ident_hash, spd->entries, spd->nslots, spd->nelements, false);
00249 spd = NULL;
00250 }
00251
00252 #include "gt-stringpool.h"