rust/src/mono_item.rs

40 lines
1.7 KiB
Rust
Raw Normal View History

2020-05-10 09:54:30 -05:00
use rustc_codegen_ssa::traits::PreDefineMethods;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::mono::{Linkage, Visibility};
use rustc_middle::ty::{self, Instance, TypeFoldable};
use rustc_middle::ty::layout::{FnAbiExt, LayoutOf};
2020-05-10 09:54:30 -05:00
use rustc_span::def_id::DefId;
use rustc_target::abi::call::FnAbi;
use crate::base;
use crate::context::CodegenCx;
use crate::type_of::LayoutGccExt;
impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
fn predefine_static(&self, def_id: DefId, _linkage: Linkage, _visibility: Visibility, symbol_name: &str) {
let attrs = self.tcx.codegen_fn_attrs(def_id);
let instance = Instance::mono(self.tcx, def_id);
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
let gcc_type = self.layout_of(ty).gcc_type(self, true);
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let global = self.define_global(symbol_name, gcc_type, is_tls, attrs.link_section);
2020-05-10 09:54:30 -05:00
2021-08-15 07:28:46 -05:00
// TODO(antoyo): set linkage and visibility.
2020-05-10 09:54:30 -05:00
self.instances.borrow_mut().insert(instance, global);
}
fn predefine_fn(&self, instance: Instance<'tcx>, linkage: Linkage, _visibility: Visibility, symbol_name: &str) {
assert!(!instance.substs.needs_infer());
2020-05-10 09:54:30 -05:00
let fn_abi = FnAbi::of_instance(self, instance, &[]);
self.linkage.set(base::linkage_to_gcc(linkage));
let _decl = self.declare_fn(symbol_name, &fn_abi);
//let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
2021-08-15 07:28:46 -05:00
// TODO(antoyo): call set_link_section() to allow initializing argc/argv.
// TODO(antoyo): set unique comdat.
// TODO(antoyo): use inline attribute from there in linkage.set() above.
2020-05-10 09:54:30 -05:00
}
}