libcc1 base API: add set_verbose and new version of compile

for  include/ChangeLog

	* gcc-interface.h (enum gcc_base_api_version): Add comment to
	GCC_FE_VERSION_1.
	(struct gcc_base_vtable): Rename compile to compile_v0.
	Update comment for compile.  New methods set_verbose and
	compile.

for  libcc1/ChangeLog

	* libcc1.cc: Include intl.h.
	(struct libcc1): Add field verbose.
	(libcc1::libcc1): Initialize it.
	(libcc1_set_verbose): New function.
	(libcc1_set_arguments): Print messages for VERBOSE.
	(libcc1_compile): Remove parameter verbose.  Use VERBOSE from
	SELF.
	(libcc1_compile_v0): New function.
	(vtable): Use libcc1_compile_v0 and add libcc1_compile and
	libcc1_set_verbose.

From-SVN: r245048
This commit is contained in:
Jan Kratochvil 2017-01-31 01:00:51 +00:00 committed by Alexandre Oliva
parent 023721aab1
commit 3b5c10724d
4 changed files with 76 additions and 12 deletions

View File

@ -1,5 +1,11 @@
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): Add comment to
GCC_FE_VERSION_1.
(struct gcc_base_vtable): Rename compile to compile_v0.
Update comment for compile. New methods set_verbose and
compile.
* gcc-interface.h (enum gcc_base_api_version): Add * gcc-interface.h (enum gcc_base_api_version): Add
GCC_FE_VERSION_1. GCC_FE_VERSION_1.

View File

@ -45,6 +45,8 @@ struct gcc_base_context;
enum gcc_base_api_version 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. */
GCC_FE_VERSION_1 = 1, GCC_FE_VERSION_1 = 1,
}; };
@ -94,18 +96,35 @@ struct gcc_base_vtable
const char *message), const char *message),
void *datum); void *datum);
/* Perform the compilation. FILENAME is the name of the resulting /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1
object file. VERBOSE can be set to cause GCC to print some compile method. GCC_FE_VERSION_0 version verbose parameter has
information as it works. Returns true on success, false on been replaced by the set_verbose method. */
error. */
int /* bool */ (*compile) (struct gcc_base_context *self, int /* bool */ (*compile_v0) (struct gcc_base_context *self,
const char *filename, const char *filename,
int /* bool */ verbose); int /* bool */ verbose);
/* Destroy this object. */ /* Destroy this object. */
void (*destroy) (struct gcc_base_context *self); void (*destroy) (struct gcc_base_context *self);
/* VERBOSE can be set to non-zero to cause GCC to print some
information as it works. Calling this method overrides its
possible previous calls.
This method is only available since GCC_FE_VERSION_1. */
void (*set_verbose) (struct gcc_base_context *self,
int /* bool */ verbose);
/* Perform the compilation. FILENAME is the name of the resulting
object file. Either set_triplet_regexp or set_driver_filename must
be called before. Returns true on success, false on error.
This method is only available since GCC_FE_VERSION_1. */
int /* bool */ (*compile) (struct gcc_base_context *self,
const char *filename);
}; };
/* The GCC object. */ /* The GCC object. */

View File

@ -1,5 +1,16 @@
2017-01-30 Jan Kratochvil <jan.kratochvil@redhat.com> 2017-01-30 Jan Kratochvil <jan.kratochvil@redhat.com>
* libcc1.cc: Include intl.h.
(struct libcc1): Add field verbose.
(libcc1::libcc1): Initialize it.
(libcc1_set_verbose): New function.
(libcc1_set_arguments): Print messages for VERBOSE.
(libcc1_compile): Remove parameter verbose. Use VERBOSE from
SELF.
(libcc1_compile_v0): New function.
(vtable): Use libcc1_compile_v0 and add libcc1_compile and
libcc1_set_verbose.
* libcc1.cc (vtable): Update to GCC_FE_VERSION_1. * libcc1.cc (vtable): Update to GCC_FE_VERSION_1.
(gcc_c_fe_context): Accept also GCC_FE_VERSION_1. (gcc_c_fe_context): Accept also GCC_FE_VERSION_1.

View File

