use base;
use builder::Builder;
use common::{ty_fn_sig, C_usize};
-use context::CrateContext;
+use context::CodegenCx;
use cabi_x86;
use cabi_x86_64;
use cabi_x86_win64;
}
impl Reg {
- pub fn align(&self, ccx: &CrateContext) -> Align {
+ pub fn align(&self, ccx: &CodegenCx) -> Align {
let dl = ccx.data_layout();
match self.kind {
RegKind::Integer => {
}
}
- pub fn llvm_type(&self, ccx: &CrateContext) -> Type {
+ pub fn llvm_type(&self, ccx: &CodegenCx) -> Type {
match self.kind {
RegKind::Integer => Type::ix(ccx, self.size.bits()),
RegKind::Float => {
}
impl Uniform {
- pub fn align(&self, ccx: &CrateContext) -> Align {
+ pub fn align(&self, ccx: &CodegenCx) -> Align {
self.unit.align(ccx)
}
- pub fn llvm_type(&self, ccx: &CrateContext) -> Type {
+ pub fn llvm_type(&self, ccx: &CodegenCx) -> Type {
let llunit = self.unit.llvm_type(ccx);
if self.total <= self.unit.size {
pub trait LayoutExt<'tcx> {
fn is_aggregate(&self) -> bool;
- fn homogeneous_aggregate<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Option<Reg>;
+ fn homogeneous_aggregate<'a>(&self, ccx: &CodegenCx<'a, 'tcx>) -> Option<Reg>;
}
impl<'tcx> LayoutExt<'tcx> for TyLayout<'tcx> {
}
}
- fn homogeneous_aggregate<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Option<Reg> {
+ fn homogeneous_aggregate<'a>(&self, ccx: &CodegenCx<'a, 'tcx>) -> Option<Reg> {
match self.abi {
layout::Abi::Uninhabited => None,
}
impl CastTarget {
- pub fn size(&self, ccx: &CrateContext) -> Size {
+ pub fn size(&self, ccx: &CodegenCx) -> Size {
match *self {
CastTarget::Uniform(u) => u.total,
CastTarget::Pair(a, b) => {
}
}
- pub fn align(&self, ccx: &CrateContext) -> Align {
+ pub fn align(&self, ccx: &CodegenCx) -> Align {
match *self {
CastTarget::Uniform(u) => u.align(ccx),
CastTarget::Pair(a, b) => {
}
}
- pub fn llvm_type(&self, ccx: &CrateContext) -> Type {
+ pub fn llvm_type(&self, ccx: &CodegenCx) -> Type {
match *self {
CastTarget::Uniform(u) => u.llvm_type(ccx),
CastTarget::Pair(a, b) => {
/// Get the LLVM type for an place of the original Rust type of
/// this argument/return, i.e. the result of `type_of::type_of`.
- pub fn memory_ty(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
+ pub fn memory_ty(&self, ccx: &CodegenCx<'a, 'tcx>) -> Type {
self.layout.llvm_type(ccx)
}
}
impl<'a, 'tcx> FnType<'tcx> {
- pub fn of_instance(ccx: &CrateContext<'a, 'tcx>, instance: &ty::Instance<'tcx>)
+ pub fn of_instance(ccx: &CodegenCx<'a, 'tcx>, instance: &ty::Instance<'tcx>)
-> Self {
let fn_ty = instance.ty(ccx.tcx);
let sig = ty_fn_sig(ccx, fn_ty);
FnType::new(ccx, sig, &[])
}
- pub fn new(ccx: &CrateContext<'a, 'tcx>,
+ pub fn new(ccx: &CodegenCx<'a, 'tcx>,
sig: ty::FnSig<'tcx>,
extra_args: &[Ty<'tcx>]) -> FnType<'tcx> {
let mut fn_ty = FnType::unadjusted(ccx, sig, extra_args);
fn_ty
}
- pub fn new_vtable(ccx: &CrateContext<'a, 'tcx>,
+ pub fn new_vtable(ccx: &CodegenCx<'a, 'tcx>,
sig: ty::FnSig<'tcx>,
extra_args: &[Ty<'tcx>]) -> FnType<'tcx> {
let mut fn_ty = FnType::unadjusted(ccx, sig, extra_args);
fn_ty
}
- pub fn unadjusted(ccx: &CrateContext<'a, 'tcx>,
+ pub fn unadjusted(ccx: &CodegenCx<'a, 'tcx>,
sig: ty::FnSig<'tcx>,
extra_args: &[Ty<'tcx>]) -> FnType<'tcx> {
debug!("FnType::unadjusted({:?}, {:?})", sig, extra_args);
}
fn adjust_for_abi(&mut self,
- ccx: &CrateContext<'a, 'tcx>,
+ ccx: &CodegenCx<'a, 'tcx>,
abi: Abi) {
if abi == Abi::Unadjusted { return }
}
}
- pub fn llvm_type(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
+ pub fn llvm_type(&self, ccx: &CodegenCx<'a, 'tcx>) -> Type {
let mut llargument_tys = Vec::new();
let llreturn_ty = match self.ret.mode {
}
}
-pub fn trans_global_asm<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn trans_global_asm<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
ga: &hir::GlobalAsm) {
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
unsafe {
use llvm_util;
pub use syntax::attr::{self, InlineAttr};
use syntax::ast;
-use context::CrateContext;
+use context::CodegenCx;
/// Mark LLVM function to use provided inline heuristic.
#[inline]
Attribute::Naked.toggle_llfn(Function, val, is_naked);
}
-pub fn set_frame_pointer_elimination(ccx: &CrateContext, llfn: ValueRef) {
+pub fn set_frame_pointer_elimination(ccx: &CodegenCx, llfn: ValueRef) {
// FIXME: #11906: Omitting frame pointers breaks retrieving the value of a
// parameter.
if ccx.sess().must_not_eliminate_frame_pointers() {
}
}
-pub fn set_probestack(ccx: &CrateContext, llfn: ValueRef) {
+pub fn set_probestack(ccx: &CodegenCx, llfn: ValueRef) {
// Only use stack probes if the target specification indicates that we
// should be using stack probes
if !ccx.sess().target.target.options.stack_probes {
/// Composite function which sets LLVM attributes for function depending on its AST (#[attribute])
/// attributes.
-pub fn from_fn_attrs(ccx: &CrateContext, llfn: ValueRef, id: DefId) {
+pub fn from_fn_attrs(ccx: &CodegenCx, llfn: ValueRef, id: DefId) {
use syntax::attr::*;
let attrs = ccx.tcx.get_attrs(id);
inline(llfn, find_inline_attr(Some(ccx.sess().diagnostic()), &attrs));
use rustc_mir::monomorphize::collector::{self, MonoItemCollectionMode};
use common::{self, C_struct_in_context, C_array, val_ty};
use consts;
-use context::{self, CrateContext};
+use context::{self, CodegenCx};
use debuginfo;
use declare;
use meth;
pub use rustc_mir::monomorphize::item::linkage_by_name;
pub struct StatRecorder<'a, 'tcx: 'a> {
- ccx: &'a CrateContext<'a, 'tcx>,
+ ccx: &'a CodegenCx<'a, 'tcx>,
name: Option<String>,
istart: usize,
}
impl<'a, 'tcx> StatRecorder<'a, 'tcx> {
- pub fn new(ccx: &'a CrateContext<'a, 'tcx>, name: String) -> StatRecorder<'a, 'tcx> {
+ pub fn new(ccx: &'a CodegenCx<'a, 'tcx>, name: String) -> StatRecorder<'a, 'tcx> {
let istart = ccx.stats.borrow().n_llvm_insns;
StatRecorder {
ccx,
/// The `old_info` argument is a bit funny. It is intended for use
/// in an upcast, where the new vtable for an object will be derived
/// from the old one.
-pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
+pub fn unsized_info<'ccx, 'tcx>(ccx: &CodegenCx<'ccx, 'tcx>,
source: Ty<'tcx>,
target: Ty<'tcx>,
old_info: Option<ValueRef>)
b.call(llintrinsicfn, &[ptr, fill_byte, size, align, volatile], None)
}
-pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance<'tcx>) {
+pub fn trans_instance<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, instance: Instance<'tcx>) {
let _s = if ccx.sess().trans_stats() {
let mut instance_name = String::new();
DefPathBasedNames::new(ccx.tcx, true, true)
mir::trans_mir(ccx, lldecl, &mir, instance, sig);
}
-pub fn set_link_section(ccx: &CrateContext,
+pub fn set_link_section(ccx: &CodegenCx,
llval: ValueRef,
attrs: &[ast::Attribute]) {
if let Some(sect) = attr::first_attr_value_str_by_name(attrs, "link_section") {
/// Create the `main` function which will initialize the rust runtime and call
/// users main function.
-fn maybe_create_entry_wrapper(ccx: &CrateContext) {
+fn maybe_create_entry_wrapper(ccx: &CodegenCx) {
let (main_def_id, span) = match *ccx.sess().entry_fn.borrow() {
Some((id, span)) => {
(ccx.tcx.hir.local_def_id(id), span)
config::EntryNone => {} // Do nothing.
}
- fn create_entry_fn<'ccx>(ccx: &'ccx CrateContext,
+ fn create_entry_fn<'ccx>(ccx: &'ccx CodegenCx,
sp: Span,
rust_main: ValueRef,
rust_main_def_id: DefId,
.to_fingerprint().to_hex());
// Instantiate translation items without filling out definitions yet...
- let ccx = CrateContext::new(tcx, cgu, &llmod_id);
+ let ccx = CodegenCx::new(tcx, cgu, &llmod_id);
let module = {
let trans_items = ccx.codegen_unit
.items_in_deterministic_order(ccx.tcx);
#[must_use]
pub struct Builder<'a, 'tcx: 'a> {
pub llbuilder: BuilderRef,
- pub ccx: &'a CrateContext<'a, 'tcx>,
+ pub ccx: &'a CodegenCx<'a, 'tcx>,
}
impl<'a, 'tcx> Drop for Builder<'a, 'tcx> {
}
impl<'a, 'tcx> Builder<'a, 'tcx> {
- pub fn new_block<'b>(ccx: &'a CrateContext<'a, 'tcx>, llfn: ValueRef, name: &'b str) -> Self {
+ pub fn new_block<'b>(ccx: &'a CodegenCx<'a, 'tcx>, llfn: ValueRef, name: &'b str) -> Self {
let builder = Builder::with_ccx(ccx);
let llbb = unsafe {
let name = CString::new(name).unwrap();
builder
}
- pub fn with_ccx(ccx: &'a CrateContext<'a, 'tcx>) -> Self {
+ pub fn with_ccx(ccx: &'a CodegenCx<'a, 'tcx>) -> Self {
// Create a fresh builder from the crate context.
let llbuilder = unsafe {
llvm::LLVMCreateBuilderInContext(ccx.llcx)
// except according to those terms.
use abi::{FnType, ArgType, LayoutExt, Reg, RegKind, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
-fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>)
+fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>)
-> Option<Uniform> {
arg.layout.homogeneous_aggregate(ccx).and_then(|unit| {
let size = arg.layout.size;
})
}
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(32);
return;
ret.make_indirect();
}
-fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
+fn classify_arg_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(32);
return;
arg.make_indirect();
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
if !fty.ret.is_ignore() {
classify_ret_ty(ccx, &mut fty.ret);
}
// except according to those terms.
use abi::{FnType, ArgType, LayoutExt, Reg, RegKind, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
use llvm::CallConv;
-fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>)
+fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>)
-> Option<Uniform> {
arg.layout.homogeneous_aggregate(ccx).and_then(|unit| {
let size = arg.layout.size;
})
}
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>, vfp: bool) {
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, ret: &mut ArgType<'tcx>, vfp: bool) {
if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(32);
return;
ret.make_indirect();
}
-fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>, vfp: bool) {
+fn classify_arg_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>, vfp: bool) {
if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(32);
return;
});
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
// If this is a target with a hard-float ABI, and the function is not explicitly
// `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates.
let vfp = ccx.sess().target.target.llvm_target.ends_with("hf")
// except according to those terms.
use abi::{FnType, ArgType, LayoutExt, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
// Data layout: e-p:32:32-i64:64-v128:32:128-n32-S128
// See the https://github.com/kripken/emscripten-fastcomp-clang repository.
// The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions.
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
if ret.layout.is_aggregate() {
if let Some(unit) = ret.layout.homogeneous_aggregate(ccx) {
let size = ret.layout.size;
}
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
if !fty.ret.is_ignore() {
classify_ret_ty(ccx, &mut fty.ret);
}
// except according to those terms.
use abi::{ArgType, FnType, LayoutExt, Reg, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
use rustc::ty::layout::Size;
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
ret: &mut ArgType<'tcx>,
offset: &mut Size) {
if !ret.layout.is_aggregate() {
}
}
-fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
+fn classify_arg_ty(ccx: &CodegenCx, arg: &mut ArgType, offset: &mut Size) {
let dl = &ccx.tcx.data_layout;
let size = arg.layout.size;
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
*offset = offset.abi_align(align) + size.abi_align(align);
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
let mut offset = Size::from_bytes(0);
if !fty.ret.is_ignore() {
classify_ret_ty(ccx, &mut fty.ret, &mut offset);
// except according to those terms.
use abi::{ArgType, FnType, LayoutExt, Reg, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
use rustc::ty::layout::Size;
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
ret: &mut ArgType<'tcx>,
offset: &mut Size) {
if !ret.layout.is_aggregate() {
}
}
-fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
+fn classify_arg_ty(ccx: &CodegenCx, arg: &mut ArgType, offset: &mut Size) {
let dl = &ccx.tcx.data_layout;
let size = arg.layout.size;
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
*offset = offset.abi_align(align) + size.abi_align(align);
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
let mut offset = Size::from_bytes(0);
if !fty.ret.is_ignore() {
classify_ret_ty(ccx, &mut fty.ret, &mut offset);
// except according to those terms.
use abi::{ArgType, FnType, LayoutExt, Reg, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
use rustc::ty::layout::Size;
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
ret: &mut ArgType<'tcx>,
offset: &mut Size) {
if !ret.layout.is_aggregate() {
}
}
-fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
+fn classify_arg_ty(ccx: &CodegenCx, arg: &mut ArgType, offset: &mut Size) {
let dl = &ccx.tcx.data_layout;
let size = arg.layout.size;
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
*offset = offset.abi_align(align) + size.abi_align(align);
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
let mut offset = Size::from_bytes(0);
if !fty.ret.is_ignore() {
classify_ret_ty(ccx, &mut fty.ret, &mut offset);
// need to be fixed when PowerPC vector support is added.
use abi::{FnType, ArgType, LayoutExt, Reg, RegKind, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
use rustc::ty::layout;
#[derive(Debug, Clone, Copy, PartialEq)]
}
use self::ABI::*;
-fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
arg: &mut ArgType<'tcx>,
abi: ABI)
-> Option<Uniform> {
})
}
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>, abi: ABI) {
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, ret: &mut ArgType<'tcx>, abi: ABI) {
if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(64);
return;
ret.make_indirect();
}
-fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>, abi: ABI) {
+fn classify_arg_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>, abi: ABI) {
if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(64);
return;
});
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
let abi = match ccx.sess().target.target.target_endian.as_str() {
"big" => ELFv1,
"little" => ELFv2,
// for a pre-z13 machine or using -mno-vx.
use abi::{FnType, ArgType, LayoutExt, Reg};
-use context::CrateContext;
+use context::CodegenCx;
use rustc::ty::layout::{self, TyLayout};
}
}
-fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn is_single_fp_element<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
layout: TyLayout<'tcx>) -> bool {
match layout.abi {
layout::Abi::Scalar(ref scalar) => {
}
}
-fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
+fn classify_arg_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
arg.extend_integer_width_to(64);
return;
}
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
if !fty.ret.is_ignore() {
classify_ret_ty(&mut fty.ret);
}
// except according to those terms.
use abi::{ArgType, FnType, LayoutExt, Reg, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
use rustc::ty::layout::Size;
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
ret: &mut ArgType<'tcx>,
offset: &mut Size) {
if !ret.layout.is_aggregate() {
}
}
-fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
+fn classify_arg_ty(ccx: &CodegenCx, arg: &mut ArgType, offset: &mut Size) {
let dl = &ccx.tcx.data_layout;
let size = arg.layout.size;
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
*offset = offset.abi_align(align) + size.abi_align(align);
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
let mut offset = Size::from_bytes(0);
if !fty.ret.is_ignore() {
classify_ret_ty(ccx, &mut fty.ret, &mut offset);
// FIXME: This needs an audit for correctness and completeness.
use abi::{FnType, ArgType, LayoutExt, Reg, RegKind, Uniform};
-use context::CrateContext;
+use context::CodegenCx;
-fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>)
+fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>)
-> Option<Uniform> {
arg.layout.homogeneous_aggregate(ccx).and_then(|unit| {
// Ensure we have at most eight uniquely addressable members.
})
}
-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
+fn classify_ret_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(64);
return;
ret.make_indirect();
}
-fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
+fn classify_arg_ty<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(64);
return;
});
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
if !fty.ret.is_ignore() {
classify_ret_ty(ccx, &mut fty.ret);
}
// except according to those terms.
use abi::{ArgAttribute, FnType, LayoutExt, PassMode, Reg, RegKind};
-use common::CrateContext;
+use common::CodegenCx;
use rustc::ty::layout::{self, TyLayout};
Fastcall
}
-fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn is_single_fp_element<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
layout: TyLayout<'tcx>) -> bool {
match layout.abi {
layout::Abi::Scalar(ref scalar) => {
}
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
fty: &mut FnType<'tcx>,
flavor: Flavor) {
if !fty.ret.is_ignore() {
// https://github.com/jckarter/clay/blob/master/compiler/src/externals.cpp
use abi::{ArgType, CastTarget, FnType, LayoutExt, Reg, RegKind};
-use context::CrateContext;
+use context::CodegenCx;
use rustc::ty::layout::{self, TyLayout, Size};
const LARGEST_VECTOR_SIZE: usize = 512;
const MAX_EIGHTBYTES: usize = LARGEST_VECTOR_SIZE / 64;
-fn classify_arg<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &ArgType<'tcx>)
+fn classify_arg<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, arg: &ArgType<'tcx>)
-> Result<[Class; MAX_EIGHTBYTES], Memory> {
fn unify(cls: &mut [Class],
off: Size,
cls[i] = to_write;
}
- fn classify<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+ fn classify<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
layout: TyLayout<'tcx>,
cls: &mut [Class],
off: Size)
target
}
-pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
+pub fn compute_abi_info<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
let mut int_regs = 6; // RDI, RSI, RDX, RCX, R8, R9
let mut sse_regs = 8; // XMM0-7
//! closure.
use attributes;
-use common::{self, CrateContext};
+use common::{self, CodegenCx};
use consts;
use declare;
use llvm::{self, ValueRef};
///
/// - `ccx`: the crate context
/// - `instance`: the instance to be instantiated
-pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn get_fn<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
instance: Instance<'tcx>)
-> ValueRef
{
llfn
}
-pub fn resolve_and_get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn resolve_and_get_fn<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>)
-> ValueRef
use syntax::symbol::InternedString;
use syntax_pos::{Span, DUMMY_SP};
-pub use context::CrateContext;
+pub use context::CodegenCx;
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All))
}
}
-pub fn C_bool(ccx: &CrateContext, val: bool) -> ValueRef {
+pub fn C_bool(ccx: &CodegenCx, val: bool) -> ValueRef {
C_uint(Type::i1(ccx), val as u64)
}
-pub fn C_i32(ccx: &CrateContext, i: i32) -> ValueRef {
+pub fn C_i32(ccx: &CodegenCx, i: i32) -> ValueRef {
C_int(Type::i32(ccx), i as i64)
}
-pub fn C_u32(ccx: &CrateContext, i: u32) -> ValueRef {
+pub fn C_u32(ccx: &CodegenCx, i: u32) -> ValueRef {
C_uint(Type::i32(ccx), i as u64)
}
-pub fn C_u64(ccx: &CrateContext, i: u64) -> ValueRef {
+pub fn C_u64(ccx: &CodegenCx, i: u64) -> ValueRef {
C_uint(Type::i64(ccx), i)
}
-pub fn C_usize(ccx: &CrateContext, i: u64) -> ValueRef {
+pub fn C_usize(ccx: &CodegenCx, i: u64) -> ValueRef {
let bit_size = ccx.data_layout().pointer_size.bits();
if bit_size < 64 {
// make sure it doesn't overflow
C_uint(ccx.isize_ty, i)
}
-pub fn C_u8(ccx: &CrateContext, i: u8) -> ValueRef {
+pub fn C_u8(ccx: &CodegenCx, i: u8) -> ValueRef {
C_uint(Type::i8(ccx), i as u64)
}
// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
-pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef {
+pub fn C_cstr(cx: &CodegenCx, s: InternedString, null_terminated: bool) -> ValueRef {
unsafe {
if let Some(&llval) = cx.const_cstr_cache.borrow().get(&s) {
return llval;
// NB: Do not use `do_spill_noroot` to make this into a constant string, or
// you will be kicked off fast isel. See issue #4352 for an example of this.
-pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
+pub fn C_str_slice(cx: &CodegenCx, s: InternedString) -> ValueRef {
let len = s.len();
let cs = consts::ptrcast(C_cstr(cx, s, false),
cx.layout_of(cx.tcx.mk_str()).llvm_type(cx).ptr_to());
C_fat_ptr(cx, cs, C_usize(cx, len as u64))
}
-pub fn C_fat_ptr(cx: &CrateContext, ptr: ValueRef, meta: ValueRef) -> ValueRef {
+pub fn C_fat_ptr(cx: &CodegenCx, ptr: ValueRef, meta: ValueRef) -> ValueRef {
assert_eq!(abi::FAT_PTR_ADDR, 0);
assert_eq!(abi::FAT_PTR_EXTRA, 1);
C_struct(cx, &[ptr, meta], false)
}
-pub fn C_struct(cx: &CrateContext, elts: &[ValueRef], packed: bool) -> ValueRef {
+pub fn C_struct(cx: &CodegenCx, elts: &[ValueRef], packed: bool) -> ValueRef {
C_struct_in_context(cx.llcx, elts, packed)
}
}
}
-pub fn C_bytes(cx: &CrateContext, bytes: &[u8]) -> ValueRef {
+pub fn C_bytes(cx: &CodegenCx, bytes: &[u8]) -> ValueRef {
C_bytes_in_context(cx.llcx, bytes)
}
}
}
-pub fn ty_fn_sig<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn ty_fn_sig<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
ty: Ty<'tcx>)
-> ty::PolyFnSig<'tcx>
{
use debuginfo;
use base;
use monomorphize::{MonoItem, MonoItemExt};
-use common::{CrateContext, val_ty};
+use common::{CodegenCx, val_ty};
use declare;
use monomorphize::Instance;
use type_::Type;
}
}
-fn set_global_alignment(ccx: &CrateContext,
+fn set_global_alignment(ccx: &CodegenCx,
gv: ValueRef,
mut align: Align) {
// The target may require greater alignment for globals than the type does.
}
}
-pub fn addr_of_mut(ccx: &CrateContext,
+pub fn addr_of_mut(ccx: &CodegenCx,
cv: ValueRef,
align: Align,
kind: &str)
}
}
-pub fn addr_of(ccx: &CrateContext,
+pub fn addr_of(ccx: &CodegenCx,
cv: ValueRef,
align: Align,
kind: &str)
gv
}
-pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
+pub fn get_static(ccx: &CodegenCx, def_id: DefId) -> ValueRef {
let instance = Instance::mono(ccx.tcx, def_id);
if let Some(&g) = ccx.instances.borrow().get(&instance) {
return g;
g
}
-pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn trans_static<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
m: hir::Mutability,
id: ast::NodeId,
attrs: &[ast::Attribute])
use syntax::symbol::InternedString;
use abi::Abi;
-/// There is one `CrateContext` per compilation unit. Each one has its own LLVM
+/// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
/// `ContextRef` so that several compilation units may be optimized in parallel.
-/// All other LLVM data structures in the `CrateContext` are tied to that `ContextRef`.
-pub struct CrateContext<'a, 'tcx: 'a> {
+/// All other LLVM data structures in the `CodegenCx` are tied to that `ContextRef`.
+pub struct CodegenCx<'a, 'tcx: 'a> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub check_overflow: bool,
pub use_dll_storage_attrs: bool,
local_gen_sym_counter: Cell<usize>,
}
-impl<'a, 'tcx> DepGraphSafe for CrateContext<'a, 'tcx> {
+impl<'a, 'tcx> DepGraphSafe for CodegenCx<'a, 'tcx> {
}
pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
(llcx, llmod)
}
-impl<'a, 'tcx> CrateContext<'a, 'tcx> {
+impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
codegen_unit: Arc<CodegenUnit<'tcx>>,
llmod_id: &str)
- -> CrateContext<'a, 'tcx> {
+ -> CodegenCx<'a, 'tcx> {
// An interesting part of Windows which MSVC forces our hand on (and
// apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
// attributes in LLVM IR as well as native dependencies (in C these
None
};
- let mut ccx = CrateContext {
+ let mut ccx = CodegenCx {
tcx,
check_overflow,
use_dll_storage_attrs,
}
}
-impl<'b, 'tcx> CrateContext<'b, 'tcx> {
+impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
pub fn sess<'a>(&'a self) -> &'a Session {
&self.tcx.sess
}
}
}
-impl<'a, 'tcx> ty::layout::HasDataLayout for &'a CrateContext<'a, 'tcx> {
+impl<'a, 'tcx> ty::layout::HasDataLayout for &'a CodegenCx<'a, 'tcx> {
fn data_layout(&self) -> &ty::layout::TargetDataLayout {
&self.tcx.data_layout
}
}
-impl<'a, 'tcx> ty::layout::HasTyCtxt<'tcx> for &'a CrateContext<'a, 'tcx> {
+impl<'a, 'tcx> ty::layout::HasTyCtxt<'tcx> for &'a CodegenCx<'a, 'tcx> {
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
self.tcx
}
}
-impl<'a, 'tcx> LayoutOf<Ty<'tcx>> for &'a CrateContext<'a, 'tcx> {
+impl<'a, 'tcx> LayoutOf<Ty<'tcx>> for &'a CodegenCx<'a, 'tcx> {
type TyLayout = TyLayout<'tcx>;
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
}
/// Declare any llvm intrinsics that you might need
-fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
+fn declare_intrinsic(ccx: &CodegenCx, key: &str) -> Option<ValueRef> {
macro_rules! ifn {
($name:expr, fn() -> $ret:expr) => (
if key == $name {
use llvm;
use llvm::debuginfo::DIScope;
-use common::CrateContext;
+use common::CodegenCx;
use rustc::mir::{Mir, VisibilityScope};
use libc::c_uint;
/// Produce DIScope DIEs for each MIR Scope which has variables defined in it.
/// If debuginfo is disabled, the returned vector is empty.
-pub fn create_mir_scopes(ccx: &CrateContext, mir: &Mir, debug_context: &FunctionDebugContext)
+pub fn create_mir_scopes(ccx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebugContext)
-> IndexVec<VisibilityScope, MirDebugScope> {
let null_scope = MirDebugScope {
scope_metadata: ptr::null_mut(),
scopes
}
-fn make_mir_scope(ccx: &CrateContext,
+fn make_mir_scope(ccx: &CodegenCx,
mir: &Mir,
has_variables: &BitVector,
debug_context: &FunctionDebugContextData,
//! that exact file path.
//!
//! All private state used by the module is stored within either the
-//! CrateDebugContext struct (owned by the CrateContext) or the
+//! CrateDebugContext struct (owned by the CodegenCx) or the
//! FunctionDebugContext (owned by the MirContext).
//!
//! This file consists of three conceptual sections:
use llvm;
-use common::{C_bytes, CrateContext, C_i32};
+use common::{C_bytes, CodegenCx, C_i32};
use builder::Builder;
use declare;
use type_::Type;
/// Inserts a side-effect free instruction sequence that makes sure that the
/// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.
-pub fn insert_reference_to_gdb_debug_scripts_section_global(ccx: &CrateContext, builder: &Builder) {
+pub fn insert_reference_to_gdb_debug_scripts_section_global(ccx: &CodegenCx, builder: &Builder) {
if needs_gdb_debug_scripts_section(ccx) {
let gdb_debug_scripts_section_global = get_or_insert_gdb_debug_scripts_section_global(ccx);
// Load just the first byte as that's all that's necessary to force
/// Allocates the global variable responsible for the .debug_gdb_scripts binary
/// section.
-pub fn get_or_insert_gdb_debug_scripts_section_global(ccx: &CrateContext)
+pub fn get_or_insert_gdb_debug_scripts_section_global(ccx: &CodegenCx)
-> llvm::ValueRef {
let c_section_var_name = "__rustc_debug_gdb_scripts_section__\0";
let section_var_name = &c_section_var_name[..c_section_var_name.len()-1];
}
}
-pub fn needs_gdb_debug_scripts_section(ccx: &CrateContext) -> bool {
+pub fn needs_gdb_debug_scripts_section(ccx: &CodegenCx) -> bool {
let omit_gdb_pretty_printer_section =
attr::contains_name(&ccx.tcx.hir.krate_attrs(),
"omit_gdb_pretty_printer_section");
use rustc::ty::util::TypeIdHasher;
use rustc::ich::Fingerprint;
use rustc::ty::Instance;
-use common::CrateContext;
+use common::CodegenCx;
use rustc::ty::{self, AdtKind, Ty, TyCtxt};
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
use rustc::session::config;
// Get the UniqueTypeId for the given type. If the UniqueTypeId for the given
// type has been requested before, this is just a table lookup. Otherwise an
// ID will be generated and stored for later lookup.
- fn get_unique_type_id_of_type<'a>(&mut self, cx: &CrateContext<'a, 'tcx>,
+ fn get_unique_type_id_of_type<'a>(&mut self, cx: &CodegenCx<'a, 'tcx>,
type_: Ty<'tcx>) -> UniqueTypeId {
// Let's see if we already have something in the cache
match self.type_to_unique_id.get(&type_).cloned() {
// types of their own, so they need special handling. We still need a
// UniqueTypeId for them, since to debuginfo they *are* real types.
fn get_unique_type_id_of_enum_variant<'a>(&mut self,
- cx: &CrateContext<'a, 'tcx>,
+ cx: &CodegenCx<'a, 'tcx>,
enum_type: Ty<'tcx>,
variant_name: &str)
-> UniqueTypeId {
}
fn create_and_register_recursive_type_forward_declaration<'a, 'tcx>(
- cx: &CrateContext<'a, 'tcx>,
+ cx: &CodegenCx<'a, 'tcx>,
unfinished_type: Ty<'tcx>,
unique_type_id: UniqueTypeId,
metadata_stub: DICompositeType,
// Finishes up the description of the type in question (mostly by providing
// descriptions of the fields of the given type) and returns the final type
// metadata.
- fn finalize<'a>(&self, cx: &CrateContext<'a, 'tcx>) -> MetadataCreationResult {
+ fn finalize<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> MetadataCreationResult {
match *self {
FinalMetadata(metadata) => MetadataCreationResult::new(metadata, false),
UnfinishedMetadata {
)
}
-fn fixed_vec_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn fixed_vec_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
unique_type_id: UniqueTypeId,
array_or_slice_type: Ty<'tcx>,
element_type: Ty<'tcx>,
return MetadataCreationResult::new(metadata, false);
}
-fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn vec_slice_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
slice_ptr_type: Ty<'tcx>,
element_type: Ty<'tcx>,
unique_type_id: UniqueTypeId,
MetadataCreationResult::new(metadata, false)
}
-fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn subroutine_type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
unique_type_id: UniqueTypeId,
signature: ty::PolyFnSig<'tcx>,
span: Span)
// trait_type should be the actual trait (e.g., Trait). Where the trait is part
// of a DST struct, there is no trait_object_type and the results of this
// function will be a little bit weird.
-fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn trait_pointer_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
trait_type: Ty<'tcx>,
trait_object_type: Option<Ty<'tcx>>,
unique_type_id: UniqueTypeId)
syntax_pos::DUMMY_SP)
}
-pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+pub fn type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
t: Ty<'tcx>,
usage_site_span: Span)
-> DIType {
metadata
}
-pub fn file_metadata(cx: &CrateContext,
+pub fn file_metadata(cx: &CodegenCx,
file_name: &FileName,
defining_crate: CrateNum) -> DIFile {
debug!("file_metadata: file_name: {}, defining_crate: {}",
file_metadata_raw(cx, &file_name.to_string(), &directory.to_string_lossy())
}
-pub fn unknown_file_metadata(cx: &CrateContext) -> DIFile {
+pub fn unknown_file_metadata(cx: &CodegenCx) -> DIFile {
file_metadata_raw(cx, "<unknown>", "")
}
-fn file_metadata_raw(cx: &CrateContext,
+fn file_metadata_raw(cx: &CodegenCx,
file_name: &str,
directory: &str)
-> DIFile {
file_metadata
}
-fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn basic_type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
t: Ty<'tcx>) -> DIType {
debug!("basic_type_metadata: {:?}", t);
return ty_metadata;
}
-fn foreign_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn foreign_type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
t: Ty<'tcx>,
unique_type_id: UniqueTypeId) -> DIType {
debug!("foreign_type_metadata: {:?}", t);
create_struct_stub(cx, t, &name, unique_type_id, NO_SCOPE_METADATA)
}
-fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn pointer_type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
pointer_type: Ty<'tcx>,
pointee_type_metadata: DIType)
-> DIType {
}
impl<'tcx> MemberDescriptionFactory<'tcx> {
- fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
+ fn create_member_descriptions<'a>(&self, cx: &CodegenCx<'a, 'tcx>)
-> Vec<MemberDescription> {
match *self {
StructMDF(ref this) => {
}
impl<'tcx> StructMemberDescriptionFactory<'tcx> {
- fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
+ fn create_member_descriptions<'a>(&self, cx: &CodegenCx<'a, 'tcx>)
-> Vec<MemberDescription> {
let layout = cx.layout_of(self.ty);
self.variant.fields.iter().enumerate().map(|(i, f)| {
}
-fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn prepare_struct_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
struct_type: Ty<'tcx>,
unique_type_id: UniqueTypeId,
span: Span)
}
impl<'tcx> TupleMemberDescriptionFactory<'tcx> {
- fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
+ fn create_member_descriptions<'a>(&self, cx: &CodegenCx<'a, 'tcx>)
-> Vec<MemberDescription> {
let layout = cx.layout_of(self.ty);
self.component_types.iter().enumerate().map(|(i, &component_type)| {
}
}
-fn prepare_tuple_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn prepare_tuple_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
tuple_type: Ty<'tcx>,
component_types: &[Ty<'tcx>],
unique_type_id: UniqueTypeId,
}
impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
- fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
+ fn create_member_descriptions<'a>(&self, cx: &CodegenCx<'a, 'tcx>)
-> Vec<MemberDescription> {
self.variant.fields.iter().enumerate().map(|(i, f)| {
let field = self.layout.field(cx, i);
}
}
-fn prepare_union_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn prepare_union_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
union_type: Ty<'tcx>,
unique_type_id: UniqueTypeId,
span: Span)
}
impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
- fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
+ fn create_member_descriptions<'a>(&self, cx: &CodegenCx<'a, 'tcx>)
-> Vec<MemberDescription> {
let adt = &self.enum_type.ty_adt_def().unwrap();
match self.layout.variants {
// of discriminant instead of us having to recover its path.
// Right now it's not even going to work for `niche_start > 0`,
// and for multiple niche variants it only supports the first.
- fn compute_field_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+ fn compute_field_path<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
name: &mut String,
layout: TyLayout<'tcx>,
offset: Size,
}
impl<'tcx> VariantMemberDescriptionFactory<'tcx> {
- fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
+ fn create_member_descriptions<'a>(&self, cx: &CodegenCx<'a, 'tcx>)
-> Vec<MemberDescription> {
self.args.iter().enumerate().map(|(i, &(ref name, ty))| {
let (size, align) = cx.size_and_align_of(ty);
// of the variant, and (3) a MemberDescriptionFactory for producing the
// descriptions of the fields of the variant. This is a rudimentary version of a
// full RecursiveTypeDescription.
-fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn describe_enum_variant<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
layout: layout::TyLayout<'tcx>,
variant: &'tcx ty::VariantDef,
discriminant_info: EnumDiscriminantInfo,
(metadata_stub, member_description_factory)
}
-fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn prepare_enum_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
enum_type: Ty<'tcx>,
enum_def_id: DefId,
unique_type_id: UniqueTypeId,
}),
);
- fn get_enum_discriminant_name(cx: &CrateContext,
+ fn get_enum_discriminant_name(cx: &CodegenCx,
def_id: DefId)
-> InternedString {
cx.tcx.item_name(def_id)
/// results in a LLVM struct.
///
/// Examples of Rust types to use this are: structs, tuples, boxes, vecs, and enums.
-fn composite_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn composite_type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
composite_type: Ty<'tcx>,
composite_type_name: &str,
composite_type_unique_id: UniqueTypeId,
return composite_type_metadata;
}
-fn set_members_of_composite_type(cx: &CrateContext,
+fn set_members_of_composite_type(cx: &CodegenCx,
composite_type_metadata: DICompositeType,
member_descriptions: &[MemberDescription]) {
// In some rare cases LLVM metadata uniquing would lead to an existing type
// A convenience wrapper around LLVMRustDIBuilderCreateStructType(). Does not do
// any caching, does not add any fields to the struct. This can be done later
// with set_members_of_composite_type().
-fn create_struct_stub<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn create_struct_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
struct_type: Ty<'tcx>,
struct_type_name: &str,
unique_type_id: UniqueTypeId,
return metadata_stub;
}
-fn create_union_stub<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+fn create_union_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
union_type: Ty<'tcx>,
union_type_name: &str,
unique_type_id: UniqueTypeId,
/// Creates debug information for the given global variable.
///
/// Adds the created metadata nodes directly to the crate's IR.
-pub fn create_global_var_metadata(cx: &CrateContext,
+pub fn create_global_var_metadata(cx: &CodegenCx,
node_id: ast::NodeId,
global: ValueRef) {
if cx.dbg_cx.is_none() {
}
// Creates an "extension" of an existing DIScope into another file.
-pub fn extend_scope_to_file(ccx: &CrateContext,
+pub fn extend_scope_to_file(ccx: &CodegenCx,
scope_metadata: DIScope,
file: &syntax_pos::FileMap,
defining_crate: CrateNum)
/// given type.
///
/// Adds the created metadata nodes directly to the crate's IR.
-pub fn create_vtable_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+pub fn create_vtable_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
ty: ty::Ty<'tcx>,
vtable: ValueRef) {
if cx.dbg_cx.is_none() {
use rustc::ty::subst::Substs;
use abi::Abi;
-use common::CrateContext;
+use common::CodegenCx;
use builder::Builder;
use monomorphize::Instance;
use rustc::ty::{self, Ty};
}
/// Create any deferred debug metadata nodes
-pub fn finalize(cx: &CrateContext) {
+pub fn finalize(cx: &CodegenCx) {
if cx.dbg_cx.is_none() {
return;
}
/// for debug info creation. The function may also return another variant of the
/// FunctionDebugContext enum which indicates why no debuginfo should be created
/// for the function.
-pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
instance: Instance<'tcx>,
sig: ty::FnSig<'tcx>,
llfn: ValueRef,
return FunctionDebugContext::RegularContext(fn_debug_context);
- fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+ fn get_function_signature<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
sig: ty::FnSig<'tcx>) -> DIArray {
if cx.sess().opts.debuginfo == LimitedDebugInfo {
return create_DIArray(DIB(cx), &[]);
return create_DIArray(DIB(cx), &signature[..]);
}
- fn get_template_parameters<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+ fn get_template_parameters<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
generics: &ty::Generics,
substs: &Substs<'tcx>,
file_metadata: DIFile,
return create_DIArray(DIB(cx), &template_params[..]);
}
- fn get_type_parameter_names(cx: &CrateContext, generics: &ty::Generics) -> Vec<ast::Name> {
+ fn get_type_parameter_names(cx: &CodegenCx, generics: &ty::Generics) -> Vec<ast::Name> {
let mut names = generics.parent.map_or(vec![], |def_id| {
get_type_parameter_names(cx, cx.tcx.generics_of(def_id))
});
names
}
- fn get_containing_scope<'ccx, 'tcx>(cx: &CrateContext<'ccx, 'tcx>,
+ fn get_containing_scope<'ccx, 'tcx>(cx: &CodegenCx<'ccx, 'tcx>,
instance: Instance<'tcx>)
-> DIScope {
// First, let's see if this is a method within an inherent impl. Because
use llvm::debuginfo::DIScope;
use rustc::hir::def_id::DefId;
use rustc::hir::map::DefPathData;
-use common::CrateContext;
+use common::CodegenCx;
use std::ffi::CString;
use std::ptr;
pub fn mangled_name_of_instance<'a, 'tcx>(
- ccx: &CrateContext<'a, 'tcx>,
+ ccx: &CodegenCx<'a, 'tcx>,
instance: Instance<'tcx>,
) -> ty::SymbolName {
let tcx = ccx.tcx;
}
pub fn mangled_name_of_item<'a, 'tcx>(
- ccx: &CrateContext<'a, 'tcx>,
+ ccx: &CodegenCx<'a, 'tcx>,
node_id: ast::NodeId,
) -> ty::SymbolName {
let tcx = ccx.tcx;
tcx.symbol_name(instance)
}
-pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {
+pub fn item_namespace(ccx: &CodegenCx, def_id: DefId) -> DIScope {
if let Some(&scope) = debug_context(ccx).namespace_map.borrow().get(&def_id) {
return scope;
}
// Type Names for Debug Info.
-use common::CrateContext;
+use common::CodegenCx;
use rustc::hir::def_id::DefId;
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty};
// any caching, i.e. calling the function twice with the same type will also do
// the work twice. The `qualified` parameter only affects the first level of the
// type name, further levels (i.e. type parameters) are always fully qualified.
-pub fn compute_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+pub fn compute_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
t: Ty<'tcx>,
qualified: bool)
-> String {
// Pushes the name of the type as it should be stored in debuginfo on the
// `output` String. See also compute_debuginfo_type_name().
-pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
t: Ty<'tcx>,
qualified: bool,
output: &mut String) {
}
}
- fn push_item_name(cx: &CrateContext,
+ fn push_item_name(cx: &CodegenCx,
def_id: DefId,
qualified: bool,
output: &mut String) {
// reconstructed for items from non-local crates. For local crates, this
// would be possible but with inlining and LTO we have to use the least
// common denominator - otherwise we would run into conflicts.
- fn push_type_params<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
+ fn push_type_params<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
substs: &Substs<'tcx>,
output: &mut String) {
if substs.types().next().is_none() {
use llvm;
use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor, DIArray};
-use common::{CrateContext};
+use common::{CodegenCx};
use syntax_pos::{self, Span};
use syntax::ast;
-pub fn is_node_local_to_unit(cx: &CrateContext, node_id: ast::NodeId) -> bool
+pub fn is_node_local_to_unit(cx: &CodegenCx, node_id: ast::NodeId) -> bool
{
// The is_local_to_unit flag indicates whether a function is local to the
// current compilation unit (i.e. if it is *static* in the C-sense). The
}
/// Return syntax_pos::Loc corresponding to the beginning of the span
-pub fn span_start(cx: &CrateContext, span: Span) -> syntax_pos::Loc {
+pub fn span_start(cx: &CodegenCx, span: Span) -> syntax_pos::Loc {
cx.sess().codemap().lookup_char_pos(span.lo())
}
#[inline]
-pub fn debug_context<'a, 'tcx>(cx: &'a CrateContext<'a, 'tcx>)
+pub fn debug_context<'a, 'tcx>(cx: &'a CodegenCx<'a, 'tcx>)
-> &'a CrateDebugContext<'tcx> {
cx.dbg_cx.as_ref().unwrap()
}
#[inline]
#[allow(non_snake_case)]
-pub fn DIB(cx: &CrateContext) -> DIBuilderRef {
+pub fn DIB(cx: &CodegenCx) -> DIBuilderRef {
cx.dbg_cx.as_ref().unwrap().builder
}
-pub fn get_namespace_for_item(cx: &CrateContext, def_id: DefId) -> DIScope {
+pub fn get_namespace_for_item(cx: &CodegenCx, def_id: DefId) -> DIScope {
item_namespace(cx, cx.tcx.parent(def_id)
.expect("get_namespace_for_item: missing parent?"))
}
use rustc_back::PanicStrategy;
use abi::{Abi, FnType};
use attributes;
-use context::CrateContext;
+use context::CodegenCx;
use common;
use type_::Type;
use value::Value;
///
/// If there’s a value with the same name already declared, the function will
/// return its ValueRef instead.
-pub fn declare_global(ccx: &CrateContext, name: &str, ty: Type) -> llvm::ValueRef {
+pub fn declare_global(ccx: &CodegenCx, name: &str, ty: Type) -> llvm::ValueRef {
debug!("declare_global(name={:?})", name);
let namebuf = CString::new(name).unwrap_or_else(|_|{
bug!("name {:?} contains an interior null byte", name)
///
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing ValueRef instead.
-fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty: Type) -> ValueRef {
+fn declare_raw_fn(ccx: &CodegenCx, name: &str, callconv: llvm::CallConv, ty: Type) -> ValueRef {
debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
let namebuf = CString::new(name).unwrap_or_else(|_|{
bug!("name {:?} contains an interior null byte", name)
///
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing ValueRef instead.
-pub fn declare_cfn(ccx: &CrateContext, name: &str, fn_type: Type) -> ValueRef {
+pub fn declare_cfn(ccx: &CodegenCx, name: &str, fn_type: Type) -> ValueRef {
declare_raw_fn(ccx, name, llvm::CCallConv, fn_type)
}
///
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing ValueRef instead.
-pub fn declare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
+pub fn declare_fn<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>, name: &str,
fn_type: Ty<'tcx>) -> ValueRef {
debug!("declare_rust_fn(name={:?}, fn_type={:?})", name, fn_type);
let sig = common::ty_fn_sig(ccx, fn_type);
/// return None if the name already has a definition associated with it. In that
/// case an error should be reported to the user, because it usually happens due
/// to user’s fault (e.g. misuse of #[no_mangle] or #[export_name] attributes).
-pub fn define_global(ccx: &CrateContext, name: &str, ty: Type) -> Option<ValueRef> {
+pub fn define_global(ccx: &CodegenCx, name: &str, ty: Type) -> Option<ValueRef> {
if get_defined_value(ccx, name).is_some() {
None
} else {
/// Use this function when you intend to define a function. This function will
/// return panic if the name already has a definition associated with it. This
/// can happen with #[no_mangle] or #[export_name], for example.
-pub fn define_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn define_fn<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
name: &str,
fn_type: Ty<'tcx>) -> ValueRef {
if get_defined_value(ccx, name).is_some() {
/// Use this function when you intend to define a function. This function will
/// return panic if the name already has a definition associated with it. This
/// can happen with #[no_mangle] or #[export_name], for example.
-pub fn define_internal_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn define_internal_fn<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
name: &str,
fn_type: Ty<'tcx>) -> ValueRef {
let llfn = define_fn(ccx, name, fn_type);
/// Get declared value by name.
-pub fn get_declared_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
+pub fn get_declared_value(ccx: &CodegenCx, name: &str) -> Option<ValueRef> {
debug!("get_declared_value(name={:?})", name);
let namebuf = CString::new(name).unwrap_or_else(|_|{
bug!("name {:?} contains an interior null byte", name)
/// Get defined or externally defined (AvailableExternally linkage) value by
/// name.
-pub fn get_defined_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
+pub fn get_defined_value(ccx: &CodegenCx, name: &str) -> Option<ValueRef> {
get_declared_value(ccx, name).and_then(|val|{
let declaration = unsafe {
llvm::LLVMIsDeclaration(val) != 0
use std::cmp::Ordering;
use std::iter;
-fn get_simple_intrinsic(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
+fn get_simple_intrinsic(ccx: &CodegenCx, name: &str) -> Option<ValueRef> {
let llvm_name = match name {
"sqrtf32" => "llvm.sqrt.f32",
"sqrtf64" => "llvm.sqrt.f64",
assert_eq!(x.len(), 1);
x.into_iter().next().unwrap()
}
- fn ty_to_type(ccx: &CrateContext, t: &intrinsics::Type) -> Vec<Type> {
+ fn ty_to_type(ccx: &CodegenCx, t: &intrinsics::Type) -> Vec<Type> {
use intrinsics::Type::*;
match *t {
Void => vec![Type::void(ccx)],
fn try_intrinsic<'a, 'tcx>(
bcx: &Builder<'a, 'tcx>,
- ccx: &CrateContext,
+ ccx: &CodegenCx,
func: ValueRef,
data: ValueRef,
local_ptr: ValueRef,
// writing, however, LLVM does not recommend the usage of these new instructions
// as the old ones are still more optimized.
fn trans_msvc_try<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
- ccx: &CrateContext,
+ ccx: &CodegenCx,
func: ValueRef,
data: ValueRef,
local_ptr: ValueRef,
// functions in play. By calling a shim we're guaranteed that our shim will have
// the right personality function.
fn trans_gnu_try<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
- ccx: &CrateContext,
+ ccx: &CodegenCx,
func: ValueRef,
data: ValueRef,
local_ptr: ValueRef,
// Helper function to give a Block to a closure to translate a shim function.
// This is currently primarily used for the `try` intrinsic functions above.
-fn gen_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn gen_fn<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
name: &str,
inputs: Vec<Ty<'tcx>>,
output: Ty<'tcx>,
// catch exceptions.
//
// This function is only generated once and is then cached.
-fn get_rust_try_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn get_rust_try_fn<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
trans: &mut for<'b> FnMut(Builder<'b, 'tcx>))
-> ValueRef {
if let Some(llfn) = ccx.rust_try_fn.get() {
// Returns None if the type is not an integer
// FIXME: there’s multiple of this functions, investigate using some of the already existing
// stuffs.
-fn int_type_width_signed(ty: Ty, ccx: &CrateContext) -> Option<(u64, bool)> {
+fn int_type_width_signed(ty: Ty, ccx: &CodegenCx) -> Option<(u64, bool)> {
match ty.sty {
ty::TyInt(t) => Some((match t {
ast::IntTy::Isize => {
/// The `trait_ref` encodes the erased self type. Hence if we are
/// making an object `Foo<Trait>` from a value of type `Foo<T>`, then
/// `trait_ref` would map `T:Trait`.
-pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn get_vtable<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
ty: Ty<'tcx>,
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>)
-> ValueRef
use abi::{self, Abi};
use callee;
use builder::Builder;
-use common::{self, CrateContext, const_get_elt, val_ty};
+use common::{self, CodegenCx, const_get_elt, val_ty};
use common::{C_array, C_bool, C_bytes, C_int, C_uint, C_uint_big, C_u32, C_u64};
use common::{C_null, C_struct, C_str_slice, C_undef, C_usize, C_vector, C_fat_ptr};
use common::const_to_opt_u128;
}
}
- pub fn from_constint(ccx: &CrateContext<'a, 'tcx>, ci: &ConstInt) -> Const<'tcx> {
+ pub fn from_constint(ccx: &CodegenCx<'a, 'tcx>, ci: &ConstInt) -> Const<'tcx> {
let tcx = ccx.tcx;
let (llval, ty) = match *ci {
I8(v) => (C_int(Type::i8(ccx), v as i64), tcx.types.i8),
}
/// Translate ConstVal into a LLVM constant value.
- pub fn from_constval(ccx: &CrateContext<'a, 'tcx>,
+ pub fn from_constval(ccx: &CodegenCx<'a, 'tcx>,
cv: &ConstVal,
ty: Ty<'tcx>)
-> Const<'tcx> {
Const::new(val, ty)
}
- fn get_field(&self, ccx: &CrateContext<'a, 'tcx>, i: usize) -> ValueRef {
+ fn get_field(&self, ccx: &CodegenCx<'a, 'tcx>, i: usize) -> ValueRef {
let layout = ccx.layout_of(self.ty);
let field = layout.field(ccx, i);
if field.is_zst() {
}
}
- fn get_pair(&self, ccx: &CrateContext<'a, 'tcx>) -> (ValueRef, ValueRef) {
+ fn get_pair(&self, ccx: &CodegenCx<'a, 'tcx>) -> (ValueRef, ValueRef) {
(self.get_field(ccx, 0), self.get_field(ccx, 1))
}
- fn get_fat_ptr(&self, ccx: &CrateContext<'a, 'tcx>) -> (ValueRef, ValueRef) {
+ fn get_fat_ptr(&self, ccx: &CodegenCx<'a, 'tcx>) -> (ValueRef, ValueRef) {
assert_eq!(abi::FAT_PTR_ADDR, 0);
assert_eq!(abi::FAT_PTR_EXTRA, 1);
self.get_pair(ccx)
}
}
- pub fn to_operand(&self, ccx: &CrateContext<'a, 'tcx>) -> OperandRef<'tcx> {
+ pub fn to_operand(&self, ccx: &CodegenCx<'a, 'tcx>) -> OperandRef<'tcx> {
let layout = ccx.layout_of(self.ty);
let llty = layout.immediate_llvm_type(ccx);
let llvalty = val_ty(self.llval);
}
}
- pub fn len<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> ValueRef {
+ pub fn len<'a>(&self, ccx: &CodegenCx<'a, 'tcx>) -> ValueRef {
match self.ty.sty {
ty::TyArray(_, n) => {
C_usize(ccx, n.val.to_const_int().unwrap().to_u64().unwrap())
/// Machinery for translating a constant's MIR to LLVM values.
/// FIXME(eddyb) use miri and lower its allocations to LLVM.
struct MirConstContext<'a, 'tcx: 'a> {
- ccx: &'a CrateContext<'a, 'tcx>,
+ ccx: &'a CodegenCx<'a, 'tcx>,
mir: &'a mir::Mir<'tcx>,
/// Type parameters for const fn and associated constants.
}
impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
- fn new(ccx: &'a CrateContext<'a, 'tcx>,
+ fn new(ccx: &'a CodegenCx<'a, 'tcx>,
mir: &'a mir::Mir<'tcx>,
substs: &'tcx Substs<'tcx>,
args: IndexVec<mir::Local, Result<Const<'tcx>, ConstEvalErr<'tcx>>>)
context
}
- fn trans_def(ccx: &'a CrateContext<'a, 'tcx>,
+ fn trans_def(ccx: &'a CodegenCx<'a, 'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>,
args: IndexVec<mir::Local, Result<Const<'tcx>, ConstEvalErr<'tcx>>>)
}
}
-unsafe fn cast_const_float_to_int(ccx: &CrateContext,
+unsafe fn cast_const_float_to_int(ccx: &CodegenCx,
operand: &Const,
signed: bool,
int_ty: Type,
C_uint_big(int_ty, cast_result.value)
}
-unsafe fn cast_const_int_to_float(ccx: &CrateContext,
+unsafe fn cast_const_int_to_float(ccx: &CodegenCx,
llval: ValueRef,
signed: bool,
float_ty: Type) -> ValueRef {
pub fn trans_static_initializer<'a, 'tcx>(
- ccx: &CrateContext<'a, 'tcx>,
+ ccx: &CodegenCx<'a, 'tcx>,
def_id: DefId)
-> Result<ValueRef, ConstEvalErr<'tcx>>
{
/// this could be changed in the future to avoid allocating unnecessary
/// space after values of shorter-than-maximum cases.
fn trans_const_adt<'a, 'tcx>(
- ccx: &CrateContext<'a, 'tcx>,
+ ccx: &CodegenCx<'a, 'tcx>,
t: Ty<'tcx>,
kind: &mir::AggregateKind,
vals: &[Const<'tcx>]
/// initializer is 4-byte aligned then simply translating the tuple as
/// a two-element struct will locate it at offset 4, and accesses to it
/// will read the wrong memory.
-fn build_const_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn build_const_struct<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
layout: layout::TyLayout<'tcx>,
vals: &[Const<'tcx>],
discr: Option<Const<'tcx>>)
Const::new(C_struct(ccx, &cfields, packed), layout.ty)
}
-fn padding(ccx: &CrateContext, size: Size) -> ValueRef {
+fn padding(ccx: &CodegenCx, size: Size) -> ValueRef {
C_undef(Type::array(&Type::i8(ccx), size.bytes()))
}
use rustc::session::config::FullDebugInfo;
use base;
use builder::Builder;
-use common::{CrateContext, Funclet};
+use common::{CodegenCx, Funclet};
use debuginfo::{self, declare_local, VariableAccess, VariableKind, FunctionDebugContext};
use monomorphize::Instance;
use abi::{ArgAttribute, FnType, PassMode};
llfn: ValueRef,
- ccx: &'a CrateContext<'a, 'tcx>,
+ ccx: &'a CodegenCx<'a, 'tcx>,
fn_ty: FnType<'tcx>,
}
impl<'a, 'tcx> LocalRef<'tcx> {
- fn new_operand(ccx: &CrateContext<'a, 'tcx>, layout: TyLayout<'tcx>) -> LocalRef<'tcx> {
+ fn new_operand(ccx: &CodegenCx<'a, 'tcx>, layout: TyLayout<'tcx>) -> LocalRef<'tcx> {
if layout.is_zst() {
// Zero-size temporaries aren't always initialized, which
// doesn't matter because they don't contain data, but
///////////////////////////////////////////////////////////////////////////
pub fn trans_mir<'a, 'tcx: 'a>(
- ccx: &'a CrateContext<'a, 'tcx>,
+ ccx: &'a CodegenCx<'a, 'tcx>,
llfn: ValueRef,
mir: &'a Mir<'tcx>,
instance: Instance<'tcx>,
use rustc_data_structures::indexed_vec::Idx;
use base;
-use common::{self, CrateContext, C_undef, C_usize};
+use common::{self, CodegenCx, C_undef, C_usize};
use builder::Builder;
use value::Value;
use type_of::LayoutLlvmExt;
}
impl<'a, 'tcx> OperandRef<'tcx> {
- pub fn new_zst(ccx: &CrateContext<'a, 'tcx>,
+ pub fn new_zst(ccx: &CodegenCx<'a, 'tcx>,
layout: TyLayout<'tcx>) -> OperandRef<'tcx> {
assert!(layout.is_zst());
OperandRef {
}
}
- pub fn deref(self, ccx: &CrateContext<'a, 'tcx>) -> PlaceRef<'tcx> {
+ pub fn deref(self, ccx: &CodegenCx<'a, 'tcx>) -> PlaceRef<'tcx> {
let projected_ty = self.layout.ty.builtin_deref(true, ty::NoPreference)
.unwrap_or_else(|| bug!("deref of non-pointer {:?}", self)).ty;
let (llptr, llextra) = match self.val {
use rustc_data_structures::indexed_vec::Idx;
use base;
use builder::Builder;
-use common::{CrateContext, C_usize, C_u8, C_u32, C_uint, C_int, C_null, C_uint_big};
+use common::{CodegenCx, C_usize, C_u8, C_u32, C_uint, C_int, C_null, C_uint_big};
use consts;
use type_of::LayoutLlvmExt;
use type_::Type;
Self::new_sized(tmp, layout, layout.align)
}
- pub fn len(&self, ccx: &CrateContext<'a, 'tcx>) -> ValueRef {
+ pub fn len(&self, ccx: &CodegenCx<'a, 'tcx>) -> ValueRef {
if let layout::FieldPlacement::Array { count, .. } = self.layout.fields {
if self.layout.is_unsized() {
assert!(self.has_extra());
use attributes;
use base;
use consts;
-use context::CrateContext;
+use context::CodegenCx;
use declare;
use llvm;
use monomorphize::Instance;
pub use rustc_mir::monomorphize::item::MonoItemExt as BaseMonoItemExt;
pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
- fn define(&self, ccx: &CrateContext<'a, 'tcx>) {
+ fn define(&self, ccx: &CodegenCx<'a, 'tcx>) {
debug!("BEGIN IMPLEMENTING '{} ({})' in cgu {}",
self.to_string(ccx.tcx),
self.to_raw_string(),
}
fn predefine(&self,
- ccx: &CrateContext<'a, 'tcx>,
+ ccx: &CodegenCx<'a, 'tcx>,
linkage: Linkage,
visibility: Visibility) {
debug!("BEGIN PREDEFINING '{} ({})' in cgu {}",
impl<'a, 'tcx> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {}
-fn predefine_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn predefine_static<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
node_id: ast::NodeId,
linkage: Linkage,
visibility: Visibility,
ccx.statics.borrow_mut().insert(g, def_id);
}
-fn predefine_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn predefine_fn<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
instance: Instance<'tcx>,
linkage: Linkage,
visibility: Visibility,
use llvm::{ContextRef, TypeRef, Bool, False, True, TypeKind};
use llvm::{Float, Double, X86_FP80, PPC_FP128, FP128};
-use context::CrateContext;
+use context::CodegenCx;
use syntax::ast;
use rustc::ty::layout::{self, Align, Size};
unsafe { mem::transmute(slice) }
}
- pub fn void(ccx: &CrateContext) -> Type {
+ pub fn void(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMVoidTypeInContext(ccx.llcx))
}
- pub fn metadata(ccx: &CrateContext) -> Type {
+ pub fn metadata(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMRustMetadataTypeInContext(ccx.llcx))
}
- pub fn i1(ccx: &CrateContext) -> Type {
+ pub fn i1(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMInt1TypeInContext(ccx.llcx))
}
- pub fn i8(ccx: &CrateContext) -> Type {
+ pub fn i8(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMInt8TypeInContext(ccx.llcx))
}
ty!(llvm::LLVMInt8TypeInContext(llcx))
}
- pub fn i16(ccx: &CrateContext) -> Type {
+ pub fn i16(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMInt16TypeInContext(ccx.llcx))
}
- pub fn i32(ccx: &CrateContext) -> Type {
+ pub fn i32(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMInt32TypeInContext(ccx.llcx))
}
- pub fn i64(ccx: &CrateContext) -> Type {
+ pub fn i64(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMInt64TypeInContext(ccx.llcx))
}
- pub fn i128(ccx: &CrateContext) -> Type {
+ pub fn i128(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMIntTypeInContext(ccx.llcx, 128))
}
// Creates an integer type with the given number of bits, e.g. i24
- pub fn ix(ccx: &CrateContext, num_bits: u64) -> Type {
+ pub fn ix(ccx: &CodegenCx, num_bits: u64) -> Type {
ty!(llvm::LLVMIntTypeInContext(ccx.llcx, num_bits as c_uint))
}
- pub fn f32(ccx: &CrateContext) -> Type {
+ pub fn f32(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMFloatTypeInContext(ccx.llcx))
}
- pub fn f64(ccx: &CrateContext) -> Type {
+ pub fn f64(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMDoubleTypeInContext(ccx.llcx))
}
- pub fn bool(ccx: &CrateContext) -> Type {
+ pub fn bool(ccx: &CodegenCx) -> Type {
Type::i8(ccx)
}
- pub fn char(ccx: &CrateContext) -> Type {
+ pub fn char(ccx: &CodegenCx) -> Type {
Type::i32(ccx)
}
- pub fn i8p(ccx: &CrateContext) -> Type {
+ pub fn i8p(ccx: &CodegenCx) -> Type {
Type::i8(ccx).ptr_to()
}
Type::i8_llcx(llcx).ptr_to()
}
- pub fn isize(ccx: &CrateContext) -> Type {
+ pub fn isize(ccx: &CodegenCx) -> Type {
match &ccx.tcx.sess.target.target.target_pointer_width[..] {
"16" => Type::i16(ccx),
"32" => Type::i32(ccx),
}
}
- pub fn c_int(ccx: &CrateContext) -> Type {
+ pub fn c_int(ccx: &CodegenCx) -> Type {
match &ccx.tcx.sess.target.target.target_c_int_width[..] {
"16" => Type::i16(ccx),
"32" => Type::i32(ccx),
}
}
- pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type {
+ pub fn int_from_ty(ccx: &CodegenCx, t: ast::IntTy) -> Type {
match t {
ast::IntTy::Isize => ccx.isize_ty,
ast::IntTy::I8 => Type::i8(ccx),
}
}
- pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type {
+ pub fn uint_from_ty(ccx: &CodegenCx, t: ast::UintTy) -> Type {
match t {
ast::UintTy::Usize => ccx.isize_ty,
ast::UintTy::U8 => Type::i8(ccx),
}
}
- pub fn float_from_ty(ccx: &CrateContext, t: ast::FloatTy) -> Type {
+ pub fn float_from_ty(ccx: &CodegenCx, t: ast::FloatTy) -> Type {
match t {
ast::FloatTy::F32 => Type::f32(ccx),
ast::FloatTy::F64 => Type::f64(ccx),
args.len() as c_uint, True))
}
- pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type {
+ pub fn struct_(ccx: &CodegenCx, els: &[Type], packed: bool) -> Type {
let els: &[TypeRef] = Type::to_ref_slice(els);
ty!(llvm::LLVMStructTypeInContext(ccx.llcx, els.as_ptr(),
els.len() as c_uint,
packed as Bool))
}
- pub fn named_struct(ccx: &CrateContext, name: &str) -> Type {
+ pub fn named_struct(ccx: &CodegenCx, name: &str) -> Type {
let name = CString::new(name).unwrap();
ty!(llvm::LLVMStructCreateNamed(ccx.llcx, name.as_ptr()))
}
}
}
- pub fn from_integer(cx: &CrateContext, i: layout::Integer) -> Type {
+ pub fn from_integer(cx: &CodegenCx, i: layout::Integer) -> Type {
use rustc::ty::layout::Integer::*;
match i {
I8 => Type::i8(cx),
/// Return a LLVM type that has at most the required alignment,
/// as a conservative approximation for unknown pointee types.
- pub fn pointee_for_abi_align(ccx: &CrateContext, align: Align) -> Type {
+ pub fn pointee_for_abi_align(ccx: &CodegenCx, align: Align) -> Type {
// FIXME(eddyb) We could find a better approximation if ity.align < align.
let ity = layout::Integer::approximate_abi_align(ccx, align);
Type::from_integer(ccx, ity)
/// Return a LLVM type that has at most the required alignment,
/// and exactly the required size, as a best-effort padding array.
- pub fn padding_filler(ccx: &CrateContext, size: Size, align: Align) -> Type {
+ pub fn padding_filler(ccx: &CodegenCx, size: Size, align: Align) -> Type {
let unit = layout::Integer::approximate_abi_align(ccx, align);
let size = size.bytes();
let unit_size = unit.size().bytes();
Type::array(&Type::from_integer(ccx, unit), size / unit_size)
}
- pub fn x86_mmx(ccx: &CrateContext) -> Type {
+ pub fn x86_mmx(ccx: &CodegenCx) -> Type {
ty!(llvm::LLVMX86MMXTypeInContext(ccx.llcx))
}
}
use std::fmt::Write;
-fn uncached_llvm_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn uncached_llvm_type<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
layout: TyLayout<'tcx>,
defer: &mut Option<(Type, TyLayout<'tcx>)>)
-> Type {
}
}
-fn struct_llfields<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+fn struct_llfields<'a, 'tcx>(ccx: &CodegenCx<'a, 'tcx>,
layout: TyLayout<'tcx>)
-> (Vec<Type>, bool) {
debug!("struct_llfields: {:#?}", layout);
(result, packed)
}
-impl<'a, 'tcx> CrateContext<'a, 'tcx> {
+impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
pub fn align_of(&self, ty: Ty<'tcx>) -> Align {
self.layout_of(ty).align
}
pub trait LayoutLlvmExt<'tcx> {
fn is_llvm_immediate(&self) -> bool;
fn is_llvm_scalar_pair<'a>(&self) -> bool;
- fn llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type;
- fn immediate_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type;
- fn scalar_llvm_type_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
+ fn llvm_type<'a>(&self, ccx: &CodegenCx<'a, 'tcx>) -> Type;
+ fn immediate_llvm_type<'a>(&self, ccx: &CodegenCx<'a, 'tcx>) -> Type;
+ fn scalar_llvm_type_at<'a>(&self, ccx: &CodegenCx<'a, 'tcx>,
scalar: &layout::Scalar, offset: Size) -> Type;
- fn scalar_pair_element_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
+ fn scalar_pair_element_llvm_type<'a>(&self, ccx: &CodegenCx<'a, 'tcx>,
index: usize) -> Type;
fn llvm_field_index(&self, index: usize) -> u64;
- fn pointee_info_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>, offset: Size)
+ fn pointee_info_at<'a>(&self, ccx: &CodegenCx<'a, 'tcx>, offset: Size)
-> Option<PointeeInfo>;
}
/// with the inner-most trailing unsized field using the "minimal unit"
/// of that field's type - this is useful for taking the address of
/// that field and ensuring the struct has the right alignment.
- fn llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
+ fn llvm_type<'a>(&self, ccx: &CodegenCx<'a, 'tcx>) -> Type {
if let layout::Abi::Scalar(ref scalar) = self.abi {
// Use a different cache for scalars because pointers to DSTs
// can be either fat or thin (data pointers of fat pointers).
llty
}
- fn immediate_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
+ fn immediate_llvm_type<'a>(&self, ccx: &CodegenCx<'a, 'tcx>) -> Type {
if let layout::Abi::Scalar(ref scalar) = self.abi {
if scalar.is_bool() {
return Type::i1(ccx);
self.llvm_type(ccx)
}
- fn scalar_llvm_type_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
+ fn scalar_llvm_type_at<'a>(&self, ccx: &CodegenCx<'a, 'tcx>,
scalar: &layout::Scalar, offset: Size) -> Type {
match scalar.value {
layout::Int(i, _) => Type::from_integer(ccx, i),
}
}
- fn scalar_pair_element_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
+ fn scalar_pair_element_llvm_type<'a>(&self, ccx: &CodegenCx<'a, 'tcx>,
index: usize) -> Type {
// HACK(eddyb) special-case fat pointers until LLVM removes
// pointee types, to avoid bitcasting every `OperandRef::deref`.
}
}
- fn pointee_info_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>, offset: Size)
+ fn pointee_info_at<'a>(&self, ccx: &CodegenCx<'a, 'tcx>, offset: Size)
-> Option<PointeeInfo> {
if let Some(&pointee) = ccx.pointee_infos.borrow().get(&(self.ty, offset)) {
return pointee;