On Monday, October 26, 2015, Ariel Arelovich via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi:<div><br></div><div>Where I'm working I've been asked to look into developing a C (by this I mean C89 C standard) compiler a new processor architecture being created inhouse. </div><div><br></div><div>On looking at the options and brushing up on compiler theory, I came up with Flex/Bison, Writing the compiler from scratch or use Clang. I liked this option better because parsing and and analyzing c code to genereate somthing intermediate, and do this from scratch, seemed like reinventing the wheel (an incredibly complex wheel, at that).</div><div><br></div><div>I've figured that if Clang, works with the standard compiler flow (that I've seen everywhere), it takes a C program and transforms it until it gets a intermediate language (which is machine independant). The Dragon Book, even calls this the output of the compiler Front End. From what I've read from the documentation This is what Clang is: a compiler front end. LLVM does optimization and translation to opcodes of known architectures. Is this correct? Or am I getting this wrong?</div></div></blockquote><div><br></div><div>Correct.  clang is just the front end for C-like languages.  It will parse and analyze the code (generating the AST).  The IR it generates is the LLVM IR.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>So, my question is: Would it be possible to use Clang in such a way that it takes a C program and generates an intermediate language so that I can work directly on that language to generate opcodes based on the architecture that we are currently developing?</div></div></blockquote><div><br></div><div>Yes.  This is how clang already works.  It sounds like you should be looking at LLVM, not clang since you are trying to support a new architecture, not a language feature.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Thank you, for any answers.</div><div><br></div><div>PD: I know my question might be very hard to answer as it is not very specific. All I'm asking for, here, is a simple: "It could be done, start reading about this and that" or "It will be next to impossible, just try something else" (with a little explanation as to why, if that were possible, please).</div></div>
</blockquote><br><br>-- <br>Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org<br>