@@ -13,6 +13,8 @@ use crate::{AtomicOrdering, AtomicRMWBinOp, IntPredicate, FloatPredicate};
13
13
use crate :: basic_block:: BasicBlock ;
14
14
use crate :: support:: to_c_str;
15
15
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 ;
16
18
#[ llvm_versions( 3.9 ..=latest) ]
17
19
use crate :: values:: StructValue ;
18
20
use crate :: types:: { AsTypeRef , BasicType , IntMathType , FloatMathType , PointerType , PointerMathType } ;
@@ -1763,6 +1765,60 @@ impl<'ctx> Builder<'ctx> {
1763
1765
1764
1766
Ok ( StructValue :: new ( val) )
1765
1767
}
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
+ }
1766
1822
}
1767
1823
1768
1824
/// Used by build_memcpy and build_memmove
0 commit comments