[cfe-dev] Executing a FrontendAction on a MemoryBuffer

Mike Miller michael.g.miller at gmail.com
Fri May 7 15:40:36 PDT 2010


Hi,

I'm currently using the following code(excerpted) to execute a
FrontendAction(an EmitObjAction specifically) on source code contained in a
MemoryBuffer:

llvm::MemoryBuffer* Buffer = llvm::MemoryBuffer::getMemBuffer(Source);
SourceManager& SM = Clang.getSourceManager();
FileID MainFileID = SM.createMainFileIDForMemBuffer(Buffer);

EmitObjAction E;
E.setCompilerInstance(&Clang);
E.Execute();

The code fails at "E.Execute()" with:

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.


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.

How can I set the current file to point to a MemoryBuffer?

Thanks!
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100507/c0590e5e/attachment.html>


More information about the cfe-dev mailing list