[cfe-dev] Building AST at runtime

Daniel Albuschat d.albuschat at gmail.com
Sat Jul 13 09:16:29 PDT 2013


2013/7/13 Daniel Albuschat <d.albuschat at gmail.com>

> Hello there,
>
> I'm having a hard time building a simple AST at runtime. I think that only
> small pieces are missing, but it's rather difficult for me to find which
> ones and where.
>
> [snip]

>
> I get the following error mesage from the code:
> > error: unknown target triple '', please use -triple or -arch
>
> I thought I provided the required triple in the call to
> clang::TargetInfo::CreateTargetInfo, passing targetOptions, which "Triple"
> member has been set to "i386-pc-win32" (which was only a guess, since I did
> not find a reference for the string syntax of a target triple).
>
> Here's the code:
>
 [snip]

> void clang_sandbox ()
> {
>     clang::FileManager fileManager = clang::FileManager
> (clang::FileSystemOptions ());
>     auto targetOptions = new clang::TargetOptions ();
>     targetOptions->Triple = "i386-pc-win32";
>
>     clang::CompilerInstance instance;
>     instance.createDiagnostics ();
>     clang::TargetInfo * target (clang::TargetInfo::CreateTargetInfo
> (instance.getDiagnostics (), targetOptions));
>     instance.setTarget (target);
>

I found out what was causing the error-message.
CompilerInstance::ExecuteAction does this:

> setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
&getTargetOpts()));

This effectively overrides my setTarget from before. I solved that issue by
doing instance.getTargetOpts () = *targetOptions, hence set second call to
setTarget sets basically the same target options as before. Still, it's a
bit awkward that createPreprocessor () forces me to do a setTarget (), and
ExecuteAction () always overrides that target.

Greetings,
Daniel Albuschat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130713/13823cf5/attachment.html>


More information about the cfe-dev mailing list