1 /* Compiler handling for plugin
2 Copyright (C) 2014-2022 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include <cc1plugin-config.h>
23 #include "libiberty.h"
24 #include "compiler.hh"
26 #include "findcomp.hh"
29 // Construct an appropriate regexp to match the compiler name.
31 make_regexp (const std::string &triplet_regexp, const char *compiler)
33 std::stringstream buf;
35 buf << "^" << triplet_regexp << "-";
37 // Quote the compiler name in case it has something funny in it.
38 for (const char *p = compiler; *p; ++p)
65 cc1_plugin::compiler::find (const char *, std::string &) const
67 return xstrdup (_("Compiler has not been specified"));
71 cc1_plugin::compiler_triplet_regexp::find (const char *base,
72 std::string &compiler) const
74 std::string rx = make_regexp (triplet_regexp_, base);
76 fprintf (stderr, _("searching for compiler matching regex %s\n"),
79 int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
82 size_t len = regerror (code, &triplet, NULL, 0);
85 regerror (code, &triplet, err, len);
87 return concat ("Could not compile regexp \"",
94 if (!find_compiler (triplet, &compiler))
97 return concat ("Could not find a compiler matching \"",
104 fprintf (stderr, _("found compiler %s\n"), compiler.c_str());
109 cc1_plugin::compiler_driver_filename::find (const char *,
110 std::string &compiler) const
112 // Simulate fnotice by fprintf.
114 fprintf (stderr, _("using explicit compiler filename %s\n"),
115 driver_filename_.c_str());
116 compiler = driver_filename_;