Index: bindings/ocaml/llvm/llvm.ml =================================================================== --- bindings/ocaml/llvm/llvm.ml +++ bindings/ocaml/llvm/llvm.ml @@ -566,6 +566,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 @@ -908,6 +908,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 @@ -863,6 +863,48 @@ return Val_unit; } +/* llvalue -> string option */ +CAMLprim value llvm_get_debug_loc_directory(LLVMValueRef Val) { + CAMLparam0(); + CAMLlocal2(Option, String); + unsigned Length; + const char *Chars; + if ((Chars = LLVMGetDebugLocDirectory(Val, &Length))) { + String = caml_alloc_string(Length); + memcpy(String_val(String), Chars, Length); + Option = caml_alloc_small(1, 0); + Store_field(Option, 0, String); + CAMLreturn(Option); + } + CAMLreturn(Val_int(0)); +} + +/* llvalue -> string option */ +CAMLprim value llvm_get_debug_loc_filename(LLVMValueRef Val) { + CAMLparam0(); + CAMLlocal2(Option, String); + unsigned Length; + const char *Chars; + if ((Chars = LLVMGetDebugLocFilename(Val, &Length))) { + String = caml_alloc_string(Length); + memcpy(String_val(String), Chars, Length); + Option = caml_alloc_small(1, 0); + Store_field(Option, 0, String); + CAMLreturn(Option); + } + 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 */