Fixed compile warnings.

Fixed whitespace "errors".
This commit is contained in:
Vadim Chugunov 2013-06-11 12:41:09 -07:00
parent 00bb15bf72
commit 62e86e044d
3 changed files with 96 additions and 95 deletions

View File

@ -966,10 +966,10 @@ pub mod llvm {
-> BasicBlockRef; -> BasicBlockRef;
#[fast_ffi] #[fast_ffi]
pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef); pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
#[fast_ffi] #[fast_ffi]
pub unsafe fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef, MoveAfter: BasicBlockRef); pub unsafe fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef, MoveAfter: BasicBlockRef);
#[fast_ffi] #[fast_ffi]
pub unsafe fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef, MoveBefore: BasicBlockRef); pub unsafe fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef, MoveBefore: BasicBlockRef);
@ -2072,13 +2072,13 @@ pub mod llvm {
Val: ValueRef, Val: ValueRef,
VarInfo: DIVariable, VarInfo: DIVariable,
InsertAtEnd: BasicBlockRef) -> ValueRef; InsertAtEnd: BasicBlockRef) -> ValueRef;
#[fast_ffi] #[fast_ffi]
pub unsafe fn LLVMDIBuilderInsertDeclareBefore( pub unsafe fn LLVMDIBuilderInsertDeclareBefore(
Builder: DIBuilderRef, Builder: DIBuilderRef,
Val: ValueRef, Val: ValueRef,
VarInfo: DIVariable, VarInfo: DIVariable,
InsertBefore: ValueRef) -> ValueRef; InsertBefore: ValueRef) -> ValueRef;
} }
} }

View File

@ -1907,7 +1907,7 @@ pub fn trans_closure(ccx: @mut CrateContext,
finish(bcx); finish(bcx);
cleanup_and_Br(bcx, bcx_top, fcx.llreturn); cleanup_and_Br(bcx, bcx_top, fcx.llreturn);
unsafe { llvm::LLVMMoveBasicBlockAfter(fcx.llreturn, bcx.llbb); } unsafe { llvm::LLVMMoveBasicBlockAfter(fcx.llreturn, bcx.llbb); }
// Insert the mandatory first few basic blocks before lltop. // Insert the mandatory first few basic blocks before lltop.

View File

@ -25,12 +25,10 @@ use core::hashmap::HashMap;
use core::libc; use core::libc;
use core::libc::c_uint; use core::libc::c_uint;
use core::ptr; use core::ptr;
use core::str;
use core::str::as_c_str; use core::str::as_c_str;
use core::sys; use core::sys;
use core::vec; use core::vec;
use syntax::codemap::span; use syntax::codemap::span;
use syntax::parse::token::ident_interner;
use syntax::{ast, codemap, ast_util, ast_map}; use syntax::{ast, codemap, ast_util, ast_map};
static LLVMDebugVersion: int = (12 << 16); static LLVMDebugVersion: int = (12 << 16);
@ -98,8 +96,8 @@ fn dbg_cx(cx: &CrateContext) -> DebugContext
} }
fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray { fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
return unsafe { return unsafe {
llvm::LLVMDIBuilderGetOrCreateArray(builder, vec::raw::to_ptr(arr), arr.len() as u32) llvm::LLVMDIBuilderGetOrCreateArray(builder, vec::raw::to_ptr(arr), arr.len() as u32)
}; };
} }
@ -108,7 +106,7 @@ pub fn finalize(cx: @CrateContext) {
debug!("finalize"); debug!("finalize");
create_compile_unit(cx); create_compile_unit(cx);
let dcx = dbg_cx(cx); let dcx = dbg_cx(cx);
unsafe { unsafe {
llvm::LLVMDIBuilderFinalize(dcx.builder); llvm::LLVMDIBuilderFinalize(dcx.builder);
llvm::LLVMDIBuilderDispose(dcx.builder); llvm::LLVMDIBuilderDispose(dcx.builder);
}; };
@ -118,14 +116,14 @@ fn create_compile_unit(cx: @CrateContext) {
let crate_name: &str = dbg_cx(cx).crate_file; let crate_name: &str = dbg_cx(cx).crate_file;
let work_dir = cx.sess.working_dir.to_str(); let work_dir = cx.sess.working_dir.to_str();
let producer = fmt!("rustc version %s", env!("CFG_VERSION")); let producer = fmt!("rustc version %s", env!("CFG_VERSION"));
do as_c_str(crate_name) |crate_name| { do as_c_str(crate_name) |crate_name| {
do as_c_str(work_dir) |work_dir| { do as_c_str(work_dir) |work_dir| {
do as_c_str(producer) |producer| { do as_c_str(producer) |producer| {
do as_c_str("") |flags| { do as_c_str("") |flags| {
do as_c_str("") |split_name| { unsafe { do as_c_str("") |split_name| { unsafe {
llvm::LLVMDIBuilderCreateCompileUnit(dbg_cx(cx).builder, llvm::LLVMDIBuilderCreateCompileUnit(dbg_cx(cx).builder,
DW_LANG_RUST as c_uint, crate_name, work_dir, producer, DW_LANG_RUST as c_uint, crate_name, work_dir, producer,
cx.sess.opts.optimize != session::No, cx.sess.opts.optimize != session::No,
flags, 0, split_name); flags, 0, split_name);
}}}}}}; }}}}}};
@ -133,28 +131,28 @@ fn create_compile_unit(cx: @CrateContext) {
fn create_file(cx: @CrateContext, full_path: &str) -> DIFile { fn create_file(cx: @CrateContext, full_path: &str) -> DIFile {
let dcx = dbg_cx(cx); let dcx = dbg_cx(cx);
match dcx.created_files.find_equiv(&full_path) { match dcx.created_files.find_equiv(&full_path) {
Some(file_md) => return *file_md, Some(file_md) => return *file_md,
None => () None => ()
} }
debug!("create_file: %s", full_path); debug!("create_file: %s", full_path);
let work_dir = cx.sess.working_dir.to_str(); let work_dir = cx.sess.working_dir.to_str();
let file_name = let file_name =
if full_path.starts_with(work_dir) { if full_path.starts_with(work_dir) {
full_path.slice(work_dir.len() + 1u, full_path.len()) full_path.slice(work_dir.len() + 1u, full_path.len())
} else { } else {
full_path full_path
}; };
let file_md = let file_md =
do as_c_str(file_name) |file_name| { do as_c_str(file_name) |file_name| {
do as_c_str(work_dir) |work_dir| { unsafe { do as_c_str(work_dir) |work_dir| { unsafe {
llvm::LLVMDIBuilderCreateFile(dcx.builder, file_name, work_dir) llvm::LLVMDIBuilderCreateFile(dcx.builder, file_name, work_dir)
}}}; }}};
dcx.created_files.insert(full_path.to_owned(), file_md); dcx.created_files.insert(full_path.to_owned(), file_md);
return file_md; return file_md;
} }
@ -166,8 +164,8 @@ fn span_start(cx: @CrateContext, span: span) -> codemap::Loc {
fn create_block(bcx: block) -> DILexicalBlock { fn create_block(bcx: block) -> DILexicalBlock {
let mut bcx = bcx; let mut bcx = bcx;
let cx = bcx.ccx(); let cx = bcx.ccx();
let mut dcx = dbg_cx(cx); let dcx = dbg_cx(cx);
while bcx.node_info.is_none() { while bcx.node_info.is_none() {
match bcx.parent { match bcx.parent {
Some(b) => bcx = b, Some(b) => bcx = b,
@ -176,14 +174,14 @@ fn create_block(bcx: block) -> DILexicalBlock {
} }
let span = bcx.node_info.get().span; let span = bcx.node_info.get().span;
let id = bcx.node_info.get().id; let id = bcx.node_info.get().id;
match dcx.created_blocks.find(&id) { match dcx.created_blocks.find(&id) {
Some(block) => return *block, Some(block) => return *block,
None => () None => ()
} }
debug!("create_block: %s", bcx.sess().codemap.span_to_str(span)); debug!("create_block: %s", bcx.sess().codemap.span_to_str(span));
let parent = match bcx.parent { let parent = match bcx.parent {
None => create_function(bcx.fcx), None => create_function(bcx.fcx),
Some(b) => create_block(b) Some(b) => create_block(b)
@ -191,16 +189,16 @@ fn create_block(bcx: block) -> DILexicalBlock {
let cx = bcx.ccx(); let cx = bcx.ccx();
let loc = span_start(cx, span); let loc = span_start(cx, span);
let file_md = create_file(cx, loc.file.name); let file_md = create_file(cx, loc.file.name);
let block_md = unsafe { let block_md = unsafe {
llvm::LLVMDIBuilderCreateLexicalBlock( llvm::LLVMDIBuilderCreateLexicalBlock(
dcx.builder, dcx.builder,
parent, file_md, parent, file_md,
loc.line as c_uint, loc.col.to_uint() as c_uint) loc.line as c_uint, loc.col.to_uint() as c_uint)
}; };
dcx.created_blocks.insert(id, block_md); dcx.created_blocks.insert(id, block_md);
return block_md; return block_md;
} }
@ -211,14 +209,14 @@ fn size_and_align_of(cx: @CrateContext, t: ty::t) -> (uint, uint) {
} }
fn create_basic_type(cx: @CrateContext, t: ty::t, span: span) -> DIType{ fn create_basic_type(cx: @CrateContext, t: ty::t, span: span) -> DIType{
let mut dcx = dbg_cx(cx); let dcx = dbg_cx(cx);
let ty_id = ty::type_id(t); let ty_id = ty::type_id(t);
match dcx.created_types.find(&ty_id) { match dcx.created_types.find(&ty_id) {
Some(ty_md) => return *ty_md, Some(ty_md) => return *ty_md,
None => () None => ()
} }
debug!("create_basic_type: %?", ty::get(t)); debug!("create_basic_type: %?", ty::get(t));
let (name, encoding) = match ty::get(t).sty { let (name, encoding) = match ty::get(t).sty {
ty::ty_nil | ty::ty_bot => (~"uint", DW_ATE_unsigned), ty::ty_nil | ty::ty_bot => (~"uint", DW_ATE_unsigned),
@ -249,10 +247,10 @@ fn create_basic_type(cx: @CrateContext, t: ty::t, span: span) -> DIType{
let (size, align) = size_and_align_of(cx, t); let (size, align) = size_and_align_of(cx, t);
let ty_md = do as_c_str(name) |name| { unsafe { let ty_md = do as_c_str(name) |name| { unsafe {
llvm::LLVMDIBuilderCreateBasicType( llvm::LLVMDIBuilderCreateBasicType(
dcx.builder, name, dcx.builder, name,
size * 8 as u64, align * 8 as u64, encoding as c_uint) size * 8 as u64, align * 8 as u64, encoding as c_uint)
}}; }};
dcx.created_types.insert(ty_id, ty_md); dcx.created_types.insert(ty_id, ty_md);
return ty_md; return ty_md;
} }
@ -261,7 +259,7 @@ fn create_pointer_type(cx: @CrateContext, t: ty::t, span: span, pointee: DIType)
let (size, align) = size_and_align_of(cx, t); let (size, align) = size_and_align_of(cx, t);
let name = ty_to_str(cx.tcx, t); let name = ty_to_str(cx.tcx, t);
let ptr_md = do as_c_str(name) |name| { unsafe { let ptr_md = do as_c_str(name) |name| { unsafe {
llvm::LLVMDIBuilderCreatePointerType(dbg_cx(cx).builder, llvm::LLVMDIBuilderCreatePointerType(dbg_cx(cx).builder,
pointee, size * 8 as u64, align * 8 as u64, name) pointee, size * 8 as u64, align * 8 as u64, name)
}}; }};
return ptr_md; return ptr_md;
@ -290,27 +288,27 @@ impl StructContext {
}; };
return scx; return scx;
} }
fn add_member(&mut self, name: &str, line: uint, size: uint, align: uint, ty: DIType) { fn add_member(&mut self, name: &str, line: uint, size: uint, align: uint, ty: DIType) {
let mem_t = do as_c_str(name) |name| { unsafe { let mem_t = do as_c_str(name) |name| { unsafe {
llvm::LLVMDIBuilderCreateMemberType(dbg_cx(self.cx).builder, llvm::LLVMDIBuilderCreateMemberType(dbg_cx(self.cx).builder,
ptr::null(), name, self.file, line as c_uint, ptr::null(), name, self.file, line as c_uint,
size * 8 as u64, align * 8 as u64, self.total_size as u64, size * 8 as u64, align * 8 as u64, self.total_size as u64,
0, ty) 0, ty)
}}; }};
// XXX What about member alignment??? // XXX What about member alignment???
self.members.push(mem_t); self.members.push(mem_t);
self.total_size += size * 8; self.total_size += size * 8;
} }
fn finalize(&self) -> DICompositeType { fn finalize(&self) -> DICompositeType {
let dcx = dbg_cx(self.cx); let dcx = dbg_cx(self.cx);
let members_md = create_DIArray(dcx.builder, self.members); let members_md = create_DIArray(dcx.builder, self.members);
let struct_md = let struct_md =
do as_c_str(self.name) |name| { unsafe { do as_c_str(self.name) |name| { unsafe {
llvm::LLVMDIBuilderCreateStructType( llvm::LLVMDIBuilderCreateStructType(
dcx.builder, ptr::null(), name, dcx.builder, ptr::null(), name,
self.file, self.line as c_uint, self.file, self.line as c_uint,
self.total_size as u64, self.align as u64, 0, ptr::null(), self.total_size as u64, self.align as u64, 0, ptr::null(),
members_md, 0, ptr::null()) members_md, 0, ptr::null())
@ -322,7 +320,7 @@ impl StructContext {
fn create_struct(cx: @CrateContext, t: ty::t, fields: ~[ty::field], span: span) -> DICompositeType { fn create_struct(cx: @CrateContext, t: ty::t, fields: ~[ty::field], span: span) -> DICompositeType {
let loc = span_start(cx, span); let loc = span_start(cx, span);
let file_md = create_file(cx, loc.file.name); let file_md = create_file(cx, loc.file.name);
let mut scx = StructContext::create(cx, file_md, ty_to_str(cx.tcx, t), loc.line); let mut scx = StructContext::create(cx, file_md, ty_to_str(cx.tcx, t), loc.line);
for fields.each |field| { for fields.each |field| {
let field_t = field.mt.ty; let field_t = field.mt.ty;
@ -339,7 +337,7 @@ fn voidptr(cx: @CrateContext) -> (DIDerivedType, uint, uint) {
let size = sys::size_of::<ValueRef>(); let size = sys::size_of::<ValueRef>();
let align = sys::min_align_of::<ValueRef>(); let align = sys::min_align_of::<ValueRef>();
let vp = do as_c_str("*void") |name| { unsafe { let vp = do as_c_str("*void") |name| { unsafe {
llvm::LLVMDIBuilderCreatePointerType(dbg_cx(cx).builder, ptr::null(), llvm::LLVMDIBuilderCreatePointerType(dbg_cx(cx).builder, ptr::null(),
size*8 as u64, align*8 as u64, name) size*8 as u64, align*8 as u64, name)
}}; }};
return (vp, size, align); return (vp, size, align);
@ -352,7 +350,7 @@ fn create_tuple(cx: @CrateContext, t: ty::t, elements: &[ty::t], span: span) ->
let name = (cx.sess.str_of((dcx.names)("tuple"))).to_owned(); let name = (cx.sess.str_of((dcx.names)("tuple"))).to_owned();
let mut scx = StructContext::create(cx, file_md, name, loc.line); let mut scx = StructContext::create(cx, file_md, name, loc.line);
for elements.each |element| { for elements.each |element| {
let ty_md = create_ty(cx, *element, span); let ty_md = create_ty(cx, *element, span);
let (size, align) = size_and_align_of(cx, *element); let (size, align) = size_and_align_of(cx, *element);
@ -368,7 +366,7 @@ fn create_boxed_type(cx: @CrateContext, contents: ty::t,
let int_t = ty::mk_int(); let int_t = ty::mk_int();
let refcount_type = create_basic_type(cx, int_t, span); let refcount_type = create_basic_type(cx, int_t, span);
let name = ty_to_str(cx.tcx, contents); let name = ty_to_str(cx.tcx, contents);
let mut scx = StructContext::create(cx, file_md, fmt!("box<%s>", name), 0); let mut scx = StructContext::create(cx, file_md, fmt!("box<%s>", name), 0);
scx.add_member("refcnt", 0, sys::size_of::<uint>(), scx.add_member("refcnt", 0, sys::size_of::<uint>(),
sys::min_align_of::<uint>(), refcount_type); sys::min_align_of::<uint>(), refcount_type);
@ -391,13 +389,13 @@ fn create_fixed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
let file_md = create_file(cx, loc.file.name); let file_md = create_file(cx, loc.file.name);
let (size, align) = size_and_align_of(cx, elem_t); let (size, align) = size_and_align_of(cx, elem_t);
let subrange = unsafe { let subrange = unsafe {
llvm::LLVMDIBuilderGetOrCreateSubrange(dcx.builder, 0_i64, (len-1) as i64) }; llvm::LLVMDIBuilderGetOrCreateSubrange(dcx.builder, 0_i64, (len-1) as i64) };
let subscripts = create_DIArray(dcx.builder, [subrange]); let subscripts = create_DIArray(dcx.builder, [subrange]);
return unsafe { return unsafe {
llvm::LLVMDIBuilderCreateVectorType(dcx.builder, llvm::LLVMDIBuilderCreateVectorType(dcx.builder,
size * len as u64, align as u64, elem_ty_md, subscripts) size * len as u64, align as u64, elem_ty_md, subscripts)
}; };
} }
@ -407,9 +405,9 @@ fn create_boxed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
let loc = span_start(cx, vec_ty_span); let loc = span_start(cx, vec_ty_span);
let file_md = create_file(cx, loc.file.name); let file_md = create_file(cx, loc.file.name);
let elem_ty_md = create_ty(cx, elem_t, vec_ty_span); let elem_ty_md = create_ty(cx, elem_t, vec_ty_span);
let mut vec_scx = StructContext::create(cx, file_md, ty_to_str(cx.tcx, vec_t), 0); let mut vec_scx = StructContext::create(cx, file_md, ty_to_str(cx.tcx, vec_t), 0);
let size_t_type = create_basic_type(cx, ty::mk_uint(), vec_ty_span); let size_t_type = create_basic_type(cx, ty::mk_uint(), vec_ty_span);
vec_scx.add_member("fill", 0, sys::size_of::<libc::size_t>(), vec_scx.add_member("fill", 0, sys::size_of::<libc::size_t>(),
sys::min_align_of::<libc::size_t>(), size_t_type); sys::min_align_of::<libc::size_t>(), size_t_type);
@ -418,9 +416,9 @@ fn create_boxed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
let subrange = unsafe { llvm::LLVMDIBuilderGetOrCreateSubrange(dcx.builder, 0_i64, 0_i64) }; let subrange = unsafe { llvm::LLVMDIBuilderGetOrCreateSubrange(dcx.builder, 0_i64, 0_i64) };
let (arr_size, arr_align) = size_and_align_of(cx, elem_t); let (arr_size, arr_align) = size_and_align_of(cx, elem_t);
let name = fmt!("[%s]", ty_to_str(cx.tcx, elem_t)); let name = fmt!("[%s]", ty_to_str(cx.tcx, elem_t));
let subscripts = create_DIArray(dcx.builder, [subrange]); let subscripts = create_DIArray(dcx.builder, [subrange]);
let data_ptr = unsafe { llvm::LLVMDIBuilderCreateVectorType(dcx.builder, let data_ptr = unsafe { llvm::LLVMDIBuilderCreateVectorType(dcx.builder,
arr_size as u64, arr_align as u64, elem_ty_md, subscripts) }; arr_size as u64, arr_align as u64, elem_ty_md, subscripts) };
vec_scx.add_member("data", 0, 0, // clang says the size should be 0 vec_scx.add_member("data", 0, 0, // clang says the size should be 0
sys::min_align_of::<u8>(), data_ptr); sys::min_align_of::<u8>(), data_ptr);
@ -448,7 +446,7 @@ fn create_vec_slice(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t, span: span)
let elem_ty_md = create_ty(cx, elem_t, span); let elem_ty_md = create_ty(cx, elem_t, span);
let uint_type = create_basic_type(cx, ty::mk_uint(), span); let uint_type = create_basic_type(cx, ty::mk_uint(), span);
let elem_ptr = create_pointer_type(cx, elem_t, span, elem_ty_md); let elem_ptr = create_pointer_type(cx, elem_t, span, elem_ty_md);
let mut scx = StructContext::create(cx, file_md, ty_to_str(cx.tcx, vec_t), 0); let mut scx = StructContext::create(cx, file_md, ty_to_str(cx.tcx, vec_t), 0);
let (_, ptr_size, ptr_align) = voidptr(cx); let (_, ptr_size, ptr_align) = voidptr(cx);
scx.add_member("vec", 0, ptr_size, ptr_align, elem_ptr); scx.add_member("vec", 0, ptr_size, ptr_align, elem_ptr);
@ -467,15 +465,15 @@ fn create_fn_ty(cx: @CrateContext, fn_ty: ty::t, inputs: ~[ty::t], output: ty::t
let output_ptr_md = create_pointer_type(cx, output, span, output_md); let output_ptr_md = create_pointer_type(cx, output, span, output_md);
let inputs_vals = do inputs.map |arg| { create_ty(cx, *arg, span) }; let inputs_vals = do inputs.map |arg| { create_ty(cx, *arg, span) };
let members = ~[output_ptr_md, vp] + inputs_vals; let members = ~[output_ptr_md, vp] + inputs_vals;
return unsafe { return unsafe {
llvm::LLVMDIBuilderCreateSubroutineType(dcx.builder, file_md, llvm::LLVMDIBuilderCreateSubroutineType(dcx.builder, file_md,
create_DIArray(dcx.builder, members)) create_DIArray(dcx.builder, members))
}; };
} }
fn create_ty(cx: @CrateContext, t: ty::t, span: span) -> DIType { fn create_ty(cx: @CrateContext, t: ty::t, span: span) -> DIType {
let mut dcx = dbg_cx(cx); let dcx = dbg_cx(cx);
let ty_id = ty::type_id(t); let ty_id = ty::type_id(t);
match dcx.created_types.find(&ty_id) { match dcx.created_types.find(&ty_id) {
Some(ty_md) => return *ty_md, Some(ty_md) => return *ty_md,
@ -552,7 +550,7 @@ fn create_ty(cx: @CrateContext, t: ty::t, span: span) -> DIType {
}, },
_ => cx.sess.bug(~"debuginfo: unexpected type in create_ty") _ => cx.sess.bug(~"debuginfo: unexpected type in create_ty")
}; };
dcx.created_types.insert(ty_id, ty_md); dcx.created_types.insert(ty_id, ty_md);
return ty_md; return ty_md;
} }
@ -568,7 +566,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) -> DIVariable {
}; };
let name: &str = cx.sess.str_of(ident); let name: &str = cx.sess.str_of(ident);
debug!("create_local_var: %s", name); debug!("create_local_var: %s", name);
let loc = span_start(cx, local.span); let loc = span_start(cx, local.span);
let ty = node_id_type(bcx, local.node.id); let ty = node_id_type(bcx, local.node.id);
let tymd = create_ty(cx, ty, local.node.ty.span); let tymd = create_ty(cx, ty, local.node.ty.span);
@ -577,14 +575,14 @@ pub fn create_local_var(bcx: block, local: @ast::local) -> DIVariable {
None => create_function(bcx.fcx), None => create_function(bcx.fcx),
Some(_) => create_block(bcx) Some(_) => create_block(bcx)
}; };
let var_md = do as_c_str(name) |name| { unsafe { let var_md = do as_c_str(name) |name| { unsafe {
llvm::LLVMDIBuilderCreateLocalVariable( llvm::LLVMDIBuilderCreateLocalVariable(
dcx.builder, AutoVariableTag as u32, dcx.builder, AutoVariableTag as u32,
context, name, filemd, context, name, filemd,
loc.line as c_uint, tymd, false, 0, 0) loc.line as c_uint, tymd, false, 0, 0)
}}; }};
// FIXME(#6814) Should use `pat_util::pat_bindings` for pats like (a, b) etc // FIXME(#6814) Should use `pat_util::pat_bindings` for pats like (a, b) etc
let llptr = match bcx.fcx.lllocals.find_copy(&local.node.pat.id) { let llptr = match bcx.fcx.lllocals.find_copy(&local.node.pat.id) {
Some(v) => v, Some(v) => v,
@ -594,30 +592,33 @@ pub fn create_local_var(bcx: block, local: @ast::local) -> DIVariable {
fmt!("No entry in lllocals table for %?", local.node.id)); fmt!("No entry in lllocals table for %?", local.node.id));
} }
}; };
set_debug_location(bcx, loc.line, loc.col.to_uint()); set_debug_location(bcx, loc.line, loc.col.to_uint());
unsafe { unsafe {
let instr = llvm::LLVMDIBuilderInsertDeclareAtEnd(dcx.builder, llptr, var_md, bcx.llbb); let instr = llvm::LLVMDIBuilderInsertDeclareAtEnd(dcx.builder, llptr, var_md, bcx.llbb);
llvm::LLVMSetInstDebugLocation(trans::build::B(bcx), instr); llvm::LLVMSetInstDebugLocation(trans::build::B(bcx), instr);
} }
return var_md; return var_md;
} }
pub fn create_arg(bcx: block, arg: ast::arg, span: span) -> Option<DIVariable> { pub fn create_arg(bcx: block, arg: ast::arg, span: span) -> Option<DIVariable> {
debug!("create_arg"); debug!("create_arg");
let fcx = bcx.fcx, cx = *fcx.ccx; if true {
// FIXME(5848) create_arg disabled for now because "node_id_type(bcx, arg.id)" below blows
// up: "error: internal compiler error: node_id_to_type: no type for node `arg (id=10)`"
return None;
}
let fcx = bcx.fcx;
let cx = *fcx.ccx;
let dcx = dbg_cx(cx); let dcx = dbg_cx(cx);
let loc = span_start(cx, span); let loc = span_start(cx, span);
if "<intrinsic>" == loc.file.name { if "<intrinsic>" == loc.file.name {
return None; return None;
} }
// FIXME: Disabled for now because "node_id_type(bcx, arg.id)" below blows up:
// "error: internal compiler error: node_id_to_type: no type for node `arg (id=10)`"
// (same as https://github.com/mozilla/rust/issues/5848)
return None;
let ty = node_id_type(bcx, arg.id); let ty = node_id_type(bcx, arg.id);
let tymd = create_ty(cx, ty, arg.ty.span); let tymd = create_ty(cx, ty, arg.ty.span);
let filemd = create_file(cx, loc.file.name); let filemd = create_file(cx, loc.file.name);
@ -629,12 +630,12 @@ pub fn create_arg(bcx: block, arg: ast::arg, span: span) -> Option<DIVariable> {
let ident = path.idents.last(); let ident = path.idents.last();
let name: &str = cx.sess.str_of(*ident); let name: &str = cx.sess.str_of(*ident);
let mdnode = do as_c_str(name) |name| { unsafe { let mdnode = do as_c_str(name) |name| { unsafe {
llvm::LLVMDIBuilderCreateLocalVariable(dcx.builder, llvm::LLVMDIBuilderCreateLocalVariable(dcx.builder,
ArgVariableTag as u32, context, name, ArgVariableTag as u32, context, name,
filemd, loc.line as c_uint, tymd, false, 0, 0) filemd, loc.line as c_uint, tymd, false, 0, 0)
// FIXME need to pass a real argument number // FIXME need to pass a real argument number
}}; }};
let llptr = fcx.llargs.get_copy(&arg.id); let llptr = fcx.llargs.get_copy(&arg.id);
unsafe { unsafe {
llvm::LLVMDIBuilderInsertDeclareAtEnd(dcx.builder, llptr, mdnode, bcx.llbb); llvm::LLVMDIBuilderInsertDeclareAtEnd(dcx.builder, llptr, mdnode, bcx.llbb);
@ -652,7 +653,7 @@ fn set_debug_location(bcx: block, line: uint, col: uint) {
let elems = ~[C_i32(line as i32), C_i32(col as i32), blockmd, ptr::null()]; let elems = ~[C_i32(line as i32), C_i32(col as i32), blockmd, ptr::null()];
unsafe { unsafe {
let dbg_loc = llvm::LLVMMDNode(vec::raw::to_ptr(elems), elems.len() as libc::c_uint); let dbg_loc = llvm::LLVMMDNode(vec::raw::to_ptr(elems), elems.len() as libc::c_uint);
llvm::LLVMSetCurrentDebugLocation(trans::build::B(bcx), dbg_loc); llvm::LLVMSetCurrentDebugLocation(trans::build::B(bcx), dbg_loc);
} }
} }
@ -660,13 +661,13 @@ pub fn update_source_pos(bcx: block, span: span) {
if !bcx.sess().opts.debuginfo || (*span.lo == 0 && *span.hi == 0) { if !bcx.sess().opts.debuginfo || (*span.lo == 0 && *span.hi == 0) {
return; return;
} }
debug!("update_source_pos: %s", bcx.sess().codemap.span_to_str(span)); debug!("update_source_pos: %s", bcx.sess().codemap.span_to_str(span));
let cx = bcx.ccx(); let cx = bcx.ccx();
let loc = span_start(cx, span); let loc = span_start(cx, span);
let mut dcx = dbg_cx(cx); let dcx = dbg_cx(cx);
let loc = (loc.line, loc.col.to_uint()); let loc = (loc.line, loc.col.to_uint());
if loc == dcx.curr_loc { if loc == dcx.curr_loc {
return; return;
@ -678,7 +679,7 @@ pub fn update_source_pos(bcx: block, span: span) {
pub fn create_function(fcx: fn_ctxt) -> DISubprogram { pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
let cx = *fcx.ccx; let cx = *fcx.ccx;
let mut dcx = dbg_cx(cx); let dcx = dbg_cx(cx);
let fcx = &mut *fcx; let fcx = &mut *fcx;
let span = fcx.span.get(); let span = fcx.span.get();
@ -705,7 +706,7 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
} }
_ => fcx.ccx.sess.bug("create_function: unexpected sort of node") _ => fcx.ccx.sess.bug("create_function: unexpected sort of node")
}; };
match dcx.created_functions.find(&id) { match dcx.created_functions.find(&id) {
Some(fn_md) => return *fn_md, Some(fn_md) => return *fn_md,
None => () None => ()
@ -725,27 +726,27 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
} else { } else {
ptr::null() ptr::null()
}; };
let fn_ty = unsafe { let fn_ty = unsafe {
llvm::LLVMDIBuilderCreateSubroutineType(dcx.builder, llvm::LLVMDIBuilderCreateSubroutineType(dcx.builder,
file_md, create_DIArray(dcx.builder, [ret_ty_md])) file_md, create_DIArray(dcx.builder, [ret_ty_md]))
}; };
let fn_md = let fn_md =
do as_c_str(cx.sess.str_of(ident)) |name| { do as_c_str(cx.sess.str_of(ident)) |name| {
do as_c_str(cx.sess.str_of(ident)) |linkage| { unsafe { do as_c_str(cx.sess.str_of(ident)) |linkage| { unsafe {
llvm::LLVMDIBuilderCreateFunction( llvm::LLVMDIBuilderCreateFunction(
dcx.builder, dcx.builder,
file_md, file_md,
name, linkage, name, linkage,
file_md, loc.line as c_uint, file_md, loc.line as c_uint,
fn_ty, false, true, fn_ty, false, true,
loc.line as c_uint, loc.line as c_uint,
FlagPrototyped as c_uint, FlagPrototyped as c_uint,
cx.sess.opts.optimize != session::No, cx.sess.opts.optimize != session::No,
fcx.llfn, ptr::null(), ptr::null()) fcx.llfn, ptr::null(), ptr::null())
}}}; }}};
dcx.created_functions.insert(id, fn_md); dcx.created_functions.insert(id, fn_md);
return fn_md; return fn_md;
} }