X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc%2Fmiddle%2Ftrans%2Fbuilder.rs;h=a9c1adac3d7cf01e07c3926d4706708e8a087367;hb=68ead460f9029fd8de508a46fe944afb83e99da3;hp=a02453a2554f4e4acdf1516851c8d07009358069;hpb=7b6e7ebe73b5f046faa81406ed58866364f6cfee;p=rust.git diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index a02453a2554..a9c1adac3d7 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -19,9 +19,9 @@ use middle::trans::common::*; use middle::trans::machine::llalign_of_pref; use middle::trans::type_::Type; -use collections::HashMap; +use std::collections::HashMap; use libc::{c_uint, c_ulonglong, c_char}; -use std::strbuf::StrBuf; +use std::string::String; use syntax::codemap::Span; pub struct Builder<'a> { @@ -31,9 +31,9 @@ pub struct Builder<'a> { // This is a really awful way to get a zero-length c-string, but better (and a // lot more efficient) than doing str::as_c_str("", ...) every time. -pub fn noname() -> *c_char { +pub fn noname() -> *const c_char { static cnull: c_char = 0; - &cnull as *c_char + &cnull as *const c_char } impl<'a> Builder<'a> { @@ -69,7 +69,7 @@ pub fn count_insn(&self, category: &str) { // Pass 2: concat strings for each elt, skipping // forwards over any cycles by advancing to rightmost // occurrence of each element in path. - let mut s = StrBuf::from_str("."); + let mut s = String::from_str("."); i = 0u; while i < len { i = *mm.get(&v[i]); @@ -81,8 +81,7 @@ pub fn count_insn(&self, category: &str) { s.push_char('/'); s.push_str(category); - let s = s.into_owned(); - let n = match h.find_equiv(&s) { + let n = match h.find(&s) { Some(&n) => n, _ => 0u }; @@ -157,9 +156,17 @@ pub fn invoke(&self, args: &[ValueRef], then: BasicBlockRef, catch: BasicBlockRef, - attributes: &[(uint, lib::llvm::Attribute)]) + attributes: &[(uint, u64)]) -> ValueRef { self.count_insn("invoke"); + + debug!("Invoke {} with args ({})", + self.ccx.tn.val_to_str(llfn), + args.iter() + .map(|&v| self.ccx.tn.val_to_str(v)) + .collect::>() + .connect(", ")); + unsafe { let v = llvm::LLVMBuildInvoke(self.llbuilder, llfn, @@ -169,7 +176,7 @@ pub fn invoke(&self, catch, noname()); for &(idx, attr) in attributes.iter() { - llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr as c_uint); + llvm::LLVMAddCallSiteAttribute(v, idx as c_uint, attr); } v } @@ -565,14 +572,14 @@ pub fn struct_gep(&self, ptr: ValueRef, idx: uint) -> ValueRef { } } - pub fn global_string(&self, _str: *c_char) -> ValueRef { + pub fn global_string(&self, _str: *const c_char) -> ValueRef { self.count_insn("globalstring"); unsafe { llvm::LLVMBuildGlobalString(self.llbuilder, _str, noname()) } } - pub fn global_string_ptr(&self, _str: *c_char) -> ValueRef { + pub fn global_string_ptr(&self, _str: *const c_char) -> ValueRef { self.count_insn("globalstringptr"); unsafe { llvm::LLVMBuildGlobalStringPtr(self.llbuilder, _str, noname()) @@ -751,18 +758,21 @@ pub fn phi(&self, ty: Type, vals: &[ValueRef], bbs: &[BasicBlockRef]) -> ValueRe pub fn add_span_comment(&self, sp: Span, text: &str) { if self.ccx.sess().asm_comments() { - let s = format!("{} ({})", text, self.ccx.sess().codemap().span_to_str(sp)); - debug!("{}", s); - self.add_comment(s); + let s = format!("{} ({})", + text, + self.ccx.sess().codemap().span_to_str(sp)); + debug!("{}", s.as_slice()); + self.add_comment(s.as_slice()); } } pub fn add_comment(&self, text: &str) { if self.ccx.sess().asm_comments() { let sanitized = text.replace("$", ""); - let comment_text = format!("\\# {}", sanitized.replace("\n", "\n\t# ")); + let comment_text = format!("{} {}", "#", + sanitized.replace("\n", "\n\t# ")); self.count_insn("inlineasm"); - let asm = comment_text.with_c_str(|c| { + let asm = comment_text.as_slice().with_c_str(|c| { unsafe { llvm::LLVMConstInlineAsm(Type::func([], &Type::void(self.ccx)).to_ref(), c, noname(), False, False) @@ -772,7 +782,7 @@ pub fn add_comment(&self, text: &str) { } } - pub fn inline_asm_call(&self, asm: *c_char, cons: *c_char, + pub fn inline_asm_call(&self, asm: *const c_char, cons: *const c_char, inputs: &[ValueRef], output: Type, volatile: bool, alignstack: bool, dia: AsmDialect) -> ValueRef { @@ -798,28 +808,28 @@ pub fn inline_asm_call(&self, asm: *c_char, cons: *c_char, } pub fn call(&self, llfn: ValueRef, args: &[ValueRef], - attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef { + attributes: &[(uint, u64)]) -> ValueRef { self.count_insn("call"); debug!("Call {} with args ({})", self.ccx.tn.val_to_str(llfn), args.iter() .map(|&v| self.ccx.tn.val_to_str(v)) - .collect::>() + .collect::>() .connect(", ")); unsafe { let v = llvm::LLVMBuildCall(self.llbuilder, llfn, args.as_ptr(), args.len() as c_uint, noname()); for &(idx, attr) in attributes.iter() { - llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr as c_uint); + llvm::LLVMAddCallSiteAttribute(v, idx as c_uint, attr); } v } } pub fn call_with_conv(&self, llfn: ValueRef, args: &[ValueRef], - conv: CallConv, attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef { + conv: CallConv, attributes: &[(uint, u64)]) -> ValueRef { self.count_insn("callwithconv"); let v = self.call(llfn, args, attributes); lib::llvm::SetInstructionCallConv(v, conv);