Hello. I work at Apple on our linker. We are working to improve support for llvm in our tools. A while back Devang created <llvm/LinkTimeOptimizer.h> a C++ interface which allows the linker to process llvm bitcode files along with native mach-o object files. For the next step we'd like our other tools like nm, ar, and lipo to be able to transparently process bitcode files too. But those tools are all written in C. So, I've reworked the LTO interface as a C interfaces and broke out the steps so that it could be used by other (non-linker) tools. Below is the proposed interface. The project (llvm/tools/lto2 for now) will build a shared object that can be used by other tools. I'd be interested to know if any one else has use for this. One area we know we need to augment the API is to allow various optimizations to be selected on the linker command line. -Nick //===-- llvm-c/lto.h - LTO Public C Interface -------------------*- C+ + -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // // ===--------------------------------------------------------------------- -===// // // This header provides public interface to an abstract link time optimization // library. LLVM provides an implementation of this interface for use with // llvm bitcode files. // // ===--------------------------------------------------------------------- -===// #ifndef __LTO__H__ #define __LTO__H__ #include <stdint.h> #include <stdbool.h> #include <stddef.h> typedef enum { LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */ LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, LTO_SYMBOL_DEFINITION_MASK = 0x00000700, LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, LTO_SYMBOL_SCOPE_MASK = 0x00001800, LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800 } lto_symbol_attributes; typedef enum { LTO_DEBUG_MODEL_NONE = 0, LTO_DEBUG_MODEL_DWARF = 1 } lto_debug_model; typedef enum { LTO_CODEGEN_PIC_MODEL_STATIC = 0, LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2 } lto_codegen_model; // opaque reference to a loaded object module typedef struct LTOModule* lto_module_t; // opaque reference to a code generator typedef struct LTOCodeGenerator* lto_code_gen_t; #ifdef __cplusplus extern "C" { #endif // // returns a printable string // extern const char* lto_get_version(); // // returns the last error string or NULL if last operation was sucessful // extern const char* lto_get_error_message(); // // validates if a file is a loadable object file // extern bool lto_module_is_object_file(const char* path); // // validates if a file is a loadable object file compilable for requested target // extern bool lto_module_is_object_file_for_target(const char* path, const char* target_triplet_prefix); // // validates if a buffer is a loadable object file // extern bool lto_module_is_object_file_in_memory(const uint8_t* mem, size_t length); // // validates if a buffer is a loadable object file compilable for requested target // extern bool lto_module_is_object_file_in_memory_for_target(const uint8_t* mem, size_t length, const char* target_triplet_prefix); // // loads an object file from disk // returns NULL on error (check lto_get_error_message() for details) // extern lto_module_t lto_module_create(const char* path); // // loads an object file from memory // returns NULL on error (check lto_get_error_message() for details) // extern lto_module_t lto_module_create_from_memory(const uint8_t* mem, size_t length); // // frees all memory for a module // upon return the lto_module_t is no longer valid // extern void lto_module_release(lto_module_t mod); // // returns triplet string which the object module was compiled under // extern const char* lto_module_get_target_triplet(lto_module_t mod); // // returns the number of symbols in the object module // extern uint32_t lto_module_get_num_symbols(lto_module_t mod); // // returns the name of the ith symbol in the object module // extern const char* lto_module_get_symbol_name(lto_module_t mod, uint32_t index); // // returns the attributes of the ith symbol in the object module // extern lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod, uint32_t index); // // instantiates a code generator // returns NULL if there is an error // extern lto_code_gen_t lto_codegen_create(); // // frees all memory for a code generator // upon return the lto_code_gen_t is no longer valid // extern void lto_codegen_release(lto_code_gen_t); // // add an object module to the set of modules for which code will be generated // returns true on error (check lto_get_error_message() for details) // extern bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); // // sets what if any format of debug info should be generated // returns true on error (check lto_get_error_message() for details) // extern bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); // // sets what code model to generated // returns true on error (check lto_get_error_message() for details) // extern bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); // // adds to a list of all global symbols that must exist in the final // generated code. If a function is not listed there, it might be // inlined into every usage and optimized away. // extern void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol); // // writes a new file at the specified path that contains the // merged contents of all modules added so far. // returns true on error (check lto_get_error_message() for details) // extern bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); // // generates code for all added modules into one object file // On sucess returns a pointer to a generated mach-o buffer and // length set to the buffer size. Client must free() the buffer // when done. // On failure, returns NULL (check lto_get_error_message() for details) // extern const uint8_t* lto_codegen_compile(lto_code_gen_t cg, size_t* length); #ifdef __cplusplus } #endif #endif -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080222/81b5d50e/attachment.html>
I would probably just use the C++ interface version, but I could certainly see a C interface like that being very useful for binding purposes. On Fri, Feb 22, 2008 at 11:34 PM, Nick Kledzik <kledzik at apple.com> wrote:> Hello. I work at Apple on our linker. We are working to improve support > for llvm > in our tools. A while back Devang created <llvm/LinkTimeOptimizer.h> a > C++ > interface which allows the linker to process llvm bitcode files along with > native > mach-o object files. > > For the next step we'd like our other tools like nm, ar, and lipo to be > able to > transparently process bitcode files too. But those tools are all written > in C. So, I've > reworked the LTO interface as a C interfaces and broke out the steps > so that it > could be used by other (non-linker) tools. > > Below is the proposed interface. The project (llvm/tools/lto2 for now) > will build > a shared object that can be used by other tools. > > I'd be interested to know if any one else has use for this. > > One area we know we need to augment the API is to allow various > optimizations > to be selected on the linker command line. > > -Nick > > > //===-- llvm-c/lto.h - LTO Public C Interface -------------------*- C++ > -*-===// > // > // The LLVM Compiler Infrastructure > // > // This file is distributed under the University of Illinois Open Source > // License. See LICENSE.TXT for details. > // > > //===----------------------------------------------------------------------===// > // > // This header provides public interface to an abstract link time > optimization > // library. LLVM provides an implementation of this interface for use > with > // llvm bitcode files. > // > > //===----------------------------------------------------------------------===// > > #ifndef __LTO__H__ > #define __LTO__H__ > > #include <stdint.h> > #include <stdbool.h> > #include <stddef.h> > > typedef enum { > LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of > alignment */ > LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, > LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, > LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, > LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, > LTO_SYMBOL_DEFINITION_MASK = 0x00000700, > LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, > LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, > LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, > LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, > LTO_SYMBOL_SCOPE_MASK = 0x00001800, > LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, > LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, > LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800 > } lto_symbol_attributes; > > typedef enum { > LTO_DEBUG_MODEL_NONE = 0, > LTO_DEBUG_MODEL_DWARF = 1 > } lto_debug_model; > > typedef enum { > LTO_CODEGEN_PIC_MODEL_STATIC = 0, > LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, > LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2 > } lto_codegen_model; > > > // opaque reference to a loaded object module > typedef struct LTOModule* lto_module_t; > > // opaque reference to a code generator > typedef struct LTOCodeGenerator* lto_code_gen_t; > > > #ifdef __cplusplus > extern "C" { > #endif > > // > // returns a printable string > // > extern const char* > lto_get_version(); > > > // > // returns the last error string or NULL if last operation was sucessful > // > extern const char* > lto_get_error_message(); > > > // > // validates if a file is a loadable object file > // > extern bool > lto_module_is_object_file(const char* path); > > > // > // validates if a file is a loadable object file compilable for requested > target > // > extern bool > lto_module_is_object_file_for_target(const char* path, > const char* > target_triplet_prefix); > > > // > // validates if a buffer is a loadable object file > // > extern bool > lto_module_is_object_file_in_memory(const uint8_t* mem, size_t length); > > > // > // validates if a buffer is a loadable object file compilable for > requested target > // > extern bool > lto_module_is_object_file_in_memory_for_target(const uint8_t* mem, size_t > length, > const char* > target_triplet_prefix); > > > // > // loads an object file from disk > // returns NULL on error (check lto_get_error_message() for details) > // > extern lto_module_t > lto_module_create(const char* path); > > > // > // loads an object file from memory > // returns NULL on error (check lto_get_error_message() for details) > // > extern lto_module_t > lto_module_create_from_memory(const uint8_t* mem, size_t length); > > > // > // frees all memory for a module > // upon return the lto_module_t is no longer valid > // > extern void > lto_module_release(lto_module_t mod); > > > // > // returns triplet string which the object module was compiled under > // > extern const char* > lto_module_get_target_triplet(lto_module_t mod); > > > // > // returns the number of symbols in the object module > // > extern uint32_t > lto_module_get_num_symbols(lto_module_t mod); > > > // > // returns the name of the ith symbol in the object module > // > extern const char* > lto_module_get_symbol_name(lto_module_t mod, uint32_t index); > > > // > // returns the attributes of the ith symbol in the object module > // > extern lto_symbol_attributes > lto_module_get_symbol_attribute(lto_module_t mod, uint32_t index); > > > // > // instantiates a code generator > // returns NULL if there is an error > // > extern lto_code_gen_t > lto_codegen_create(); > > > // > // frees all memory for a code generator > // upon return the lto_code_gen_t is no longer valid > // > extern void > lto_codegen_release(lto_code_gen_t); > > > > // > // add an object module to the set of modules for which code will be > generated > // returns true on error (check lto_get_error_message() for details) > // > extern bool > lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); > > > > // > // sets what if any format of debug info should be generated > // returns true on error (check lto_get_error_message() for details) > // > extern bool > lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); > > > // > // sets what code model to generated > // returns true on error (check lto_get_error_message() for details) > // > extern bool > lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); > > > // > // adds to a list of all global symbols that must exist in the final > // generated code. If a function is not listed there, it might be > // inlined into every usage and optimized away. > // > extern void > lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* > symbol); > > > // > // writes a new file at the specified path that contains the > // merged contents of all modules added so far. > // returns true on error (check lto_get_error_message() for details) > // > extern bool > lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); > > > // > // generates code for all added modules into one object file > // On sucess returns a pointer to a generated mach-o buffer and > // length set to the buffer size. Client must free() the buffer > // when done. > // On failure, returns NULL (check lto_get_error_message() for details) > // > extern const uint8_t* > lto_codegen_compile(lto_code_gen_t cg, size_t* length); > > > #ifdef __cplusplus > } > #endif > > > #endif > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080224/dcbd6ac8/attachment.html>
Hi Nick, I don't have any comments on the substance of the APIs (I'm not expert in this area), just some style notes. Overall, the capitalization style is inconsistent with the bulk of the C bindings, which are more Carbon than GNU. On Feb 23, 2008, at 01:34, Nick Kledzik wrote:> #include <stdint.h> > #include <stdbool.h>Note that MSVC++ still doesn't support C99, and is a target for LLVM. I'd suggest bool -> int and uint8_t* -> void* to resolve the dependency.> #include <stddef.h> > > extern const char* > lto_get_error_message();I've tried not to create thread-unsafe designs in the rest of the bindings. I return a malloced error message by optional output parameters and provide a generic dispose function (LLVMDisposeMessage). Copying CFError's design might be smarter still.> extern bool > lto_module_is_object_file_in_memory(const uint8_t* mem, size_t > length); > > extern bool > lto_module_is_object_file_in_memory_for_target(const uint8_t* mem, > size_t length, > const char* > target_triplet_prefix); > > extern lto_module_t > lto_module_create_from_memory(const uint8_t* mem, size_t length);Why not void*? Saves casting.> // > // generates code for all added modules into one object file > // On sucess returns a pointer to a generated mach-o buffer and > // length set to the buffer size. Client must free() the buffer > // when done. > // On failure, returns NULL (check lto_get_error_message() for > details) > // > extern const uint8_t* > lto_codegen_compile(lto_code_gen_t cg, size_t* length);The return value should be non-const. free takes a void*, not a const void*. Windows people like to play hideous macro tricks with malloc, so I'd provide a corresponding dispose method, keeping the API self-contained.> extern const char* > lto_module_get_target_triplet(lto_module_t mod);LLVM nomenclature is triple, not triplet.> extern uint32_t > lto_module_get_num_symbols(lto_module_t mod); > > extern const char* > lto_module_get_symbol_name(lto_module_t mod, uint32_t index); > > extern lto_symbol_attributes > lto_module_get_symbol_attribute(lto_module_t mod, uint32_t index);Why uint32_t instead of size_t?> // > // frees all memory for a code generator > // upon return the lto_code_gen_t is no longer valid > // > extern void > lto_codegen_release(lto_code_gen_t);Existing bindings use the term dispose to avoid any possible retain/ release confusion. — Gordon -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080224/42e7da52/attachment.html>
More stylistic nitpicking for consistency sakes... 1. __LTO__ -> LLVM_C_LTO 2. Do we need those #include's? 3. Rather than using underscore in function names, e.g. lt_foo_bar, use capital letters and also start with prefix LLVM. e.g. LLVMLTOFooBar. 4. lto_codegen_release -> lto_codegen_release_memory to be clearer and more consistent. 5. Use C comments /* ... */? 6. Please start comments with capital letters and end sentences with periods! Or perhaps not since it'll drive Chris nuts. :-) Evan On Feb 22, 2008, at 10:34 PM, Nick Kledzik wrote:> Hello. I work at Apple on our linker. We are working to improve > support for llvm > in our tools. A while back Devang created <llvm/ > LinkTimeOptimizer.h> a C++ > interface which allows the linker to process llvm bitcode files > along with native > mach-o object files. > > For the next step we'd like our other tools like nm, ar, and lipo to > be able to > transparently process bitcode files too. But those tools are all > written in C. So, I've > reworked the LTO interface as a C interfaces and broke out the steps > so that it > could be used by other (non-linker) tools. > > Below is the proposed interface. The project (llvm/tools/lto2 for > now) will build > a shared object that can be used by other tools. > > I'd be interested to know if any one else has use for this. > > One area we know we need to augment the API is to allow various > optimizations > to be selected on the linker command line. > > -Nick > > > //===-- llvm-c/lto.h - LTO Public C Interface -------------------*- C > ++ -*-===// > // > // The LLVM Compiler Infrastructure > // > // This file is distributed under the University of Illinois Open > Source > // License. See LICENSE.TXT for details. > // > // > = > = > = > ----------------------------------------------------------------------= > ==// > // > // This header provides public interface to an abstract link time > optimization > // library. LLVM provides an implementation of this interface for > use with > // llvm bitcode files. > // > // > = > = > = > ----------------------------------------------------------------------= > ==// > > #ifndef __LTO__H__ > #define __LTO__H__ > > #include <stdint.h> > #include <stdbool.h> > #include <stddef.h> > > typedef enum { > LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of > alignment */ > LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, > LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, > LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, > LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, > LTO_SYMBOL_DEFINITION_MASK = 0x00000700, > LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, > LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, > LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, > LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, > LTO_SYMBOL_SCOPE_MASK = 0x00001800, > LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, > LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, > LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800 > } lto_symbol_attributes; > > typedef enum { > LTO_DEBUG_MODEL_NONE = 0, > LTO_DEBUG_MODEL_DWARF = 1 > } lto_debug_model; > > typedef enum { > LTO_CODEGEN_PIC_MODEL_STATIC = 0, > LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, > LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2 > } lto_codegen_model; > > > // opaque reference to a loaded object module > typedef struct LTOModule* lto_module_t; > > // opaque reference to a code generator > typedef struct LTOCodeGenerator* lto_code_gen_t; > > > #ifdef __cplusplus > extern "C" { > #endif > > // > // returns a printable string > // > extern const char* > lto_get_version(); > > > // > // returns the last error string or NULL if last operation was > sucessful > // > extern const char* > lto_get_error_message(); > > > // > // validates if a file is a loadable object file > // > extern bool > lto_module_is_object_file(const char* path); > > > // > // validates if a file is a loadable object file compilable for > requested target > // > extern bool > lto_module_is_object_file_for_target(const char* path, > const char* > target_triplet_prefix); > > > // > // validates if a buffer is a loadable object file > // > extern bool > lto_module_is_object_file_in_memory(const uint8_t* mem, size_t > length); > > > // > // validates if a buffer is a loadable object file compilable for > requested target > // > extern bool > lto_module_is_object_file_in_memory_for_target(const uint8_t* mem, > size_t length, > const char* > target_triplet_prefix); > > > // > // loads an object file from disk > // returns NULL on error (check lto_get_error_message() for details) > // > extern lto_module_t > lto_module_create(const char* path); > > > // > // loads an object file from memory > // returns NULL on error (check lto_get_error_message() for details) > // > extern lto_module_t > lto_module_create_from_memory(const uint8_t* mem, size_t length); > > > // > // frees all memory for a module > // upon return the lto_module_t is no longer valid > // > extern void > lto_module_release(lto_module_t mod); > > > // > // returns triplet string which the object module was compiled under > // > extern const char* > lto_module_get_target_triplet(lto_module_t mod); > > > // > // returns the number of symbols in the object module > // > extern uint32_t > lto_module_get_num_symbols(lto_module_t mod); > > > // > // returns the name of the ith symbol in the object module > // > extern const char* > lto_module_get_symbol_name(lto_module_t mod, uint32_t index); > > > // > // returns the attributes of the ith symbol in the object module > // > extern lto_symbol_attributes > lto_module_get_symbol_attribute(lto_module_t mod, uint32_t index); > > > // > // instantiates a code generator > // returns NULL if there is an error > // > extern lto_code_gen_t > lto_codegen_create(); > > > // > // frees all memory for a code generator > // upon return the lto_code_gen_t is no longer valid > // > extern void > lto_codegen_release(lto_code_gen_t); > > > > // > // add an object module to the set of modules for which code will be > generated > // returns true on error (check lto_get_error_message() for details) > // > extern bool > lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); > > > > // > // sets what if any format of debug info should be generated > // returns true on error (check lto_get_error_message() for details) > // > extern bool > lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); > > > // > // sets what code model to generated > // returns true on error (check lto_get_error_message() for details) > // > extern bool > lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); > > > // > // adds to a list of all global symbols that must exist in the final > // generated code. If a function is not listed there, it might be > // inlined into every usage and optimized away. > // > extern void > lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* > symbol); > > > // > // writes a new file at the specified path that contains the > // merged contents of all modules added so far. > // returns true on error (check lto_get_error_message() for details) > // > extern bool > lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); > > > // > // generates code for all added modules into one object file > // On sucess returns a pointer to a generated mach-o buffer and > // length set to the buffer size. Client must free() the buffer > // when done. > // On failure, returns NULL (check lto_get_error_message() for > details) > // > extern const uint8_t* > lto_codegen_compile(lto_code_gen_t cg, size_t* length); > > > #ifdef __cplusplus > } > #endif > > > #endif > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080224/b8964ea0/attachment.html>
I'll work on another round with the feedback so far. On SundayFeb 24, at Feb 24, Sunday11:24 PM, Evan Cheng wrote:> 1. __LTO__ -> LLVM_C_LTOThis one is actually interesting. The names started out with llvm in them, but then we realized that this was a generic interface from the linker to some foreign object file format. So, some other compiler could create an LTO shared object that exports the same lto_ interface and it would just work with the linker. Therefore, although this implementation is llvm specific, the interface is not. -Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080225/7bd5b3c5/attachment.html>
I've updated the header (enclosed).  On Feb 24, 2008, at 11:24 PM, Evan Cheng wrote:> 1. __LTO__ -> LLVM_C_LTO > 3. Rather than using underscore in function names, e.g. lt_foo_bar, > use capital letters and also start with prefix LLVM. e.g. > LLVMLTOFooBar.As we discussed, this is interface is llvm independent. It may even migrate out of include/llvm-c at some point.> 2. Do we need those #include's?We need stddef.h for size_t and stdbool.h for bool.> 4. lto_codegen_release -> lto_codegen_release_memory to be clearer > and more consistent.Renamed to lto_codegen_dispose()> 5. Use C comments /* ... */?Fixed.> 6. Please start comments with capital letters and end sentences > with periods! Or perhaps not since it'll drive Chris nuts. :-)Fixed. On Feb 24, 2008, at 6:10 PM, Gordon Henriksen wrote:>> #include <stdint.h> >> #include <stdbool.h> > > Note that MSVC++ still doesn't support C99, and is a target for > LLVM. I'd suggest bool -> int and uint8_t* -> void* to resolve the > dependency.I've change all the uint8_t to void. I'm going to leave the use of bool. The implementation of lto is all in C++, so it will build with MSVC++. The only thing that might get tripped up by the use of bool in the interface is if someone tries to write a C (not C++) client (meaning a linker) using MSVC.>> #include <stddef.h> >> >> extern const char* >> lto_get_error_message(); > > I've tried not to create thread-unsafe designs in the rest of the > bindings. I return a malloced error message by optional output > parameters and provide a generic dispose function > (LLVMDisposeMessage). Copying CFError's design might be smarter still.There are other things not thread safe about the API. Adding a string return would complicate the API. And it is possible to make the API thread safe in the future by making lto_get_error_message() return a per-thread string.> >> extern bool >> lto_module_is_object_file_in_memory(const uint8_t* mem, size_t >> length); >> >> extern bool >> lto_module_is_object_file_in_memory_for_target(const uint8_t* mem, >> size_t length, >> const char* >> target_triplet_prefix); >> >> extern lto_module_t >> lto_module_create_from_memory(const uint8_t* mem, size_t length); > > Why not void*? Saves casting.Fixed.>> // >> // generates code for all added modules into one object file >> // On sucess returns a pointer to a generated mach-o buffer and >> // length set to the buffer size. Client must free() the buffer >> // when done. >> // On failure, returns NULL (check lto_get_error_message() for >> details) >> // >> extern const uint8_t* >> lto_codegen_compile(lto_code_gen_t cg, size_t* length); > > The return value should be non-const. free takes a void*, not a > const void*.Fixed.>> extern const char* >> lto_module_get_target_triplet(lto_module_t mod); > > LLVM nomenclature is triple, not triplet.Fixed.> >> extern uint32_t >> lto_module_get_num_symbols(lto_module_t mod); >> >> extern const char* >> lto_module_get_symbol_name(lto_module_t mod, uint32_t index); >> >> extern lto_symbol_attributes >> lto_module_get_symbol_attribute(lto_module_t mod, uint32_t index); > > Why uint32_t instead of size_t?I changed it to unsigned int. It is not pointer size dependent.> >> // >> // frees all memory for a code generator >> // upon return the lto_code_gen_t is no longer valid >> // >> extern void >> lto_codegen_release(lto_code_gen_t); > > Existing bindings use the term dispose to avoid any possible retain/ > release confusion.Changed both _release functions to _dispose. -Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080225/7fc6b7f5/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: lto.h Type: application/octet-stream Size: 6597 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080225/7fc6b7f5/attachment.obj> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080225/7fc6b7f5/attachment-0001.html>