Shrinkify Thumb2 r = add sp, imm.
[llvm/avr.git] / bindings / ocaml / target / target_ocaml.c
blobcc20e8187a7a43522ed4abe3c187050d9e7209c2
1 /*===-- target_ocaml.c - LLVM Ocaml Glue ------------------------*- C++ -*-===*\
2 |* *|
3 |* The LLVM Compiler Infrastructure *|
4 |* *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This file glues LLVM's ocaml interface to its C interface. These functions *|
11 |* are by and large transparent wrappers to the corresponding C functions. *|
12 |* *|
13 |* Note that these functions intentionally take liberties with the CAMLparamX *|
14 |* macros, since most of the parameters are not GC heap objects. *|
15 |* *|
16 \*===----------------------------------------------------------------------===*/
18 #include "llvm-c/Target.h"
19 #include "caml/alloc.h"
21 /* string -> TargetData.t */
22 CAMLprim LLVMTargetDataRef llvm_targetdata_create(value StringRep) {
23 return LLVMCreateTargetData(String_val(StringRep));
26 /* TargetData.t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
27 CAMLprim value llvm_targetdata_add(LLVMTargetDataRef TD, LLVMPassManagerRef PM){
28 LLVMAddTargetData(TD, PM);
29 return Val_unit;
32 /* TargetData.t -> string */
33 CAMLprim value llvm_targetdata_as_string(LLVMTargetDataRef TD) {
34 char *StringRep = LLVMCopyStringRepOfTargetData(TD);
35 value Copy = copy_string(StringRep);
36 LLVMDisposeMessage(StringRep);
37 return Copy;
40 /* TargetData.t -> Llvm.lltype -> unit */
41 CAMLprim value llvm_targetdata_invalidate_struct_layout(LLVMTargetDataRef TD,
42 LLVMTypeRef Ty) {
43 LLVMInvalidateStructLayout(TD, Ty);
44 return Val_unit;
47 /* TargetData.t -> unit */
48 CAMLprim value llvm_targetdata_dispose(LLVMTargetDataRef TD) {
49 LLVMDisposeTargetData(TD);
50 return Val_unit;
53 /* TargetData.t -> Endian.t */
54 CAMLprim value llvm_byte_order(LLVMTargetDataRef TD) {
55 return Val_int(LLVMByteOrder(TD));
58 /* TargetData.t -> int */
59 CAMLprim value llvm_pointer_size(LLVMTargetDataRef TD) {
60 return Val_int(LLVMPointerSize(TD));
63 /* TargetData.t -> Llvm.lltype -> Int64.t */
64 CAMLprim value llvm_size_in_bits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
65 return caml_copy_int64(LLVMSizeOfTypeInBits(TD, Ty));
68 /* TargetData.t -> Llvm.lltype -> Int64.t */
69 CAMLprim value llvm_store_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
70 return caml_copy_int64(LLVMStoreSizeOfType(TD, Ty));
73 /* TargetData.t -> Llvm.lltype -> Int64.t */
74 CAMLprim value llvm_abi_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
75 return caml_copy_int64(LLVMABISizeOfType(TD, Ty));
78 /* TargetData.t -> Llvm.lltype -> int */
79 CAMLprim value llvm_abi_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
80 return Val_int(LLVMABIAlignmentOfType(TD, Ty));
83 /* TargetData.t -> Llvm.lltype -> int */
84 CAMLprim value llvm_stack_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
85 return Val_int(LLVMCallFrameAlignmentOfType(TD, Ty));
88 /* TargetData.t -> Llvm.lltype -> int */
89 CAMLprim value llvm_preferred_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
90 return Val_int(LLVMPreferredAlignmentOfType(TD, Ty));
93 /* TargetData.t -> Llvm.llvalue -> int */
94 CAMLprim value llvm_preferred_align_of_global(LLVMTargetDataRef TD,
95 LLVMValueRef GlobalVar) {
96 return Val_int(LLVMPreferredAlignmentOfGlobal(TD, GlobalVar));
99 /* TargetData.t -> Llvm.lltype -> Int64.t -> int */
100 CAMLprim value llvm_element_at_offset(LLVMTargetDataRef TD, LLVMTypeRef Ty,
101 value Offset) {
102 return Val_int(LLVMElementAtOffset(TD, Ty, Int_val(Offset)));
105 /* TargetData.t -> Llvm.lltype -> int -> Int64.t */
106 CAMLprim value llvm_offset_of_element(LLVMTargetDataRef TD, LLVMTypeRef Ty,
107 value Index) {
108 return caml_copy_int64(LLVMOffsetOfElement(TD, Ty, Int_val(Index)));