special case TyAndLayout
debug impl
This commit is contained in:
parent
06a76ab415
commit
71cab64079
4 changed files with 53 additions and 19 deletions
|
@ -2,6 +2,7 @@ use crate::abi::{self, Abi, Align, FieldsShape, Size};
|
|||
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
|
||||
use crate::spec::{self, HasTargetSpec};
|
||||
use rustc_span::Symbol;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
mod aarch64;
|
||||
|
@ -515,12 +516,20 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
|
|||
|
||||
/// Information about how to pass an argument to,
|
||||
/// or return a value from, a function, under some ABI.
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash, HashStable_Generic)]
|
||||
pub struct ArgAbi<'a, Ty> {
|
||||
pub layout: TyAndLayout<'a, Ty>,
|
||||
pub mode: PassMode,
|
||||
}
|
||||
|
||||
// Needs to be a custom impl because of the bounds on the `TyAndLayout` debug impl.
|
||||
impl<'a, Ty: fmt::Display> fmt::Debug for ArgAbi<'a, Ty> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let ArgAbi { layout, mode } = self;
|
||||
f.debug_struct("ArgAbi").field("layout", layout).field("mode", mode).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ty> ArgAbi<'a, Ty> {
|
||||
/// This defines the "default ABI" for that type, that is then later adjusted in `fn_abi_adjust_for_abi`.
|
||||
pub fn new(
|
||||
|
@ -694,7 +703,7 @@ impl RiscvInterruptKind {
|
|||
///
|
||||
/// I will do my best to describe this structure, but these
|
||||
/// comments are reverse-engineered and may be inaccurate. -NDM
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash, HashStable_Generic)]
|
||||
pub struct FnAbi<'a, Ty> {
|
||||
/// The LLVM types of each argument.
|
||||
pub args: Box<[ArgAbi<'a, Ty>]>,
|
||||
|
@ -715,6 +724,21 @@ pub struct FnAbi<'a, Ty> {
|
|||
pub can_unwind: bool,
|
||||
}
|
||||
|
||||
// Needs to be a custom impl because of the bounds on the `TyAndLayout` debug impl.
|
||||
impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let FnAbi { args, ret, c_variadic, fixed_count, conv, can_unwind } = self;
|
||||
f.debug_struct("FnAbi")
|
||||
.field("args", args)
|
||||
.field("ret", ret)
|
||||
.field("c_variadic", c_variadic)
|
||||
.field("fixed_count", fixed_count)
|
||||
.field("conv", conv)
|
||||
.field("can_unwind", can_unwind)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
|
||||
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||
pub enum AdjustForForeignAbiError {
|
||||
|
|
|
@ -3,6 +3,7 @@ pub use Primitive::*;
|
|||
|
||||
use crate::json::{Json, ToJson};
|
||||
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
use rustc_macros::HashStable_Generic;
|
||||
|
@ -24,12 +25,22 @@ impl ToJson for Endian {
|
|||
/// to that obtained from `layout_of(ty)`, as we need to produce
|
||||
/// layouts for which Rust types do not exist, such as enum variants
|
||||
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
|
||||
pub struct TyAndLayout<'a, Ty> {
|
||||
pub ty: Ty,
|
||||
pub layout: Layout<'a>,
|
||||
}
|
||||
|
||||
impl<'a, Ty: fmt::Display> fmt::Debug for TyAndLayout<'a, Ty> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// Print the type in a readable way, not its debug representation.
|
||||
f.debug_struct("TyAndLayout")
|
||||
.field("ty", &format_args!("{}", self.ty))
|
||||
.field("layout", &self.layout)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {
|
||||
type Target = &'a LayoutS;
|
||||
fn deref(&self) -> &&'a LayoutS {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue