tags:

views:

60

answers:

2

Suppose I want to write my own preprocessor.

So I want something like this:

all *.cpp and *.hpp (even the included ones), before they go to g++, they go:

file --> my preprocessor -> g++

Is there a easy way to do this in the LLVM framework? i.e. to add in a stage that says: "after you load up the source file, pipe it through this program before compling it" ?

Thanks!

A: 

Ideas:

  1. Hack cpp. You can easily (-no-integrated-cpp) make gcc to call your version of cpp that will call real cpp.
  2. Request gcc -E, collect the included filenames, read all that files with your program, removing "#include" lines.
  3. Make prepreprocessor build step that will convert all files to intermediate form. *.cppanon -> *.cpp -> *.o; *.hppanon -> *.hpp;
  4. Abandon idea of hooking "#define"s.
  5. Create FUSE filesystem that will present filtered data to gcc.

Variant preference: 4,3,1,2,5.

Vi
A: 

Yes, it would be very easy to make the Clang driver do what you want, although it does not have support for exactly what you want out-of-the-box.

Daniel Dunbar