Merge branch 'master' into main

This commit is contained in:
Jasper Bekkers 2020-07-24 12:03:51 +01:00
commit dd93edce2a
No known key found for this signature in database
GPG Key ID: C59CE25F4DA6625D
3 changed files with 57 additions and 5 deletions

View File

@ -1 +1 @@
rustc +nightly -Zcodegen-backend=target\debug\rustc_codegen_spirv.dll --crate-type lib tests\empty.rs rustc +nightly -Zcodegen-backend=target\debug\rustc_codegen_spirv.dll --crate-name=empty --crate-type lib tests\empty.rs

View File

@ -3,6 +3,7 @@
extern crate rustc_codegen_ssa; extern crate rustc_codegen_ssa;
extern crate rustc_errors; extern crate rustc_errors;
extern crate rustc_middle; extern crate rustc_middle;
extern crate rustc_mir;
#[macro_use] #[macro_use]
extern crate rustc_data_structures; extern crate rustc_data_structures;
extern crate rustc_driver; extern crate rustc_driver;
@ -27,6 +28,8 @@ use rustc_target::spec::Target;
use std::any::Any; use std::any::Any;
use std::path::Path; use std::path::Path;
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
pub struct NoLlvmMetadataLoader; pub struct NoLlvmMetadataLoader;
impl MetadataLoader for NoLlvmMetadataLoader { impl MetadataLoader for NoLlvmMetadataLoader {
@ -52,9 +55,10 @@ impl CodegenBackend for TheBackend {
fn provide(&self, providers: &mut Providers) { fn provide(&self, providers: &mut Providers) {
rustc_symbol_mangling::provide(providers); rustc_symbol_mangling::provide(providers);
// providers.supported_target_features = |tcx, _cnum| { // jb-todo: target_features_whitelist is old name for supported_target_features
// Default::default() // Just a dummy providers.target_features_whitelist = |tcx, _cnum| {
// }; Default::default() // Just a dummy
};
providers.is_reachable_non_generic = |_tcx, _defid| true; providers.is_reachable_non_generic = |_tcx, _defid| true;
providers.exported_symbols = |_tcx, _crate| &[]; providers.exported_symbols = |_tcx, _crate| &[];
} }
@ -73,6 +77,42 @@ impl CodegenBackend for TheBackend {
println!("In codegen_crate"); println!("In codegen_crate");
let cgus = if tcx.sess.opts.output_types.should_codegen() {
tcx.collect_and_partition_mono_items(LOCAL_CRATE).1
} else {
// If only `--emit metadata` is used, we shouldn't perform any codegen.
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
&[]
};
dbg!(cgus.len());
cgus.iter().for_each(|cgu| {
dbg!(cgu.name());
let cgu = tcx.codegen_unit(cgu.name());
let mono_items = cgu.items_in_deterministic_order(tcx);
for (mono_item, (linkage, visibility)) in mono_items {
match mono_item {
MonoItem::Fn(inst) => {
let mut mir = ::std::io::Cursor::new(Vec::new());
crate::rustc_mir::util::write_mir_pretty(
tcx,
Some(inst.def_id()),
&mut mir,
).unwrap();
let s = String::from_utf8(mir.into_inner()).unwrap();
println!("{}", s);
},
_ => {}
}
}
});
Box::new(tcx.crate_name(LOCAL_CRATE) as Symbol) Box::new(tcx.crate_name(LOCAL_CRATE) as Symbol)
} }

View File

@ -1,2 +1,14 @@
#![feature(no_core)] #![feature(no_core, lang_items)]
#![no_core] #![no_core]
#[lang = "sized"]
pub trait Sized {}
#[lang = "unsize"]
pub trait Unsize<T: ?Sized> {}
#[lang = "coerce_unsized"]
pub trait CoerceUnsized<T> {}
pub fn jasper() {}