llvm.org GIT mirror llvm / d80ce75
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 Erick Tryzelaar 10 years ago
4 changed file(s) with 27 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
164164 = "llvm_add_type_name"
165165 external delete_type_name : string -> llmodule -> unit
166166 = "llvm_delete_type_name"
167 external type_by_name : llmodule -> string -> lltype option
168 = "llvm_type_by_name"
167169 external dump_module : llmodule -> unit = "llvm_dump_module"
168170
169171 (*===-- Types -------------------------------------------------------------===*)
272272 table. *)
273273 external delete_type_name : string -> llmodule -> unit
274274 = "llvm_delete_type_name"
275
276 (** [type_by_name m n] returns the type in the module [m] named [n], or [None]
277 if it does not exist. See the method [llvm::Module::getTypeByName]. *)
278 external type_by_name : llmodule -> string -> lltype option
279 = "llvm_type_by_name"
275280
276281 (** [dump_module m] prints the .ll representation of the module [m] to standard
277282 error. See the method [llvm::Module::dump]. *)
163163 return Val_unit;
164164 }
165165
166 /* llmodule -> string -> lltype option */
167 CAMLprim value llvm_type_by_name(LLVMModuleRef M, value Name) {
168 CAMLparam1(Name);
169 LLVMTypeRef T;
170 if ((T = LLVMGetTypeByName(M, String_val(Name)))) {
171 value Option = alloc(1, 0);
172 Field(Option, 0) = (value) T;
173 CAMLreturn(Option);
174 }
175 CAMLreturn(Val_int(0));
176 }
177
166178 /* llmodule -> unit */
167179 CAMLprim value llvm_dump_module(LLVMModuleRef M) {
168180 LLVMDumpModule(M);
184184 let ty = opaque_type context in
185185 insist (define_type_name "delete_type" ty m);
186186 delete_type_name "delete_type" m;
187
188 (* RUN: grep {type_name.*opaque} < %t.ll
189 *)
190 group "type_name"; begin
191 let ty = opaque_type context in
192 insist (define_type_name "type_name" ty m);
193 insist ((type_by_name m "type_name") = Some ty)
194 end;
187195
188196 (* RUN: grep -v {recursive_type.*recursive_type} < %t.ll
189197 *)