[llvm-c]

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;

By debugging the LLVM library (a custom DLL, which works fine
otherwise), I can see that there is no information, but I'm not that
deep into C and the LLVM structure to identify what went wrong. Also I
did a lot of tests the other day, trying several things without luck.

However, since I do not need this code at the moment, it's not urgent,
just felt to let you know about my problems.

Kind regards,

    Christian

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?

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.

-Tom

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

I just found the bug. It was all my fault. When migrating the pascal
interface code from 3.2 to 3.3, I accidentally removed the explicit
declaration of the calling convention (should have been cdecl).

Now everything works as expected.

Thanks for the clarification,

    Christian