llvm.org GIT mirror llvm / 0941534
add attributes and module level asm to the ocaml bindings, patch by Patrick Walton! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100932 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
5 changed file(s) with 93 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
8989 | Optsize
9090 | Ssp
9191 | Sspreq
92 | Alignment
92 | Alignment of int
9393 | Nocapture
9494 | Noredzone
9595 | Noimplicitfloat
9696 | Naked
9797 | Inlinehint
98 | Stackalignment
98 | Stackalignment of int
9999 end
100100
101101 module Icmp = struct
169169 external type_by_name : llmodule -> string -> lltype option
170170 = "llvm_type_by_name"
171171 external dump_module : llmodule -> unit = "llvm_dump_module"
172 external set_module_inline_asm : llmodule -> string -> unit
173 = "llvm_set_module_inline_asm"
172174
173175 (*===-- Types -------------------------------------------------------------===*)
174176 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
547549 let fold_right_functions f m init =
548550 fold_right_function_range f (function_end m) (At_start m) init
549551
550 external add_function_attr : llvalue -> Attribute.t -> unit
551 = "llvm_add_function_attr"
552 external remove_function_attr : llvalue -> Attribute.t -> unit
553 = "llvm_remove_function_attr"
552 external llvm_add_function_attr : llvalue -> int -> unit
553 = "llvm_add_function_attr"
554 external llvm_remove_function_attr : llvalue -> int -> unit
555 = "llvm_remove_function_attr"
556
557 let pack_attr (attr:Attribute.t) : int =
558 match attr with
559 Attribute.Zext -> 1 lsl 0
560 | Attribute.Sext -> 1 lsl 1
561 | Attribute.Noreturn -> 1 lsl 2
562 | Attribute.Inreg -> 1 lsl 3
563 | Attribute.Structret -> 1 lsl 4
564 | Attribute.Nounwind -> 1 lsl 5
565 | Attribute.Noalias -> 1 lsl 6
566 | Attribute.Byval -> 1 lsl 7
567 | Attribute.Nest -> 1 lsl 8
568 | Attribute.Readnone -> 1 lsl 9
569 | Attribute.Readonly -> 1 lsl 10
570 | Attribute.Noinline -> 1 lsl 11
571 | Attribute.Alwaysinline -> 1 lsl 12
572 | Attribute.Optsize -> 1 lsl 13
573 | Attribute.Ssp -> 1 lsl 14
574 | Attribute.Sspreq -> 1 lsl 15
575 | Attribute.Alignment n -> n lsl 16
576 | Attribute.Nocapture -> 1 lsl 21
577 | Attribute.Noredzone -> 1 lsl 22
578 | Attribute.Noimplicitfloat -> 1 lsl 23
579 | Attribute.Naked -> 1 lsl 24
580 | Attribute.Inlinehint -> 1 lsl 25
581 | Attribute.Stackalignment n -> n lsl 26
582
583 let add_function_attr llval attr =
584 llvm_add_function_attr llval (pack_attr attr)
585
586 let remove_function_attr llval attr =
587 llvm_remove_function_attr llval (pack_attr attr)
554588
555589 (*--... Operations on params ...............................................--*)
556590 external params : llvalue -> llvalue array = "llvm_params"
601635 let fold_right_params f fn init =
602636 fold_right_param_range f init (param_end fn) (At_start fn)
603637
604 external add_param_attr : llvalue -> Attribute.t -> unit
605 = "llvm_add_param_attr"
606 external remove_param_attr : llvalue -> Attribute.t -> unit
607 = "llvm_remove_param_attr"
638 external llvm_add_param_attr : llvalue -> int -> unit
639 = "llvm_add_param_attr"
640 external llvm_remove_param_attr : llvalue -> int -> unit
641 = "llvm_remove_param_attr"
642
643 let add_param_attr llval attr =
644 llvm_add_param_attr llval (pack_attr attr)
645
646 let remove_param_attr llval attr =
647 llvm_remove_param_attr llval (pack_attr attr)
648
608649 external set_param_alignment : llvalue -> int -> unit
609650 = "llvm_set_param_alignment"
610651
726767 = "llvm_instruction_call_conv"
727768 external set_instruction_call_conv: int -> llvalue -> unit
728769 = "llvm_set_instruction_call_conv"
729 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
730 = "llvm_add_instruction_param_attr"
731 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
732 = "llvm_remove_instruction_param_attr"
770
771 external llvm_add_instruction_param_attr : llvalue -> int -> int -> unit
772 = "llvm_add_instruction_param_attr"
773 external llvm_remove_instruction_param_attr : llvalue -> int -> int -> unit
774 = "llvm_remove_instruction_param_attr"
775
776 let add_instruction_param_attr llval i attr =
777 llvm_add_instruction_param_attr llval i (pack_attr attr)
778
779 let remove_instruction_param_attr llval i attr =
780 llvm_remove_instruction_param_attr llval i (pack_attr attr)
733781
734782 (*--... Operations on call instructions (only) .............................--*)
735783 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
138138 | Optsize
139139 | Ssp
140140 | Sspreq
141 | Alignment
141 | Alignment of int
142142 | Nocapture
143143 | Noredzone
144144 | Noimplicitfloat
145145 | Naked
146146 | Inlinehint
147 | Stackalignment
147 | Stackalignment of int
148148 end
149149
150150 (** The predicate for an integer comparison ([icmp]) instruction.
283283 error. See the method [llvm::Module::dump]. *)
284284 external dump_module : llmodule -> unit = "llvm_dump_module"
285285
286 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
287 the method [llvm::Module::setModuleInlineAsm]. *)
288 external set_module_inline_asm : llmodule -> string -> unit
289 = "llvm_set_module_inline_asm"
290
286291
287292 (** {6 Types} *)
288293
12811286
12821287 (** [add_function_attr f a] adds attribute [a] to the return type of function
12831288 [f]. *)
1284 external add_function_attr : llvalue -> Attribute.t -> unit
1285 = "llvm_add_function_attr"
1289 val add_function_attr : llvalue -> Attribute.t -> unit
12861290
12871291 (** [remove_function_attr f a] removes attribute [a] from the return type of
12881292 function [f]. *)
1289 external remove_function_attr : llvalue -> Attribute.t -> unit
1290 = "llvm_remove_function_attr"
1293 val remove_function_attr : llvalue -> Attribute.t -> unit
12911294
12921295 (** {7 Operations on params} *)
12931296
13421345 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
13431346
13441347 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1345 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1348 val add_param_attr : llvalue -> Attribute.t -> unit
13461349
13471350 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1348 external remove_param_attr : llvalue -> Attribute.t -> unit
1349 = "llvm_remove_param_attr"
1351 val remove_param_attr : llvalue -> Attribute.t -> unit
13501352
13511353 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
13521354 external set_param_alignment : llvalue -> int -> unit
14981500 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
14991501 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
15001502 value. *)
1501 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1502 = "llvm_add_instruction_param_attr"
1503 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
15031504
15041505 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
15051506 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
15061507 return value. *)
1507 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1508 = "llvm_remove_instruction_param_attr"
1508 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
15091509
15101510 (** {Operations on call instructions (only)} *)
15111511
181181 return Val_unit;
182182 }
183183
184 /* llmodule -> string -> unit */
185 CAMLprim value llvm_set_module_inline_asm(LLVMModuleRef M, value Asm) {
186 LLVMSetModuleInlineAsm(M, String_val(Asm));
187 return Val_unit;
188 }
184189
185190 /*===-- Types -------------------------------------------------------------===*/
186191
940945
941946 /* llvalue -> Attribute.t -> unit */
942947 CAMLprim value llvm_add_function_attr(LLVMValueRef Arg, value PA) {
943 LLVMAddFunctionAttr(Arg, 1<<Int_val(PA));
948 LLVMAddFunctionAttr(Arg, Int_val(PA));
944949 return Val_unit;
945950 }
946951
947952 /* llvalue -> Attribute.t -> unit */
948953 CAMLprim value llvm_remove_function_attr(LLVMValueRef Arg, value PA) {
949 LLVMRemoveFunctionAttr(Arg, 1<<Int_val(PA));
954 LLVMRemoveFunctionAttr(Arg, Int_val(PA));
950955 return Val_unit;
951956 }
952957 /*--... Operations on parameters ...........................................--*/
967972
968973 /* llvalue -> Attribute.t -> unit */
969974 CAMLprim value llvm_add_param_attr(LLVMValueRef Arg, value PA) {
970 LLVMAddAttribute(Arg, 1<<Int_val(PA));
975 LLVMAddAttribute(Arg, Int_val(PA));
971976 return Val_unit;
972977 }
973978
974979 /* llvalue -> Attribute.t -> unit */
975980 CAMLprim value llvm_remove_param_attr(LLVMValueRef Arg, value PA) {
976 LLVMRemoveAttribute(Arg, 1<<Int_val(PA));
981 LLVMRemoveAttribute(Arg, Int_val(PA));
977982 return Val_unit;
978983 }
979984
10411046 CAMLprim value llvm_add_instruction_param_attr(LLVMValueRef Instr,
10421047 value index,
10431048 value PA) {
1044 LLVMAddInstrAttribute(Instr, Int_val(index), 1<<Int_val(PA));
1049 LLVMAddInstrAttribute(Instr, Int_val(index), Int_val(PA));
10451050 return Val_unit;
10461051 }
10471052
10491054 CAMLprim value llvm_remove_instruction_param_attr(LLVMValueRef Instr,
10501055 value index,
10511056 value PA) {
1052 LLVMRemoveInstrAttribute(Instr, Int_val(index), 1<<Int_val(PA));
1057 LLVMRemoveInstrAttribute(Instr, Int_val(index), Int_val(PA));
10531058 return Val_unit;
10541059 }
10551060
318318 /** See Module::dump. */
319319 void LLVMDumpModule(LLVMModuleRef M);
320320
321 /** See Module::setModuleInlineAsm. */
322 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
321323
322324 /*===-- Types -------------------------------------------------------------===*/
323325
116116
117117 void LLVMDumpModule(LLVMModuleRef M) {
118118 unwrap(M)->dump();
119 }
120
121 /*--.. Operations on inline assembler ......................................--*/
122 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
123 unwrap(M)->setModuleInlineAsm(StringRef(Asm));
119124 }
120125
121126