public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gaius Mulley <gaiusmod2@gmail.com>
To: gcc-patches@gcc.gnu.org, Joseph Myers <joseph@codesourcery.com>
Subject: [PATCH] Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]
Date: Sun, 19 Feb 2023 18:05:51 +0000	[thread overview]
Message-ID: <87zg99pm2o.fsf@debian> (raw)


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.  */
 

             reply	other threads:[~2023-02-20 10:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-19 18:05 Gaius Mulley [this message]
2023-02-20  1:06 Gaius Mulley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zg99pm2o.fsf@debian \
    --to=gaiusmod2@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).