aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-07-26 16:48:37 +0200
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2023-07-27 12:25:20 +0000
commit5b36e8993a5629ac8a1aacb9fac86507187d5a70 (patch)
treef77792ee67d78e2a802f4b984ca7897f1a10e115
parent1074c90c8057cfb5c55a6e3f863a5413c34b75c8 (diff)
downloadgcc-5b36e8993a5629ac8a1aacb9fac86507187d5a70.zip
gcc-5b36e8993a5629ac8a1aacb9fac86507187d5a70.tar.gz
gcc-5b36e8993a5629ac8a1aacb9fac86507187d5a70.tar.bz2
proc_macro: Add is_available callback
Add a callback from gcc to determine wether the bridge is available or not. gcc/rust/ChangeLog: * expand/rust-proc-macro.cc (available): Add symbol registration. (load_macros_array): Likewise. ChangeLog: * libgrust/libproc_macro/proc_macro.cc (not_available): Add a function to express bridge unavailability. * libgrust/libproc_macro/proc_macro.h (not_available): Likewise. * libgrust/libproc_macro/registration.h: Add symbol type. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--gcc/rust/expand/rust-proc-macro.cc9
-rw-r--r--libgrust/libproc_macro/proc_macro.cc8
-rw-r--r--libgrust/libproc_macro/proc_macro.h3
-rw-r--r--libgrust/libproc_macro/registration.h3
4 files changed, 23 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-proc-macro.cc b/gcc/rust/expand/rust-proc-macro.cc
index 7843ead..b6cfe25 100644
--- a/gcc/rust/expand/rust-proc-macro.cc
+++ b/gcc/rust/expand/rust-proc-macro.cc
@@ -56,6 +56,12 @@ static_assert (
ProcMacro::from_str_function_t>::value,
"Registration callback signature not synced, check proc macro internals.");
+static bool
+available ()
+{
+ return true;
+}
+
template <typename Symbol, typename Callback>
bool
register_callback (void *handle, Symbol, std::string symbol_name,
@@ -95,6 +101,9 @@ load_macros_array (std::string path)
if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_from_str_fn,
tokenstream_from_string))
return nullptr;
+ if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_is_available_fn,
+ available))
+ return nullptr;
// FIXME: Add CrateStableId handling, right now all versions may be loaded,
// even incompatible ones.
diff --git a/libgrust/libproc_macro/proc_macro.cc b/libgrust/libproc_macro/proc_macro.cc
index a404691..1e9e3fd 100644
--- a/libgrust/libproc_macro/proc_macro.cc
+++ b/libgrust/libproc_macro/proc_macro.cc
@@ -49,6 +49,14 @@ Procmacro::make_bang (const char *name, BangMacro macro)
return {BANG, payload};
}
+bool
+not_available ()
+{
+ return false;
+}
+
} // namespace ProcMacro
ProcMacro::from_str_function_t __gccrs_proc_macro_from_str_fn = nullptr;
+ProcMacro::is_available_function_t __gccrs_proc_macro_is_available_fn
+ = ProcMacro::not_available;
diff --git a/libgrust/libproc_macro/proc_macro.h b/libgrust/libproc_macro/proc_macro.h
index 80dd282..0b3ec3c 100644
--- a/libgrust/libproc_macro/proc_macro.h
+++ b/libgrust/libproc_macro/proc_macro.h
@@ -99,6 +99,9 @@ struct ProcmacroArray
Procmacro *macros;
};
+bool
+not_available ();
+
} // namespace ProcMacro
#endif /* ! PROC_MACRO_H */
diff --git a/libgrust/libproc_macro/registration.h b/libgrust/libproc_macro/registration.h
index 5cefc37..7668863 100644
--- a/libgrust/libproc_macro/registration.h
+++ b/libgrust/libproc_macro/registration.h
@@ -29,9 +29,12 @@
namespace ProcMacro {
using from_str_function_t = ProcMacro::TokenStream (*) (std::string &, bool &);
+using is_available_function_t = bool (*) ();
} // namespace ProcMacro
extern "C" ProcMacro::from_str_function_t __gccrs_proc_macro_from_str_fn;
+extern "C" ProcMacro::is_available_function_t
+ __gccrs_proc_macro_is_available_fn;
#endif /* !REGISTRATION_H */