diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2023-04-14 23:00:36 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-14 23:00:36 +0900 |
| commit | 425913367b79680068d7cb358b7609ea2be0da14 (patch) | |
| tree | d2a0087d7649b2e67feeb0f311ec28dabc7b80ed /compiler | |
| parent | 35a34932774db9e8180025b8d3287a9b593461f4 (diff) | |
| parent | e404e77c0b148029f9903920d46362056c658be5 (diff) | |
| download | rust-425913367b79680068d7cb358b7609ea2be0da14.tar.gz rust-425913367b79680068d7cb358b7609ea2be0da14.zip | |
Rollup merge of #110315 - oli-obk:mor_smir, r=WaffleLapkin
Add a stable MIR way to get the main function This is useful for analysis tools that only analyze the code paths that a specific program actually goes through. Or for code generators built on top of stable MIR.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_smir/src/rustc_smir/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/stable_mir/mod.rs | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 0befff894ef..4dad3c6bce7 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -40,6 +40,10 @@ pub fn all_local_items() -> stable_mir::CrateItems { with(|tcx| tcx.mir_keys(()).iter().map(|item| crate_item(item.to_def_id())).collect()) } +pub fn entry_fn() -> Option<stable_mir::CrateItem> { + with(|tcx| Some(crate_item(tcx.entry_fn(())?.0))) +} + /// Build a stable mir crate from a given crate number. fn smir_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> stable_mir::Crate { let crate_name = tcx.crate_name(crate_num).to_string(); diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index ba23186224a..1d2efb5eab9 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -45,6 +45,13 @@ impl CrateItem { } } +/// Return the function where execution starts if the current +/// crate defines that. This is usually `main`, but could be +/// `start` if the crate is a no-std crate. +pub fn entry_fn() -> Option<CrateItem> { + crate::rustc_smir::entry_fn() +} + /// Access to the local crate. pub fn local_crate() -> Crate { crate::rustc_smir::local_crate() |
