extending C with Clang

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

extending C with Clang

Wei Li
Dear All:

I am  extending C language for my research work and using Clang for
this. I am adding some annotations which are not part of C language
but will be helpful for my specific work.

 Now consider the following:

int  foo() { return 1; }

is a legal  expression in C and is acceptable by the Clang. Now if I
introduce a new annotation say "Wei"  and write the above expression
as

int foo() Wei { return 1;}

I have to make changes in Clang at the front end to make it work. I
see my extension as super set of C. That is my work should accept the
legal C program as well.

Now here is the problem. When I make changes in the Clang . It accepts
the new annotation but breaks the C programs. My understanding is that
as I am adding to C so if my stuff works, any legal C  program should
also work. But its not happening. I am not a compiler person. I am an
engineer. Any suggestions? why clang is doing this or am I doing
something    which is not compatible with the C grammar.?

--
Regards,

Wei Li
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: extending C with Clang

John McCall

On Sep 2, 2010, at 3:01 PM, Wei Li wrote:

> Dear All:
>
> I am  extending C language for my research work and using Clang for
> this. I am adding some annotations which are not part of C language
> but will be helpful for my specific work.
>
> Now consider the following:
>
> int  foo() { return 1; }
>
> is a legal  expression in C and is acceptable by the Clang. Now if I
> introduce a new annotation say "Wei"  and write the above expression
> as
>
> int foo() Wei { return 1;}
>
> I have to make changes in Clang at the front end to make it work. I
> see my extension as super set of C. That is my work should accept the
> legal C program as well.
>
> Now here is the problem. When I make changes in the Clang . It accepts
> the new annotation but breaks the C programs. My understanding is that
> as I am adding to C so if my stuff works, any legal C  program should
> also work. But its not happening. I am not a compiler person. I am an
> engineer. Any suggestions? why clang is doing this or am I doing
> something    which is not compatible with the C grammar.?

Your parser modifications are probably broken.  I would strongly
suggest implementing Wei as a macro for __attribute__((Wei)) and then
just adding support for your new attribute.

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: extending C with Clang

Abramo Bagnara-2
Il 03/09/2010 00:12, John McCall ha scritto:

>
> On Sep 2, 2010, at 3:01 PM, Wei Li wrote:
>
>> Dear All:
>>
>> I am  extending C language for my research work and using Clang for
>> this. I am adding some annotations which are not part of C language
>> but will be helpful for my specific work.
>>
>> Now consider the following:
>>
>> int  foo() { return 1; }
>>
>> is a legal  expression in C and is acceptable by the Clang. Now if I
>> introduce a new annotation say "Wei"  and write the above expression
>> as
>>
>> int foo() Wei { return 1;}
>>
>> I have to make changes in Clang at the front end to make it work. I
>> see my extension as super set of C. That is my work should accept the
>> legal C program as well.
>>
>> Now here is the problem. When I make changes in the Clang . It accepts
>> the new annotation but breaks the C programs. My understanding is that
>> as I am adding to C so if my stuff works, any legal C  program should
>> also work. But its not happening. I am not a compiler person. I am an
>> engineer. Any suggestions? why clang is doing this or am I doing
>> something    which is not compatible with the C grammar.?
>
> Your parser modifications are probably broken.  I would strongly
> suggest implementing Wei as a macro for __attribute__((Wei)) and then
> just adding support for your new attribute.

Isn't a better idea for user that need this to have only one

__attribute__((custom(Expr)))

and store the Expr in the AST?

In this way the Expr is subject to template trasformation and each
application can use it how it needs to.

Some application will prefer to use a string literal as Expr, while
others will prefer to have a function call like Expr where arguments are
reference to program objects.

Another option is change AnnotateAttr to accept an arbitrary expression.

Are you willing to accept a patch for one of this alternatives?
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: extending C with Clang

John McCall

On Sep 2, 2010, at 11:08 PM, Abramo Bagnara wrote:

> Il 03/09/2010 00:12, John McCall ha scritto:
>>
>> On Sep 2, 2010, at 3:01 PM, Wei Li wrote:
>>
>>> Dear All:
>>>
>>> I am  extending C language for my research work and using Clang for
>>> this. I am adding some annotations which are not part of C language
>>> but will be helpful for my specific work.
>>>
>>> Now consider the following:
>>>
>>> int  foo() { return 1; }
>>>
>>> is a legal  expression in C and is acceptable by the Clang. Now if I
>>> introduce a new annotation say "Wei"  and write the above expression
>>> as
>>>
>>> int foo() Wei { return 1;}
>>>
>>> I have to make changes in Clang at the front end to make it work. I
>>> see my extension as super set of C. That is my work should accept the
>>> legal C program as well.
>>>
>>> Now here is the problem. When I make changes in the Clang . It accepts
>>> the new annotation but breaks the C programs. My understanding is that
>>> as I am adding to C so if my stuff works, any legal C  program should
>>> also work. But its not happening. I am not a compiler person. I am an
>>> engineer. Any suggestions? why clang is doing this or am I doing
>>> something    which is not compatible with the C grammar.?
>>
>> Your parser modifications are probably broken.  I would strongly
>> suggest implementing Wei as a macro for __attribute__((Wei)) and then
>> just adding support for your new attribute.
>
> Isn't a better idea for user that need this to have only one
>
> __attribute__((custom(Expr)))
>
> and store the Expr in the AST?

