llvm.org GIT mirror llvm / 3e0c835
C and Objective Caml bindings for the TargetData class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48422 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 11 years ago
10 changed file(s) with 583 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
242242 9FEDD5F10D8D73AB009F6DF1 /* Scalar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Scalar.h; sourceTree = ""; };
243243 9FEDD5F70D8D797D009F6DF1 /* Scalar.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Scalar.cpp; sourceTree = ""; };
244244 9FEDD6140D8D7C3B009F6DF1 /* scalar_opts.ml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = scalar_opts.ml; sourceTree = ""; };
245 9FEDD6B60D8D83D0009F6DF1 /* Target.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Target.cpp; sourceTree = ""; };
246 9FEDD6B80D8D83EC009F6DF1 /* Target.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Target.h; sourceTree = ""; };
247 9FEDD6BB0D8D8408009F6DF1 /* lto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lto.h; sourceTree = ""; };
248 9FEDD6BD0D8D8426009F6DF1 /* target.ml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = target.ml; sourceTree = ""; };
249 9FEDD6C10D8D844E009F6DF1 /* llvm_target.ml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = llvm_target.ml; sourceTree = ""; };
250 9FEDD6C20D8D844E009F6DF1 /* llvm_target.mli */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = llvm_target.mli; sourceTree = ""; };
251 9FEDD6C40D8D844E009F6DF1 /* target_ocaml.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = target_ocaml.c; sourceTree = ""; };
245252 CF1ACC9709C9DE4400D3C5EB /* IntrinsicInst.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IntrinsicInst.cpp; path = ../lib/VMCore/IntrinsicInst.cpp; sourceTree = ""; };
246253 CF26835B09178F5500C5F253 /* TargetInstrItineraries.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetInstrItineraries.h; sourceTree = ""; };
247254 CF32AF5C0AEE6A4E00D24CD4 /* LLVMTargetMachine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LLVMTargetMachine.cpp; sourceTree = ""; };
12741281 9F7C2C520CB9496C00498408 /* bitwriter.ml */,
12751282 9F502AEC0D1D8CF8007939DF /* executionengine.ml */,
12761283 9FEDD6140D8D7C3B009F6DF1 /* scalar_opts.ml */,
1284 9FEDD6BD0D8D8426009F6DF1 /* target.ml */,
12771285 9F7C2C5D0CB9496C00498408 /* vmcore.ml */,
12781286 );
12791287 path = Ocaml;
12991307 9FD3E56F0CA0116100E54D15 /* ocaml */ = {
13001308 isa = PBXGroup;
13011309 children = (
1302 9F7040170D8D72FF00FD06FF /* transforms */,
13031310 9F502ACD0D1D8CA3007939DF /* executionengine */,
13041311 9F7C240B0CB81ECD00498408 /* analysis */,
13051312 9F4B0E5D0D0E02580061F270 /* bitreader */,
13061313 9FD3E5700CA0116100E54D15 /* bitwriter */,
13071314 9FD3E57A0CA0116100E54D15 /* llvm */,
1315 9FEDD6C00D8D844E009F6DF1 /* target */,
1316 9F7040170D8D72FF00FD06FF /* transforms */,
13081317 );
13091318 path = ocaml;
13101319 sourceTree = "";
13471356 9FEDD5F10D8D73AB009F6DF1 /* Scalar.h */,
13481357 );
13491358 path = Transforms;
1359 sourceTree = "";
1360 };
1361 9FEDD6C00D8D844E009F6DF1 /* target */ = {
1362 isa = PBXGroup;
1363 children = (
1364 9FEDD6C10D8D844E009F6DF1 /* llvm_target.ml */,
1365 9FEDD6C20D8D844E009F6DF1 /* llvm_target.mli */,
1366 9FEDD6C40D8D844E009F6DF1 /* target_ocaml.c */,
1367 );
1368 path = target;
13501369 sourceTree = "";
13511370 };
13521371 CF8F1B480B64F7AB00BB4199 /* include/llvm-c */ = {
13581377 9FD3E58E0CA0125F00E54D15 /* Core.h */,
13591378 9FEB8C550D1CD1E200EE46BC /* ExecutionEngine.h */,
13601379 CF8F1B490B64F7AB00BB4199 /* LinkTimeOptimizer.h */,
1380 9FEDD6BB0D8D8408009F6DF1 /* lto.h */,
1381 9FEDD6B80D8D83EC009F6DF1 /* Target.h */,
13611382 9FEDD5F00D8D73AB009F6DF1 /* Transforms */,
13621383 );
13631384 name = "include/llvm-c";
17981819 DE66F09308ABEE6000323D32 /* X86 */,
17991820 DE66EF1008ABEE5E00323D32 /* TargetRegisterInfo.cpp */,
18001821 CF9BCD1508C75070001E7011 /* SubtargetFeature.cpp */,
1822 9FEDD6B60D8D83D0009F6DF1 /* Target.cpp */,
18011823 DE66F08A08ABEE6000323D32 /* Target.td */,
18021824 CF47BD860AAF487E00A8B13E /* TargetAsmInfo.cpp */,
18031825 9FE25D960CAB1759005383FC /* TargetCallingConv.td */,
77 ##===----------------------------------------------------------------------===##
88
99 LEVEL := ../..
10 DIRS = llvm bitreader bitwriter analysis executionengine transforms
10 DIRS = llvm bitreader bitwriter analysis target executionengine transforms
1111 ExtraMakefiles = $(PROJ_OBJ_DIR)/Makefile.ocaml
1212
1313 ocamldoc:
0 ##===- bindings/ocaml/target/Makefile ----------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 #
9 # This is the makefile for the Objective Caml Llvm_target interface.
10 #
11 ##===----------------------------------------------------------------------===##
12
13 LEVEL := ../../..
14 LIBRARYNAME := llvm_target
15 DONT_BUILD_RELINKED := 1
16 UsedComponents := target
17 UsedOcamlInterfaces := llvm
18
19 include ../Makefile.ocaml
0 (*===-- llvm_target.ml - LLVM Ocaml Interface ------------------*- OCaml -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*)
8
9 module Endian = struct
10 type t =
11 | Big
12 | Little
13 end
14
15 module TargetData = struct
16 type t
17
18 external create : string -> t = "llvm_targetdata_create"
19 external add : t -> [ unit
20 = "llvm_targetdata_add"
21 external as_string : t -> string = "llvm_targetdata_as_string"
22 external invalidate_struct_layout : t -> Llvm.lltype -> unit
23 = "llvm_targetdata_invalidate_struct_layout"
24 external dispose : t -> unit = "llvm_targetdata_dispose"
25 end
26
27 external byte_order : TargetData.t -> Endian.t = "llvm_byte_order"
28 external pointer_size : TargetData.t -> int = "llvm_pointer_size"
29 external intptr_type : TargetData.t -> Llvm.lltype = "LLVMIntPtrType"
30 external size_in_bits : TargetData.t -> Llvm.lltype -> Int64.t
31 = "llvm_size_in_bits"
32 external store_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
33 external abi_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
34 external abi_align : TargetData.t -> Llvm.lltype -> int = "llvm_abi_align"
35 external stack_align : TargetData.t -> Llvm.lltype -> int = "llvm_stack_align"
36 external preferred_align : TargetData.t -> Llvm.lltype -> int
37 = "llvm_preferred_align"
38 external preferred_align_of_global : TargetData.t -> Llvm.llvalue -> int
39 = "llvm_preferred_align_of_global"
40 external element_at_offset : TargetData.t -> Llvm.lltype -> Int64.t -> int
41 = "llvm_element_at_offset"
42 external offset_of_element : TargetData.t -> Llvm.lltype -> int -> Int64.t
43 = "llvm_offset_of_element"
0 (*===-- llvm_target.mli - LLVM Ocaml Interface -----------------*- OCaml -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*)
8
9 (** Target Information.
10
11 This interface provides an ocaml API for LLVM target information,
12 the classes in the Target library. *)
13
14 module Endian : sig
15 type t =
16 | Big
17 | Little
18 end
19
20 module TargetData : sig
21 type t
22
23 (** [TargetData.create rep] parses the target data string representation [rep].
24 See the constructor llvm::TargetData::TargetData. *)
25 external create : string -> t = "llvm_targetdata_create"
26
27 (** [add_target_data td pm] adds the target data [td] to the pass manager [pm].
28 Does not take ownership of the target data.
29 See the method llvm::PassManagerBase::add. *)
30 external add : t -> [ unit
31 = "llvm_targetdata_add"
32
33 (** [as_string td] is the string representation of the target data [td].
34 See the constructor llvm::TargetData::TargetData. *)
35 external as_string : t -> string = "llvm_targetdata_as_string"
36
37 (** Struct layouts are speculatively cached. If a TargetDataRef is alive when
38 types are being refined and removed, this method must be called whenever a
39 struct type is removed to avoid a dangling pointer in this cache.
40 See the method llvm::TargetData::InvalidateStructLayoutInfo. *)
41 external invalidate_struct_layout : t -> Llvm.lltype -> unit
42 = "llvm_targetdata_invalidate_struct_layout"
43
44 (** Deallocates a TargetData.
45 See the destructor llvm::TargetData::~TargetData. *)
46 external dispose : t -> unit = "llvm_targetdata_dispose"
47 end
48
49 (** Returns the byte order of a target, either LLVMBigEndian or
50 LLVMLittleEndian.
51 See the method llvm::TargetData::isLittleEndian. *)
52 external byte_order : TargetData.t -> Endian.t = "llvm_byte_order"
53
54 (** Returns the pointer size in bytes for a target.
55 See the method llvm::TargetData::getPointerSize. *)
56 external pointer_size : TargetData.t -> int = "llvm_pointer_size"
57
58 (** Returns the integer type that is the same size as a pointer on a target.
59 See the method llvm::TargetData::getIntPtrType. *)
60 external intptr_type : TargetData.t -> Llvm.lltype = "LLVMIntPtrType"
61
62 (** Computes the size of a type in bytes for a target.
63 See the method llvm::TargetData::getTypeSizeInBits. *)
64 external size_in_bits : TargetData.t -> Llvm.lltype -> Int64.t
65 = "llvm_size_in_bits"
66
67 (** Computes the storage size of a type in bytes for a target.
68 See the method llvm::TargetData::getTypeStoreSize. *)
69 external store_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
70
71 (** Computes the ABI size of a type in bytes for a target.
72 See the method llvm::TargetData::getABITypeSize. *)
73 external abi_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
74
75 (** Computes the ABI alignment of a type in bytes for a target.
76 See the method llvm::TargetData::getTypeABISize. *)
77 external abi_align : TargetData.t -> Llvm.lltype -> int = "llvm_abi_align"
78
79 (** Computes the call frame alignment of a type in bytes for a target.
80 See the method llvm::TargetData::getTypeABISize. *)
81 external stack_align : TargetData.t -> Llvm.lltype -> int = "llvm_stack_align"
82
83 (** Computes the preferred alignment of a type in bytes for a target.
84 See the method llvm::TargetData::getTypeABISize. *)
85 external preferred_align : TargetData.t -> Llvm.lltype -> int
86 = "llvm_preferred_align"
87
88 (** Computes the preferred alignment of a global variable in bytes for a target.
89 See the method llvm::TargetData::getPreferredAlignment. *)
90 external preferred_align_of_global : TargetData.t -> Llvm.llvalue -> int
91 = "llvm_preferred_align_of_global"
92
93 (** Computes the structure element that contains the byte offset for a target.
94 See the method llvm::StructLayout::getElementContainingOffset. *)
95 external element_at_offset : TargetData.t -> Llvm.lltype -> Int64.t -> int
96 = "llvm_element_at_offset"
97
98 (** Computes the byte offset of the indexed struct element for a target.
99 See the method llvm::StructLayout::getElementContainingOffset. *)
100 external offset_of_element : TargetData.t -> Llvm.lltype -> int -> Int64.t
101 = "llvm_offset_of_element"
0 /*===-- target_ocaml.c - LLVM Ocaml Glue ------------------------*- C++ -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file is distributed under the University of Illinois Open Source *|
5 |* License. See LICENSE.TXT for details. *|
6 |* *|
7 |*===----------------------------------------------------------------------===*|
8 |* *|
9 |* This file glues LLVM's ocaml interface to its C interface. These functions *|
10 |* are by and large transparent wrappers to the corresponding C functions. *|
11 |* *|
12 |* Note that these functions intentionally take liberties with the CAMLparamX *|
13 |* macros, since most of the parameters are not GC heap objects. *|
14 |* *|
15 \*===----------------------------------------------------------------------===*/
16
17 #include "llvm-c/Target.h"
18 #include "caml/alloc.h"
19
20 /* string -> TargetData.t */
21 CAMLprim LLVMTargetDataRef llvm_targetdata_create(value StringRep) {
22 return LLVMCreateTargetData(String_val(StringRep));
23 }
24
25 /* TargetData.t -> [ unit */
26 CAMLprim value llvm_targetdata_add(LLVMTargetDataRef TD, LLVMPassManagerRef PM){
27 LLVMAddTargetData(TD, PM);
28 return Val_unit;
29 }
30
31 /* TargetData.t -> string */
32 CAMLprim value llvm_targetdata_as_string(LLVMTargetDataRef TD) {
33 char *StringRep = LLVMCopyStringRepOfTargetData(TD);
34 value Copy = copy_string(StringRep);
35 LLVMDisposeMessage(StringRep);
36 return Copy;
37 }
38
39 /* TargetData.t -> Llvm.lltype -> unit */
40 CAMLprim value llvm_targetdata_invalidate_struct_layout(LLVMTargetDataRef TD,
41 LLVMTypeRef Ty) {
42 LLVMInvalidateStructLayout(TD, Ty);
43 return Val_unit;
44 }
45
46 /* TargetData.t -> unit */
47 CAMLprim value llvm_targetdata_dispose(LLVMTargetDataRef TD) {
48 LLVMDisposeTargetData(TD);
49 return Val_unit;
50 }
51
52 /* TargetData.t -> Endian.t */
53 CAMLprim value llvm_byte_order(LLVMTargetDataRef TD) {
54 return Val_int(LLVMByteOrder(TD));
55 }
56
57 /* TargetData.t -> int */
58 CAMLprim value llvm_pointer_size(LLVMTargetDataRef TD) {
59 return Val_int(LLVMPointerSize(TD));
60 }
61
62 /* TargetData.t -> Llvm.lltype -> Int64.t */
63 CAMLprim value llvm_size_in_bits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
64 return caml_copy_int64(LLVMSizeOfTypeInBits(TD, Ty));
65 }
66
67 /* TargetData.t -> Llvm.lltype -> Int64.t */
68 CAMLprim value llvm_store_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
69 return caml_copy_int64(LLVMStoreSizeOfType(TD, Ty));
70 }
71
72 /* TargetData.t -> Llvm.lltype -> Int64.t */
73 CAMLprim value llvm_abi_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
74 return caml_copy_int64(LLVMABISizeOfType(TD, Ty));
75 }
76
77 /* TargetData.t -> Llvm.lltype -> int */
78 CAMLprim value llvm_abi_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
79 return Val_int(LLVMABIAlignmentOfType(TD, Ty));
80 }
81
82 /* TargetData.t -> Llvm.lltype -> int */
83 CAMLprim value llvm_stack_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
84 return Val_int(LLVMCallFrameAlignmentOfType(TD, Ty));
85 }
86
87 /* TargetData.t -> Llvm.lltype -> int */
88 CAMLprim value llvm_preferred_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
89 return Val_int(LLVMPreferredAlignmentOfType(TD, Ty));
90 }
91
92 /* TargetData.t -> Llvm.llvalue -> int */
93 CAMLprim value llvm_preferred_align_of_global(LLVMTargetDataRef TD,
94 LLVMValueRef GlobalVar) {
95 return Val_int(LLVMPreferredAlignmentOfGlobal(TD, GlobalVar));
96 }
97
98 /* TargetData.t -> Llvm.lltype -> Int64.t -> int */
99 CAMLprim value llvm_element_at_offset(LLVMTargetDataRef TD, LLVMTypeRef Ty,
100 value Offset) {
101 return Val_int(LLVMElementAtOffset(TD, Ty, Int_val(Offset)));
102 }
103
104 /* TargetData.t -> Llvm.lltype -> int -> Int64.t */
105 CAMLprim value llvm_offset_of_element(LLVMTargetDataRef TD, LLVMTypeRef Ty,
106 value Index) {
107 return caml_copy_int64(LLVMOffsetOfElement(TD, Ty, Int_val(Index)));
108 }
0 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file is distributed under the University of Illinois Open Source *|
5 |* License. See LICENSE.TXT for details. *|
6 |* *|
7 |*===----------------------------------------------------------------------===*|
8 |* *|
9 |* This header declares the C interface to libLLVMTarget.a, which *|
10 |* implements target information. *|
11 |* *|
12 |* Many exotic languages can interoperate with C code but have a harder time *|
13 |* with C++ due to name mangling. So in addition to C, this interface enables *|
14 |* tools written in such languages. *|
15 |* *|
16 \*===----------------------------------------------------------------------===*/
17
18 #ifndef LLVM_C_TARGET_H
19 #define LLVM_C_TARGET_H
20
21 #include "llvm-c/Core.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 enum { LLVMBigEndian, LLVMLittleEndian };
28 typedef int LLVMByteOrdering;
29
30 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
31 typedef struct LLVMStructLayout *LLVMStructLayoutRef;
32
33
34 /*===-- Target Data -------------------------------------------------------===*/
35
36 /** Creates target data from a target layout string.
37 See the constructor llvm::TargetData::TargetData. */
38 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
39
40 /** Adds target data information to a pass manager. This does not take ownership
41 of the target data.
42 See the method llvm::PassManagerBase::add. */
43 void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
44
45 /** Converts target data to a target layout string. The string must be disposed
46 with LLVMDisposeMessage.
47 See the constructor llvm::TargetData::TargetData. */
48 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
49
50 /** Returns the byte order of a target, either LLVMBigEndian or
51 LLVMLittleEndian.
52 See the method llvm::TargetData::isLittleEndian. */
53 LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
54
55 /** Returns the pointer size in bytes for a target.
56 See the method llvm::TargetData::getPointerSize. */
57 unsigned LLVMPointerSize(LLVMTargetDataRef);
58
59 /** Returns the integer type that is the same size as a pointer on a target.
60 See the method llvm::TargetData::getIntPtrType. */
61 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
62
63 /** Computes the size of a type in bytes for a target.
64 See the method llvm::TargetData::getTypeSizeInBits. */
65 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
66
67 /** Computes the storage size of a type in bytes for a target.
68 See the method llvm::TargetData::getTypeStoreSize. */
69 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
70
71 /** Computes the ABI size of a type in bytes for a target.
72 See the method llvm::TargetData::getABITypeSize. */
73 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
74
75 /** Computes the ABI alignment of a type in bytes for a target.
76 See the method llvm::TargetData::getTypeABISize. */
77 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
78
79 /** Computes the call frame alignment of a type in bytes for a target.
80 See the method llvm::TargetData::getTypeABISize. */
81 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
82
83 /** Computes the preferred alignment of a type in bytes for a target.
84 See the method llvm::TargetData::getTypeABISize. */
85 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
86
87 /** Computes the preferred alignment of a global variable in bytes for a target.
88 See the method llvm::TargetData::getPreferredAlignment. */
89 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
90 LLVMValueRef GlobalVar);
91
92 /** Computes the structure element that contains the byte offset for a target.
93 See the method llvm::StructLayout::getElementContainingOffset. */
94 unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
95 unsigned long long Offset);
96
97 /** Computes the byte offset of the indexed struct element for a target.
98 See the method llvm::StructLayout::getElementContainingOffset. */
99 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
100 unsigned Element);
101
102 /** Struct layouts are speculatively cached. If a TargetDataRef is alive when
103 types are being refined and removed, this method must be called whenever a
104 struct type is removed to avoid a dangling pointer in this cache.
105 See the method llvm::TargetData::InvalidateStructLayoutInfo. */
106 void LLVMInvalidateStructLayout(LLVMTargetDataRef, LLVMTypeRef StructTy);
107
108 /** Deallocates a TargetData.
109 See the destructor llvm::TargetData::~TargetData. */
110 void LLVMDisposeTargetData(LLVMTargetDataRef);
111
112
113 #ifdef __cplusplus
114 }
115
116 namespace llvm {
117 class TargetData;
118
119 inline TargetData *unwrap(LLVMTargetDataRef P) {
120 return reinterpret_cast(P);
121 }
122
123 inline LLVMTargetDataRef wrap(const TargetData *P) {
124 return reinterpret_cast(const_cast(P));
125 }
126 }
127
128 #endif /* defined(__cplusplus) */
129
130 #endif
0 //===-- Target.cpp --------------------------------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the C bindings for libLLVMTarget.a, which implements
10 // target information.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm-c/Target.h"
15 #include "llvm/PassManager.h"
16 #include "llvm/Target/TargetData.h"
17
18 using namespace llvm;
19
20 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
21 return wrap(new TargetData(StringRep));
22 }
23
24 void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
25 unwrap(PM)->add(new TargetData(*unwrap(TD)));
26 }
27
28 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) {
29 std::string StringRep = unwrap(TD)->getStringRepresentation();
30 return strdup(StringRep.c_str());
31 }
32
33 LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) {
34 return unwrap(TD)->isLittleEndian();
35 }
36
37 unsigned LLVMPointerSize(LLVMTargetDataRef TD) {
38 return unwrap(TD)->getPointerSize();
39 }
40
41 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
42 return wrap(unwrap(TD)->getIntPtrType());
43 }
44
45 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
46 return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
47 }
48
49 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
50 return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
51 }
52
53 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
54 return unwrap(TD)->getABITypeSize(unwrap(Ty));
55 }
56
57 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
58 return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
59 }
60
61 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
62 return unwrap(TD)->getCallFrameTypeAlignment(unwrap(Ty));
63 }
64
65 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
66 return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
67 }
68
69 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
70 LLVMValueRef GlobalVar) {
71 return unwrap(TD)->getPreferredAlignment(unwrap(GlobalVar));
72 }
73
74 unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
75 unsigned long long Offset) {
76 const StructType *STy = unwrap(StructTy);
77 return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
78 }
79
80 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
81 unsigned Element) {
82 const StructType *STy = unwrap(StructTy);
83 return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
84 }
85
86 void LLVMInvalidateStructLayout(LLVMTargetDataRef TD, LLVMTypeRef StructTy) {
87 unwrap(TD)->InvalidateStructLayoutInfo(unwrap(StructTy));
88 }
89
90 void LLVMDisposeTargetData(LLVMTargetDataRef TD) {
91 delete unwrap(TD);
92 }
None (* RUN: %ocamlc -warn-error A llvm.cma llvm_scalar_opts.cma %s -o %t
0 (* RUN: %ocamlc -warn-error A llvm.cma llvm_scalar_opts.cma llvm_target.cma %s -o %t
11 *)
22
33 (* Note: It takes several seconds for ocamlc to link an executable with
66
77 open Llvm
88 open Llvm_scalar_opts
9 open Llvm_target
910
1011
1112 (* Tiny unit test framework - really just to help find which line is busted *)
3031 let fn = define_function "fn" fty m in
3132 ignore (build_ret_void (builder_at_end (entry_block fn)));
3233
34 let td = TargetData.create (target_triple m) in
35
3336 ignore (PassManager.create_function mp
34 (* ++ add_instruction_combining Requires target data. *)
37 ++ TargetData.add td
38 ++ add_instruction_combining
3539 ++ add_reassociation
3640 ++ add_gvn
3741 ++ add_cfg_simplification
3943 ++ PassManager.initialize
4044 ++ PassManager.run_function fn
4145 ++ PassManager.finalize
42 ++ PassManager.dispose)
46 ++ PassManager.dispose);
47
48 TargetData.dispose td
4349
4450
4551 (*===-- Driver ------------------------------------------------------------===*)
0 (* RUN: %ocamlc -warn-error A llvm.cma llvm_target.cma %s -o %t
1 *)
2
3 (* Note: It takes several seconds for ocamlc to link an executable with
4 libLLVMCore.a, so it's better to write a big test than a bunch of
5 little ones. *)
6
7 open Llvm
8 open Llvm_target
9
10
11 (* Tiny unit test framework - really just to help find which line is busted *)
12 let suite name f =
13 prerr_endline (name ^ ":");
14 f ()
15
16
17 (*===-- Fixture -----------------------------------------------------------===*)
18
19 let filename = Sys.argv.(1)
20 let m = create_module filename
21
22
23 (*===-- Target Data -------------------------------------------------------===*)
24
25 let test_target_data () =
26 let td = TargetData.create (target_triple m) in
27 let sty = struct_type [| i32_type; i64_type |] in
28
29 ignore (TargetData.as_string td);
30 ignore (TargetData.invalidate_struct_layout td sty);
31 ignore (byte_order td);
32 ignore (pointer_size td);
33 ignore (intptr_type td);
34 ignore (size_in_bits td sty);
35 ignore (store_size td sty);
36 ignore (abi_size td sty);
37 ignore (stack_align td sty);
38 ignore (preferred_align td sty);
39 ignore (preferred_align_of_global td (declare_global sty "g" m));
40 ignore (element_at_offset td sty (Int64.of_int 1));
41 ignore (offset_of_element td sty 1);
42
43 TargetData.dispose td
44
45
46 (*===-- Driver ------------------------------------------------------------===*)
47
48 let _ =
49 suite "target data" test_target_data;
50 dispose_module m