Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #ifndef RUST_EXPORT_METADATA_H
20 : #define RUST_EXPORT_METADATA_H
21 :
22 : #include "rust-system.h"
23 : #include "rust-hir-full-decls.h"
24 : #include "rust-hir-map.h"
25 :
26 : namespace Rust {
27 : namespace Metadata {
28 :
29 : static const char kMagicHeader[4] = {'G', 'R', 'S', 'T'};
30 : static const char kSzDelim[1] = {'$'};
31 :
32 : class ExportContext
33 : {
34 : public:
35 : ExportContext ();
36 :
37 : ~ExportContext ();
38 :
39 : void emit_crate (AST::Crate &c);
40 :
41 : /**
42 : * Macros are a bit particular - they only live at the AST level, so we can
43 : * directly refer to them using their NodeId. There's no need to keep an HIR
44 : * node for them.
45 : */
46 : void emit_macro (AST::MacroRulesDefinition ¯o);
47 :
48 : const std::string &get_interface_buffer () const;
49 :
50 : private:
51 : Analysis::Mappings &mappings;
52 :
53 : std::vector<std::reference_wrapper<const HIR::Module>> module_stack;
54 : std::string public_interface_buffer;
55 : };
56 :
57 4305 : class PublicInterface
58 : {
59 : public:
60 : static void Export (HIR::Crate &crate);
61 :
62 : static void ExportTo (HIR::Crate &crate, const std::string &output_path);
63 :
64 : static bool is_crate_public (const HIR::VisItem &item);
65 :
66 : static std::string expected_metadata_filename ();
67 :
68 : protected:
69 : void gather_export_data ();
70 :
71 : void write_to_object_file () const;
72 :
73 : void write_to_path (const std::string &path) const;
74 :
75 : private:
76 : PublicInterface (HIR::Crate &crate);
77 :
78 : HIR::Crate &crate;
79 : Analysis::Mappings &mappings;
80 : ExportContext context;
81 : };
82 :
83 : } // namespace Metadata
84 : } // namespace Rust
85 :
86 : #endif // RUST_EXPORT_METADATA_H
|