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

Nico Weber thakis at chromium.org
Fri May 6 16:13:23 PDT 2011


On Fri, May 6, 2011 at 3:32 PM, Jason E. Aten <j.e.aten at gmail.com> wrote:
> 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(

This function is defined in lib/Tooling/Tooling.cpp. If I'm reading
this file right, the function RunSyntaxOnlyToolOnCode() in the same
file does what you want.

>                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.
>
>
>




More information about the cfe-dev mailing list