libstdc++: Update tzdata to 2023d
[official-gcc.git] / libcc1 / compiler.cc
blob88bb4f6e2ed9772738fb1cac6d29d84003c6ace3
1 /* Compiler handling for plugin
2 Copyright (C) 2014-2024 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
9 version.
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
14 for more details.
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>
21 #include <string>
22 #include <sstream>
23 #include "libiberty.h"
24 #include "compiler.hh"
25 #include "xregex.h"
26 #include "findcomp.hh"
27 #include "intl.h"
29 // Construct an appropriate regexp to match the compiler name.
30 static std::string
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)
40 switch (*p)
42 case '.':
43 case '^':
44 case '$':
45 case '*':
46 case '+':
47 case '?':
48 case '(':
49 case ')':
50 case '[':
51 case '{':
52 case '\\':
53 case '|':
54 buf << '\\';
55 break;
57 buf << *p;
59 buf << "$";
61 return buf.str ();
64 char *
65 cc1_plugin::compiler::find (const char *, std::string &) const
67 return xstrdup (_("Compiler has not been specified"));
70 char *
71 cc1_plugin::compiler_triplet_regexp::find (const char *base,
72 std::string &compiler) const
74 std::string rx = make_regexp (triplet_regexp_, base);
75 if (verbose)
76 fprintf (stderr, _("searching for compiler matching regex %s\n"),
77 rx.c_str());
78 regex_t triplet;
79 int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
80 if (code != 0)
82 size_t len = regerror (code, &triplet, NULL, 0);
83 char err[len];
85 regerror (code, &triplet, err, len);
87 return concat ("Could not compile regexp \"",
88 rx.c_str (),
89 "\": ",
90 err,
91 (char *) NULL);
94 if (!find_compiler (triplet, &compiler))
96 regfree (&triplet);
97 return concat ("Could not find a compiler matching \"",
98 rx.c_str (),
99 "\"",
100 (char *) NULL);
102 regfree (&triplet);
103 if (verbose)
104 fprintf (stderr, _("found compiler %s\n"), compiler.c_str());
105 return NULL;
108 char *
109 cc1_plugin::compiler_driver_filename::find (const char *,
110 std::string &compiler) const
112 // Simulate fnotice by fprintf.
113 if (verbose)
114 fprintf (stderr, _("using explicit compiler filename %s\n"),
115 driver_filename_.c_str());
116 compiler = driver_filename_;
117 return NULL;