]>
Commit | Line | Data |
---|---|---|
353b0b11 FG |
1 | //! Module that implements the public interface to the Stable MIR. |
2 | //! | |
3 | //! This module shall contain all type definitions and APIs that we expect 3P tools to invoke to | |
4 | //! interact with the compiler. | |
5 | //! | |
6 | //! The goal is to eventually move this module to its own crate which shall be published on | |
7 | //! [crates.io](https://crates.io). | |
8 | //! | |
9 | //! ## Note: | |
10 | //! | |
11 | //! There shouldn't be any direct references to internal compiler constructs in this module. | |
12 | //! If you need an internal construct, consider using `rustc_internal` or `rustc_smir`. | |
13 | ||
14 | pub mod mir; | |
15 | ||
16 | /// Use String for now but we should replace it. | |
17 | pub type Symbol = String; | |
18 | ||
19 | /// The number that identifies a crate. | |
20 | pub type CrateNum = usize; | |
21 | ||
22 | /// A unique identification number for each item accessible for the current compilation unit. | |
23 | pub type DefId = usize; | |
24 | ||
25 | /// A list of crate items. | |
26 | pub type CrateItems = Vec<CrateItem>; | |
27 | ||
28 | /// Holds information about a crate. | |
29 | #[derive(Clone, PartialEq, Eq, Debug)] | |
30 | pub struct Crate { | |
31 | pub(crate) id: CrateNum, | |
32 | pub name: Symbol, | |
33 | pub is_local: bool, | |
34 | } | |
35 | ||
36 | /// Holds information about an item in the crate. | |
37 | /// For now, it only stores the item DefId. Use functions inside `rustc_internal` module to | |
38 | /// use this item. | |
39 | #[derive(Clone, PartialEq, Eq, Debug)] | |
40 | pub struct CrateItem(pub(crate) DefId); | |
41 | ||
42 | impl CrateItem { | |
43 | pub fn body(&self) -> mir::Body { | |
44 | crate::rustc_smir::mir_body(self) | |
45 | } | |
46 | } | |
47 | ||
48 | /// Return the function where execution starts if the current | |
49 | /// crate defines that. This is usually `main`, but could be | |
50 | /// `start` if the crate is a no-std crate. | |
51 | pub fn entry_fn() -> Option<CrateItem> { | |
52 | crate::rustc_smir::entry_fn() | |
53 | } | |
54 | ||
55 | /// Access to the local crate. | |
56 | pub fn local_crate() -> Crate { | |
57 | crate::rustc_smir::local_crate() | |
58 | } | |
59 | ||
60 | /// Try to find a crate with the given name. | |
61 | pub fn find_crate(name: &str) -> Option<Crate> { | |
62 | crate::rustc_smir::find_crate(name) | |
63 | } | |
64 | ||
65 | /// Try to find a crate with the given name. | |
66 | pub fn external_crates() -> Vec<Crate> { | |
67 | crate::rustc_smir::external_crates() | |
68 | } | |
69 | ||
70 | /// Retrieve all items in the local crate that have a MIR associated with them. | |
71 | pub fn all_local_items() -> CrateItems { | |
72 | crate::rustc_smir::all_local_items() | |
73 | } |