llvm-d

Moritz Maxeiner moritz at ucworks.org
Sat Mar 23 14:40:45 PDT 2013


On Saturday, 23 March 2013 at 21:24:50 UTC, Jens Mueller wrote:
> Moritz Maxeiner wrote:
>> On Saturday, 23 March 2013 at 16:37:35 UTC, Jens Mueller wrote:
>> >Moritz Maxeiner wrote:
>> >>On Saturday, 23 March 2013 at 10:31:30 UTC, Jens Mueller 
>> >>wrote:
>> >>
>> >>It looks mostly okay to me with one problem: Afaict the code
>> >>enforces the presence of the initialization routines of all
>> >>targets,
>> >>e.g. if one target is missing LLVMInitializeAllTargets will 
>> >>not
>> >>link, as there are undefined references for that missing 
>> >>target,
>> >>but
>> >>LLVM may or may not be compiled with that target so you 
>> >>cannot
>> >>enforce its presence in the bindings. For runtime loading the
>> >>solution I used was to check the function pointer for null; 
>> >>for
>> >>linking you have this problem: When using linking, knowing 
>> >>which
>> >>targets are available happens at link time (when the LLVM
>> >>libraries
>> >>are linked in), which means you cannot use any compile time
>> >>tricks
>> >>for automatic detection of which targets are available.
>> >>The only solution for that problem I can think of would be to
>> >>use
>> >>runtime reflection and check at runtime for each 
>> >>initialiation
>> >>routine if it is a callable function, but afaik D only has
>> >>compile
>> >>time reflection.
>> >
>> >I wonder how they do it in C. Don't you have to set a macro?
>> 
>> Afaict they rely on the fact that when you install llvm on your
>> system you get the {/usr/include/}llvm/Config/Targets.def 
>> file, in
>> which is set what targets LLVM was compiled with (it gets 
>> generated
>> at LLVM compile-time). Then the Target.h, in which the
>> LLVMInitializeAllTargets function rests, includes that file 
>> and does
>> some of that macro-voodoo that makes C/C++ so "lovable" to only
>> create calls for the targets enabled in the Targets.def file 
>> when
>> LLVMInitalizeAllTargets gets inlined. Of course, that solution 
>> isn't
>> viable because afaik you cannot access filesystem IO functions 
>> in D
>> CTFE, meaning the Targets.def file is useless to you. 
>> <rant>Hooray
>> for the C/C++ preprocessor, may it die, die, die!</rant>
>
> If I knew the path to the Targets.def file at compile I could 
> load its
> contents and use it.
> http://dlang.org/expression.html#ImportExpression
> Still have to find out how to get the path.
>
> Jens

Oh, I did not know that was possible, thanks for the link!
Can't really help you with the path, though. On Linux it's 
probably either /usr/include/llvm/Config/Targets.def or 
/usr/local/include/llvm/Config/Targets.def, but some people might 
install it on /opt/llvm or other custom paths. You also have a 
problem when there's only a shared lib available for LLVM and no 
headers.. No idea about OSX though. And on Windows you'll 
probably only deal with a DLL and not have the headers available 
anyway - at least I do (I cross compile the LLVM dll on linux 
with a mingw64 gcc toolchain, so no headers on windows for me).

Moritz


More information about the Digitalmars-d-announce mailing list