From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway20.websitewelcome.com (gateway20.websitewelcome.com [192.185.65.13]) by sourceware.org (Postfix) with ESMTPS id D165C39B8C19 for ; Wed, 28 Apr 2021 01:01:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D165C39B8C19 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway20.websitewelcome.com (Postfix) with ESMTP id D3E0B400EE90F for ; Tue, 27 Apr 2021 19:50:19 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id bYaElqSziL7DmbYaElsbBw; Tue, 27 Apr 2021 20:01:42 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=VY8UoLhwEdFGYbwwLCdiTnSQ7EpCQRl/CzDiT/1islU=; b=evNd2PETc6WuY94ccQhPdUXz1P OMNbwcz+tRfVRlK6sgf7E0nYgyiIroFGH70VPbWiOSrqwcRchtxnwuNdLFIp0LAeRi058XkGLZ5Rp 6bZTqVx8iIFm0X3rcz2EBVXKb; Received: from 97-122-70-176.hlrn.qwest.net ([97.122.70.176]:32966 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lbYaE-003tiR-8Q; Tue, 27 Apr 2021 19:01:42 -0600 From: Tom Tromey To: gcc-patches@gcc.gnu.org Cc: Tom Tromey Subject: [PATCH v2 11/21] libcc1: unify compiler handling Date: Tue, 27 Apr 2021 19:01:09 -0600 Message-Id: <20210428010119.806184-12-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210428010119.806184-1-tom@tromey.com> References: <20210428010119.806184-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.70.176 X-Source-L: No X-Exim-ID: 1lbYaE-003tiR-8Q X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-176.hlrn.qwest.net (localhost.localdomain) [97.122.70.176]:32966 X-Source-Auth: tom+tromey.com X-Email-Count: 12 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A 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: , X-List-Received-Date: Wed, 28 Apr 2021 01:01:51 -0000 Both libcc1 plugins have nearly identical copies of code to find the underlying compiler. This seemed wasteful to me, so this patch unifies the copies. Two minor API changes were needed. First, the old code used a back-link from the compiler object to the plugin object to check the 'verbose' setting. This patch adds a 'verbose' setting directly to the compiler object instead. Second, the 'find' method implicitly knew which compiler base name ("gcc" or "g++") to use. This patch makes this a parameter that is passed in by the plugin. libcc1/ChangeLog 2021-04-27 Tom Tromey * libcc1.cc (compiler, compiler_triplet_regexp) (compiler_driver_filename): Remove. (libcp1::libcp1): Update. (make_regexp, libcp1::compiler::find) (libcp1::compiler_triplet_regexp::find) (libcp1::compiler_driver_filename::find): Remove. (libcp1_set_verbose, libcp1_set_arguments) (libcp1_set_triplet_regexp, libcp1_set_driver_filename): Update. * libcc1.cc (compiler, compiler_triplet_regexp) (compiler_driver_filename): Remove. (libcc1::libcc1): Update. (make_regexp, libcc1::compiler::find) (libcc1::compiler_triplet_regexp::find) (libcc1::compiler_driver_filename::find): Remove. (libcc1_set_verbose, libcc1_set_arguments) (libcc1_set_triplet_regexp, libcc1_set_driver_filename): Update. * compiler.cc: New file. * compiler.hh: New file. * Makefile.in: Rebuild. * Makefile.am (libcc1_la_SOURCES): Add compiler.hh, compiler.cc. --- libcc1/ChangeLog | 23 +++++++ libcc1/Makefile.am | 2 +- libcc1/Makefile.in | 7 +- libcc1/compiler.cc | 118 +++++++++++++++++++++++++++++++++ libcc1/compiler.hh | 83 +++++++++++++++++++++++ libcc1/libcc1.cc | 159 ++++----------------------------------------- libcc1/libcp1.cc | 159 ++++----------------------------------------- 7 files changed, 253 insertions(+), 298 deletions(-) create mode 100644 libcc1/compiler.cc create mode 100644 libcc1/compiler.hh diff --git a/libcc1/Makefile.am b/libcc1/Makefile.am index f148fdd7aa28..3f20513d11b7 100644 --- a/libcc1/Makefile.am +++ b/libcc1/Makefile.am @@ -75,7 +75,7 @@ libcp1plugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) libcc1_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1.sym libcc1_la_SOURCES = findcomp.cc libcc1.cc libcp1.cc \ - names.cc names.hh $(shared_source) \ + compiler.cc compiler.hh names.cc names.hh $(shared_source) \ $(marshall_c_source) $(marshall_cxx_source) libcc1_la_LIBADD = $(libiberty) libcc1_la_DEPENDENCIES = $(libiberty_dep) diff --git a/libcc1/Makefile.in b/libcc1/Makefile.in index 753d435c9cbe..d76893e3a24e 100644 --- a/libcc1/Makefile.in +++ b/libcc1/Makefile.in @@ -144,8 +144,8 @@ am__installdirs = "$(DESTDIR)$(cc1libdir)" "$(DESTDIR)$(plugindir)" LTLIBRARIES = $(cc1lib_LTLIBRARIES) $(plugin_LTLIBRARIES) am__objects_1 = callbacks.lo connection.lo marshall.lo am__objects_2 = -am_libcc1_la_OBJECTS = findcomp.lo libcc1.lo libcp1.lo names.lo \ - $(am__objects_1) $(am__objects_2) $(am__objects_2) +am_libcc1_la_OBJECTS = findcomp.lo libcc1.lo libcp1.lo compiler.lo \ + names.lo $(am__objects_1) $(am__objects_2) $(am__objects_2) libcc1_la_OBJECTS = $(am_libcc1_la_OBJECTS) @ENABLE_PLUGIN_TRUE@am_libcc1_la_rpath = -rpath $(cc1libdir) am_libcc1plugin_la_OBJECTS = libcc1plugin.lo $(am__objects_1) \ @@ -428,7 +428,7 @@ libcp1plugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) libcc1_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1.sym libcc1_la_SOURCES = findcomp.cc libcc1.cc libcp1.cc \ - names.cc names.hh $(shared_source) \ + compiler.cc compiler.hh names.cc names.hh $(shared_source) \ $(marshall_c_source) $(marshall_cxx_source) libcc1_la_LIBADD = $(libiberty) @@ -577,6 +577,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/callbacks.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/compiler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/findcomp.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcc1.Plo@am__quote@ diff --git a/libcc1/compiler.cc b/libcc1/compiler.cc new file mode 100644 index 000000000000..fede84968625 --- /dev/null +++ b/libcc1/compiler.cc @@ -0,0 +1,118 @@ +/* Compiler handling for plugin + Copyright (C) 2014-2021 Free Software Foundation, Inc. + +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 +#include +#include +#include "libiberty.h" +#include "compiler.hh" +#include "xregex.h" +#include "findcomp.hh" +#include "intl.h" + +// Construct an appropriate regexp to match the compiler name. +static std::string +make_regexp (const char *triplet_regexp, const char *compiler) +{ + std::stringstream buf; + + buf << "^" << triplet_regexp << "-"; + + // Quote the compiler name in case it has something funny in it. + for (const char *p = compiler; *p; ++p) + { + switch (*p) + { + case '.': + case '^': + case '$': + case '*': + case '+': + case '?': + case '(': + case ')': + case '[': + case '{': + case '\\': + case '|': + buf << '\\'; + break; + } + buf << *p; + } + buf << "$"; + + return buf.str (); +} + +char * +cc1_plugin::compiler::find (const char *, std::string &) const +{ + return xstrdup (_("Compiler has not been specified")); +} + +char * +cc1_plugin::compiler_triplet_regexp::find (const char *base, + std::string &compiler) const +{ + std::string rx = make_regexp (triplet_regexp_.c_str (), base); + if (verbose) + fprintf (stderr, _("searching for compiler matching regex %s\n"), + rx.c_str()); + regex_t triplet; + int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB); + if (code != 0) + { + size_t len = regerror (code, &triplet, NULL, 0); + char err[len]; + + regerror (code, &triplet, err, len); + + return concat ("Could not compile regexp \"", + rx.c_str (), + "\": ", + err, + (char *) NULL); + } + + if (!find_compiler (triplet, &compiler)) + { + regfree (&triplet); + return concat ("Could not find a compiler matching \"", + rx.c_str (), + "\"", + (char *) NULL); + } + regfree (&triplet); + if (verbose) + fprintf (stderr, _("found compiler %s\n"), compiler.c_str()); + return NULL; +} + +char * +cc1_plugin::compiler_driver_filename::find (const char *, + std::string &compiler) const +{ + // Simulate fnotice by fprintf. + if (verbose) + fprintf (stderr, _("using explicit compiler filename %s\n"), + driver_filename_.c_str()); + compiler = driver_filename_; + return NULL; +} diff --git a/libcc1/compiler.hh b/libcc1/compiler.hh new file mode 100644 index 000000000000..638f7c09f634 --- /dev/null +++ b/libcc1/compiler.hh @@ -0,0 +1,83 @@ +/* Compiler handling for plugin + Copyright (C) 2014-2020 Free Software Foundation, Inc. + +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 CC1_PLUGIN_COMPILER_HH +#define CC1_PLUGIN_COMPILER_HH + +namespace cc1_plugin +{ + + // Base class for compiler. + class compiler + { + public: + explicit compiler (bool v) + : verbose (v) + { + } + + virtual ~compiler () = default; + + // Find the compiler. BASE is the base name of the compiler, see + // compiler-name.hh. This sets COMPILER to the resulting path. + // Returns nullptr on success, or a malloc'd error string on + // failure. + virtual char *find (const char *base, std::string &compiler) const; + + void set_verbose (bool v) + { + verbose = v; + } + + protected: + bool verbose; + }; + + /* Compiler to set by set_triplet_regexp. */ + class compiler_triplet_regexp : public compiler + { + private: + std::string triplet_regexp_; + public: + + char *find (const char *base, std::string &compiler) const override; + + compiler_triplet_regexp (bool v, std::string triplet_regexp) + : compiler (v), triplet_regexp_ (triplet_regexp) + { + } + }; + + /* Compiler to set by set_driver_filename. */ + class compiler_driver_filename : public compiler + { + private: + std::string driver_filename_; + public: + char *find (const char *base, std::string &compiler) const override; + + compiler_driver_filename (bool v, std::string driver_filename) + : compiler (v), driver_filename_ (driver_filename) + { + } + }; + +} + +#endif // CC1_PLUGIN_COMPILER_HH diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc index e00355955b6e..ea52c26d7832 100644 --- a/libcc1/libcc1.cc +++ b/libcc1/libcc1.cc @@ -28,18 +28,15 @@ along with GCC; see the file COPYING3. If not see #include #include #include -#include #include "marshall.hh" #include "rpc.hh" #include "connection.hh" #include "names.hh" #include "callbacks.hh" #include "libiberty.h" -#include "xregex.h" -#include "findcomp.hh" #include "compiler-name.hh" -#include "intl.h" #include "gcc-c-interface.h" +#include "compiler.hh" struct libcc1; @@ -71,54 +68,7 @@ struct libcc1 : public gcc_c_context /* Non-zero as an equivalent to gcc driver option "-v". */ bool verbose; - /* Compiler to set by set_triplet_regexp or set_driver_filename. */ - class compiler - { - protected: - libcc1 *self_; - public: - compiler (libcc1 *self) : self_ (self) - { - } - virtual char *find (std::string &compiler) const; - virtual ~compiler () - { - } - }; - - std::unique_ptr compilerp; - - /* Compiler to set by set_triplet_regexp. */ - class compiler_triplet_regexp : public compiler - { - private: - std::string triplet_regexp_; - public: - char *find (std::string &compiler) const override; - compiler_triplet_regexp (libcc1 *self, std::string triplet_regexp) - : compiler (self), triplet_regexp_ (triplet_regexp) - { - } - virtual ~compiler_triplet_regexp () - { - } - }; - - /* Compiler to set by set_driver_filename. */ - class compiler_driver_filename : public compiler - { - private: - std::string driver_filename_; - public: - char *find (std::string &compiler) const override; - compiler_driver_filename (libcc1 *self, std::string driver_filename) - : compiler (self), driver_filename_ (driver_filename) - { - } - virtual ~compiler_driver_filename () - { - } - }; + std::unique_ptr compilerp; }; // A local subclass of connection that holds a back-pointer to the @@ -151,7 +101,7 @@ libcc1::libcc1 (const gcc_base_vtable *v, args (), source_file (), verbose (false), - compilerp (new libcc1::compiler (this)) + compilerp (new cc1_plugin::compiler (verbose)) { base.ops = v; c_ops = cv; @@ -252,101 +202,14 @@ static const struct gcc_c_fe_vtable c_vtable = -// Construct an appropriate regexp to match the compiler name. -static std::string -make_regexp (const char *triplet_regexp, const char *compiler) -{ - std::stringstream buf; - - buf << "^" << triplet_regexp << "-"; - - // Quote the compiler name in case it has something funny in it. - for (const char *p = compiler; *p; ++p) - { - switch (*p) - { - case '.': - case '^': - case '$': - case '*': - case '+': - case '?': - case '(': - case ')': - case '[': - case '{': - case '\\': - case '|': - buf << '\\'; - break; - } - buf << *p; - } - buf << "$"; - - return buf.str (); -} - static void libcc1_set_verbose (struct gcc_base_context *s, int /* bool */ verbose) { libcc1 *self = (libcc1 *) s; self->verbose = verbose != 0; -} - -char * -libcc1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const -{ - return xstrdup (_("Compiler has not been specified")); -} - -char * -libcc1::compiler_triplet_regexp::find (std::string &compiler) const -{ - std::string rx = make_regexp (triplet_regexp_.c_str (), C_COMPILER_NAME); - if (self_->verbose) - fprintf (stderr, _("searching for compiler matching regex %s\n"), - rx.c_str()); - regex_t triplet; - int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB); - if (code != 0) - { - size_t len = regerror (code, &triplet, NULL, 0); - char err[len]; - - regerror (code, &triplet, err, len); - - return concat ("Could not compile regexp \"", - rx.c_str (), - "\": ", - err, - (char *) NULL); - } - - if (!find_compiler (triplet, &compiler)) - { - regfree (&triplet); - return concat ("Could not find a compiler matching \"", - rx.c_str (), - "\"", - (char *) NULL); - } - regfree (&triplet); - if (self_->verbose) - fprintf (stderr, _("found compiler %s\n"), compiler.c_str()); - return NULL; -} - -char * -libcc1::compiler_driver_filename::find (std::string &compiler) const -{ - // Simulate fnotice by fprintf. - if (self_->verbose) - fprintf (stderr, _("using explicit compiler filename %s\n"), - driver_filename_.c_str()); - compiler = driver_filename_; - return NULL; + if (self->compilerp != nullptr) + self->compilerp->set_verbose (self->verbose); } static char * @@ -356,7 +219,7 @@ libcc1_set_arguments (struct gcc_base_context *s, libcc1 *self = (libcc1 *) s; std::string compiler; - char *errmsg = self->compilerp->find (compiler); + char *errmsg = self->compilerp->find (C_COMPILER_NAME, compiler); if (errmsg != NULL) return errmsg; @@ -374,8 +237,9 @@ libcc1_set_triplet_regexp (struct gcc_base_context *s, { libcc1 *self = (libcc1 *) s; - self->compilerp.reset (new libcc1::compiler_triplet_regexp (self, - triplet_regexp)); + self->compilerp.reset + (new cc1_plugin::compiler_triplet_regexp (self->verbose, + triplet_regexp)); return NULL; } @@ -385,8 +249,9 @@ libcc1_set_driver_filename (struct gcc_base_context *s, { libcc1 *self = (libcc1 *) s; - self->compilerp.reset (new libcc1::compiler_driver_filename (self, - driver_filename)); + self->compilerp.reset + (new cc1_plugin::compiler_driver_filename (self->verbose, + driver_filename)); return NULL; } diff --git a/libcc1/libcp1.cc b/libcc1/libcp1.cc index 4bd8c6b00b65..c57ac8c66a6b 100644 --- a/libcc1/libcp1.cc +++ b/libcc1/libcp1.cc @@ -28,17 +28,14 @@ along with GCC; see the file COPYING3. If not see #include #include #include -#include #include "marshall-cp.hh" #include "rpc.hh" #include "connection.hh" #include "names.hh" #include "callbacks.hh" #include "libiberty.h" -#include "xregex.h" -#include "findcomp.hh" #include "compiler-name.hh" -#include "intl.h" +#include "compiler.hh" struct libcp1; @@ -72,54 +69,7 @@ struct libcp1 : public gcc_cp_context /* Non-zero as an equivalent to gcc driver option "-v". */ bool verbose; - /* Compiler to set by set_triplet_regexp or set_driver_filename. */ - class compiler - { - protected: - libcp1 *self_; - public: - compiler (libcp1 *self) : self_ (self) - { - } - virtual char *find (std::string &compiler) const; - virtual ~compiler () - { - } - }; - - std::unique_ptr compilerp; - - /* Compiler to set by set_triplet_regexp. */ - class compiler_triplet_regexp : public compiler - { - private: - std::string triplet_regexp_; - public: - char *find (std::string &compiler) const override; - compiler_triplet_regexp (libcp1 *self, std::string triplet_regexp) - : compiler (self), triplet_regexp_ (triplet_regexp) - { - } - virtual ~compiler_triplet_regexp () - { - } - }; - - /* Compiler to set by set_driver_filename. */ - class compiler_driver_filename : public compiler - { - private: - std::string driver_filename_; - public: - char *find (std::string &compiler) const override; - compiler_driver_filename (libcp1 *self, std::string driver_filename) - : compiler (self), driver_filename_ (driver_filename) - { - } - virtual ~compiler_driver_filename () - { - } - }; + std::unique_ptr compilerp; }; // A local subclass of connection that holds a back-pointer to the @@ -152,7 +102,7 @@ libcp1::libcp1 (const gcc_base_vtable *v, args (), source_file (), verbose (false), - compilerp (new libcp1::compiler (this)) + compilerp (new cc1_plugin::compiler (verbose)) { base.ops = v; cp_ops = cv; @@ -275,101 +225,14 @@ static const struct gcc_cp_fe_vtable cp_vtable = -// Construct an appropriate regexp to match the compiler name. -static std::string -make_regexp (const char *triplet_regexp, const char *compiler) -{ - std::stringstream buf; - - buf << "^" << triplet_regexp << "-"; - - // Quote the compiler name in case it has something funny in it. - for (const char *p = compiler; *p; ++p) - { - switch (*p) - { - case '.': - case '^': - case '$': - case '*': - case '+': - case '?': - case '(': - case ')': - case '[': - case '{': - case '\\': - case '|': - buf << '\\'; - break; - } - buf << *p; - } - buf << "$"; - - return buf.str (); -} - static void libcp1_set_verbose (struct gcc_base_context *s, int /* bool */ verbose) { libcp1 *self = (libcp1 *) s; self->verbose = verbose != 0; -} - -char * -libcp1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const -{ - return xstrdup (_("Compiler has not been specified")); -} - -char * -libcp1::compiler_triplet_regexp::find (std::string &compiler) const -{ - std::string rx = make_regexp (triplet_regexp_.c_str (), CP_COMPILER_NAME); - if (self_->verbose) - fprintf (stderr, _("searching for compiler matching regex %s\n"), - rx.c_str()); - regex_t triplet; - int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB); - if (code != 0) - { - size_t len = regerror (code, &triplet, NULL, 0); - char err[len]; - - regerror (code, &triplet, err, len); - - return concat ("Could not compile regexp \"", - rx.c_str (), - "\": ", - err, - (char *) NULL); - } - - if (!find_compiler (triplet, &compiler)) - { - regfree (&triplet); - return concat ("Could not find a compiler matching \"", - rx.c_str (), - "\"", - (char *) NULL); - } - regfree (&triplet); - if (self_->verbose) - fprintf (stderr, _("found compiler %s\n"), compiler.c_str()); - return NULL; -} - -char * -libcp1::compiler_driver_filename::find (std::string &compiler) const -{ - // Simulate fnotice by fprintf. - if (self_->verbose) - fprintf (stderr, _("using explicit compiler filename %s\n"), - driver_filename_.c_str()); - compiler = driver_filename_; - return NULL; + if (self->compilerp != nullptr) + self->compilerp->set_verbose (self->verbose); } static char * @@ -379,7 +242,7 @@ libcp1_set_arguments (struct gcc_base_context *s, libcp1 *self = (libcp1 *) s; std::string compiler; - char *errmsg = self->compilerp->find (compiler); + char *errmsg = self->compilerp->find (CP_COMPILER_NAME, compiler); if (errmsg != NULL) return errmsg; @@ -397,8 +260,9 @@ libcp1_set_triplet_regexp (struct gcc_base_context *s, { libcp1 *self = (libcp1 *) s; - self->compilerp.reset (new libcp1::compiler_triplet_regexp (self, - triplet_regexp)); + self->compilerp.reset + (new cc1_plugin::compiler_triplet_regexp (self->verbose, + triplet_regexp)); return NULL; } @@ -408,8 +272,9 @@ libcp1_set_driver_filename (struct gcc_base_context *s, { libcp1 *self = (libcp1 *) s; - self->compilerp.reset (new libcp1::compiler_driver_filename (self, - driver_filename)); + self->compilerp.reset + (new cc1_plugin::compiler_driver_filename (self->verbose, + driver_filename)); return NULL; } -- 2.26.2