New to Clang

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

New to Clang

Wei Li
Dear  all;

I am a PhD student in EE at The university of Waterloo. I am planning
to use the Clang front end for my work.

I will be extending the C language to support my needs for the
research i.e. I will be creating some new keywords.

I am an electrical engineer not a compiler person. However, I am
reading on compiler. My question is how to start in the Clang? I see
LEX directory . My understating is to walk through this first in order
to create new tokens. But which file to touch first?

Any guidance regarding how to start this?

Thanking in advance,
--
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: New to Clang

Douglas Gregor

On Aug 26, 2010, at 9:46 AM, Wei Li wrote:

> Dear  all;
>
> I am a PhD student in EE at The university of Waterloo. I am planning
> to use the Clang front end for my work.

Welcome!

> I will be extending the C language to support my needs for the
> research i.e. I will be creating some new keywords.
>
> I am an electrical engineer not a compiler person. However, I am
> reading on compiler. My question is how to start in the Clang? I see
> LEX directory . My understating is to walk through this first in order
> to create new tokens. But which file to touch first?
>
> Any guidance regarding how to start this?

You can start by adding your new keyword in include/clang/Basic/TokenKinds.def Then, go into the parser (lib/Parser) and add code to parse that keyword. After that you'll probably need to add an action (include/Sema/Action.h) and its implementation for semantic analysis (include/Sema/Sema.h, lib/Sema/wherever). In general, pick something in the C family of languages that's close to what you want to do, then follow it through the compiler.


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

Re: New to Clang

Sebastian Redl
In reply to this post by Wei Li

On Aug 26, 2010, at 9:46 AM, Wei Li wrote:

> Dear  all;
>
> I am a PhD student in EE at The university of Waterloo. I am planning
> to use the Clang front end for my work.
>
> I will be extending the C language to support my needs for the
> research i.e. I will be creating some new keywords.
>
> I am an electrical engineer not a compiler person. However, I am
> reading on compiler. My question is how to start in the Clang? I see
> LEX directory . My understating is to walk through this first in order
> to create new tokens. But which file to touch first?

The only part of Lex you'll ever need to touch (unless you're extending the preprocessor) is TokenKinds.td, which actually lives in Basic. It defines the special tokens and keywords that exist in Clang. If you need a new keyword, you simply add it there.
Everything else should probably go into Parser, Sema and CodeGen.

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