[cfe-dev] HELP FOR CLANG

Eli Friedman eli.friedman at gmail.com
Tue Jul 16 18:35:36 PDT 2013


(Adding the mailing list back to the discussion, again; please use
reply-to-all.)

If I'm following you correctly, you're trying to dynamically verify
contracts written in ACSL?  In that case, you probably want to be
looking at CodeGenFunction::GenerateCode in CodeGenFunction.cpp.  The
basic outline is that when clang generates the prologue/epilogue for
the function, you want to insert some additional code based on the
contract written in the ACSL attached to the function declaration.
You grab the comment associated with the current function using
ASTContext::getRawCommentForDecl, build an AST to represent the ASCL,
and generate code based on your ACSL AST.  Since the ACSL syntax is
only vaguely C-like, you'll probably want to write your own ACSL
parser and AST.

If you're not familiar with compiler architecture in general, you
might want to pick up a textbook about compilers and do some reading
("Compilers: Principles, Techniques, and Tools" is a popular one).
clang is pretty much a textbook compiler if you ignore the fact that
parsing C is a bit nasty.

-Eli

On Tue, Jul 16, 2013 at 3:52 AM, Arpit Sancheti
<arpit.sancheti at iiitdmj.ac.in> wrote:
> Respected Sir,
>
> Actually what I want to do is to produce LLVM-IR for ACSL programs using
> CLANG. I am new to CLANG and don't know much about it. What I am looking
> for is how to learn about architecture of CLANG so that I can make changes
> in its source code so as to make it support for my ACSL constructs. This
> language is a specification language of C. The specifications of the
> program are written in annotated comments. I want tho produce LLVM-IR for
> such type of code. So, what I want to know is learn about clang so as to
> know what changes to make in it and where. Please help me with this as I
> seriously want to work on clang. It is awesome.
>
> Thanks
> Arpit
>> On Mon, Jul 15, 2013 at 8:42 PM, Arpit Sancheti
>> <arpit.sancheti at iiitdmj.ac.in> wrote:
>>> Respected Sir,
>>> Actually by mistake I have written ACSL as ASCL its a ANSI C Specific
>>> Language.More detail about it u can found at
>>> http://frama-c.com/acsl_tutorial_index.html. And I want to add some new
>>> keywords, new tokens and then parse them also.
>>
>> (Adding the mailing list back to the discussion.)
>>
>> You actually asking for the wrong thing.  Given how ACSL works, you
>> don't want to modify the lexer at all.  You can get the comment
>> associated with a declaration in the AST by calling
>> ASTContext::getRawCommentForDecl.  (clang_Cursor_getRawCommentText in
>> the C API.)
>>
>> -Eli
>>
>
>
> --
> Arpit Sancheti
> roll no:2010033
> programme:b.tech
> discipline:cse
> -------------------
> The difference between a successful person and others is not lack of
> knowledge or strength but the lack of will.



More information about the cfe-dev mailing list