X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_codegen_llvm%2Fasm.rs;h=e816bdeb1c92cded3a49a8eaea49a353af67d96e;hb=a50a8967552d886a91b20fcd33310ad0f28857fd;hp=fa43e0829190b02f304ea1a670652033aa24d2b1;hpb=1c12dc8cdf36b62e93ce74cecc15f13e57f281d3;p=rust.git diff --git a/src/librustc_codegen_llvm/asm.rs b/src/librustc_codegen_llvm/asm.rs index fa43e082919..e816bdeb1c9 100644 --- a/src/librustc_codegen_llvm/asm.rs +++ b/src/librustc_codegen_llvm/asm.rs @@ -1,18 +1,18 @@ -use crate::llvm; +use crate::builder::Builder; use crate::context::CodegenCx; +use crate::llvm; use crate::type_of::LayoutLlvmExt; -use crate::builder::Builder; use crate::value::Value; -use rustc::hir; -use rustc_codegen_ssa::traits::*; -use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::mir::operand::OperandValue; -use syntax_pos::Span; +use rustc_codegen_ssa::mir::place::PlaceRef; +use rustc_codegen_ssa::traits::*; +use rustc_hir as hir; +use rustc_span::Span; -use std::ffi::{CStr, CString}; -use libc::{c_uint, c_char}; +use libc::{c_char, c_uint}; use log::debug; +use std::ffi::{CStr, CString}; impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { fn codegen_inline_asm( @@ -43,24 +43,26 @@ fn codegen_inline_asm( inputs = indirect_outputs; } - let clobbers = ia.clobbers.iter() - .map(|s| format!("~{{{}}}", &s)); + let clobbers = ia.clobbers.iter().map(|s| format!("~{{{}}}", &s)); // Default per-arch clobbers // Basically what clang does let arch_clobbers = match &self.sess().target.target.arch[..] { - "x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"], + "x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"], "mips" | "mips64" => vec!["~{$1}"], - _ => Vec::new() + _ => Vec::new(), }; - let all_constraints = - ia.outputs.iter().map(|out| out.constraint.to_string()) - .chain(ia.inputs.iter().map(|s| s.to_string())) - .chain(ext_constraints) - .chain(clobbers) - .chain(arch_clobbers.iter().map(|s| s.to_string())) - .collect::>().join(","); + let all_constraints = ia + .outputs + .iter() + .map(|out| out.constraint.to_string()) + .chain(ia.inputs.iter().map(|s| s.to_string())) + .chain(ext_constraints) + .chain(clobbers) + .chain(arch_clobbers.iter().map(|s| s.to_string())) + .collect::>() + .join(","); debug!("Asm Constraints: {}", &all_constraints); @@ -69,7 +71,7 @@ fn codegen_inline_asm( let output_type = match num_outputs { 0 => self.type_void(), 1 => output_types[0], - _ => self.type_struct(&output_types, false) + _ => self.type_struct(&output_types, false), }; let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap(); @@ -82,7 +84,7 @@ fn codegen_inline_asm( output_type, ia.volatile, ia.alignstack, - ia.dialect + ia.dialect, ); if r.is_none() { return false; @@ -100,13 +102,15 @@ fn codegen_inline_asm( // back to source locations. See #17552. unsafe { let key = "srcloc"; - let kind = llvm::LLVMGetMDKindIDInContext(self.llcx, - key.as_ptr() as *const c_char, key.len() as c_uint); + let kind = llvm::LLVMGetMDKindIDInContext( + self.llcx, + key.as_ptr() as *const c_char, + key.len() as c_uint, + ); let val: &'ll Value = self.const_i32(span.ctxt().outer_expn().as_u32() as i32); - llvm::LLVMSetMetadata(r, kind, - llvm::LLVMMDNodeInContext(self.llcx, &val, 1)); + llvm::LLVMSetMetadata(r, kind, llvm::LLVMMDNodeInContext(self.llcx, &val, 1)); } true @@ -132,15 +136,16 @@ fn inline_asm_call( alignstack: bool, dia: ::syntax::ast::AsmDialect, ) -> Option<&'ll Value> { - let volatile = if volatile { llvm::True } - else { llvm::False }; - let alignstack = if alignstack { llvm::True } - else { llvm::False }; - - let argtys = inputs.iter().map(|v| { - debug!("Asm Input Type: {:?}", *v); - bx.cx.val_ty(*v) - }).collect::>(); + let volatile = if volatile { llvm::True } else { llvm::False }; + let alignstack = if alignstack { llvm::True } else { llvm::False }; + + let argtys = inputs + .iter() + .map(|v| { + debug!("Asm Input Type: {:?}", *v); + bx.cx.val_ty(*v) + }) + .collect::>(); debug!("Asm Output Type: {:?}", output); let fty = bx.cx.type_func(&argtys[..], output);