Using Web Assembly to Teach Code Generation in a Compiler Design Course Academic Article in Scopus uri icon

abstract

  • © 2022 Owner/Author.For many students, code generation is the most demanding topic covered in a typical undergraduate Compiler Design course. In this poster, the author will present how he has successfully used the fairly novel and promising WebAssembly technology in his course in order to make the said topic more relevant and engaging for learners. Once we have a compiler frontend that produces an abstract syntax tree (AST) and a symbol table for a given source program, the code generation phase involves traversing the AST and emitting the corresponding WebAssembly instructions in a generally straightforward fashion. The code generation phase is significantly simplified given that WebAssembly is actually an intermediate code for a stack-based virtual machine. The real machine code is produced later by the WebAssembly runtime's just-in-time (JIT) compiler. During execution, the generated code may call functions written in a high-level language directly supported by the runtime. This allows having basic I/O capabilities, like printing to the screen or reading input from the keyboard. At the end of the semester, students have authored the frontend and backend of a fully working compiler that translates a simple C-like procedural language into platform-neutral executable WebAssembly code.

publication date

  • March 3, 2022