https://gcc.gnu.org/g:03ebe9a6418a729b3dadb09a0b5caf8d5b4d5eb8

commit r17-3068-g03ebe9a6418a729b3dadb09a0b5caf8d5b4d5eb8
Author: Pierre-Emmanuel Patry <[email protected]>
Date:   Sun Jun 28 04:59:01 2026 +0200

    gccrs: Export extern block metadata
    
    Extern block metadata is required to identify intrinsics from an extern
    crate.
    
    gcc/rust/ChangeLog:
    
            * metadata/rust-export-metadata.cc 
(ExportContext::begin_extern_block):
            Dump the prefix of an extern block.
            (ExportContext::end_extern_block): Likewise with extern block 
suffix.
            * metadata/rust-export-metadata.h: Add function prototypes.
    
    Signed-off-by: Pierre-Emmanuel Patry <[email protected]>

Diff:
---
 gcc/rust/metadata/rust-export-metadata.cc | 18 ++++++++++++++++++
 gcc/rust/metadata/rust-export-metadata.h  |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/gcc/rust/metadata/rust-export-metadata.cc 
b/gcc/rust/metadata/rust-export-metadata.cc
index 93574284c523..3388d0e920da 100644
--- a/gcc/rust/metadata/rust-export-metadata.cc
+++ b/gcc/rust/metadata/rust-export-metadata.cc
@@ -106,6 +106,18 @@ ExportContext::emit_function (AST::Function &fn)
   public_interface_buffer += oss.str ();
 }
 
+void
+ExportContext::begin_extern_block (AST::ExternBlock &block)
+{
+  public_interface_buffer += "extern \"" + block.get_abi () + "\" {\n";
+}
+
+void
+ExportContext::end_extern_block ()
+{
+  public_interface_buffer += "}\n";
+}
+
 void
 ExportContext::begin_module (const AST::Module &module)
 {
@@ -152,6 +164,12 @@ public:
   {
     ctx.emit_function (function);
   }
+  void visit (AST::ExternBlock &block) override
+  {
+    ctx.begin_extern_block (block);
+    AST::DefaultASTVisitor::visit (block);
+    ctx.end_extern_block ();
+  }
   void visit (AST::Trait &trait) override { ctx.emit_trait (trait); }
   void visit (AST::Module &module) override
   {
diff --git a/gcc/rust/metadata/rust-export-metadata.h 
b/gcc/rust/metadata/rust-export-metadata.h
index 399b92951757..17dc20a7d5f2 100644
--- a/gcc/rust/metadata/rust-export-metadata.h
+++ b/gcc/rust/metadata/rust-export-metadata.h
@@ -42,6 +42,8 @@ public:
 
   void emit_trait (AST::Trait &trait);
   void emit_function (AST::Function &fn);
+  void begin_extern_block (AST::ExternBlock &block);
+  void end_extern_block ();
   void emit_use_declaration (AST::UseDeclaration &use_decl);
   void begin_module (const AST::Module &module);
   void end_module (const AST::Module &module);

Reply via email to