[cfe-dev] Reusing clang::CompilerInstance object for multiple compilations

KrishnaPG krishnapg at yahoo.com
Wed May 28 20:03:20 PDT 2014


Please confirm if it is possible to reuse a clang::CompilerInstance object
for multiple compilations of a file (or different set of files).

We have a source file, that gets updated frequently and we need to compile
it every time it changes. However, to improve the response time, instead of
creating a new clang::CompilerInstance object every time, we plan to create
the object once and reuse it multiple times (since most of the options, such
as header search paths, include dirs etc. stay same).

Wondering how to achieve this. Any example could be of great use.

>From the code it looks like clang::CompilerInstance class was created mainly
for single use (compile/parse once and throw it away) and not for reuse
(using the same object for compiling different set of files, with all other
settings, such as include dirs. etc. being same).

For example, the SourceManager associated with clang::CompilerInstance has
setMainFileID() that throws assertion() if you call it twice on the same
object with different file id later. (Looks like we have call
clearIDTables() to be able to reuse the SourceManager for different set of
files). 

What is not clear is: what is the point of creating file caching in the
source manager, if one has to clear all that cache to be able to reuse that
object. 

Since all these classes are heavy duty classes with lot of member variables,
creating once and reusing the object for multiple compilations is better
than creating a throw away object different for every compilation.

Please inform which parts are safely "reusable" and which need attention.

Thank you,
GK (Gopalakrishna)
http://gk.palem.in/ 



--
View this message in context: http://clang-developers.42468.n3.nabble.com/Reusing-clang-CompilerInstance-object-for-multiple-compilations-tp4039723.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list