llvm-d

Jens Mueller jens.k.mueller at gmx.de
Sat Mar 23 14:24:38 PDT 2013


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


More information about the Digitalmars-d-announce mailing list