@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see
#include "xregex.h" #include "xregex.h"
#include "findcomp.hh" #include "findcomp.hh"
#include "compiler-name.h" #include "compiler-name.h"
#include "intl.h"
struct libcc1; struct libcc1;
@ -66,6 +67,9 @@ struct libcc1 : public gcc_c_context
std::vector<std::string> args; std::vector<std::string> args;
std::string source_file; std::string source_file;
/* Non-zero as an equivalent to gcc driver option "-v". */
bool verbose;
}; };
// A local subclass of connection that holds a back-pointer to the // A local subclass of connection that holds a back-pointer to the
@ -97,7 +101,8 @@ libcc1::libcc1 (const gcc_base_vtable *v,
print_function (NULL), print_function (NULL),
print_datum (NULL), print_datum (NULL),
args (), args (),
source_file () source_file (),
verbose (false)
{ {
base.ops = v; base.ops = v;
c_ops = cv; c_ops = cv;
@ -306,6 +311,14 @@ make_regexp (const char *triplet_regexp, const char *compiler)
return buf.str (); return buf.str ();
} }
static void
libcc1_set_verbose (struct gcc_base_context *s, int /* bool */ verbose)
{
libcc1 *self = (libcc1 *) s;
self->verbose = verbose != 0;
}
static char * static char *
libcc1_set_arguments (struct gcc_base_context *s, libcc1_set_arguments (struct gcc_base_context *s,
const char *triplet_regexp, const char *triplet_regexp,
@ -316,6 +329,10 @@ libcc1_set_arguments (struct gcc_base_context *s,
int code; int code;
std::string rx = make_regexp (triplet_regexp, COMPILER_NAME); std::string rx = make_regexp (triplet_regexp, COMPILER_NAME);
// Simulate fnotice by fprintf.
if (self->verbose)
fprintf (stderr, _("searching for compiler matching regex %s\n"),
rx.c_str());
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)
{ {
@ -341,6 +358,8 @@ libcc1_set_arguments (struct gcc_base_context *s,
(char *) NULL); (char *) NULL);
} }
regfree (&triplet); regfree (&triplet);
if (self->verbose)
fprintf (stderr, _("found compiler %s\n"), compiler.c_str());
self->args.push_back (compiler); self->args.push_back (compiler);
@ -434,8 +453,7 @@ fork_exec (libcc1 *self, char **argv, int spair_fds[2], int stderr_fds[2])
static int static int
libcc1_compile (struct gcc_base_context *s, libcc1_compile (struct gcc_base_context *s,
const char *filename, const char *filename)
int verbose)
{ {
libcc1 *self = (libcc1 *) s; libcc1 *self = (libcc1 *) s;
@ -466,7 +484,7 @@ libcc1_compile (struct gcc_base_context *s,
self->args.push_back ("-c"); self->args.push_back ("-c");
self->args.push_back ("-o"); self->args.push_back ("-o");
self->args.push_back (filename); self->args.push_back (filename);
if (verbose) if (self->verbose)
self->args.push_back ("-v"); self->args.push_back ("-v");
self->connection = new libcc1_connection (fds[0], stderr_fds[0], self); self->connection = new libcc1_connection (fds[0], stderr_fds[0], self);
@ -494,6 +512,14 @@ libcc1_compile (struct gcc_base_context *s,
return fork_exec (self, argv, fds, stderr_fds); return fork_exec (self, argv, fds, stderr_fds);
} }
static int
libcc1_compile_v0 (struct gcc_base_context *s, const char *filename,
int verbose)
{
libcc1_set_verbose (s, verbose);
return libcc1_compile (s, filename);
}
static void static void
libcc1_destroy (struct gcc_base_context *s) libcc1_destroy (struct gcc_base_context *s)
{ {
@ -508,8 +534,10 @@ static const struct gcc_base_vtable vtable =
libcc1_set_arguments, libcc1_set_arguments,
libcc1_set_source_file, libcc1_set_source_file,
libcc1_set_print_callback, libcc1_set_print_callback,
libcc1_compile_v0,
libcc1_destroy,
libcc1_set_verbose,
libcc1_compile, libcc1_compile,
libcc1_destroy
}; };
extern "C" gcc_c_fe_context_function gcc_c_fe_context; extern "C" gcc_c_fe_context_function gcc_c_fe_context;