[cfe-dev] clang compile from/to memory buffer

Jason E. Aten j.e.aten at gmail.com
Fri May 6 15:32:42 PDT 2011


On Fri, May 6, 2011 at 3:02 PM, Nico Weber <thakis at chromium.org> wrote:
Take a look at llvm/tools/clang/examples/Tooling/ClangCheck.cpp


Thank you Nico!

could you elaborate... would I put the C++ source to be compiled in
the JsonDatabase  MemoryBuffer?

Jason

Examining the code from examples/Tooling/ClangCheck.cpp...

int main(int argc, char **argv) {
...
  llvm::OwningPtr<llvm::MemoryBuffer> JsonDatabase;  # line

  llvm::SmallString<1024> JsonDatabasePath(argv[1]);

  llvm::sys::path::append(JsonDatabasePath, "compile_commands.json");

  llvm::error_code Result =
      llvm::MemoryBuffer::getFile(JsonDatabasePath, JsonDatabase);

...

    clang::tooling::CompileCommand LookupResult =
        clang::tooling::FindCompileArgsInJsonDatabase(
            File.str(), JsonDatabase->getBuffer(), ErrorMessage);
...
    if (!LookupResult.CommandLine.empty()) {
      if (!clang::tooling::RunToolWithFlags(
               new clang::SyntaxOnlyAction,
               LookupResult.CommandLine.size(),
               clang::tooling::CommandLineToArgv(
                   &LookupResult.CommandLine).data())) {

        llvm::outs() << "Error while processing " << File << ".\n";
      }
    } else {
      llvm::outs() << "Skipping " << File << ". Command line not found.\n";
    }
  }
  return 0;
}



On Fri, May 6, 2011 at 3:02 PM, Nico Weber <thakis at chromium.org> wrote:

> Take a look at llvm/tools/clang/examples/Tooling/ClangCheck.cpp
>
> Nico
>
> On Fri, May 6, 2011 at 12:56 PM, Jason E. Aten <j.e.aten at gmail.com> wrote:
> > I'm looking at the examples/clang-interpreter example.  I'd like to
> expand
> > the interpreter a little.
> >
> > It looks like it currently only reads from a file.  Is it possible to
> have
> > clang compile from a memory buffer?  And to a memory buffer?
> >
> > Thank you!
> >
> > Jason
> >
> > --
> > Jason E. Aten, Ph.D.
> >
> >
> >
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >
> >
>



-- 
Jason E. Aten, Ph.D.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110506/7d560e9c/attachment.html>


More information about the cfe-dev mailing list