Skip to main content

rustc_codegen_ssa/traits/
asm.rs

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