Module llvm_targetmachine

This header declares the C interface to the Target and TargetMachine classes, which can be used to generate assembly or object files.

Many exotic languages can interoperate with C code but have a harder time with C++ due to name mangling. So in addition to C, this interface enables tools written in such languages.

Types

TargetMachineRef = ptr object 
TargetRef = ptr object 
CodeGenOptLevel = enum 
  CodeGenLevelNone, CodeGenLevelLess, CodeGenLevelDefault, 
  CodeGenLevelAggressive
RelocMode = enum 
  RelocDefault, RelocStatic, RelocPIC, RelocDynamicNoPic
CodeModel = enum 
  CodeModelDefault, CodeModelJITDefault, CodeModelSmall, CodeModelKernel, 
  CodeModelMedium, CodeModelLarge
CodeGenFileType = enum 
  AssemblyFile, ObjectFile

Procs

proc getFirstTarget(): TargetRef {.importc: "LLVMGetFirstTarget", 
                                   cdecl, dynlib: dllname.}
Returns the first llvm::Target in the registered targets list.
proc getNextTarget(t: TargetRef): TargetRef {.importc: "LLVMGetNextTarget", 
    cdecl, dynlib: dllname.}
Returns the next llvm::Target given a previous one (or null if there's none)
proc getTargetFromName(name: cstring): TargetRef {.
    importc: "LLVMGetTargetFromName", cdecl, dynlib: dllname.}
Finds the target corresponding to the given name and stores it in T. Returns 0 on success.
proc getTargetFromTriple(triple: cstring; t: ptr TargetRef; 
                         errorMessage: cstringArray): Bool {.
    importc: "LLVMGetTargetFromTriple", cdecl, dynlib: dllname.}
Finds the target corresponding to the given triple and stores it in T. Returns 0 on success. Optionally returns any error in ErrorMessage. Use LLVMDisposeMessage to dispose the message.
proc getTargetName(t: TargetRef): cstring {.importc: "LLVMGetTargetName", 
    cdecl, dynlib: dllname.}
Returns the name of a target. See llvm::Target::getName
proc getTargetDescription(t: TargetRef): cstring {.
    importc: "LLVMGetTargetDescription", cdecl, dynlib: dllname.}
Returns the description of a target. See llvm::Target::getDescription
proc targetHasJIT(t: TargetRef): Bool {.importc: "LLVMTargetHasJIT", 
                                        cdecl, dynlib: dllname.}
Returns if the target has a JIT
proc targetHasTargetMachine(t: TargetRef): Bool {.
    importc: "LLVMTargetHasTargetMachine", cdecl, dynlib: dllname.}
Returns if the target has a TargetMachine associated
proc targetHasAsmBackend(t: TargetRef): Bool {.
    importc: "LLVMTargetHasAsmBackend", cdecl, dynlib: dllname.}
Returns if the target as an ASM backend (required for emitting output)
proc createTargetMachine(t: TargetRef; triple: cstring; cpu: cstring; 
                         features: cstring; level: CodeGenOptLevel; 
                         reloc: RelocMode; codeModel: CodeModel): TargetMachineRef {.
    importc: "LLVMCreateTargetMachine", cdecl, dynlib: dllname.}
Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine
proc disposeTargetMachine(t: TargetMachineRef) {.
    importc: "LLVMDisposeTargetMachine", cdecl, dynlib: dllname.}
Dispose the LLVMTargetMachineRef instance generated by LLVMCreateTargetMachine.
proc getTargetMachineTarget(t: TargetMachineRef): TargetRef {.
    importc: "LLVMGetTargetMachineTarget", cdecl, dynlib: dllname.}
Returns the Target used in a TargetMachine
proc getTargetMachineTriple(t: TargetMachineRef): cstring {.
    importc: "LLVMGetTargetMachineTriple", cdecl, dynlib: dllname.}
Returns the triple used creating this target machine. See llvm::TargetMachine::getTriple. The result needs to be disposed with LLVMDisposeMessage.
proc getTargetMachineCPU(t: TargetMachineRef): cstring {.
    importc: "LLVMGetTargetMachineCPU", cdecl, dynlib: dllname.}
Returns the cpu used creating this target machine. See llvm::TargetMachine::getCPU. The result needs to be disposed with LLVMDisposeMessage.
proc getTargetMachineFeatureString(t: TargetMachineRef): cstring {.
    importc: "LLVMGetTargetMachineFeatureString", cdecl, dynlib: dllname.}
Returns the feature string used creating this target machine. See llvm::TargetMachine::getFeatureString. The result needs to be disposed with LLVMDisposeMessage.
proc getTargetMachineData(t: TargetMachineRef): TargetDataRef {.
    importc: "LLVMGetTargetMachineData", cdecl, dynlib: dllname.}
Returns the llvm::DataLayout used for this llvm:TargetMachine.
proc setTargetMachineAsmVerbosity(t: TargetMachineRef; verboseAsm: Bool) {.
    importc: "LLVMSetTargetMachineAsmVerbosity", cdecl, dynlib: dllname.}
Set the target machine's ASM verbosity.
proc targetMachineEmitToFile(t: TargetMachineRef; m: ModuleRef; 
                             filename: cstring; codegen: CodeGenFileType; 
                             errorMessage: cstringArray): Bool {.
    importc: "LLVMTargetMachineEmitToFile", cdecl, dynlib: dllname.}
Emits an asm or object file for the given module to the filename. This wraps several c++ only classes (among them a file stream). Returns any error in ErrorMessage. Use LLVMDisposeMessage to dispose the message.
proc targetMachineEmitToMemoryBuffer(t: TargetMachineRef; m: ModuleRef; 
                                     codegen: CodeGenFileType; 
                                     errorMessage: cstringArray; 
                                     outMemBuf: ptr MemoryBufferRef): Bool {.
    importc: "LLVMTargetMachineEmitToMemoryBuffer", cdecl, dynlib: dllname.}
Compile the LLVM IR stored in p M and store the result in p OutMemBuf.
proc getDefaultTargetTriple(): cstring {.importc: "LLVMGetDefaultTargetTriple", 
    cdecl, dynlib: dllname.}
Get a triple for the host machine as a string. The result needs to be disposed with LLVMDisposeMessage.
proc addAnalysisPasses(t: TargetMachineRef; pm: PassManagerRef) {.
    importc: "LLVMAddAnalysisPasses", cdecl, dynlib: dllname.}
Adds the target-specific analysis passes to the pass manager.