Posted on January 6, 2018 and last updated on February 20, 2023 by Mistral Contrastin

Compiler Construction Example Sheet III

  1. In C, when you are allocating memory with malloc you need to pass the size of the memory you want to be allocated and the routine returns a pointer. When you later want to free this memory you use the free routine and only pass the pointer. How come libc knows how much memory to deallocate?

  2. How can multiple source files can be compiled separately and linked together? How and which parts of ELF help you do that?

  3. After reviewing lecture notes on garbage collection, read Bacon et al. (2004) up to and including section 4.

  4. How is environment implemented in Slang interpreters 0 and 2. Pay special attention to handling of functions.

  5. What is the main difference between interpreter 0 and interpreter 2? What are the purposes of this change? What are the additions to the interpreter 2 in the version 3? How do they improve the compiler?

  6. 2020/4/3

  7. 2018/4/4

  8. As you know Java virtual machine is a bytecode interpreter. Here are the instructions of a function f. What is the high-level code that produces these instructions? Annotate fragments of the code. This will require you to lookup what these instructions do online. Please do not use a decompiler.

    public static int f(int);
       0: iload_0
       1: ifne          6
       4: iconst_1
       5: ireturn
       6: iload_0
       7: iload_0
       8: iconst_1
       9: isub
      10: invokestatic  #4     // Method f
      13: imul
      14: ireturn
  9. Write a program with the following specification on Linux outputting an ELF binary using x86_64 instruction set:

    Input: An integer N (supplied as command line argument or standard input)

    Output: N lines. In the first of which there is a * and in each subsequent lines there is an extra star.


    Input: 5
Bacon, D.F., Cheng, P., Rajan, V., 2004. A unified theory of garbage collection. ACM SIGPLAN Notices 39, 50–68.