compiler.hh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Compiler handling for plugin
  2. Copyright (C) 2014-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef CC1_PLUGIN_COMPILER_HH
  16. #define CC1_PLUGIN_COMPILER_HH
  17. namespace cc1_plugin
  18. {
  19. // Base class for compiler.
  20. class compiler
  21. {
  22. public:
  23. explicit compiler (bool v)
  24. : verbose (v)
  25. {
  26. }
  27. virtual ~compiler () = default;
  28. // Find the compiler. BASE is the base name of the compiler, see
  29. // compiler-name.hh. This sets COMPILER to the resulting path.
  30. // Returns nullptr on success, or a malloc'd error string on
  31. // failure.
  32. virtual char *find (const char *base, std::string &compiler) const;
  33. void set_verbose (bool v)
  34. {
  35. verbose = v;
  36. }
  37. protected:
  38. bool verbose;
  39. };
  40. /* Compiler to set by set_triplet_regexp. */
  41. class compiler_triplet_regexp : public compiler
  42. {
  43. private:
  44. std::string triplet_regexp_;
  45. public:
  46. char *find (const char *base, std::string &compiler) const override;
  47. compiler_triplet_regexp (bool v, const char *triplet_regexp)
  48. : compiler (v), triplet_regexp_ (triplet_regexp)
  49. {
  50. }
  51. };
  52. /* Compiler to set by set_driver_filename. */
  53. class compiler_driver_filename : public compiler
  54. {
  55. private:
  56. std::string driver_filename_;
  57. public:
  58. char *find (const char *base, std::string &compiler) const override;
  59. compiler_driver_filename (bool v, const char *driver_filename)
  60. : compiler (v), driver_filename_ (driver_filename)
  61. {
  62. }
  63. };
  64. }
  65. #endif // CC1_PLUGIN_COMPILER_HH