Skip to main content

rustc_codegen_ssa/traits/
asm.rs

1use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
2use rustc_hir::def_id::DefId;
3use rustc_middle::mir::interpret::Scalar;
4use rustc_middle::ty::{Instance, Ty};
5use rustc_span::Span;
6use rustc_target::asm::InlineAsmRegOrRegClass;
7
8use super::BackendTypes;
9use crate::mir::operand::OperandRef;
10use crate::mir::place::PlaceRef;
11
12#[derive(#[automatically_derived]
impl<'tcx, B: ::core::fmt::Debug + BackendTypes + ?Sized> ::core::fmt::Debug
    for InlineAsmOperandRef<'tcx, B> where B::Value: ::core::fmt::Debug,
    B::Value: ::core::fmt::Debug, B::Value: ::core::fmt::Debug,
    B::Value: ::core::fmt::Debug, B::BasicBlock: ::core::fmt::Debug {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            InlineAsmOperandRef::In { reg: __self_0, value: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f, "In",
                    "reg", __self_0, "value", &__self_1),
            InlineAsmOperandRef::Out {
                reg: __self_0, late: __self_1, place: __self_2 } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f, "Out",
                    "reg", __self_0, "late", __self_1, "place", &__self_2),
            InlineAsmOperandRef::InOut {
                reg: __self_0,
                late: __self_1,
                in_value: __self_2,
                out_place: __self_3 } =>
                ::core::fmt::Formatter::debug_struct_field4_finish(f, "InOut",
                    "reg", __self_0, "late", __self_1, "in_value", __self_2,
                    "out_place", &__self_3),
            InlineAsmOperandRef::Const { value: __self_0, ty: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f, "Const",
                    "value", __self_0, "ty", &__self_1),
            InlineAsmOperandRef::SymThreadLocalStatic { def_id: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "SymThreadLocalStatic", "def_id", &__self_0),
            InlineAsmOperandRef::Label { label: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Label",
                    "label", &__self_0),
        }
    }
}Debug)]
13pub enum InlineAsmOperandRef<'tcx, B: BackendTypes + ?Sized> {
14    In {
15        reg: InlineAsmRegOrRegClass,
16        value: OperandRef<'tcx, B::Value>,
17    },
18    Out {
19        reg: InlineAsmRegOrRegClass,
20        late: bool,
21        place: Option<PlaceRef<'tcx, B::Value>>,
22    },
23    InOut {
24        reg: InlineAsmRegOrRegClass,
25        late: bool,
26        in_value: OperandRef<'tcx, B::Value>,
27        out_place: Option<PlaceRef<'tcx, B::Value>>,
28    },
29    Const {
30        value: Scalar,
31        /// Type of the constant. This is needed to extract width and signedness.
32        ty: Ty<'tcx>,
33    },
34    SymThreadLocalStatic {
35        def_id: DefId,
36    },
37    Label {
38        label: B::BasicBlock,
39    },
40}
41
42#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for GlobalAsmOperandRef<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            GlobalAsmOperandRef::Const { value: __self_0, ty: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f, "Const",
                    "value", __self_0, "ty", &__self_1),
            GlobalAsmOperandRef::SymThreadLocalStatic { def_id: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "SymThreadLocalStatic", "def_id", &__self_0),
        }
    }
}Debug)]
43pub enum GlobalAsmOperandRef<'tcx> {
44    Const {
45        value: Scalar,
46        /// Type of the constant. This is needed to extract width and signedness.
47        ty: Ty<'tcx>,
48    },
49    SymThreadLocalStatic {
50        def_id: DefId,
51    },
52}
53
54pub trait AsmBuilderMethods<'tcx>: BackendTypes {
55    /// Take an inline assembly expression and splat it out via LLVM
56    fn codegen_inline_asm(
57        &mut self,
58        template: &[InlineAsmTemplatePiece],
59        operands: &[InlineAsmOperandRef<'tcx, Self>],
60        options: InlineAsmOptions,
61        line_spans: &[Span],
62        instance: Instance<'_>,
63        dest: Option<Self::BasicBlock>,
64        catch_funclet: Option<(Self::BasicBlock, Option<&Self::Funclet>)>,
65    );
66}
67
68pub trait AsmCodegenMethods<'tcx> {
69    fn codegen_global_asm(
70        &mut self,
71        template: &[InlineAsmTemplatePiece],
72        operands: &[GlobalAsmOperandRef<'tcx>],
73        options: InlineAsmOptions,
74        line_spans: &[Span],
75    );
76
77    /// The mangled name of this instance
78    ///
79    /// Additional mangling is used on
80    /// some targets to add a leading underscore (Mach-O)
81    /// or byte count suffixes (x86 Windows).
82    fn mangled_name(&self, instance: Instance<'tcx>) -> String;
83}