diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-10-04 12:01:44 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:09:32 +0100 |
commit | 9e30e140bea608267bfe74f80fbf59989e6877b4 (patch) | |
tree | c57180197aee22c3ab6273c2c3feb13f88d4b7e9 | |
parent | 150403984d818895e40629ea7c5369f32f96fc1c (diff) | |
download | gcc-9e30e140bea608267bfe74f80fbf59989e6877b4.zip gcc-9e30e140bea608267bfe74f80fbf59989e6877b4.tar.gz gcc-9e30e140bea608267bfe74f80fbf59989e6877b4.tar.bz2 |
gccrs: Change proc macro entrypoint
Change proc macro entrypoint from a fixed constant declaration to a
proper generation from the stable crate id. Although the stable crate id
is not in use yet, the mechanism to handle it is.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc (CustomDeriveProcMacro::CustomDeriveProcMacro):
Remove constant string declaration.
(load_macros_array): Add call to the new generation function.
(generate_proc_macro_decls_symbol): Add a new function to generate the
entrypoint symbol name from the stable crate id.
(PROC_MACRO_DECLS_FMT_ARGS):
New macro to keep formats arguments in sync between each call.
* expand/rust-proc-macro.h (generate_proc_macro_decls_symbol): Add
function prototype.
* rust-system.h: Include <iomanip>.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/expand/rust-proc-macro.cc | 18 | ||||
-rw-r--r-- | gcc/rust/expand/rust-proc-macro.h | 3 | ||||
-rw-r--r-- | gcc/rust/rust-system.h | 1 |
3 files changed, 19 insertions, 3 deletions
diff --git a/gcc/rust/expand/rust-proc-macro.cc b/gcc/rust/expand/rust-proc-macro.cc index 2fdfcb2..e861848 100644 --- a/gcc/rust/expand/rust-proc-macro.cc +++ b/gcc/rust/expand/rust-proc-macro.cc @@ -14,12 +14,14 @@ // along with GCC; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. +#include "rust-system.h" #include "rust-diagnostics.h" #include "rust-proc-macro.h" #include "rust-session-manager.h" #include "rust-lex.h" #include "rust-token-converter.h" #include "rust-attributes.h" + #ifndef _WIN32 #include <dlfcn.h> #endif @@ -45,8 +47,6 @@ CustomDeriveProcMacro::CustomDeriveProcMacro (ProcMacro::CustomDerive macro) macro (macro.macro) {} -const std::string PROC_MACRO_DECL_PREFIX = "__gccrs_proc_macro_decls_"; - namespace { ProcMacro::Literal @@ -150,8 +150,10 @@ load_macros_array (std::string path) // FIXME: Add CrateStableId handling, right now all versions may be loaded, // even incompatible ones. + auto symbol_name = generate_proc_macro_decls_symbol (0 /* FIXME */); + return *reinterpret_cast<const ProcMacro::ProcmacroArray **> ( - dlsym (handle, PROC_MACRO_DECL_PREFIX.c_str ())); + dlsym (handle, symbol_name.c_str ())); #else rust_sorry_at (UNDEF_LOCATION, "Procedural macros are not yet supported on windows host"); @@ -175,4 +177,14 @@ load_macros (std::string path) array->macros + array->length); } +std::string +generate_proc_macro_decls_symbol (std::uint32_t stable_crate_id) +{ + std::ostringstream stream; + stream << "__gccrs_proc_macro_decls_" << std::setfill ('0') << std::hex + << std::setw (8) << stable_crate_id << "__"; + + return stream.str (); +} + } // namespace Rust diff --git a/gcc/rust/expand/rust-proc-macro.h b/gcc/rust/expand/rust-proc-macro.h index d994ed9..6ffaaf6 100644 --- a/gcc/rust/expand/rust-proc-macro.h +++ b/gcc/rust/expand/rust-proc-macro.h @@ -85,6 +85,9 @@ public: const std::vector<ProcMacro::Procmacro> load_macros (std::string path); +std::string +generate_proc_macro_decls_symbol (std::uint32_t stable_crate_id); + } // namespace Rust #endif /* ! RUST_PROC_MACRO_H */ diff --git a/gcc/rust/rust-system.h b/gcc/rust/rust-system.h index 5d08411..88d6c10 100644 --- a/gcc/rust/rust-system.h +++ b/gcc/rust/rust-system.h @@ -54,6 +54,7 @@ * before the macro magic of safe-ctype.h, which is included by * system.h. */ #include <iostream> +#include <iomanip> #include "system.h" #include "ansidecl.h" |