gccrs: 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.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc (not_available): Add a
	function to express bridge unavailability.
	* libproc_macro/proc_macro.h (not_available): Likewise.
	* libproc_macro/registration.h: Add symbol type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This commit is contained in:
Pierre-Emmanuel Patry 2023-07-26 16:48:37 +02:00 committed by Arthur Cohen
parent b190aaeff7
commit c0763eac05
4 changed files with 23 additions and 0 deletions

View File

@ -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.

View File

@ -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;

View File

@ -99,6 +99,9 @@ struct ProcmacroArray
Procmacro *macros;
};
bool
not_available ();
} // namespace ProcMacro
#endif /* ! PROC_MACRO_H */

View File

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