#!/bin/bash : <<'````````bash' # Programming Exercise 8: Assembly Printing This is the continuation of hw7 and the last part of this series. You can continue from your own code or use the parser from the website as starting point. ## Implementation Print out assembly code from your register allocated IR that can be compiled by a standard assembler (e.g., GNU as). - Export functions with `.global` and set a proper symbol type and size, e.g. using `.type func, @function` and (at the end) `.size func, .-func`. - Create a sufficiently large and suitably aligned stack frame, which you clean up before return. Remember to save callee-saved registers (rbx, rbp, r12-r15) that your code uses; you might need to adjust references to the stack frame. - Take care of basic block labels; make use of fallthrough where easily possible, but don't forget to emit proper branches if this is impossible. - Annotate your function correctly with CFI directives. Enjoy your working compiler! ## Command Line Interface usage: ./bc5 (-a|-c|-l|-i|-L|-r|-S) program_file B compiler. Exit with non-zero status code on invalid input. -a: print AST as S-Expressions. -c: syntax/semantic check only (build AST nonetheless). No output other than the exit code. -l: emit LLVM-IR. -i: emit instruction-selected IR. -L: emit instruction-selected IR with liveness information. -r: emit register-allocated IR. -S: emit textual assembly code. program_file: file that contains the input program Note that `program_file` is not necessarily a regular file, but can also be a pipe as used in the tests below, where you cannot determine the input size without reading it. You can add extra options, e.g., to control optimizations or for debugging. ## Submission - Submission deadline: 2026-01-28 23:59 - Submit using `curl --data-binary "@" 'https://db.in.tum.de/teaching/ws2526/codegen/submit.py?hw=8&matrno='` There is no test script or automatic verification. For the programs of the previous homeworks, the following should work: `cat prog.input | ./bc5 -S /dev/stdin | gcc -x assembler - && ./a.out`. I'm not aware of a good way to programmatically verify the correctness of the CFI directives with reasonable effort. ````````bash set -euo pipefail exit 0