Why would this be better for users?  Easier to implement new annotations,
maybe, but easier for users?

Sean Hunt has done a lot of work to make it easy to add new attributes,
and more is forthcoming;  I would much prefer that over making a private
language of annotations expressed cumbersomely with expressions.

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: extending C with Clang (bug in buildsystem?)

Mattias Holm
Speaking about attributes, it seems that if I change Attr.td, then
AttrImpl.inc and Attrs.inc are not regenerated (I am using Makefiles
generated by CMake).

I assume this is a bug, at the moment I have type make clean before
rebuilding clang everytime I change the Attr.td file.

/ Mattias


On 2010-09-03 08:19, John McCall wrote:

>
> On Sep 2, 2010, at 11:08 PM, Abramo Bagnara wrote:
>
>> Il 03/09/2010 00:12, John McCall ha scritto:
>>>
>>> On Sep 2, 2010, at 3:01 PM, Wei Li wrote:
>>>
>>>> Dear All:
>>>>
>>>> I am  extending C language for my research work and using Clang for
>>>> this. I am adding some annotations which are not part of C language
>>>> but will be helpful for my specific work.
>>>>
>>>> Now consider the following:
>>>>
>>>> int  foo() { return 1; }
>>>>
>>>> is a legal  expression in C and is acceptable by the Clang. Now if I
>>>> introduce a new annotation say "Wei"  and write the above expression
>>>> as
>>>>
>>>> int foo() Wei { return 1;}
>>>>
>>>> I have to make changes in Clang at the front end to make it work. I
>>>> see my extension as super set of C. That is my work should accept the
>>>> legal C program as well.
>>>>
>>>> Now here is the problem. When I make changes in the Clang . It accepts
>>>> the new annotation but breaks the C programs. My understanding is that
>>>> as I am adding to C so if my stuff works, any legal C  program should
>>>> also work. But its not happening. I am not a compiler person. I am an
>>>> engineer. Any suggestions? why clang is doing this or am I doing
>>>> something    which is not compatible with the C grammar.?
>>>
>>> Your parser modifications are probably broken.  I would strongly
>>> suggest implementing Wei as a macro for __attribute__((Wei)) and then
>>> just adding support for your new attribute.
>>
>> Isn't a better idea for user that need this to have only one
>>
>> __attribute__((custom(Expr)))
>>
>> and store the Expr in the AST?
>
> Why would this be better for users?  Easier to implement new annotations,
> maybe, but easier for users?
>
> Sean Hunt has done a lot of work to make it easy to add new attributes,
> and more is forthcoming;  I would much prefer that over making a private
> language of annotations expressed cumbersomely with expressions.
>
> John.


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: extending C with Clang (bug in buildsystem?)

Francois Pichet
On Fri, Sep 3, 2010 at 6:42 AM, Mattias Holm <[hidden email]> wrote:
> Speaking about attributes, it seems that if I change Attr.td, then
> AttrImpl.inc and Attrs.inc are not regenerated (I am using Makefiles
> generated by CMake).
>
> I assume this is a bug, at the moment I have type make clean before
> rebuilding clang everytime I change the Attr.td file.

I have the same problem using Visual Studio 2008 projects generated by
CMake. But I don't have to do a clean, I just manually delete the
corresponding .inc file after I edit a .td and then the build works.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: extending C with Clang (bug in buildsystem?)

Michael Spencer-2
In reply to this post by Mattias Holm
On Fri, Sep 3, 2010 at 6:42 AM, Mattias Holm <[hidden email]> wrote:
> Speaking about attributes, it seems that if I change Attr.td, then
> AttrImpl.inc and Attrs.inc are not regenerated (I am using Makefiles
> generated by CMake).
>
> I assume this is a bug, at the moment I have type make clean before
> rebuilding clang everytime I change the Attr.td file.
>
> / Mattias

I looked at the CMakeLists.txt that defines that target, but it seems
fine. I'm not a CMake expert, but it's defined the same as all the
other tablegen targets, and they work.

Please file a build system bug.

- Michael Spencer
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev