Generating C++ with Sourcemaps

Apologies if this is the wrong mailing list.

I’m looking to generate some C++ from another set of input files. Now in a perfect world I’d love to get line numbers and source references that link back to my input files, and not to the C++ files. Think of something like Cython in Python. It translates Python to C, but all the error messages point back to Python.

I can think of two main ways to do this via libclang, and perhaps both of them are bad ideas, so I’m open to more options:

A) I could parse my input files and build up libclang ASTs, I could then compile these ASTs via clang and then run those ASTs through the normal optimization/code emission passes.

B) I could compile my own version of clang that accepted an external “sourcemap” file. This file would be used to replace the data held in the SourceManager code with other filenames/offsets.

C) Some other option I haven’t thought of?

So any thoughts as to the best way to go about this?

Thanks,

Apologies if this is the wrong mailing list.

I'm looking to generate some C++ from another set of input files. Now in
a perfect world I'd love to get line numbers and source references that
link back to my input files, and not to the C++ files. Think of
something like Cython in Python. It translates Python to C, but all the
error messages point back to Python.

I can think of two main ways to do this via libclang, and perhaps both
of them are bad ideas, so I'm open to more options:

A) I could parse my input files and build up libclang ASTs, I could then
compile these ASTs via clang and then run those ASTs through the normal
optimization/code emission passes.

B) I could compile my own version of clang that accepted an external
"sourcemap" file. This file would be used to replace the data held in
the SourceManager code with other filenames/offsets.

C) Some other option I haven't thought of?

Have you considered emitting your C with #line directives that correspond to the python?

Jon

Um…wow…thats perfect. Learn something new every day.