From 21b34f350bb82e3272a3967a076be848af6a2ca6 Mon Sep 17 00:00:00 2001 From: aoliva Date: Tue, 31 Jan 2017 01:01:09 +0000 Subject: [PATCH] libcc1 base API: bump set_arguments; add set_driver_filename, set_triplet_regexp for include/ChangeLog * gcc-interface.h (enum gcc_base_api_version): Update comment for GCC_FE_VERSION_1. (struct gcc_base_vtable): Rename set_arguments to set_arguments_v0. Add set_arguments, set_triplet_regexp and set_driver_filename. for libcc1/ChangeLog * libcc1.cc (libcc1): Add class compiler with field compilerp, class compiler_triplet_regexp and class compiler_driver_filename. (libcc1::libcc1): Initialize compilerp. (libcc1::~libcc1): Delete compilerp. (libcc1::compiler::find, libcc1::compiler_triplet_regexp::find) (libcc1::compiler_driver_filename::find): New methods. (libcc1_set_arguments): Remove parameter triplet_regexp. (libcc1_set_triplet_regexp, libcc1_set_driver_filename) (libcc1_set_arguments_v0): New functions. (vtable): Use libcc1_set_arguments_v0, add libcc1_set_arguments, libcc1_set_triplet_regexp and libcc1_set_driver_filename. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@245049 138bc75d-0d04-0410-961f-82ee72b054a4 --- include/ChangeLog | 6 +++ include/gcc-interface.h | 61 ++++++++++++++++----- libcc1/ChangeLog | 14 +++++ libcc1/libcc1.cc | 139 +++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 192 insertions(+), 28 deletions(-) diff --git a/include/ChangeLog b/include/ChangeLog index 5284f104523..c1a52dbfca2 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,5 +1,11 @@ 2017-01-30 Jan Kratochvil + * gcc-interface.h (enum gcc_base_api_version): Update comment + for GCC_FE_VERSION_1. + (struct gcc_base_vtable): Rename set_arguments to + set_arguments_v0. Add set_arguments, set_triplet_regexp and + set_driver_filename. + * gcc-interface.h (enum gcc_base_api_version): Add comment to GCC_FE_VERSION_1. (struct gcc_base_vtable): Rename compile to compile_v0. diff --git a/include/gcc-interface.h b/include/gcc-interface.h index c98f0784545..e3ffd18a75d 100644 --- a/include/gcc-interface.h +++ b/include/gcc-interface.h @@ -46,7 +46,9 @@ enum gcc_base_api_version { GCC_FE_VERSION_0 = 0, - /* Deprecated method compile_v0. Added method set_verbose and compile. */ + /* Deprecated methods set_arguments_v0 and compile_v0. Added methods + set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and + compile. */ GCC_FE_VERSION_1 = 1, }; @@ -67,20 +69,12 @@ struct gcc_base_vtable unsigned int version; - /* Set the compiler's command-line options for the next compilation. - TRIPLET_REGEXP is a regular expression that is used to match the - configury triplet prefix to the compiler. - The arguments are copied by GCC. ARGV need not be - NULL-terminated. The arguments must be set separately for each - compilation; that is, after a compile is requested, the - previously-set arguments cannot be reused. - - This returns NULL on success. On failure, returns a malloc()d - error message. The caller is responsible for freeing it. */ + /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 + methods set_triplet_regexp and set_arguments. */ - char *(*set_arguments) (struct gcc_base_context *self, - const char *triplet_regexp, - int argc, char **argv); + char *(*set_arguments_v0) (struct gcc_base_context *self, + const char *triplet_regexp, + int argc, char **argv); /* Set the file name of the program to compile. The string is copied by the method implementation, but the caller must @@ -125,6 +119,45 @@ struct gcc_base_vtable int /* bool */ (*compile) (struct gcc_base_context *self, const char *filename); + + /* Set the compiler's command-line options for the next compilation. + The arguments are copied by GCC. ARGV need not be + NULL-terminated. The arguments must be set separately for each + compilation; that is, after a compile is requested, the + previously-set arguments cannot be reused. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_arguments) (struct gcc_base_context *self, + int argc, char **argv); + + /* Set TRIPLET_REGEXP as a regular expression that is used to match + the configury triplet prefix to the compiler. Calling this method + overrides possible previous call of itself or set_driver_filename. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_triplet_regexp) (struct gcc_base_context *self, + const char *triplet_regexp); + + /* DRIVER_FILENAME should be filename of the gcc compiler driver + program. It will be searched in PATH components like + TRIPLET_REGEXP. Calling this method overrides possible previous + call of itself or set_triplet_regexp. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_driver_filename) (struct gcc_base_context *self, + const char *driver_filename); }; /* The GCC object. */ diff --git a/libcc1/ChangeLog b/libcc1/ChangeLog index d7c124a0d6d..ef1577b2d29 100644 --- a/libcc1/ChangeLog +++ b/libcc1/ChangeLog @@ -1,5 +1,19 @@ 2017-01-30 Jan Kratochvil + * libcc1.cc (libcc1): Add class compiler with field compilerp, + class compiler_triplet_regexp and class + compiler_driver_filename. + (libcc1::libcc1): Initialize compilerp. + (libcc1::~libcc1): Delete compilerp. + (libcc1::compiler::find, libcc1::compiler_triplet_regexp::find) + (libcc1::compiler_driver_filename::find): New methods. + (libcc1_set_arguments): Remove parameter triplet_regexp. + (libcc1_set_triplet_regexp, libcc1_set_driver_filename) + (libcc1_set_arguments_v0): New functions. + (vtable): Use libcc1_set_arguments_v0, add + libcc1_set_arguments, libcc1_set_triplet_regexp and + libcc1_set_driver_filename. + * libcc1.cc: Include intl.h. (struct libcc1): Add field verbose. (libcc1::libcc1): Initialize it. diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc index 20f08cff0cc..572bc2ae9ea 100644 --- a/libcc1/libcc1.cc +++ b/libcc1/libcc1.cc @@ -70,6 +70,53 @@ 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 () + { + } + } *compilerp; + + /* Compiler to set by set_triplet_regexp. */ + class compiler_triplet_regexp : public compiler + { + private: + std::string triplet_regexp_; + public: + virtual char *find (std::string &compiler) const; + 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: + virtual char *find (std::string &compiler) const; + compiler_driver_filename (libcc1 *self, std::string driver_filename) + : compiler (self), driver_filename_ (driver_filename) + { + } + virtual ~compiler_driver_filename () + { + } + }; }; // A local subclass of connection that holds a back-pointer to the @@ -102,7 +149,8 @@ libcc1::libcc1 (const gcc_base_vtable *v, print_datum (NULL), args (), source_file (), - verbose (false) + verbose (false), + compilerp (new libcc1::compiler (this)) { base.ops = v; c_ops = cv; @@ -111,6 +159,7 @@ libcc1::libcc1 (const gcc_base_vtable *v, libcc1::~libcc1 () { delete connection; + delete compilerp; } @@ -319,20 +368,21 @@ libcc1_set_verbose (struct gcc_base_context *s, int /* bool */ verbose) self->verbose = verbose != 0; } -static char * -libcc1_set_arguments (struct gcc_base_context *s, - const char *triplet_regexp, - int argc, char **argv) +char * +libcc1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const { - libcc1 *self = (libcc1 *) s; - regex_t triplet; - int code; + return xstrdup (_("Compiler has not been specified")); +} - std::string rx = make_regexp (triplet_regexp, COMPILER_NAME); - // Simulate fnotice by fprintf. - if (self->verbose) +char * +libcc1::compiler_triplet_regexp::find (std::string &compiler) const +{ + std::string rx = make_regexp (triplet_regexp_.c_str (), COMPILER_NAME); + if (self_->verbose) fprintf (stderr, _("searching for compiler matching regex %s\n"), rx.c_str()); + regex_t triplet; + int code; code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB); if (code != 0) { @@ -348,7 +398,6 @@ libcc1_set_arguments (struct gcc_base_context *s, (char *) NULL); } - std::string compiler; if (!find_compiler (triplet, &compiler)) { regfree (&triplet); @@ -358,8 +407,32 @@ libcc1_set_arguments (struct gcc_base_context *s, (char *) NULL); } regfree (&triplet); - if (self->verbose) + 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; +} + +static char * +libcc1_set_arguments (struct gcc_base_context *s, + int argc, char **argv) +{ + libcc1 *self = (libcc1 *) s; + + std::string compiler; + char *errmsg = self->compilerp->find (compiler); + if (errmsg != NULL) + return errmsg; self->args.push_back (compiler); @@ -369,6 +442,41 @@ libcc1_set_arguments (struct gcc_base_context *s, return NULL; } +static char * +libcc1_set_triplet_regexp (struct gcc_base_context *s, + const char *triplet_regexp) +{ + libcc1 *self = (libcc1 *) s; + + delete self->compilerp; + self->compilerp = new libcc1::compiler_triplet_regexp (self, triplet_regexp); + return NULL; +} + +static char * +libcc1_set_driver_filename (struct gcc_base_context *s, + const char *driver_filename) +{ + libcc1 *self = (libcc1 *) s; + + delete self->compilerp; + self->compilerp = new libcc1::compiler_driver_filename (self, + driver_filename); + return NULL; +} + +static char * +libcc1_set_arguments_v0 (struct gcc_base_context *s, + const char *triplet_regexp, + int argc, char **argv) +{ + char *errmsg = libcc1_set_triplet_regexp (s, triplet_regexp); + if (errmsg != NULL) + return errmsg; + + return libcc1_set_arguments (s, argc, argv); +} + static void libcc1_set_source_file (struct gcc_base_context *s, const char *file) @@ -531,13 +639,16 @@ libcc1_destroy (struct gcc_base_context *s) static const struct gcc_base_vtable vtable = { GCC_FE_VERSION_1, - libcc1_set_arguments, + libcc1_set_arguments_v0, libcc1_set_source_file, libcc1_set_print_callback, libcc1_compile_v0, libcc1_destroy, libcc1_set_verbose, libcc1_compile, + libcc1_set_arguments, + libcc1_set_triplet_regexp, + libcc1_set_driver_filename, }; extern "C" gcc_c_fe_context_function gcc_c_fe_context; -- 2.11.4.GIT