[cfe-dev] How to add an option to clang

John Criswell criswell at illinois.edu
Sun Nov 6 12:46:13 PST 2011


On 11/4/11 11:41 PM, redder_0210 wrote:
> Dear All,
>  I'm trying to add a command line option to Clang/Clang++.I want to 
> let clang do the actions coresponding to the new command option.
>       What I have done is that I have modified the driver of Clang, 
> including the "Dirver.cpp" ,"options.td", "Tools.cpp" and "Action.cpp".
>       But the compilation instance( namely Clang cc1) of Clang cannot 
> identify the new option. And the console prints the ERROR:" 
> unsupported argumnet". Perhaps, I should modified the Clang cc1 
> to make it be albe to accept the new option. But I don't know how 
> to deal with the "Clang cc1".
>        what's more,  when I have add the new command line argumnet to 
> the "CC1Options.td", the console prints the "ast infomation"(in my 
> opinion) of the source File. I have no idea about the reason.
>       Thanks in advance.

Did you get my email answering this question?  If so, was there 
something unclear in my response?

My original response is archived here: 
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-November/018451.html.

Modifying CC1Options.td will add a new command-line option to Clang's 
cc1.  However, that isn't enough: you have to modify Clang to pass the 
new option to cc1 when it appears on the clang command line (that is the 
change in lib/Drivers/Tools.cpp).  You also need to modify cc1 to do 
whatever it is you want to do when it sees that command line option.  In 
the case of the SAFECode patch, that change (or part of it) is in 
lib/CodeGen/BackendUtil.cpp (if I remember the filenames correctly).

-- John T.

>       ----Redder.
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111106/e5586ccc/attachment.html>


More information about the cfe-dev mailing list