* [PATCH] Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]
@ 2023-02-20 1:06 Gaius Mulley
0 siblings, 0 replies; 2+ messages in thread
From: Gaius Mulley @ 2023-02-20 1:06 UTC (permalink / raw)
To: gcc-patches, Joseph Myers
Hello,
bootstrapped on gcc master x86_64 and no extra failures generated on all
front ends.
Would this be ok for trunc?
regards,
Gaius
Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]
This patch allows front ends to register spec functions. It is motivated
by PR108261 which needs to retain the order of search path related
options in the modula-2 front end.
gcc/ChangeLog:
* gcc.cc (add_spec_function):
* gcc.h (add_spec_function):
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index becc56051a8..93e4e38389d 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -46,6 +46,7 @@ compilation is specified by a string called a "spec". */
#include "spellcheck.h"
#include "opts-jobserver.h"
#include "common/common-target.h"
+#include <vector>
\f
@@ -1774,6 +1775,8 @@ static const struct spec_function static_spec_functions[] =
{ 0, 0 }
};
+static std::vector<struct spec_function *>lang_spec_functions;
+
static int processing_spec_function;
\f
/* Add appropriate libgcc specs to OBSTACK, taking into account
@@ -6825,9 +6828,25 @@ lookup_spec_function (const char *name)
if (strcmp (sf->name, name) == 0)
return sf;
+ for (auto *sf : lang_spec_functions)
+ if (strcmp (sf->name, name) == 0)
+ return sf;
+
return NULL;
}
+/* Add a new spec function. */
+
+void
+add_spec_function (const char *name,
+ const char *(*func) (int, const char **))
+{
+ struct spec_function *sf = XNEW (struct spec_function);
+ sf->name = name;
+ sf->func = func;
+ lang_spec_functions.push_back (sf);
+}
+
/* Evaluate a spec function. */
static const char *
diff --git a/gcc/gcc.h b/gcc/gcc.h
index 19a61b373ee..f40de0f5520 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -73,6 +73,8 @@ struct spec_function
extern int do_spec (const char *);
extern void record_temp_file (const char *, int, int);
extern void set_input (const char *);
+extern void add_spec_function (const char *name,
+ const char *(*func) (int, const char **));
/* Spec files linked with gcc.cc must provide definitions for these. */
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]
@ 2023-02-19 18:05 Gaius Mulley
0 siblings, 0 replies; 2+ messages in thread
From: Gaius Mulley @ 2023-02-19 18:05 UTC (permalink / raw)
To: gcc-patches, Joseph Myers
Hello,
bootstrapped on gcc master x86_64 and no extra failures generated on all
front ends.
Would this be ok for trunc?
regards,
Gaius
Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]
This patch allows front ends to register spec functions. It is motivated
by PR108261 which needs to retain the order of search path related
options in the modula-2 front end.
gcc/ChangeLog:
* gcc.cc (add_spec_function):
* gcc.h (add_spec_function):
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index becc56051a8..93e4e38389d 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -46,6 +46,7 @@ compilation is specified by a string called a "spec". */
#include "spellcheck.h"
#include "opts-jobserver.h"
#include "common/common-target.h"
+#include <vector>
\f
@@ -1774,6 +1775,8 @@ static const struct spec_function static_spec_functions[] =
{ 0, 0 }
};
+static std::vector<struct spec_function *>lang_spec_functions;
+
static int processing_spec_function;
\f
/* Add appropriate libgcc specs to OBSTACK, taking into account
@@ -6825,9 +6828,25 @@ lookup_spec_function (const char *name)
if (strcmp (sf->name, name) == 0)
return sf;
+ for (auto *sf : lang_spec_functions)
+ if (strcmp (sf->name, name) == 0)
+ return sf;
+
return NULL;
}
+/* Add a new spec function. */
+
+void
+add_spec_function (const char *name,
+ const char *(*func) (int, const char **))
+{
+ struct spec_function *sf = XNEW (struct spec_function);
+ sf->name = name;
+ sf->func = func;
+ lang_spec_functions.push_back (sf);
+}
+
/* Evaluate a spec function. */
static const char *
diff --git a/gcc/gcc.h b/gcc/gcc.h
index 19a61b373ee..f40de0f5520 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -73,6 +73,8 @@ struct spec_function
extern int do_spec (const char *);
extern void record_temp_file (const char *, int, int);
extern void set_input (const char *);
+extern void add_spec_function (const char *name,
+ const char *(*func) (int, const char **));
/* Spec files linked with gcc.cc must provide definitions for these. */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-20 10:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-20 1:06 [PATCH] Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261] Gaius Mulley
-- strict thread matches above, loose matches on Subject: below --
2023-02-19 18:05 Gaius Mulley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).