Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
8.5 KiB

  1. /*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- 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 header provides public interface to an abstract link time optimization*|
  11. |* library. LLVM provides an implementation of this interface for use with *|
  12. |* llvm bitcode files. *|
  13. |* *|
  14. \*===----------------------------------------------------------------------===*/
  15. #ifndef LLVM_C_LTO_H
  16. #define LLVM_C_LTO_H
  17. #include <stdbool.h>
  18. #include <stddef.h>
  19. #include <unistd.h>
  20. /**
  21. * @defgroup LLVMCLTO LTO
  22. * @ingroup LLVMC
  23. *
  24. * @{
  25. */
  26. #define LTO_API_VERSION 4
  27. typedef enum {
  28. LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */
  29. LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0,
  30. LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0,
  31. LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0,
  32. LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080,
  33. LTO_SYMBOL_DEFINITION_MASK = 0x00000700,
  34. LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100,
  35. LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200,
  36. LTO_SYMBOL_DEFINITION_WEAK = 0x00000300,
  37. LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400,
  38. LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500,
  39. LTO_SYMBOL_SCOPE_MASK = 0x00003800,
  40. LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800,
  41. LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000,
  42. LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000,
  43. LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800,
  44. LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800
  45. } lto_symbol_attributes;
  46. typedef enum {
  47. LTO_DEBUG_MODEL_NONE = 0,
  48. LTO_DEBUG_MODEL_DWARF = 1
  49. } lto_debug_model;
  50. typedef enum {
  51. LTO_CODEGEN_PIC_MODEL_STATIC = 0,
  52. LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1,
  53. LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2
  54. } lto_codegen_model;
  55. /** opaque reference to a loaded object module */
  56. typedef struct LTOModule* lto_module_t;
  57. /** opaque reference to a code generator */
  58. typedef struct LTOCodeGenerator* lto_code_gen_t;
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. /**
  63. * Returns a printable string.
  64. */
  65. extern const char*
  66. lto_get_version(void);
  67. /**
  68. * Returns the last error string or NULL if last operation was successful.
  69. */
  70. extern const char*
  71. lto_get_error_message(void);
  72. /**
  73. * Checks if a file is a loadable object file.
  74. */
  75. extern bool
  76. lto_module_is_object_file(const char* path);
  77. /**
  78. * Checks if a file is a loadable object compiled for requested target.
  79. */
  80. extern bool
  81. lto_module_is_object_file_for_target(const char* path,
  82. const char* target_triple_prefix);
  83. /**
  84. * Checks if a buffer is a loadable object file.
  85. */
  86. extern bool
  87. lto_module_is_object_file_in_memory(const void* mem, size_t length);
  88. /**
  89. * Checks if a buffer is a loadable object compiled for requested target.
  90. */
  91. extern bool
  92. lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
  93. const char* target_triple_prefix);
  94. /**
  95. * Loads an object file from disk.
  96. * Returns NULL on error (check lto_get_error_message() for details).
  97. */
  98. extern lto_module_t
  99. lto_module_create(const char* path);
  100. /**
  101. * Loads an object file from memory.
  102. * Returns NULL on error (check lto_get_error_message() for details).
  103. */
  104. extern lto_module_t
  105. lto_module_create_from_memory(const void* mem, size_t length);
  106. /**
  107. * Loads an object file from disk. The seek point of fd is not preserved.
  108. * Returns NULL on error (check lto_get_error_message() for details).
  109. */
  110. extern lto_module_t
  111. lto_module_create_from_fd(int fd, const char *path, size_t file_size);
  112. /**
  113. * Loads an object file from disk. The seek point of fd is not preserved.
  114. * Returns NULL on error (check lto_get_error_message() for details).
  115. */
  116. extern lto_module_t
  117. lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size,
  118. size_t map_size, off_t offset);
  119. /**
  120. * Frees all memory internally allocated by the module.
  121. * Upon return the lto_module_t is no longer valid.
  122. */
  123. extern void
  124. lto_module_dispose(lto_module_t mod);
  125. /**
  126. * Returns triple string which the object module was compiled under.
  127. */
  128. extern const char*
  129. lto_module_get_target_triple(lto_module_t mod);
  130. /**
  131. * Sets triple string with which the object will be codegened.
  132. */
  133. extern void
  134. lto_module_set_target_triple(lto_module_t mod, const char *triple);
  135. /**
  136. * Returns the number of symbols in the object module.
  137. */
  138. extern unsigned int
  139. lto_module_get_num_symbols(lto_module_t mod);
  140. /**
  141. * Returns the name of the ith symbol in the object module.
  142. */
  143. extern const char*
  144. lto_module_get_symbol_name(lto_module_t mod, unsigned int index);
  145. /**
  146. * Returns the attributes of the ith symbol in the object module.
  147. */
  148. extern lto_symbol_attributes
  149. lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
  150. /**
  151. * Instantiates a code generator.
  152. * Returns NULL on error (check lto_get_error_message() for details).
  153. */
  154. extern lto_code_gen_t
  155. lto_codegen_create(void);
  156. /**
  157. * Frees all code generator and all memory it internally allocated.
  158. * Upon return the lto_code_gen_t is no longer valid.
  159. */
  160. extern void
  161. lto_codegen_dispose(lto_code_gen_t);
  162. /**
  163. * Add an object module to the set of modules for which code will be generated.
  164. * Returns true on error (check lto_get_error_message() for details).
  165. */
  166. extern bool
  167. lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
  168. /**
  169. * Sets if debug info should be generated.
  170. * Returns true on error (check lto_get_error_message() for details).
  171. */
  172. extern bool
  173. lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
  174. /**
  175. * Sets which PIC code model to generated.
  176. * Returns true on error (check lto_get_error_message() for details).
  177. */
  178. extern bool
  179. lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
  180. /**
  181. * Sets the cpu to generate code for.
  182. */
  183. extern void
  184. lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
  185. /**
  186. * Sets the location of the assembler tool to run. If not set, libLTO
  187. * will use gcc to invoke the assembler.
  188. */
  189. extern void
  190. lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
  191. /**
  192. * Sets extra arguments that libLTO should pass to the assembler.
  193. */
  194. extern void
  195. lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
  196. int nargs);
  197. /**
  198. * Adds to a list of all global symbols that must exist in the final
  199. * generated code. If a function is not listed, it might be
  200. * inlined into every usage and optimized away.
  201. */
  202. extern void
  203. lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
  204. /**
  205. * Writes a new object file at the specified path that contains the
  206. * merged contents of all modules added so far.
  207. * Returns true on error (check lto_get_error_message() for details).
  208. */
  209. extern bool
  210. lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
  211. /**
  212. * Generates code for all added modules into one native object file.
  213. * On success returns a pointer to a generated mach-o/ELF buffer and
  214. * length set to the buffer size. The buffer is owned by the
  215. * lto_code_gen_t and will be freed when lto_codegen_dispose()
  216. * is called, or lto_codegen_compile() is called again.
  217. * On failure, returns NULL (check lto_get_error_message() for details).
  218. */
  219. extern const void*
  220. lto_codegen_compile(lto_code_gen_t cg, size_t* length);
  221. /**
  222. * Generates code for all added modules into one native object file.
  223. * The name of the file is written to name. Returns true on error.
  224. */
  225. extern bool
  226. lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
  227. /**
  228. * Sets options to help debug codegen bugs.
  229. */
  230. extern void
  231. lto_codegen_debug_options(lto_code_gen_t cg, const char *);
  232. /**
  233. * Initializes LLVM disassemblers.
  234. * FIXME: This doesn't really belong here.
  235. */
  236. extern void
  237. lto_initialize_disassembler(void);
  238. #ifdef __cplusplus
  239. }
  240. #endif
  241. /**
  242. * @}
  243. */
  244. #endif