Index: bindings/ocaml/llvm/llvm.ml =================================================================== --- bindings/ocaml/llvm/llvm.ml +++ bindings/ocaml/llvm/llvm.ml @@ -567,6 +567,10 @@ = "llvm_get_namedmd" external add_named_metadata_operand : llmodule -> string -> llvalue -> unit = "llvm_append_namedmd" +external get_debug_loc_directory : llvalue -> string option = "llvm_get_debug_loc_directory" +external get_debug_loc_filename : llvalue -> string option = "llvm_get_debug_loc_filename" +external get_debug_loc_line : llvalue -> int = "llvm_get_debug_loc_line" +external get_debug_loc_column : llvalue -> int = "llvm_get_debug_loc_column" (*--... Operations on scalar constants .....................................--*) external const_int : lltype -> int -> llvalue = "llvm_const_int" Index: bindings/ocaml/llvm/llvm.mli =================================================================== --- bindings/ocaml/llvm/llvm.mli +++ bindings/ocaml/llvm/llvm.mli @@ -909,6 +909,32 @@ [llvm::MDNode::addOperand()]. *) val add_named_metadata_operand : llmodule -> string -> llvalue -> unit +(** [get_debug_loc_directory v] returns the directory of the debug location + for [v], which must be an [Instruction], [GlobalVariable], or [Function]. + See the [llvm::Instruction::getDebugLoc()], + [llvm::GlobalVariable::getDebugInfo()], and + [llvm::Function::getSubprogram()] methods. *) +val get_debug_loc_directory : llvalue -> string option + +(** [get_debug_loc_filename v] returns the filename of the debug location + for [v], which must be an [Instruction], [GlobalVariable], or [Function]. + See the [llvm::Instruction::getDebugLoc()], + [llvm::GlobalVariable::getDebugInfo()], and + [llvm::Function::getSubprogram()] methods. *) +val get_debug_loc_filename : llvalue -> string option + +(** [get_debug_loc_line v] returns the line number of the debug location + for [v], which must be an [Instruction], [GlobalVariable], or [Function]. + See the [llvm::Instruction::getDebugLoc()], + [llvm::GlobalVariable::getDebugInfo()], and + [llvm::Function::getSubprogram()] methods. *) +val get_debug_loc_line : llvalue -> int + +(** [get_debug_loc_column v] returns the column number of the debug location + for [v], which must be an [Instruction]. + See the [llvm::Instruction::getDebugLoc()] method. *) +val get_debug_loc_column : llvalue -> int + (** {7 Operations on scalar constants} *) Index: bindings/ocaml/llvm/llvm_ocaml.c =================================================================== --- bindings/ocaml/llvm/llvm_ocaml.c +++ bindings/ocaml/llvm/llvm_ocaml.c @@ -864,6 +864,44 @@ return Val_unit; } +/* llvalue -> string option */ +CAMLprim value llvm_get_debug_loc_directory(LLVMValueRef Val) { + CAMLparam0(); + unsigned Length; + const char *S = LLVMGetDebugLocDirectory(Val, &Length); + if (S) { + CAMLlocal1(result); + result = caml_alloc_small(1, 0); + Store_field(result, 0, caml_copy_string(S)); + CAMLreturn(result); + } + CAMLreturn(Val_int(0)); +} + +/* llvalue -> string option */ +CAMLprim value llvm_get_debug_loc_filename(LLVMValueRef Val) { + CAMLparam0(); + unsigned Length; + const char *S = LLVMGetDebugLocFilename(Val, &Length); + if (S) { + CAMLlocal1(result); + result = caml_alloc_small(1, 0); + Store_field(result, 0, caml_copy_string(S)); + CAMLreturn(result); + } + CAMLreturn(Val_int(0)); +} + +/* llvalue -> int */ +CAMLprim value llvm_get_debug_loc_line(LLVMValueRef Val) { + return Val_int(LLVMGetDebugLocLine(Val)); +} + +/* llvalue -> int */ +CAMLprim value llvm_get_debug_loc_column(LLVMValueRef Val) { + return Val_int(LLVMGetDebugLocColumn(Val)); +} + /*--... Operations on scalar constants .....................................--*/ /* lltype -> int -> llvalue */