[LLVMdev] Simplifying a front-end project

Vikram S. Adve vadve at cs.uiuc.edu
Tue Aug 25 15:01:04 PDT 2009


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?

Any suggestions appreciated.

--Vikram
Associate Professor, Computer Science
University of Illinois at Urbana-Champaign
http://llvm.org/~vadve




More information about the llvm-dev mailing list