[LLVMdev] Simplifying a front-end project

Jeffrey Yasskin jyasskin at google.com
Tue Aug 25 16:06:50 PDT 2009


On Tue, Aug 25, 2009 at 3:01 PM, Vikram S. Adve<vadve at cs.uiuc.edu> wrote:
> For my introductory Compiler Construction class, I have been giving
> the students a project to write a simple compiler for a toy, single-
> inheritance object-oriented language.  We give them a set of classes
> implementing an AST for the language and a type checker as well.  The
> students write (1) a scanner and parser to build the AST; (2) a
> translator from AST to LLVM; and (3) a couple of basic optimization
> passes on LLVM IR.
>
> For the translator in step (2), I've so far had them generate LLVM IR
> in memory using the LLVM APIs.  They find it a *lot* of work to learn
> the LLVM APIs, which doesn't teach them much about compiler concepts
> per se.  To simplify this project, I am considering changing the
> project so they "print out" LLVM assembly directly instead of building
> up the IR in memory and writing it out.
>
> Question: Is there a convenient way to print out the LLVM assembly
> correctly without having build the IR first?  Getting the syntax right
> for all the types, declarations, functions, instructions, etc., is non-
> trivial also and the less error-prone we can make it for them, the
> better.
>
> Otherwise, is there any other way they can write their translator that
> is easier than learning the LLVM APIs for building up the IR?

Are you using TypeBuilder
(http://llvm.org/viewvc/llvm-project/llvm/branches/release_26/include/llvm/Support/TypeBuilder.h?view=markup,
new in 2.6) and IRBuilder, or trying to use the individual type and
value classes directly? I recommend the builders when they support
what you need. I don't think they'll ever completely replace the
individual classes, but in Unladen Swallow we haven't had to fall back
to the full API very often.




More information about the llvm-dev mailing list