aboutsummaryrefslogtreecommitdiff
path: root/bindings/ocaml/target/target_ocaml.c
blob: c9d0b8771b47a96e5515de184327ee0b42a6e66f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*===-- target_ocaml.c - LLVM Ocaml Glue ------------------------*- C++ -*-===*\
|*                                                                            *|
|*                     The LLVM Compiler Infrastructure                       *|
|*                                                                            *|
|* This file is distributed under the University of Illinois Open Source      *|
|* License. See LICENSE.TXT for details.                                      *|
|*                                                                            *|
|*===----------------------------------------------------------------------===*|
|*                                                                            *|
|* This file glues LLVM's ocaml interface to its C interface. These functions *|
|* are by and large transparent wrappers to the corresponding C functions.    *|
|*                                                                            *|
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|* macros, since most of the parameters are not GC heap objects.              *|
|*                                                                            *|
\*===----------------------------------------------------------------------===*/

#include "llvm-c/Target.h"
#include "caml/alloc.h"

/* string -> DataLayout.t */
CAMLprim LLVMDataLayoutRef llvm_targetdata_create(value StringRep) {
  return LLVMCreateDataLayout(String_val(StringRep));
}

/* DataLayout.t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
CAMLprim value llvm_targetdata_add(LLVMDataLayoutRef TD, LLVMPassManagerRef PM){
  LLVMAddDataLayout(TD, PM);
  return Val_unit;
}

/* DataLayout.t -> string */
CAMLprim value llvm_targetdata_as_string(LLVMDataLayoutRef TD) {
  char *StringRep = LLVMCopyStringRepOfDataLayout(TD);
  value Copy = copy_string(StringRep);
  LLVMDisposeMessage(StringRep);
  return Copy;
}

/* DataLayout.t -> unit */
CAMLprim value llvm_targetdata_dispose(LLVMDataLayoutRef TD) {
  LLVMDisposeDataLayout(TD);
  return Val_unit;
}

/* DataLayout.t -> Endian.t */
CAMLprim value llvm_byte_order(LLVMDataLayoutRef TD) {
  return Val_int(LLVMByteOrder(TD));
}

/* DataLayout.t -> int */
CAMLprim value llvm_pointer_size(LLVMDataLayoutRef TD) {
  return Val_int(LLVMPointerSize(TD));
}

/* DataLayout.t -> Llvm.lltype -> Int64.t */
CAMLprim value llvm_size_in_bits(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
  return caml_copy_int64(LLVMSizeOfTypeInBits(TD, Ty));
}

/* DataLayout.t -> Llvm.lltype -> Int64.t */
CAMLprim value llvm_store_size(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
  return caml_copy_int64(LLVMStoreSizeOfType(TD, Ty));
}

/* DataLayout.t -> Llvm.lltype -> Int64.t */
CAMLprim value llvm_abi_size(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
  return caml_copy_int64(LLVMABISizeOfType(TD, Ty));
}

/* DataLayout.t -> Llvm.lltype -> int */
CAMLprim value llvm_abi_align(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
  return Val_int(LLVMABIAlignmentOfType(TD, Ty));
}

/* DataLayout.t -> Llvm.lltype -> int */
CAMLprim value llvm_stack_align(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
  return Val_int(LLVMCallFrameAlignmentOfType(TD, Ty));
}

/* DataLayout.t -> Llvm.lltype -> int */
CAMLprim value llvm_preferred_align(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
  return Val_int(LLVMPreferredAlignmentOfType(TD, Ty));
}

/* DataLayout.t -> Llvm.llvalue -> int */
CAMLprim value llvm_preferred_align_of_global(LLVMDataLayoutRef TD,
                                              LLVMValueRef GlobalVar) {
  return Val_int(LLVMPreferredAlignmentOfGlobal(TD, GlobalVar));
}

/* DataLayout.t -> Llvm.lltype -> Int64.t -> int */
CAMLprim value llvm_element_at_offset(LLVMDataLayoutRef TD, LLVMTypeRef Ty,
                                      value Offset) {
  return Val_int(LLVMElementAtOffset(TD, Ty, Int_val(Offset)));
}

/* DataLayout.t -> Llvm.lltype -> int -> Int64.t */
CAMLprim value llvm_offset_of_element(LLVMDataLayoutRef TD, LLVMTypeRef Ty,
                                      value Index) {
  return caml_copy_int64(LLVMOffsetOfElement(TD, Ty, Int_val(Index)));
}