forked from M-Labs/nac3
nac3core: add function debug info
This commit is contained in:
parent
ee3b18bd83
commit
4850df7874
|
@ -18,7 +18,7 @@ use inkwell::{
|
||||||
passes::{PassManager, PassManagerBuilder},
|
passes::{PassManager, PassManagerBuilder},
|
||||||
types::{AnyType, BasicType, BasicTypeEnum},
|
types::{AnyType, BasicType, BasicTypeEnum},
|
||||||
values::{BasicValueEnum, FunctionValue, PhiValue, PointerValue},
|
values::{BasicValueEnum, FunctionValue, PhiValue, PointerValue},
|
||||||
debug_info::{DebugInfoBuilder, DICompileUnit},
|
debug_info::{DebugInfoBuilder, DICompileUnit, DISubprogram, AsDIScope, DIFlagsConstants},
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nac3parser::ast::{Stmt, StrRef, Location};
|
use nac3parser::ast::{Stmt, StrRef, Location};
|
||||||
|
@ -557,6 +557,34 @@ pub fn gen_func_impl<
|
||||||
context.create_type_attribute(Attribute::get_named_enum_kind_id("sret"),
|
context.create_type_attribute(Attribute::get_named_enum_kind_id("sret"),
|
||||||
ret_type.unwrap().as_any_type_enum()));
|
ret_type.unwrap().as_any_type_enum()));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
let ditype = debug_info_builder.dibuilder.create_basic_type(
|
||||||
|
"_",
|
||||||
|
0_u64,
|
||||||
|
0x00,
|
||||||
|
inkwell::debug_info::DIFlags::PUBLIC,
|
||||||
|
).unwrap();
|
||||||
|
let subroutine_type = debug_info_builder.dibuilder.create_subroutine_type(
|
||||||
|
debug_info_builder.compile_unit.get_file(),
|
||||||
|
/* return type */ Some(ditype.as_type()),
|
||||||
|
/* parameter types */ &[],
|
||||||
|
inkwell::debug_info::DIFlags::PUBLIC,
|
||||||
|
);
|
||||||
|
let func_scope: DISubprogram<'_> = debug_info_builder.dibuilder.create_function(
|
||||||
|
/* scope */ debug_info_builder.compile_unit.as_debug_info_scope(),
|
||||||
|
/* func name */ "main",
|
||||||
|
/* linkage_name */ None,
|
||||||
|
/* file */ debug_info_builder.compile_unit.get_file(),
|
||||||
|
/* line_no */ 0,
|
||||||
|
/* DIType */ subroutine_type,
|
||||||
|
/* is_local_to_unit */ true,
|
||||||
|
/* is_definition */ true,
|
||||||
|
/* scope_line */ 0,
|
||||||
|
/* flags */ inkwell::debug_info::DIFlags::PUBLIC,
|
||||||
|
/* is_optimized */ false,
|
||||||
|
);
|
||||||
|
fn_val.set_subprogram(func_scope);
|
||||||
|
}
|
||||||
|
|
||||||
let init_bb = context.append_basic_block(fn_val, "init");
|
let init_bb = context.append_basic_block(fn_val, "init");
|
||||||
builder.position_at_end(init_bb);
|
builder.position_at_end(init_bb);
|
||||||
|
@ -636,7 +664,7 @@ pub fn gen_func_impl<
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
return Err((builder, debug_info_builder, e));
|
return Err((builder, debug_info_builder, e));
|
||||||
}
|
}
|
||||||
|
debug_info_builder.dibuilder.finalize();
|
||||||
Ok((builder, module, fn_val, debug_info_builder))
|
Ok((builder, module, fn_val, debug_info_builder))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue