Commit 5d1b2443 by Jan Kratochvil Committed by Alexandre Oliva

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.

From-SVN: r245049
parent 3b5c1072
2017-01-30 Jan Kratochvil <jan.kratochvil@redhat.com> 2017-01-30 Jan Kratochvil <jan.kratochvil@redhat.com>
* 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-interface.h (enum gcc_base_api_version): Add comment to
GCC_FE_VERSION_1. GCC_FE_VERSION_1.
(struct gcc_base_vtable): Rename compile to compile_v0. (struct gcc_base_vtable): Rename compile to compile_v0.
......
...@@ -46,7 +46,9 @@ enum gcc_base_api_version ...@@ -46,7 +46,9 @@ enum gcc_base_api_version
{ {
GCC_FE_VERSION_0 = 0, 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, GCC_FE_VERSION_1 = 1,
}; };
...@@ -67,18 +69,10 @@ struct gcc_base_vtable ...@@ -67,18 +69,10 @@ struct gcc_base_vtable
unsigned int version; unsigned int version;
/* Set the compiler's command-line options for the next compilation. /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1
TRIPLET_REGEXP is a regular expression that is used to match the methods set_triplet_regexp and set_arguments. */
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. */
char *(*set_arguments) (struct gcc_base_context *self, char *(*set_arguments_v0) (struct gcc_base_context *self,
const char *triplet_regexp, const char *triplet_regexp,
int argc, char **argv); int argc, char **argv);
...@@ -125,6 +119,45 @@ struct gcc_base_vtable ...@@ -125,6 +119,45 @@ struct gcc_base_vtable
int /* bool */ (*compile) (struct gcc_base_context *self, int /* bool */ (*compile) (struct gcc_base_context *self,
const char *filename); 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. */ /* The GCC object. */
......
2017-01-30 Jan Kratochvil <jan.kratochvil@redhat.com> 2017-01-30 Jan Kratochvil <jan.kratochvil@redhat.com>
* 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. * libcc1.cc: Include intl.h.
(struct libcc1): Add field verbose. (struct libcc1): Add field verbose.
(libcc1::libcc1): Initialize it. (libcc1::libcc1): Initialize it.
......
...@@ -70,6 +70,53 @@ struct libcc1 : public gcc_c_context ...@@ -70,6 +70,53 @@ struct libcc1 : public gcc_c_context
/* Non-zero as an equivalent to gcc driver option "-v". */ /* Non-zero as an equivalent to gcc driver option "-v". */
bool verbose; 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 // A local subclass of connection that holds a back-pointer to the
...@@ -102,7 +149,8 @@ libcc1::libcc1 (const gcc_base_vtable *v, ...@@ -102,7 +149,8 @@ libcc1::libcc1 (const gcc_base_vtable *v,
print_datum (NULL), print_datum (NULL),
args (), args (),
source_file (), source_file (),
verbose (false) verbose (false),
compilerp (new libcc1::compiler (this))
{ {
base.ops = v; base.ops = v;
c_ops = cv; c_ops = cv;
...@@ -111,6 +159,7 @@ libcc1::libcc1 (const gcc_base_vtable *v, ...@@ -111,6 +159,7 @@ libcc1::libcc1 (const gcc_base_vtable *v,
libcc1::~libcc1 () libcc1::~libcc1 ()
{ {
delete connection; delete connection;
delete compilerp;
} }
...@@ -319,20 +368,21 @@ libcc1_set_verbose (struct gcc_base_context *s, int /* bool */ verbose) ...@@ -319,20 +368,21 @@ libcc1_set_verbose (struct gcc_base_context *s, int /* bool */ verbose)
self->verbose = verbose != 0; self->verbose = verbose != 0;
} }
static char * char *
libcc1_set_arguments (struct gcc_base_context *s, libcc1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const
const char *triplet_regexp,
int argc, char **argv)
{ {
libcc1 *self = (libcc1 *) s; return xstrdup (_("Compiler has not been specified"));
regex_t triplet; }
int code;
std::string rx = make_regexp (triplet_regexp, COMPILER_NAME); char *
// Simulate fnotice by fprintf. libcc1::compiler_triplet_regexp::find (std::string &compiler) const
if (self->verbose) {
std::string rx = make_regexp (triplet_regexp_.c_str (), COMPILER_NAME);
if (self_->verbose)
fprintf (stderr, _("searching for compiler matching regex %s\n"), fprintf (stderr, _("searching for compiler matching regex %s\n"),
rx.c_str()); rx.c_str());
regex_t triplet;
int code;
code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB); code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
if (code != 0) if (code != 0)
{ {
...@@ -348,7 +398,6 @@ libcc1_set_arguments (struct gcc_base_context *s, ...@@ -348,7 +398,6 @@ libcc1_set_arguments (struct gcc_base_context *s,
(char *) NULL); (char *) NULL);
} }
std::string compiler;
if (!find_compiler (triplet, &compiler)) if (!find_compiler (triplet, &compiler))
{ {
regfree (&triplet); regfree (&triplet);
...@@ -358,8 +407,32 @@ libcc1_set_arguments (struct gcc_base_context *s, ...@@ -358,8 +407,32 @@ libcc1_set_arguments (struct gcc_base_context *s,
(char *) NULL); (char *) NULL);
} }
regfree (&triplet); regfree (&triplet);
if (self->verbose) if (self_->verbose)
fprintf (stderr, _("found compiler %s\n"), compiler.c_str()); 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); self->args.push_back (compiler);
...@@ -369,6 +442,41 @@ libcc1_set_arguments (struct gcc_base_context *s, ...@@ -369,6 +442,41 @@ libcc1_set_arguments (struct gcc_base_context *s,
return NULL; 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 static void
libcc1_set_source_file (struct gcc_base_context *s, libcc1_set_source_file (struct gcc_base_context *s,
const char *file) const char *file)
...@@ -531,13 +639,16 @@ libcc1_destroy (struct gcc_base_context *s) ...@@ -531,13 +639,16 @@ libcc1_destroy (struct gcc_base_context *s)
static const struct gcc_base_vtable vtable = static const struct gcc_base_vtable vtable =
{ {
GCC_FE_VERSION_1, GCC_FE_VERSION_1,
libcc1_set_arguments, libcc1_set_arguments_v0,
libcc1_set_source_file, libcc1_set_source_file,
libcc1_set_print_callback, libcc1_set_print_callback,
libcc1_compile_v0, libcc1_compile_v0,
libcc1_destroy, libcc1_destroy,
libcc1_set_verbose, libcc1_set_verbose,
libcc1_compile, libcc1_compile,
libcc1_set_arguments,
libcc1_set_triplet_regexp,
libcc1_set_driver_filename,
}; };
extern "C" gcc_c_fe_context_function gcc_c_fe_context; extern "C" gcc_c_fe_context_function gcc_c_fe_context;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment