From patchwork Mon Aug 5 05:19:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Dos Reis X-Patchwork-Id: 264573 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 3CBDD2C0091 for ; Mon, 5 Aug 2013 15:19:32 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=HarCwX/gRv6ufmNOwy03I8H/ZiykB7xUEbRvLSwbO2lYUcAPBdTEC zCuwCh2oPTBZWR1F1pK2ybhjUwEz3ORSrOhO4S+0nfXwUDu5ytpA6Nj0v1111c9c 7z/y7kGMivC0GopZX5GMRKMwGlIxpEb8hkqico0bQaPNGqELcuYVdU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=TdqOIgktUu7qH36TgeuOZIlAhGU=; b=cman0T1aB1Z6yqBao1xF OSTrM5qgmsIM21X0mtWsrLyUZFReTA9lnyTbcExxvjjzWDcpO4Co7GFfhBkyl6cZ 3yKm7rkyOwOzfx1mtYvR6VQ4XdzMldwFv0KKsC82rB2QB4Bt0ncbLDlVpVwPFpJv 3OupQowgqAZ2naSrtzYfAnI= Received: (qmail 30865 invoked by alias); 5 Aug 2013 05:19:25 -0000 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 Received: (qmail 30856 invoked by uid 89); 5 Aug 2013 05:19:25 -0000 X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RDNS_NONE autolearn=no version=3.3.1 Received: from Unknown (HELO mail.axiomatics.org) (66.228.53.191) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 05 Aug 2013 05:19:24 +0000 Received: by mail.axiomatics.org (Postfix, from userid 1000) id 4884EED0D; Mon, 5 Aug 2013 00:19:16 -0500 (CDT) From: Gabriel Dos Reis To: gcc-patches@gcc.gnu.org Subject: Clean up pretty printers [3/n] Date: Mon, 05 Aug 2013 00:19:16 -0500 Message-ID: <877gg0lnor.fsf@euclid.axiomatics.org> Lines: 92 MIME-Version: 1.0 This patchlet makes the asan module stop using a global pretty printer. As a result, the code is cleaner that way -- and this is in preparation of having pretty printers initialize themselves through constructors. -- Gaby 2013-08-05 Gabriel Dos Reis * asan.c (asan_pp): Remove. (asan_pp_initialized): Likewise. (asan_pp_initialize): Likewise. (asan_pp_string): Take a pretty_printer parameter. Adjust callers. (asan_emit_stack_protection): Tidy. Use local pretty printer. (asan_add_global): Likewise. Index: asan.c =================================================================== --- asan.c (revision 201479) +++ asan.c (working copy) @@ -842,25 +842,12 @@ initialize_sanitizer_builtins (); } -/* Asan pretty-printer, used for buidling of the description STRING_CSTs. */ -static pretty_printer asan_pp; -static bool asan_pp_initialized; +/* Create ADDR_EXPR of STRING_CST with the PP pretty printer text. */ -/* Initialize asan_pp. */ - -static void -asan_pp_initialize (void) -{ - pp_construct (&asan_pp, /* prefix */NULL, /* line-width */0); - asan_pp_initialized = true; -} - -/* Create ADDR_EXPR of STRING_CST with asan_pp text. */ - static tree -asan_pp_string (void) +asan_pp_string (pretty_printer *pp) { - const char *buf = pp_formatted_text (&asan_pp); + const char *buf = pp_formatted_text (pp); size_t len = strlen (buf); tree ret = build_string (len + 1, buf); TREE_TYPE (ret) @@ -950,9 +937,9 @@ asan_init_shadow_ptr_types (); /* First of all, prepare the description string. */ - if (!asan_pp_initialized) - asan_pp_initialize (); - + pretty_printer asan_pp; + pp_construct (&asan_pp, /* prefix */NULL, /* line-width */0); + pp_clear_output_area (&asan_pp); if (DECL_NAME (current_function_decl)) pp_tree_identifier (&asan_pp, DECL_NAME (current_function_decl)); @@ -978,7 +965,7 @@ pp_string (&asan_pp, "9 "); pp_space (&asan_pp); } - str_cst = asan_pp_string (); + str_cst = asan_pp_string (&asan_pp); /* Emit the prologue sequence. */ base = expand_binop (Pmode, add_optab, base, GEN_INT (base_offset), @@ -1976,8 +1963,8 @@ tree str_cst, refdecl = decl; vec *vinner = NULL; - if (!asan_pp_initialized) - asan_pp_initialize (); + pretty_printer asan_pp; + pp_construct (&asan_pp, /* prefix */NULL, /* line-width */0); pp_clear_output_area (&asan_pp); if (DECL_NAME (decl)) @@ -1988,7 +1975,7 @@ pp_left_paren (&asan_pp); pp_string (&asan_pp, main_input_filename); pp_right_paren (&asan_pp); - str_cst = asan_pp_string (); + str_cst = asan_pp_string (&asan_pp); if (asan_needs_local_alias (decl)) {