===================================================================
@@ -28,6 +28,7 @@
#include "tree.h"
#include "gimple.h"
#include "parser.h"
+#include "hashtab.h"
#include "ggc.h"
/* The GIMPLE parser. Note: do not use this variable directly. It is
@@ -44,6 +45,47 @@
/* EOF token. */
static gimple_token gl_eof_token = { CPP_EOF, 0, 0, 0 };
+/* The GIMPLE symbol table entry. */
+
+struct GTY (()) gimple_symtab_entry_def
+{
+ /* symbol table entry key, an identifier. */
+ tree id;
+
+ /* symbol table entry, a DECL. */
+ tree decl;
+};
+
+typedef struct gimple_symtab_entry_def gimple_symtab_entry;
+
+/* Gimple symbol table. */
+static htab_t gimple_symtab;
+
+/* Return the hash value of the declaration name of a gimple_symtab_entry_def
+ object pointed by ENTRY. */
+
+static hashval_t
+gimple_symtab_entry_hash (const void *entry)
+{
+ const struct gimple_symtab_entry_def *base =
+ (const struct gimple_symtab_entry_def *)entry;
+ return IDENTIFIER_HASH_VALUE (base->id);
+}
+
+/* Returns non-zero if ENTRY1 and ENTRY2 point to gimple_symtab_entry_def
+ objects corresponding to the same declaration. */
+
+static int
+gimple_symtab_eq_hash (const void *entry1, const void *entry2)
+{
+ const struct gimple_symtab_entry_def *base1 =
+ (const struct gimple_symtab_entry_def *)entry1;
+ const struct gimple_symtab_entry_def *base2 =
+ (const struct gimple_symtab_entry_def *)entry2;
+
+ return (base1->id == base2->id);
+}
+
/* Return the string representation of token TOKEN. */
static const char *
@@ -807,6 +849,7 @@
}
}
+
/* The Declaration section within a .gimple file can consist of
a) Declaration of variables.
b) Declaration of functions.
@@ -870,18 +913,34 @@
static void
gp_parse_var_decl (gimple_parser *parser)
{
- const gimple_token *next_token;
+ const gimple_token *next_token, *name_token;
+ const char *name;
enum tree_code code ;
+ struct gimple_symtab_entry_def e;
+ void **slot;
+ void **new_entry;
gl_consume_expected_token (parser->lexer, CPP_LESS);
- gl_consume_expected_token (parser->lexer, CPP_NAME);
+ name_token = gl_consume_expected_token (parser->lexer, CPP_NAME);
+ name = gl_token_as_text (name_token);
+
+ e.id = get_identifier(name);
+ slot = htab_find_slot (gimple_symtab, &e, NO_INSERT);
+ if (!slot)
+ {
+ e.decl = build_decl (name_token.location, VAR_DECL, get_identifier(name), void_type_node);
+ new_entry = htab_find_slot (gimple_symtab, &e, INSERT);
+ gcc_assert (*new_entry == NULL);
+ *new_entry = e;
+ }
+
gl_consume_expected_token (parser->lexer, CPP_COMMA);
-
next_token = gl_consume_token (parser->lexer);
code = gl_tree_code_for_token (next_token);
switch (code)
{
case INTEGER_TYPE:
+ gl_consume_expected_token (parser->lexer, CPP_LESS);
gl_consume_expected_token (parser->lexer, CPP_NUMBER);
gl_consume_expected_token (parser->lexer, CPP_RSHIFT);
break;
@@ -981,6 +1040,7 @@
gimple_parser *parser = ggc_alloc_cleared_gimple_parser ();
line_table = parser->line_table = ggc_alloc_cleared_line_maps ();
parser->ident_hash = ident_hash;
+
linemap_init (parser->line_table);
parser->lexer = gl_init (parser, fname);
@@ -1403,6 +1463,9 @@
if (parser->lexer->filename == NULL)
return;
+ gimple_symtab =
+ htab_create_ggc (1021, gimple_symtab_entry_hash,
+ gimple_symtab_eq_hash, NULL);
gl_lex (parser->lexer);
gp_parse (parser);
gp_finish (parser);