[cfe-users] Compile from source code string

2022-01-17 Thread 0dminnimda via cfe-users
I wanna use regular functionality of clang but instead of passing path to
the source I want to pass string as source code. Yes, it's preferably a
code that uses clang api and not just call to clang with source that was
put into input, as source files are usually big.
Googled that, but not really successfully.
No good source of info about that or code that's outdated.
Would really appreciate any help.
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Compile from source code string

2022-01-17 Thread 0dminnimda via cfe-users
> The phrase “clang api” is a bit vague (libclang?)

If it's possible, then of course LibClang as it's backward compatible, but
I know that it's restricted in functionality, so if LibClang don't give
such freedom, then LibTooling.

> $ echo 'int main(void) { return 0; }' | clang -x c -

Thanks for the advice! This should work on unix, but what's about other
systems? That's why I wanted to go with code, because I target at least
Linux, Macos and Windows, and with code solution it'll be no different to
support all of them as well as it'll be bit more secure, I think.


On Tue, Jan 18, 2022, 4:07 AM Matthew Fernandez 
wrote:

>
> > On Jan 17, 2022, at 14:35, 0dminnimda via cfe-users <
> cfe-users@lists.llvm.org> wrote:
> >
> > I wanna use regular functionality of clang but instead of passing path
> to the source I want to pass string as source code. Yes, it's preferably a
> code that uses clang api and not just call to clang with source that was
> put into input, as source files are usually big.
> > Googled that, but not really successfully.
> > No good source of info about that or code that's outdated.
> > Would really appreciate any help.
>
> The phrase “clang api” is a bit vague (libclang?), but it is possible to
> feed the compiler strings on the command line if you teach it the input
> language:
>
> $ echo 'int main(void) { return 0; }' | clang -x c -
>
> Hope this helps.
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Compile from source code string

2022-01-19 Thread 0dminnimda via cfe-users
Right now I'm in process of trying this approach:
Copy the code from cc1_main, write my own SourceManager and set it to
CompilerInstance with setSourceManager().


On Wed, Jan 19, 2022, 7:45 PM Matthew Fernandez 
wrote:

>
> > On Jan 17, 2022, at 21:59, 0dminnimda <0dminni...@gmail.com> wrote:
> >
> > > The phrase “clang api” is a bit vague (libclang?)
> >
> > If it's possible, then of course LibClang as it's backward compatible,
> but I know that it's restricted in functionality, so if LibClang don't give
> such freedom, then LibTooling.
> >
> > > $ echo 'int main(void) { return 0; }' | clang -x c -
> >
> > Thanks for the advice! This should work on unix, but what's about other
> systems? That's why I wanted to go with code, because I target at least
> Linux, Macos and Windows, and with code solution it'll be no different to
> support all of them as well as it'll be bit more secure, I think.
>
> I can’t see anything promising in libclang, but maybe runToolOnCode in
> libtooling might achieve what you’re after.
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users