From patchwork Thu Jul 23 13:02:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 1334879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BCCCl39Xrz9sRX for ; Thu, 23 Jul 2020 23:02:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 618A53851C33; Thu, 23 Jul 2020 13:02:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 63A073857C5A for ; Thu, 23 Jul 2020 13:02:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 63A073857C5A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=charlet@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 30B1211677A; Thu, 23 Jul 2020 09:02:04 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id y1xmRlrrxBTe; Thu, 23 Jul 2020 09:02:04 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 1D7F5116700; Thu, 23 Jul 2020 09:02:04 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 19BDDD5; Thu, 23 Jul 2020 09:02:04 -0400 (EDT) Date: Thu, 23 Jul 2020 09:02:04 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Subject: [Ada] Add push/pop capability in Output Message-ID: <20200723130204.GA68413@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Add the capability to use the Write_* procedures in an environment where you want to write debugging info but still use them to write to other files (such a C source files). [changelog] * output.ads (Push_Output, Pop_Output): New procedures. * output.adb (FD_Array, FD_Stack, FD_Stack_Idx): New type and vars. (Push_Output, Pop_Output): New procedures. Tested on x86_64-pc-linux-gnu, commited on trunk --- output.adb | 29 +++++++++++++++++++++++++++++ output.ads | 9 +++++++++ 2 files changed, 38 insertions(+) diff --git output.adb output.adb index d36aac8..971819b 100644 --- output.adb +++ output.adb @@ -45,6 +45,13 @@ package body Output is Current_FD : File_Descriptor := Standout; -- File descriptor for current output + type FD_Array is array (Nat range 1 .. 3) of File_Descriptor; + FD_Stack : FD_Array; + FD_Stack_Idx : Nat := FD_Array'First - 1; + -- Maintain a small stack for Push_Output and Pop_Output. We'd normally + -- use Table for this and allow an unlimited depth, but we're the target + -- of a pragma Elaborate_All in Table, so we can't use it here. + Special_Output_Proc : Output_Proc := null; -- Record argument to last call to Set_Special_Output. If this is -- non-null, then we are in special output mode. @@ -228,6 +235,28 @@ procedure Outdent is (Cur_Indentation - Indentation_Amount) mod Indentation_Limit; end Outdent; + ---------------- + -- Pop_Output -- + ---------------- + + procedure Pop_Output is + begin + pragma Assert (FD_Stack_Idx >= FD_Array'First); + Current_FD := FD_Stack (FD_Stack_Idx); + FD_Stack_Idx := FD_Stack_Idx - 1; + end Pop_Output; + + ----------------- + -- Push_Output -- + ----------------- + + procedure Push_Output is + begin + pragma Assert (FD_Stack_Idx < FD_Array'Last); + FD_Stack_Idx := FD_Stack_Idx + 1; + FD_Stack (FD_Stack_Idx) := Current_FD; + end Push_Output; + --------------------------- -- Restore_Output_Buffer -- --------------------------- diff --git output.ads output.ads index 4574cce..55d308a 100644 --- output.ads +++ output.ads @@ -95,6 +95,15 @@ procedure Set_Output (FD : File_Descriptor); -- output will appear on the given file descriptor only after special -- output has been cancelled. + procedure Push_Output; + -- Saves the current output destination on a stack, but leaves it + -- unchanged. This subprogram only supports a small stack and is normally + -- used with a depth of one. + + procedure Pop_Output; + -- Changes the current output destination to be the last output destination + -- popped using Push_Output. + procedure Indent; -- Increases the current indentation level. Whenever a line is written -- (triggered by Eol), an appropriate amount of whitespace is added to the