From patchwork Fri Feb 24 06:03:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sandeep Soni X-Patchwork-Id: 142755 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 003CCB6FB7 for ; Fri, 24 Feb 2012 17:04:22 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1330668264; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Received-SPF:Received:Received:MIME-Version:Received:In-Reply-To: References:From:Date:Message-ID:Subject:To:Cc:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=ZRhd74QkKeLhjvGQeouQ dI3W3DM=; b=VXSFNtdRtx5gM2CWAJh3gnv2LsLI+Mks9u0U1p8k0HeU7D6vrYTT r/y/fTYP3a+W0ebwYUPcapiCtpP3IVRTsIFKQMv+4dsO/7doEfsccZNcDooGupEu RXujOuADWsLmMHFNSn8H11JmJZZcMyadO8UBKaIZROn2D1VNd0Sfah0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received-SPF:Authentication-Results:Received:Received:MIME-Version:Received:In-Reply-To:References:From:Date:Message-ID:Subject:To:Cc:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=eY+XfjO58/nQCN0FMIqPdtNRBSwHIAYeAdSY56pTT+hZGewd83DC4xilxpjglf 5wNWXYpEcsX4Om1kT+PPltNGv5hjLN6Yq7b95jbliC3RDM/GJ+sopppsFYYDAT26 puRqVtgMYL4r5AT3zse6xbGs1tOzL6zpUdNSq48d/+S6k=; Received: (qmail 16342 invoked by alias); 24 Feb 2012 06:04:17 -0000 Received: (qmail 16332 invoked by uid 22791); 24 Feb 2012 06:04:15 -0000 X-SWARE-Spam-Status: No, hits=-2.2 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-tul01m020-f175.google.com (HELO mail-tul01m020-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 24 Feb 2012 06:04:02 +0000 Received: by obhx4 with SMTP id x4so2559739obh.20 for ; Thu, 23 Feb 2012 22:04:01 -0800 (PST) Received-SPF: pass (google.com: domain of soni.sandeepb@gmail.com designates 10.182.121.101 as permitted sender) client-ip=10.182.121.101; Authentication-Results: mr.google.com; spf=pass (google.com: domain of soni.sandeepb@gmail.com designates 10.182.121.101 as permitted sender) smtp.mail=soni.sandeepb@gmail.com; dkim=pass header.i=soni.sandeepb@gmail.com Received: from mr.google.com ([10.182.121.101]) by 10.182.121.101 with SMTP id lj5mr357175obb.39.1330063441394 (num_hops = 1); Thu, 23 Feb 2012 22:04:01 -0800 (PST) Received: by 10.182.121.101 with SMTP id lj5mr315587obb.39.1330063441330; Thu, 23 Feb 2012 22:04:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.113.104 with HTTP; Thu, 23 Feb 2012 22:03:41 -0800 (PST) In-Reply-To: References: <4E9596A1.30608@google.com> From: Sandeep Soni Date: Fri, 24 Feb 2012 11:33:41 +0530 Message-ID: Subject: Re: [gimplefe][patch] The symbol table for declarations To: Diego Novillo Cc: gcc patches 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 On Wed, Nov 30, 2011 at 9:48 AM, Sandeep Soni wrote: > Sorry. Wrong patch. New patch attached. > > I am getting the following error in the new patch though. > > ../../gimple-front-end/gcc/gimple/parser.c: In function ‘gp_parse_var_decl’: > ../../gimple-front-end/gcc/gimple/parser.c:927:3: error: implicit > declaration of function ‘ggc_alloc_cleared_gimple_symtab_entry_def’ > [-Werror=implicit-function-declaration] > ../../gimple-front-end/gcc/gimple/parser.c:927:5: error: assignment > makes pointer from integer without a cast [-Werror] > cc1: all warnings being treated as errors > > make[3]: *** [gimple/parser.o] Error 1 > make[3]: *** Waiting for unfinished jobs.... > rm gfdl.pod cpp.pod gcov.pod gfortran.pod fsf-funding.pod gcc.pod > make[3]: Leaving directory `/home/Sandy/gimple_build/gcc' > make[2]: *** [all-stage2-gcc] Error 2 > make[2]: Leaving directory `/home/Sandy/gimple_build' > make[1]: *** [stage2-bubble] Error 2 > make[1]: Leaving directory `/home/Sandy/gimple_build' > make: *** [all] Error 2 > > Is there anything that needs to be initialized to use the > ggc_alloc_cleared_* function? I was finally able to circumvent the error. I guess what I missed was I did not mark the symbol table (the global variable) for garbage collection. Once I did that the error was removed. Builds correctly on x86. Up for review. Index: gcc/gimple/parser.h =================================================================== --- gcc/gimple/parser.h (revision 174754) +++ gcc/gimple/parser.h (working copy) @@ -27,6 +27,19 @@ #include "vec.h" +/* 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_t; + /* A GIMPLE token. */ typedef struct GTY(()) gimple_token { @@ -81,7 +94,7 @@ struct GTY((skip)) ht *ident_hash; } gimple_parser; - + /* In parser.c */ extern void gimple_main (void); 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,52 @@ /* EOF token. */ static gimple_token gl_eof_token = { CPP_EOF, 0, 0, 0 }; +/* Gimple symbol table. */ + +static GTY ((if_marked ("gimple_symtab_entry_marked_p"), + param_is (struct gimple_symtab_entry_def))) + 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); +} + +/* Returns non-zero if P points to an gimple_symtab_entry_def struct that needs + to be marked for GC. */ + +static int +gimple_symtab_entry_marked_p (const void *p) +{ + const struct gimple_symtab_entry_def *base = + (const struct gimple_symtab_entry_def *) p; + + /* Keep this only if the common IDENTIFIER_NODE of the symtab chain + is marked which it will be if at least one of the DECLs in the + chain is marked. */ + return ggc_marked_p (base->id); +} + /* Return the string representation of token TOKEN. */ static const char * @@ -807,6 +854,7 @@ } } + /* The Declaration section within a .gimple file can consist of a) Declaration of variables. b) Declaration of functions. @@ -870,18 +918,35 @@ 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 ; + gimple_symtab_entry_t 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 = ggc_alloc_cleared_gimple_symtab_entry_def (); + 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 +1046,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 +1469,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);