mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-27 13:40:43 +00:00
Add a way to look up a type by it's name in a module.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97379 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
68bab9833d
commit
d80ce75687
@ -165,6 +165,8 @@ external define_type_name : string -> lltype -> llmodule -> bool
|
|||||||
= "llvm_add_type_name"
|
= "llvm_add_type_name"
|
||||||
external delete_type_name : string -> llmodule -> unit
|
external delete_type_name : string -> llmodule -> unit
|
||||||
= "llvm_delete_type_name"
|
= "llvm_delete_type_name"
|
||||||
|
external type_by_name : llmodule -> string -> lltype option
|
||||||
|
= "llvm_type_by_name"
|
||||||
external dump_module : llmodule -> unit = "llvm_dump_module"
|
external dump_module : llmodule -> unit = "llvm_dump_module"
|
||||||
|
|
||||||
(*===-- Types -------------------------------------------------------------===*)
|
(*===-- Types -------------------------------------------------------------===*)
|
||||||
|
@ -274,6 +274,11 @@ external define_type_name : string -> lltype -> llmodule -> bool
|
|||||||
external delete_type_name : string -> llmodule -> unit
|
external delete_type_name : string -> llmodule -> unit
|
||||||
= "llvm_delete_type_name"
|
= "llvm_delete_type_name"
|
||||||
|
|
||||||
|
(** [type_by_name m n] returns the type in the module [m] named [n], or [None]
|
||||||
|
if it does not exist. See the method [llvm::Module::getTypeByName]. *)
|
||||||
|
external type_by_name : llmodule -> string -> lltype option
|
||||||
|
= "llvm_type_by_name"
|
||||||
|
|
||||||
(** [dump_module m] prints the .ll representation of the module [m] to standard
|
(** [dump_module m] prints the .ll representation of the module [m] to standard
|
||||||
error. See the method [llvm::Module::dump]. *)
|
error. See the method [llvm::Module::dump]. *)
|
||||||
external dump_module : llmodule -> unit = "llvm_dump_module"
|
external dump_module : llmodule -> unit = "llvm_dump_module"
|
||||||
|
@ -164,6 +164,18 @@ CAMLprim value llvm_delete_type_name(value Name, LLVMModuleRef M) {
|
|||||||
return Val_unit;
|
return Val_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* llmodule -> string -> lltype option */
|
||||||
|
CAMLprim value llvm_type_by_name(LLVMModuleRef M, value Name) {
|
||||||
|
CAMLparam1(Name);
|
||||||
|
LLVMTypeRef T;
|
||||||
|
if ((T = LLVMGetTypeByName(M, String_val(Name)))) {
|
||||||
|
value Option = alloc(1, 0);
|
||||||
|
Field(Option, 0) = (value) T;
|
||||||
|
CAMLreturn(Option);
|
||||||
|
}
|
||||||
|
CAMLreturn(Val_int(0));
|
||||||
|
}
|
||||||
|
|
||||||
/* llmodule -> unit */
|
/* llmodule -> unit */
|
||||||
CAMLprim value llvm_dump_module(LLVMModuleRef M) {
|
CAMLprim value llvm_dump_module(LLVMModuleRef M) {
|
||||||
LLVMDumpModule(M);
|
LLVMDumpModule(M);
|
||||||
|
@ -185,6 +185,14 @@ let test_types () =
|
|||||||
let ty = opaque_type context in
|
let ty = opaque_type context in
|
||||||
insist (define_type_name "delete_type" ty m);
|
insist (define_type_name "delete_type" ty m);
|
||||||
delete_type_name "delete_type" m;
|
delete_type_name "delete_type" m;
|
||||||
|
|
||||||
|
(* RUN: grep {type_name.*opaque} < %t.ll
|
||||||
|
*)
|
||||||
|
group "type_name"; begin
|
||||||
|
let ty = opaque_type context in
|
||||||
|
insist (define_type_name "type_name" ty m);
|
||||||
|
insist ((type_by_name m "type_name") = Some ty)
|
||||||
|
end;
|
||||||
|
|
||||||
(* RUN: grep -v {recursive_type.*recursive_type} < %t.ll
|
(* RUN: grep -v {recursive_type.*recursive_type} < %t.ll
|
||||||
*)
|
*)
|
||||||
|
Loading…
Reference in New Issue
Block a user