From patchwork Mon Oct 10 21:47:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Soni X-Patchwork-Id: 118847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E8117B712A for ; Tue, 11 Oct 2011 08:48:05 +1100 (EST) Received: (qmail 20554 invoked by alias); 10 Oct 2011 21:48:02 -0000 Received: (qmail 20479 invoked by uid 22791); 10 Oct 2011 21:48:01 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-ey0-f175.google.com (HELO mail-ey0-f175.google.com) (209.85.215.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 10 Oct 2011 21:47:45 +0000 Received: by eyd9 with SMTP id 9so1406477eyd.20 for ; Mon, 10 Oct 2011 14:47:44 -0700 (PDT) Received: by 10.223.61.146 with SMTP id t18mr34851805fah.34.1318283264291; Mon, 10 Oct 2011 14:47:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.152.36.102 with HTTP; Mon, 10 Oct 2011 14:47:24 -0700 (PDT) From: Sandeep Soni Date: Tue, 11 Oct 2011 03:17:24 +0530 Message-ID: Subject: [gimplefe][patch] The symbol table for declarations To: gcc patches Cc: Diego Novillo X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, The following patch is a basic attempt to build a symbol table that stores the names of all the declarations made in the input file. next_token = gl_consume_token (parser->lexer); @@ -981,6 +1027,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 +1450,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); The changelog is as follows: 2011-10-11 Sandeep Soni * parser.c : Include hashtab.h. (struct gimple_symtab_entry_def): New. (gimple_symtab): New. The symbol table. (gimple_symtab_entry_hash): New. (gimple_symtab_eq_hash): New. (gp_parse_var_decl): Build the declaration and put it in the symbol table. (gimple_main): Creates the symbol table Index: gcc/gimple/parser.c =================================================================== --- gcc/gimple/parser.c (revision 174754) +++ gcc/gimple/parser.c (working copy) @@ -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,43 @@ /* EOF token. */ static gimple_token gl_eof_token = { CPP_EOF, 0, 0, 0 }; +/* The GIMPLE symbol table entry. */ + +struct GTY (()) gimple_symtab_entry_def +{ + /* Variable that is declared. */ + tree decl; + +}; + +/* 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 (DECL_NAME(base->decl)); +} + +/* Returns non-zero if ENTRY1 and ENTRY2 points 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 *p1 = + (const struct gimple_symtab_entry_def *)entry1; + const struct gimple_symtab_entry_def *p2 = + (const struct gimple_symtab_entry_def *)entry2; + + return DECL_NAME(p1->decl) == DECL_NAME(p2->decl); +} + /* Return the string representation of token TOKEN. */ static const char * @@ -807,6 +845,7 @@ } } + /* The Declaration section within a .gimple file can consist of a) Declaration of variables. b) Declaration of functions. @@ -870,11 +909,17 @@ 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; 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.decl = + build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier(name), void_type_node); + htab_find_slot (gimple_symtab, &e, INSERT); gl_consume_expected_token (parser->lexer, CPP_COMMA);