]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/rust/metadata/rust-export-metadata.h
Update copyright years.
[thirdparty/gcc.git] / gcc / rust / metadata / rust-export-metadata.h
CommitLineData
a945c346 1// Copyright (C) 2020-2024 Free Software Foundation, Inc.
509e4c32
PH
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
26namespace Rust {
27namespace Metadata {
28
29static const char kMagicHeader[4] = {'G', 'R', 'S', 'T'};
30static const char kSzDelim[1] = {'$'};
31
32class ExportContext
33{
34public:
35 ExportContext ();
36
37 ~ExportContext ();
38
39 void push_module_scope (const HIR::Module &module);
40
41 const HIR::Module &pop_module_scope ();
42
43 void emit_trait (const HIR::Trait &trait);
44
45 void emit_function (const HIR::Function &fn);
46
47 const std::string &get_interface_buffer () const;
48
49private:
50 Analysis::Mappings *mappings;
51
52 std::vector<std::reference_wrapper<const HIR::Module>> module_stack;
53 std::string public_interface_buffer;
54};
55
56class PublicInterface
57{
58public:
59 static void Export (HIR::Crate &crate);
60
61 static void ExportTo (HIR::Crate &crate, const std::string &output_path);
62
63 static bool is_crate_public (const HIR::VisItem &item);
64
65 static std::string expected_metadata_filename ();
66
67protected:
68 void gather_export_data ();
69
70 void write_to_object_file () const;
71
72 void write_to_path (const std::string &path) const;
73
74private:
75 PublicInterface (HIR::Crate &crate);
76
77 HIR::Crate &crate;
78 Analysis::Mappings &mappings;
79 ExportContext context;
80};
81
82} // namespace Metadata
83} // namespace Rust
84
85#endif // RUST_EXPORT_METADATA_H