[cfe-dev] Custom C++ extension
Ramin Zaghi
rzaghi at generalgates.com
Mon Jun 15 11:34:57 PDT 2015
Everyone, thank you for the very helpful comments and replies.
To answer a few of the questions:
@Nikola and @Marcello:
> develop against trunk and merge often
> setting up something automatic always helps
I do have automatic update scripts which aid me with rebasing git repositories.
I am not sure how welcome git patches are to the community but that is a longer term concern than anything else.
@Jonathan
> have you considered using __attribute__
I am aware of the syntax, however the idea behind this work goes far beyond a simple tagging.
So that wouldn’t help and even if it did it would make the code look illegible.
> that will significantly reduce your patch burden
I do agree :)
> How so?
It is a bit tricky to explain it in a few statements really. I made it sound so simple.
You would need to rewrite code to be able to do this - so I didn’t mean “magic”.
Basic idea is to create Template-like constructs for the compiler to emit code at
various “tagged" locations in the source code. This is something C++ templates
are missing and that’s being able to locate “things” in the code to do their job.
I imagine that, if we told the compiler what a “C++ [sub]statement”
looked like in Clang source code, then hypothetically we could tell the compiler
to patch the Clang source to introduce new parts to [some] “C++ statements”...
Anyway, I actually meant to post another question on a new thread regarding
source-to-source or source-to-binary compilation for this.
I may well ask the question here:
My original prototype which didn’t use Clang produced standard C++ (source to source).
I would still like to have that option. However, I would also like to be able to go from
the source directly to the backend.
I think if I implement them the way C++’s Templates are implemented
in Clang then I would get the source to backend part.
Now, I don’t know much about how Templates work in Clang yet but I had
a quick look and it seems like the template instantiation happens internally
and no code is ever produced - only ASTs.
So if I implemented these the way Templates work now, then is there no
way to switch it to a source-to-source mode?
Can Clang, for example, emit C++ code after Template instantiation, somehow?
-Ramin
> On 15 Jun 2015, at 14:48, Jonathan Roelofs <jonathan at codesourcery.com> wrote:
>
>
>
> On 6/13/15 7:53 PM, rzaghi at mosaic3dx.com wrote:
>>
>> As an example, the extension would allow us to "tag" some identifiers
>> in the code as follows:
>>
>> class CLXYZ { public: int <tag1> x; };
>>
>> The identifier tagged as such is later picked at one of the phases
>> and operated on.
>
> For this particular example, have you considered using __attribute__ syntax [1], [2]?
>
> i.e. something like:
>
> class CLXYZ { public: int x __attribute__((tag("1"))); };
>
> If you're able to leverage existing infrastructure, that will
> significantly reduce your patch burden and make following trunk _much_ easier.
>
>>
>> (ps, not so related to my question but we call this
>> "tagged-programming" paradigm. Actually we hope that the combination
>> of these extensions can eventually help programmers in scenarios as
>> the very question I am asking above!).
>
> How so?
>
>
> Cheers,
>
> Jon
>
>
> 1: https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Variable-Attributes.html#Variable-Attributes
>
> 2: http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute
>
>>
>>
>>
>> _______________________________________________ cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>
> --
> Jon Roelofs
> jonathan at codesourcery.com
> CodeSourcery / Mentor Embedded
More information about the cfe-dev
mailing list