# Programming Exercise 6: Assembly Printing This is the continuation of hw5 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 instruction-selected-and-register-allocated-LLVM-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 register 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: ./bc4 (-a|-c|-l|-i|-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 LLVM-IR. -r: emit register-allocated LLVM-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: 2025-01-22 23:59 - Submit using `curl --data-binary "@" 'https://db.in.tum.de/teaching/ws2425/codegen/submit.py?hw=6&matrno='` - Write your solution in a single C++ file. (Default file name: `bc4.cc`) - Include answers to theory questions as comments at the top of the source file. - Make sure your submission passes as many tests as possible from this test script. - Avoid dependencies, no build systems other than Makefile, etc. - If you need more than just the C++ file, combine all files s.t. this command sequence works: `split-file somedir; cd somedir; bash ` - If you write your own Makefile: - Use `$(LLVM_CONFIG) --cppflags --ldflags --libs` to find LLVM; note that libs must come after your object files when linking. - Default-initialize `LLVM_CONFIG := llvm-config`, so that `make LLVM_CONFIG=/path/to/llvm-config` overrides it. There is no test script or automatic verification. For the programs of the previous homeworks, the following should work: `cat prog.input | ./bc4 -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.