[cfe-dev] Generating C++ with Sourcemaps

Jonathan Roelofs via cfe-dev cfe-dev at lists.llvm.org
Thu Apr 6 09:55:07 PDT 2017



On 4/6/17 10:48 AM, Timothy Baldridge via cfe-dev wrote:
> 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?

https://gcc.gnu.org/onlinedocs/cpp/Line-Control.html


Jon

>
> So any thoughts as to the best way to go about this?
>
> Thanks,
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded / Siemens



More information about the cfe-dev mailing list