|
@@ -16,6 +16,8 @@ use crate::linker::link;
|
|
|
use crate::Target;
|
|
use crate::Target;
|
|
|
use inkwell::builder::Builder;
|
|
use inkwell::builder::Builder;
|
|
|
use inkwell::context::Context;
|
|
use inkwell::context::Context;
|
|
|
|
|
+use inkwell::debug_info::DICompileUnit;
|
|
|
|
|
+use inkwell::debug_info::DebugInfoBuilder;
|
|
|
use inkwell::memory_buffer::MemoryBuffer;
|
|
use inkwell::memory_buffer::MemoryBuffer;
|
|
|
use inkwell::module::{Linkage, Module};
|
|
use inkwell::module::{Linkage, Module};
|
|
|
use inkwell::passes::PassManager;
|
|
use inkwell::passes::PassManager;
|
|
@@ -39,7 +41,10 @@ pub struct Binary<'a> {
|
|
|
pub(crate) function_abort_value_transfers: bool,
|
|
pub(crate) function_abort_value_transfers: bool,
|
|
|
pub(crate) constructor_abort_value_transfers: bool,
|
|
pub(crate) constructor_abort_value_transfers: bool,
|
|
|
pub(crate) math_overflow_check: bool,
|
|
pub(crate) math_overflow_check: bool,
|
|
|
|
|
+ pub(crate) generate_debug_info: bool,
|
|
|
pub builder: Builder<'a>,
|
|
pub builder: Builder<'a>,
|
|
|
|
|
+ pub dibuilder: DebugInfoBuilder<'a>,
|
|
|
|
|
+ pub compile_unit: DICompileUnit<'a>,
|
|
|
pub(crate) context: &'a Context,
|
|
pub(crate) context: &'a Context,
|
|
|
pub(crate) functions: HashMap<usize, FunctionValue<'a>>,
|
|
pub(crate) functions: HashMap<usize, FunctionValue<'a>>,
|
|
|
code: RefCell<Vec<u8>>,
|
|
code: RefCell<Vec<u8>>,
|
|
@@ -63,6 +68,7 @@ impl<'a> Binary<'a> {
|
|
|
filename: &'a str,
|
|
filename: &'a str,
|
|
|
opt: OptimizationLevel,
|
|
opt: OptimizationLevel,
|
|
|
math_overflow_check: bool,
|
|
math_overflow_check: bool,
|
|
|
|
|
+ generate_debug_info: bool,
|
|
|
) -> Self {
|
|
) -> Self {
|
|
|
let std_lib = load_stdlib(context, &ns.target);
|
|
let std_lib = load_stdlib(context, &ns.target);
|
|
|
match ns.target {
|
|
match ns.target {
|
|
@@ -74,6 +80,7 @@ impl<'a> Binary<'a> {
|
|
|
filename,
|
|
filename,
|
|
|
opt,
|
|
opt,
|
|
|
math_overflow_check,
|
|
math_overflow_check,
|
|
|
|
|
+ generate_debug_info,
|
|
|
),
|
|
),
|
|
|
Target::Ewasm => ewasm::EwasmTarget::build(
|
|
Target::Ewasm => ewasm::EwasmTarget::build(
|
|
|
context,
|
|
context,
|
|
@@ -83,6 +90,7 @@ impl<'a> Binary<'a> {
|
|
|
filename,
|
|
filename,
|
|
|
opt,
|
|
opt,
|
|
|
math_overflow_check,
|
|
math_overflow_check,
|
|
|
|
|
+ generate_debug_info,
|
|
|
),
|
|
),
|
|
|
Target::Solana => solana::SolanaTarget::build(
|
|
Target::Solana => solana::SolanaTarget::build(
|
|
|
context,
|
|
context,
|
|
@@ -92,6 +100,7 @@ impl<'a> Binary<'a> {
|
|
|
filename,
|
|
filename,
|
|
|
opt,
|
|
opt,
|
|
|
math_overflow_check,
|
|
math_overflow_check,
|
|
|
|
|
+ generate_debug_info,
|
|
|
),
|
|
),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -103,6 +112,7 @@ impl<'a> Binary<'a> {
|
|
|
filename: &str,
|
|
filename: &str,
|
|
|
opt: OptimizationLevel,
|
|
opt: OptimizationLevel,
|
|
|
math_overflow_check: bool,
|
|
math_overflow_check: bool,
|
|
|
|
|
+ generate_debug_info: bool,
|
|
|
) -> Self {
|
|
) -> Self {
|
|
|
assert!(namespaces.iter().all(|ns| ns.target == Target::Solana));
|
|
assert!(namespaces.iter().all(|ns| ns.target == Target::Solana));
|
|
|
|
|
|
|
@@ -114,6 +124,7 @@ impl<'a> Binary<'a> {
|
|
|
filename,
|
|
filename,
|
|
|
opt,
|
|
opt,
|
|
|
math_overflow_check,
|
|
math_overflow_check,
|
|
|
|
|
+ generate_debug_info,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -249,6 +260,7 @@ impl<'a> Binary<'a> {
|
|
|
math_overflow_check: bool,
|
|
math_overflow_check: bool,
|
|
|
std_lib: &Module<'a>,
|
|
std_lib: &Module<'a>,
|
|
|
runtime: Option<Box<Binary<'a>>>,
|
|
runtime: Option<Box<Binary<'a>>>,
|
|
|
|
|
+ generate_debug_info: bool,
|
|
|
) -> Self {
|
|
) -> Self {
|
|
|
LLVM_INIT.get_or_init(|| {
|
|
LLVM_INIT.get_or_init(|| {
|
|
|
inkwell::targets::Target::initialize_webassembly(&Default::default());
|
|
inkwell::targets::Target::initialize_webassembly(&Default::default());
|
|
@@ -258,6 +270,32 @@ impl<'a> Binary<'a> {
|
|
|
let triple = target.llvm_target_triple();
|
|
let triple = target.llvm_target_triple();
|
|
|
let module = context.create_module(name);
|
|
let module = context.create_module(name);
|
|
|
|
|
|
|
|
|
|
+ let debug_metadata_version = context.i32_type().const_int(3, false);
|
|
|
|
|
+ module.add_basic_value_flag(
|
|
|
|
|
+ "Debug Info Version",
|
|
|
|
|
+ inkwell::module::FlagBehavior::Warning,
|
|
|
|
|
+ debug_metadata_version,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ let builder = context.create_builder();
|
|
|
|
|
+ let (dibuilder, compile_unit) = module.create_debug_info_builder(
|
|
|
|
|
+ true,
|
|
|
|
|
+ inkwell::debug_info::DWARFSourceLanguage::C,
|
|
|
|
|
+ filename,
|
|
|
|
|
+ ".",
|
|
|
|
|
+ "Solang",
|
|
|
|
|
+ false,
|
|
|
|
|
+ "",
|
|
|
|
|
+ 0,
|
|
|
|
|
+ "",
|
|
|
|
|
+ inkwell::debug_info::DWARFEmissionKind::Full,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ false,
|
|
|
|
|
+ false,
|
|
|
|
|
+ "",
|
|
|
|
|
+ "",
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
module.set_triple(&triple);
|
|
module.set_triple(&triple);
|
|
|
module.set_source_file_name(filename);
|
|
module.set_source_file_name(filename);
|
|
|
|
|
|
|
@@ -308,7 +346,10 @@ impl<'a> Binary<'a> {
|
|
|
function_abort_value_transfers: false,
|
|
function_abort_value_transfers: false,
|
|
|
constructor_abort_value_transfers: false,
|
|
constructor_abort_value_transfers: false,
|
|
|
math_overflow_check,
|
|
math_overflow_check,
|
|
|
- builder: context.create_builder(),
|
|
|
|
|
|
|
+ generate_debug_info,
|
|
|
|
|
+ builder,
|
|
|
|
|
+ dibuilder,
|
|
|
|
|
+ compile_unit,
|
|
|
context,
|
|
context,
|
|
|
target,
|
|
target,
|
|
|
functions: HashMap::new(),
|
|
functions: HashMap::new(),
|