This commit is contained in:
ychenfo 2022-04-22 15:57:30 +08:00
parent fed4bbe52b
commit 90e4c21f35
3 changed files with 17 additions and 16 deletions

View File

@ -1029,7 +1029,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
ctx.ctx,
ctx.current_loc.row as u32,
ctx.current_loc.column as u32,
ctx.debug_info.2.as_debug_info_scope(),
ctx.debug_info.2,
None,
);
ctx.builder.set_current_debug_location(ctx.ctx, loc);

View File

@ -19,7 +19,7 @@ use inkwell::{
types::{AnyType, BasicType, BasicTypeEnum},
values::{BasicValueEnum, FunctionValue, PhiValue, PointerValue},
debug_info::{
DebugInfoBuilder, DICompileUnit, DISubprogram, AsDIScope, DIFlagsConstants, DILexicalBlock
DebugInfoBuilder, DICompileUnit, DISubprogram, AsDIScope, DIFlagsConstants, DILexicalBlock, DIScope
},
};
use itertools::Itertools;
@ -55,7 +55,7 @@ pub type VarValue<'ctx> = (PointerValue<'ctx>, Option<Arc<dyn StaticValue + Send
pub struct CodeGenContext<'ctx, 'a> {
pub ctx: &'ctx Context,
pub builder: Builder<'ctx>,
pub debug_info: (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>, DILexicalBlock<'ctx>),
pub debug_info: (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>, DIScope<'ctx>),
pub module: Module<'ctx>,
pub top_level: &'a TopLevelContext,
pub unifier: Unifier,
@ -608,28 +608,29 @@ pub fn gen_func_impl<'ctx, G: CodeGenerator, F: FnOnce(&mut G, &mut CodeGenConte
&[],
inkwell::debug_info::DIFlags::PUBLIC,
);
let (row, col) =
task.body.get(0).map_or_else(|| (0, 0), |b| (b.location.row, b.location.column));
let func_scope: DISubprogram<'_> = dibuilder.create_function(
/* scope */ compile_unit.as_debug_info_scope(),
/* func name */ symbol,
/* linkage_name */ None,
/* file */ compile_unit.get_file(),
/* line_no */ 0,
/* line_no */ row as u32,
/* DIType */ subroutine_type,
/* is_local_to_unit */ true,
/* is_definition */ true,
/* scope_line */ 0,
/* scope_line */ row as u32,
/* flags */ inkwell::debug_info::DIFlags::PUBLIC,
/* is_optimized */ false,
);
fn_val.set_subprogram(func_scope);
let (row, col) =
task.body.get(0).map_or_else(|| (0, 0), |b| (b.location.row, b.location.column));
let lexical_block = dibuilder.create_lexical_block(
/* scope */ func_scope.as_debug_info_scope(),
/* file */ compile_unit.get_file(),
/* line_no */ row as u32,
/* column_no */ col as u32,
);
// let lexical_block = dibuilder.create_lexical_block(
// /* scope */ func_scope.as_debug_info_scope(),
// /* file */ compile_unit.get_file(),
// /* line_no */ row as u32,
// /* column_no */ col as u32,
// );
let mut code_gen_context = CodeGenContext {
ctx: context,
@ -653,14 +654,14 @@ pub fn gen_func_impl<'ctx, G: CodeGenerator, F: FnOnce(&mut G, &mut CodeGenConte
static_value_store,
need_sret: has_sret,
current_loc: Default::default(),
debug_info: (dibuilder, compile_unit, lexical_block),
debug_info: (dibuilder, compile_unit, func_scope.as_debug_info_scope()),
};
let loc = code_gen_context.debug_info.0.create_debug_location(
context,
row as u32,
col as u32,
lexical_block.as_debug_info_scope(),
func_scope.as_debug_info_scope(),
None
);
code_gen_context.builder.set_current_debug_location(context, loc);

View File

@ -995,7 +995,7 @@ pub fn gen_stmt<'ctx, 'a, G: CodeGenerator>(
ctx.ctx,
ctx.current_loc.row as u32,
ctx.current_loc.column as u32,
ctx.debug_info.2.as_debug_info_scope(),
ctx.debug_info.2,
None,
);
ctx.builder.set_current_debug_location(ctx.ctx, loc);