<div dir="ltr">2013/7/13 Daniel Albuschat <span dir="ltr"><<a href="mailto:d.albuschat@gmail.com" target="_blank">d.albuschat@gmail.com</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Hello there,<div><br></div><div>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.</div>
<div><br></div></div></blockquote><div>[snip] </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">
<div></div><div><br></div><div>I get the following error mesage from the code: </div><div>> error: unknown target triple '', please use -triple or -arch</div>
<div><br></div><div>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).</div>
<div><br></div><div>Here's the code:</div><div><div></div></div></div></blockquote><div> [snip]</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div><div>void clang_sandbox ()<br></div><div>{</div><div> clang::FileManager fileManager = clang::FileManager (clang::FileSystemOptions ());</div>
<div> auto targetOptions = new clang::TargetOptions ();</div><div> targetOptions->Triple = "i386-pc-win32";</div><div><br></div><div> clang::CompilerInstance instance;</div><div> instance.createDiagnostics ();</div>
<div> clang::TargetInfo * target (clang::TargetInfo::CreateTargetInfo (instance.getDiagnostics (), targetOptions));</div><div> instance.setTarget (target);</div></div></div></blockquote><div><br></div><div>I found out what was causing the error-message.</div>
<div>CompilerInstance::ExecuteAction does this:<br></div><div><br></div><div>> setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), &getTargetOpts()));<br></div><div><br></div><div>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.</div>
<div><br></div><div>Greetings,</div><div>Daniel Albuschat</div><div><br></div></div></div></div>