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.
Types
Bool = cuchar
SymbolAttributes = enum SymbolAlignmentMask = 0x0000001F, ## log2 of alignment SymbolPermissionsROData = 0x00000080, SymbolPermissionsCode = 0x000000A0, SymbolPermissionsData = 0x000000C0, SymbolPermissionsMask = 0x000000E0, SymbolDefinitionRegular = 0x00000100, SymbolDefinitionTentative = 0x00000200, SymbolDefinitionWeak = 0x00000300, SymbolDefinitionUndefined = 0x00000400, SymbolDefinitionWeakUndef = 0x00000500, SymbolDefinitionMask = 0x00000700, SymbolScopeInternal = 0x00000800, SymbolScopeHidden = 0x00001000, SymbolScopeDefault = 0x00001800, SymbolScopeProtected = 0x00002000, SymbolScopeDefaultCanBeHidden = 0x00002800, SymbolScopeMask = 0x00003800
- Symbol attributes
DebugModel = enum DebugModelNone = 0, DebugModelDwarf = 1
CodegenModel = enum CodegenPICModelStatic = 0, CodegenPICModelDynamic = 1, CodegenPICModelDynamicNoPIC = 2, CodegenPICModelDefault = 3
Module = ptr object
- opaque reference to a loaded object module
CodeGen = ptr object
- opaque reference to a code generator
codegenDiagnosticSeverity = enum DSError = 0, DSWarning = 1, DSNite = 2, DSRemark = 3
- Diagnostic severity.
DiagnosticHandler = proc (severity: codegenDiagnosticSeverity; diag: cstring; ctxt: pointer) {.cdecl.}
Procs
proc getVersion(): cstring {.importc: "lto_get_version", cdecl, dynlib: dllname.}
- Returns a printable string.
proc getError(): cstring {.importc: "lto_get_error_message", cdecl, dynlib: dllname.}
- Returns the last error string or NULL if last operation was successful.
proc moduleIsObjectFile(path: cstring): Bool {. importc: "lto_module_is_object_file", cdecl, dynlib: dllname.}
- Checks if a file is a loadable object file.
proc moduleIsObjectFileForTarget(path: cstring; targetTriplePrefix: cstring): Bool {. importc: "lto_module_is_object_file_for_target", cdecl, dynlib: dllname.}
- Checks if a file is a loadable object compiled for requested target.
proc moduleIsObjectFileInMemory(mem: pointer; length: csize): Bool {. importc: "lto_module_is_object_file_in_memory", cdecl, dynlib: dllname.}
- Checks if a buffer is a loadable object file.
proc moduleIsObjectFileInMemoryForTarget(mem: pointer; length: csize; targetTriplePrefix: cstring): Bool {. importc: "lto_module_is_object_file_in_memory_for_target", cdecl, dynlib: dllname.}
- Checks if a buffer is a loadable object compiled for requested target.
proc moduleCreate(path: cstring): Module {.importc: "lto_module_create", cdecl, dynlib: dllname.}
- Loads an object file from disk. Returns NULL on error (check lto_get_error_message() for details).
proc moduleCreateFromMemory(mem: pointer; length: csize): Module {. importc: "lto_module_create_from_memory", cdecl, dynlib: dllname.}
- Loads an object file from memory. Returns NULL on error (check lto_get_error_message() for details).
proc moduleCreateFromMemoryWithPath(mem: pointer; length: csize; path: cstring): Module {. importc: "lto_module_create_from_memory_with_path", cdecl, dynlib: dllname.}
- Loads an object file from memory with an extra path argument. Returns NULL on error (check lto_get_error_message() for details).
proc moduleCreateFromFD(fd: cint; path: cstring; fileSize: csize): Module {. importc: "lto_module_create_from_fd", cdecl, dynlib: dllname.}
- Loads an object file from disk. The seek point of fd is not preserved. Returns NULL on error (check lto_get_error_message() for details).
proc module_create_from_fd_at_offset(fd: cint; path: cstring; fileSize: csize; mapSize: csize; offset: csize): Module {. importc: "lto_module_create_from_fd_at_offset", cdecl, dynlib: dllname.}
- Loads an object file from disk. The seek point of fd is not preserved. Returns NULL on error (check lto_get_error_message() for details).
proc moduleDispose(module: Module) {.importc: "lto_module_dispose", cdecl, dynlib: dllname.}
- Frees all memory internally allocated by the module. Upon return the lto_module_t is no longer valid.
proc moduleGetTargetTriple(module: Module): cstring {. importc: "lto_module_get_target_triple", cdecl, dynlib: dllname.}
- Returns triple string which the object module was compiled under.
proc moduleSetTargetTriple(module: Module; triple: cstring) {. importc: "lto_module_set_target_triple", cdecl, dynlib: dllname.}
- Sets triple string with which the object will be codegened.
proc moduleGetNumSymbols(module: Module): cuint {. importc: "lto_module_get_num_symbols", cdecl, dynlib: dllname.}
- Returns the number of symbols in the object module.
proc moduleGetSymbolName(module: Module; index: cuint): cstring {. importc: "lto_module_get_symbol_name", cdecl, dynlib: dllname.}
- Returns the name of the ith symbol in the object module.
proc moduleGetSymbolAttribute(module: Module; index: cuint): SymbolAttributes {. importc: "lto_module_get_symbol_attribute", cdecl, dynlib: dllname.}
- Returns the attributes of the ith symbol in the object module.
proc moduleGetNumDeplibs(module: Module): cuint {. importc: "lto_module_get_num_deplibs", cdecl, dynlib: dllname.}
- Returns the number of dependent libraries in the object module.
proc moduleGetDeplib(module: Module; index: cuint): cstring {. importc: "lto_module_get_deplib", cdecl, dynlib: dllname.}
- Returns the ith dependent library in the module.
proc moduleGetNumLinkeropts(module: Module): cuint {. importc: "lto_module_get_num_linkeropts", cdecl, dynlib: dllname.}
- Returns the number of linker options in the object module.
proc moduleGetLinkeropt(module: Module; index: cuint): cstring {. importc: "lto_module_get_linkeropt", cdecl, dynlib: dllname.}
- Returns the ith linker option in the module.
proc codegenCreate(): CodeGen {.importc: "lto_codegen_create", cdecl, dynlib: dllname.}
- Instantiates a code generator. Returns NULL on error (check lto_get_error_message() for details).
proc codegenDispose(cg: CodeGen) {.importc: "lto_codegen_dispose", cdecl, dynlib: dllname.}
- Frees all code generator and all memory it internally allocated. Upon return the lto_code_gen_t is no longer valid.
proc codegenAddModule(cg: CodeGen; module: Module): Bool {. importc: "lto_codegen_add_module", cdecl, dynlib: dllname.}
- 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).
proc codegenSetDebugModel(cg: CodeGen; dm: DebugModel): Bool {. importc: "lto_codegen_set_debug_model", cdecl, dynlib: dllname.}
- Sets if debug info should be generated. Returns true on error (check lto_get_error_message() for details).
proc codegenSetPICModel(cg: CodeGen; cgm: CodegenModel): Bool {. importc: "lto_codegen_set_pic_model", cdecl, dynlib: dllname.}
- Sets which PIC code model to generated. Returns true on error (check lto_get_error_message() for details).
proc codegenSetCPU(cg: CodeGen; cpu: cstring) {.importc: "lto_codegen_set_cpu", cdecl, dynlib: dllname.}
- Sets the cpu to generate code for.
proc codegenSetAssemblerPath(cg: CodeGen; path: cstring) {. importc: "lto_codegen_set_assembler_path", cdecl, dynlib: dllname.}
- Sets the location of the assembler tool to run. If not set, libLTO will use gcc to invoke the assembler.
proc codegenSetAssemblerArgs(cg: CodeGen; args: cstringArray; nArgs: cint) {. importc: "lto_codegen_set_assembler_args", cdecl, dynlib: dllname.}
- Sets extra arguments that libLTO should pass to the assembler.
proc codegenAddMustPreserveSymbol(cg: CodeGen; symbol: cstring) {. importc: "lto_codegen_add_must_preserve_symbol", cdecl, dynlib: dllname.}
- 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.
proc codegenWriteMergedModules(cg: CodeGen; path: cstring): Bool {. importc: "lto_codegen_write_merged_modules", cdecl, dynlib: dllname.}
- Writes a new object 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).
proc codegenCompile(cg: CodeGen; length: ptr csize): pointer {. importc: "lto_codegen_compile", cdecl, dynlib: dllname.}
- Generates code for all added modules into one native object file. On success returns a pointer to a generated mach-o/ELF buffer and length set to the buffer size. The buffer is owned by the lto_code_gen_t and will be freed when lto_codegen_dispose() is called, or lto_codegen_compile() is called again. On failure, returns NULL (check lto_get_error_message() for details).
proc codegenCompileToFile(cg: CodeGen; name: cstring): Bool {. importc: "lto_codegen_compile_to_file", cdecl, dynlib: dllname.}
- Generates code for all added modules into one native object file. The name of the file is written to name. Returns true on error.
proc codegenDebugOptions(cg: CodeGen; opts: cstring) {. importc: "lto_codegen_debug_options", cdecl, dynlib: dllname.}
- Sets options to help debug codegen bugs.
proc initializeDisassembler() {.importc: "lto_initialize_disassembler", cdecl, dynlib: dllname.}
- Initializes LLVM disassemblers.