Thanks a lot.<div><br></div><div>Best regards</div><div>Mello<br><br><div class="gmail_quote">On Thu, Jul 19, 2012 at 7:05 PM, Sean Silva <span dir="ltr"><<a href="mailto:silvas@purdue.edu" target="_blank">silvas@purdue.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You should look at <<a href="http://clang.llvm.org/docs/DriverInternals.html" target="_blank">http://clang.llvm.org/docs/DriverInternals.html</a>>,<br>

which illustrates how the driver works. The driver is the program<br>
responsible for deciding things like compile vs. assemble vs. link.<br>
<br>
For the actual step of parsing and compiling C/C++, this diagram maybe<br>
helpful <<a href="http://web.ics.purdue.edu/~silvas/deps.svg" target="_blank">http://web.ics.purdue.edu/~silvas/deps.svg</a>>. The diagram was<br>
made just by looking at the constructor arguments of each class. The<br>
arrows represent arguments to constructors, so you can see, for<br>
example, that Parser depends on Sema and Preprocessor. The purple<br>
nodes represent interfaces/abstract classes: these usually represent<br>
points of customizability. The diagram by no means contains all the<br>
classes involved, but it should give you a better idea of the "big<br>
picture".<br>
<br>
The main actors in the compilation step are Sema, Parser, and<br>
Preprocessor. Effectively, Parser calls methods on Preprocessor to get<br>
tokens; depending on the tokens themselves (i.e., which syntactic<br>
constructs are found), Parser then takes information taken from those<br>
tokens and calls into Sema, which acts on that information and builds<br>
AST nodes. In effect, Sema is a giant class with a bunch of callbacks<br>
("semantic actions") corresponding to different aspects of<br>
semantically analyzing C/C++ and building up the C/C++ AST.<br>
<br>
For example, if you look at Parser::ParseWhileStatement in<br>
lib/Parse/ParseStmt.cpp, you can see this flow: it first consumes a<br>
`tok::kw_while` from the Preprocessor (it knows (and asserts) that the<br>
next token is a "while" token because otherwise it would not be called<br>
to parse a while (by<br>
Parser::ParseStatementOrDeclarationAfterAttributes)). It then does<br>
some diagnostics checking that it is followed by the "(" of the while<br>
condition. It then enters a scope (which through an RAII object calls<br>
Parser::EnterScope) by setting Actions.CurScope (`Actions` is a Sema<br>
object) to a new scope (and chaining the current one as the parent of<br>
this new scope). It then recursively calls ParseParenExprOrCondition<br>
and returns an error if that fails. If you then skip down a little<br>
bit, you'll see that it recursively calls ParseStatement to parse the<br>
body of the while loop. It then exits the scopes it has made and does<br>
some error checking. Finally, it calls Sema::ActOnWhileStmt<br>
(`Actions.ActOnWhileStmt([...])`) which builds the AST nodes<br>
corresponding to the "while", along with any semantic analysis it<br>
needs to do.<br>
<br>
Hope that helps.<br>
<br>
btw, there's a cfe-dev mailing list that would be more appropriate for<br>
this question (CFE=="C FrontEnd", but it should really be called<br>
"clang-dev"). I've CC'd them and un-CC'd llvmdev.<br>
<br>
--Sean Silva<br>
<div><div class="h5"><br>
On Thu, Jul 19, 2012 at 5:59 AM, Journeyer J. Joh<br>
<<a href="mailto:oosaprogrammer@gmail.com">oosaprogrammer@gmail.com</a>> wrote:<br>
> Hi list,<br>
><br>
> I am now started to read Clang source code.<br>
> And I found any conversion from input file(.c, .i, .s) to the output<br>
> file(.i, .s, .o) is done the process below.<br>
><br>
> - FrontAction::BeginSourceFile()<br>
> - FrontAction::Execute<br>
> - FrontAction::EndSourceFile()<br>
><br>
> And I drew some activity diagram below.<br>
><br>
> <a href="http://www.opencpp.kr/behavior_of_clang.html" target="_blank">http://www.opencpp.kr/behavior_of_clang.html</a><br>
><br>
> >From the diagram I can guess that these are main actors in the movie, Clang.<br>
> - Diagnostic client<br>
> - Action<br>
> - Preprocessor<br>
> - Consumer of AST and AST<br>
> - File and Source Manager<br>
><br>
><br>
> Because Clang is well-structured C++ code, I believe there would be a<br>
> big picture for it's design.<br>
> If someone provide hints about this I would read Clang much more smoothly.<br>
> I'd like to know the architecture used in the back of those below.<br>
> - FrontAction::BeginSourceFile()<br>
> - FrontAction::Execute<br>
> - FrontAction::EndSourceFile()<br>
><br>
> I even don't know where to find the starting point of compile, assemble.<br>
><br>
> The pattern used, I also want to know.<br>
><br>
> Thank you very much in advance.<br>
><br>
><br>
> Journeyer J. Joh<br>
> --<br>
> ----------------------------------------<br>
> Journeyer J. Joh<br>
> o o s a p r o g r a m m e r<br>
> a t<br>
> g m a i l  d o t  c o m<br>
> ----------------------------------------<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>