From patchwork Fri Dec 13 18:11:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1209351 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515937-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="k/M4GLKf"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="EWR1g1i0"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZJlq72gsz9sPh for ; Sat, 14 Dec 2019 05:16:55 +1100 (AEDT) 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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=AnWIgIXD95ppdt7BMOc908Yp+XG4dyv8ns7K/gr3wKWeyk4pD1dzO ppUoD2SsvpVvEO05NHRcJYWS+s4DKRefMyX4BGzYM/SKj3UrfvBXB9ht/0uJC7Qw ixY4f8s2qxkPSIEDacbdjeDn+jsKvsKuIdh3pqP+knp79iMNr8Mcpk= 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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=zFMKGdLJg00Moz/JKeGSQ4D0JqI=; b=k/M4GLKflZUOuTohkG2askK98oiI Z1Paj9GBlcvbyYqpY+jFU3T3uhK1StzPY2asos6M9DnacCeLodh7sABkYcR3zZsZ 9V2IGsmb/WO3kC1QOKcREHewp1ByWlLvQ8WdXlq6tfBTQzhkCyXiS38wwIfwcsr5 fBhd9+uiI0nSkHs= Received: (qmail 103390 invoked by alias); 13 Dec 2019 18:12:22 -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 101266 invoked by uid 89); 13 Dec 2019 18:12:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=nesting, HX-Languages-Length:4698 X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Dec 2019 18:11:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576260711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cjZQkyf5leKbqCNv3AqMx8U75WOYFSqBEvJVNtZ3OoI=; b=EWR1g1i0ZuGckJ3T/mN9KTKFfYyHh+NzgMibqRaHd2sdPCNvbN21usU18QpGUqrieXJd1x ehbH+KLpAjWjt0BDtT0eb5pX1CBuniZYwdY7K8UknkM+ewiJnHFbf8E8ZSsrl/CK+k2/Yo M+Oqckaipgwnib/xLHMAJBsZKdKTgJM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-kDy8RiBxPt2g97WRZSja3g-1; Fri, 13 Dec 2019 13:11:50 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 32B6418A6EC0 for ; Fri, 13 Dec 2019 18:11:49 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-164.phx2.redhat.com [10.3.117.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id C71715C219; Fri, 13 Dec 2019 18:11:48 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 20/45] analyzer: new files: graphviz.{cc|h} Date: Fri, 13 Dec 2019 13:11:09 -0500 Message-Id: <20191213181134.1830-21-dmalcolm@redhat.com> In-Reply-To: <20191213181134.1830-1-dmalcolm@redhat.com> References: <20191213181134.1830-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes Changed in v3: - https://gcc.gnu.org/ml/gcc-patches/2019-11/msg02461.html - moved from gcc/analyzer to gcc This patch adds a simple wrapper class to make it easier to write human-readable .dot files. gcc/ChangeLog: * graphviz.cc: New file. * graphviz.h: New file. --- gcc/graphviz.cc | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ gcc/graphviz.h | 53 +++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 gcc/graphviz.cc create mode 100644 gcc/graphviz.h diff --git a/gcc/graphviz.cc b/gcc/graphviz.cc new file mode 100644 index 000000000000..ec5045290eb3 --- /dev/null +++ b/gcc/graphviz.cc @@ -0,0 +1,100 @@ +/* Helper code for graphviz output. + Copyright (C) 2019 Free Software Foundation, Inc. + Contributed by David Malcolm . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "graphviz.h" + +/* graphviz_out's ctor, wrapping PP. */ + +graphviz_out::graphviz_out (pretty_printer *pp) +: m_pp (pp), + m_indent (0) +{ +} + +/* Formatted print of FMT. */ + +void +graphviz_out::print (const char *fmt, ...) +{ + text_info text; + va_list ap; + + va_start (ap, fmt); + text.err_no = errno; + text.args_ptr = ≈ + text.format_spec = fmt; + pp_format (m_pp, &text); + pp_output_formatted_text (m_pp); + va_end (ap); +} + +/* Formatted print of FMT. The text is indented by the current + indent, and a newline is added. */ + +void +graphviz_out::println (const char *fmt, ...) +{ + text_info text; + va_list ap; + + write_indent (); + + va_start (ap, fmt); + text.err_no = errno; + text.args_ptr = ≈ + text.format_spec = fmt; + pp_format (m_pp, &text); + pp_output_formatted_text (m_pp); + va_end (ap); + + pp_newline (m_pp); +} + +/* Print the current indent to the underlying pp. */ + +void +graphviz_out::write_indent () +{ + for (int i = 0; i < m_indent * 2; ++i) + pp_space (m_pp); +} + +/* Write the start of an HTML-like row via , writing to the stream + so that followup text can be escaped. */ + +void +graphviz_out::begin_tr () +{ + pp_string (m_pp, ""); + pp_write_text_to_stream (m_pp); +} + +/* Write the end of an HTML-like row via , writing to the stream + so that followup text can be escaped. */ + +void +graphviz_out::end_tr () +{ + pp_string (m_pp, ""); + pp_write_text_to_stream (m_pp); +} diff --git a/gcc/graphviz.h b/gcc/graphviz.h new file mode 100644 index 000000000000..7ddd4ce36c15 --- /dev/null +++ b/gcc/graphviz.h @@ -0,0 +1,53 @@ +/* Helper code for graphviz output. + Copyright (C) 2019 Free Software Foundation, Inc. + Contributed by David Malcolm . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_ANALYZER_GRAPHVIZ_H +#define GCC_ANALYZER_GRAPHVIZ_H + +#include "pretty-print.h" /* for ATTRIBUTE_GCC_PPDIAG. */ + +/* A class for writing .dot output to a pretty_printer with + indentation to show nesting. */ + +class graphviz_out { + public: + graphviz_out (pretty_printer *pp); + + void print (const char *fmt, ...) + ATTRIBUTE_GCC_PPDIAG(2,3); + void println (const char *fmt, ...) + ATTRIBUTE_GCC_PPDIAG(2,3); + + void indent () { m_indent++; } + void outdent () { m_indent--; } + + void write_indent (); + + void begin_tr (); + void end_tr (); + + pretty_printer *get_pp () const { return m_pp; } + + private: + pretty_printer *m_pp; + int m_indent; +}; + +#endif /* GCC_ANALYZER_GRAPHVIZ_H */