[LLVMdev] [llvm-c]

Christian Budde Christian at savioursofsoul.de
Tue May 14 12:42:49 PDT 2013

Am 13.05.2013 16:16, schrieb Tom Stellard:
> On Sat, May 11, 2013 at 01:48:44PM +0200, Christian Budde wrote:
>> Hello,
>> a few days ago, I was trying to access the LLVM target registry via the
>> LLVM-C interface. Unfortunately I can't seem to get some useful
>> information out of it.
>> Despite the fact that the following code is written in Pascal, can you
>> please tell me if I have done something wrong here?
>> // initialize all targets / target information
>> LLVMInitializeAllTargets;
>> LLVMInitializeAllTargetInfos;
>> // initialize native target in particular
>> LLVMInitializeNativeTarget;
>> // get first target
>> Target := LLVMGetFirstTarget;
>> // loop until the target is NULL
>> while (Target <> nil) do
>> begin
>>   // get target name & description
>>   TargetName := LLVMGetTargetName(Target);
>>   TargetDescription := LLVMGetTargetDescription(Target);
>>   // do something with these information
>>   Target := LLVMGetNextTarget(Target);
>> end;
> I don't see any obvious problems here, though someone else might.
> What exactly is the problem you are seeing?  Is LLVMGetFirstTarget
> returning NULL?

LLVMGetFirstTarget returns a pointer at a quite high address. Subsequent
calls to LLVMGetNextTarget all return the very same pointer (much
lower). If I query LLVMGetTargetName and LLVMGetTargetDescription I got
an empty string and a null pointer.

> You may want to take a look at this code:
> http://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/radeon/radeon_llvm_emit.c
> It is a pretty good example of using the C API for accessing the target
> registry.  However, if you want to test this code directly, I would
> recommend replacing the r600 target triple with your native
> architecture, because the R600 backend is not built by default.

I've done it exactly like in this example (except the fact that I'm
using pascal as language and x86 as main target). So if the sequence of
calls seems to be right, I'll be investigating whether I've done
something wrong compiling the DLL.

Thanks for the information,


Christian-W. Budde
Eleonorenstr. 17
30449 Hannover
Tel.: +49 511 31048857
E-Mail: Christian at savioursofsoul.de
WWW: http://www.savioursofsoul.de/Christian

More information about the llvm-dev mailing list