Skip to content

Commit c38c6cd

Browse files
authored
Merge pull request rust-lang#203 from wasmerio/epilys-debug
Add support for debug info.
2 parents cb6e10f + e9da280 commit c38c6cd

File tree

8 files changed

+1638
-35
lines changed

8 files changed

+1638
-35
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ experimental = ["static-alloc"]
6767
either = "1.5"
6868
inkwell_internals = { path = "./internal_macros", version = "0.2.0" }
6969
libc = "0.2"
70-
llvm-sys = "100.0.1"
70+
llvm-sys = "100.1.0"
7171
once_cell = "1.2"
7272
parking_lot = "0.11"
7373
regex = "1"

src/builder.rs

+56
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use crate::{AtomicOrdering, AtomicRMWBinOp, IntPredicate, FloatPredicate};
1313
use crate::basic_block::BasicBlock;
1414
use crate::support::to_c_str;
1515
use crate::values::{AggregateValue, AggregateValueEnum, AsValueRef, BasicValue, BasicValueEnum, PhiValue, FunctionValue, IntValue, PointerValue, VectorValue, InstructionValue, GlobalValue, IntMathValue, FloatMathValue, PointerMathValue, InstructionOpcode, CallSiteValue};
16+
#[llvm_versions(7.0..=latest)]
17+
use crate::debug_info::DILocation;
1618
#[llvm_versions(3.9..=latest)]
1719
use crate::values::StructValue;
1820
use crate::types::{AsTypeRef, BasicType, IntMathType, FloatMathType, PointerType, PointerMathType};
@@ -1763,6 +1765,60 @@ impl<'ctx> Builder<'ctx> {
17631765

17641766
Ok(StructValue::new(val))
17651767
}
1768+
1769+
/// Set the debug info source location of the instruction currently pointed at by the builder
1770+
#[llvm_versions(7.0..=latest)]
1771+
pub fn set_current_debug_location(
1772+
&self,
1773+
context: &'ctx crate::context::Context,
1774+
location: DILocation<'ctx>,
1775+
) {
1776+
use llvm_sys::core::LLVMMetadataAsValue;
1777+
use llvm_sys::core::LLVMSetCurrentDebugLocation;
1778+
unsafe {
1779+
LLVMSetCurrentDebugLocation(
1780+
self.builder,
1781+
LLVMMetadataAsValue(context.context, location.metadata_ref),
1782+
);
1783+
}
1784+
}
1785+
1786+
/// Get the debug info source location of the instruction currently pointed at by the builder,
1787+
/// if available.
1788+
#[llvm_versions(7.0..=latest)]
1789+
pub fn get_current_debug_location(
1790+
&self,
1791+
) -> Option<DILocation<'ctx>>
1792+
{
1793+
use llvm_sys::core::LLVMGetCurrentDebugLocation;
1794+
use llvm_sys::core::LLVMValueAsMetadata;
1795+
let metadata_ref = unsafe {
1796+
LLVMGetCurrentDebugLocation(
1797+
self.builder,
1798+
)
1799+
};
1800+
if metadata_ref.is_null() {
1801+
return None;
1802+
}
1803+
Some(DILocation {
1804+
metadata_ref: unsafe { LLVMValueAsMetadata(metadata_ref)},
1805+
_marker: PhantomData,
1806+
})
1807+
}
1808+
1809+
/// Unset the debug info source location of the instruction currently pointed at by the
1810+
/// builder. If there isn't any debug info, this is a no-op.
1811+
pub fn unset_current_debug_location(
1812+
&self,
1813+
) {
1814+
use llvm_sys::core::LLVMSetCurrentDebugLocation;
1815+
unsafe {
1816+
LLVMSetCurrentDebugLocation(
1817+
self.builder,
1818+
std::ptr::null_mut(),
1819+
);
1820+
}
1821+
}
17661822
}
17671823

17681824
/// Used by build_memcpy and build_memmove

0 commit comments

Comments
 (0)