llvm.org GIT mirror llvm / 07d5aef
lto.h: Use lto_bool_t instead of int to restore the ABI This reverts commit r193255 and instead creates an lto_bool_t typedef that points to bool, _Bool, or unsigned char depending on what is available. Only recent versions of MSVC provide a stdbool.h header. Reviewers: rafael.espindola Differential Revision: http://llvm-reviews.chandlerc.com/D2019 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193377 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 7 years ago
2 changed file(s) with 32 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
1717
1818 #include
1919 #include
20
21 #ifndef __cplusplus
22 #if !defined(_MSC_VER)
23 #include
24 typedef bool lto_bool_t;
25 #else
26 // MSVC in particular does not have anything like _Bool or bool in C, but we can
27 // at least make sure the type is the same size. The implementation side will
28 // use C++ bool.
29 typedef unsigned char lto_bool_t;
30 #endif
31 #else
32 typedef bool lto_bool_t;
33 #endif
2034
2135 /**
2236 * @defgroup LLVMCLTO LTO
8599 /**
86100 * Checks if a file is a loadable object file.
87101 */
88 extern int
102 extern lto_bool_t
89103 lto_module_is_object_file(const char* path);
90104
91105
92106 /**
93107 * Checks if a file is a loadable object compiled for requested target.
94108 */
95 extern int
109 extern lto_bool_t
96110 lto_module_is_object_file_for_target(const char* path,
97111 const char* target_triple_prefix);
98112
100114 /**
101115 * Checks if a buffer is a loadable object file.
102116 */
103 extern int
117 extern lto_bool_t
104118 lto_module_is_object_file_in_memory(const void* mem, size_t length);
105119
106120
107121 /**
108122 * Checks if a buffer is a loadable object compiled for requested target.
109123 */
110 extern int
124 extern lto_bool_t
111125 lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
112126 const char* target_triple_prefix);
113127
206220 * Add an object module to the set of modules for which code will be generated.
207221 * Returns true on error (check lto_get_error_message() for details).
208222 */
209 extern int
223 extern lto_bool_t
210224 lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
211225
212226
215229 * Sets if debug info should be generated.
216230 * Returns true on error (check lto_get_error_message() for details).
217231 */
218 extern int
232 extern lto_bool_t
219233 lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
220234
221235
223237 * Sets which PIC code model to generated.
224238 * Returns true on error (check lto_get_error_message() for details).
225239 */
226 extern int
240 extern lto_bool_t
227241 lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
228242
229243
269283 * merged contents of all modules added so far.
270284 * Returns true on error (check lto_get_error_message() for details).
271285 */
272 extern int
286 extern lto_bool_t
273287 lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
274288
275289 /**
287301 * Generates code for all added modules into one native object file.
288302 * The name of the file is written to name. Returns true on error.
289303 */
290 extern int
304 extern lto_bool_t
291305 lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
292306
293307
8989 }
9090
9191 /// lto_module_is_object_file - Validates if a file is a loadable object file.
92 int lto_module_is_object_file(const char* path) {
92 bool lto_module_is_object_file(const char* path) {
9393 return LTOModule::isBitcodeFile(path);
9494 }
9595
9696 /// lto_module_is_object_file_for_target - Validates if a file is a loadable
9797 /// object file compilable for requested target.
98 int lto_module_is_object_file_for_target(const char* path,
98 bool lto_module_is_object_file_for_target(const char* path,
9999 const char* target_triplet_prefix) {
100100 return LTOModule::isBitcodeFileForTarget(path, target_triplet_prefix);
101101 }
102102
103103 /// lto_module_is_object_file_in_memory - Validates if a buffer is a loadable
104104 /// object file.
105 int lto_module_is_object_file_in_memory(const void* mem, size_t length) {
105 bool lto_module_is_object_file_in_memory(const void* mem, size_t length) {
106106 return LTOModule::isBitcodeFile(mem, length);
107107 }
108108
109109 /// lto_module_is_object_file_in_memory_for_target - Validates if a buffer is a
110110 /// loadable object file compilable for the target.
111 int
111 bool
112112 lto_module_is_object_file_in_memory_for_target(const void* mem,
113113 size_t length,
114114 const char* target_triplet_prefix) {
215215 /// lto_codegen_add_module - Add an object module to the set of modules for
216216 /// which code will be generated. Returns true on error (check
217217 /// lto_get_error_message() for details).
218 int lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) {
218 bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) {
219219 return !cg->addModule(mod, sLastErrorString);
220220 }
221221
222222 /// lto_codegen_set_debug_model - Sets what if any format of debug info should
223223 /// be generated. Returns true on error (check lto_get_error_message() for
224224 /// details).
225 int lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) {
225 bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) {
226226 cg->setDebugInfo(debug);
227227 return false;
228228 }
229229
230230 /// lto_codegen_set_pic_model - Sets what code model to generated. Returns true
231231 /// on error (check lto_get_error_message() for details).
232 int lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) {
232 bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) {
233233 cg->setCodePICModel(model);
234234 return false;
235235 }
266266 /// lto_codegen_write_merged_modules - Writes a new file at the specified path
267267 /// that contains the merged contents of all modules added so far. Returns true
268268 /// on error (check lto_get_error_message() for details).
269 int lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
269 bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
270270 if (!parsedOptions) {
271271 cg->parseCodeGenDebugOptions();
272272 parsedOptions = true;
292292 /// lto_codegen_compile_to_file - Generates code for all added modules into one
293293 /// native object file. The name of the file is written to name. Returns true on
294294 /// error.
295 int lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
295 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
296296 if (!parsedOptions) {
297297 cg->parseCodeGenDebugOptions();
298298 parsedOptions = true;