[LLVMdev] new LTO C interface
Gordon Henriksen
gordonhenriksen at mac.com
Sun Feb 24 18:10:05 PST 2008
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 information about the llvm-dev
mailing list