Quantcast

Generating C++ with Sourcemaps

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Generating C++ with Sourcemaps

Brian Cain via cfe-dev
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,

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Generating C++ with Sourcemaps

Brian Cain via cfe-dev


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
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>

--
Jon Roelofs
[hidden email]
CodeSourcery / Mentor Embedded / Siemens
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Generating C++ with Sourcemaps

Brian Cain via cfe-dev
Um....wow....thats perfect. Learn something new every day.

On Thu, Apr 6, 2017 at 10:55 AM, Jonathan Roelofs <[hidden email]> wrote:


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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
Jon Roelofs
[hidden email]
CodeSourcery / Mentor Embedded / Siemens



--
“One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.”
(Robert Firth)

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...