<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Some folks on #llvm helped me with this - the solution is to create a virtual file using FileManager::getVirtualFile, and populate it with the buffer's contents using SourceManager::overrideFileContents, then pass the virtual file to the FrontendAction.<div>
<br></div><div>Hope that helps,</div><div>Mike</div></span><br><div class="gmail_quote">On Fri, May 7, 2010 at 5:40 PM, Mike Miller <span dir="ltr"><<a href="mailto:michael.g.miller@gmail.com">michael.g.miller@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi,<div><br></div><div>I'm currently using the following code(excerpted) to execute a FrontendAction(an EmitObjAction specifically) on source code contained in a MemoryBuffer:</div>
<div><br></div><div><div>llvm::MemoryBuffer* Buffer = llvm::MemoryBuffer::getMemBuffer(Source);</div>
<div>SourceManager& SM = Clang.getSourceManager();</div><div>FileID MainFileID = SM.createMainFileIDForMemBuffer(Buffer);</div><div><br></div><div>EmitObjAction E;</div><div>E.setCompilerInstance(&Clang);</div><div>

E.Execute();</div></div><div><br></div><div>The code fails at "E.Execute()" with:</div><div><br></div><div><div>Assertion failed: (!CurrentFile.empty() && "No current file!"), function isCurrentFileAST, file /Volumes/Data/Users/mike/llvm/tools/clang/lib/Frontend/../../include/clang/Frontend/FrontendAction.h, line 95.</div>

</div><div><br></div><div><br></div><div>I looked up the FrontendAction::setCurrentFile method, but it takes in a StringRef to a path. Since I don't have a path to a file, as I'm only operating on source code in memory, I'm not able to set the current file.</div>

<div><br></div><div>How can I set the current file to point to a MemoryBuffer?</div><div><br></div><div>Thanks!</div><div>Mike</div>
</blockquote></div><br>