Description
- In this homework, we will use CHA and RTA to analyze the virtual calls in C++ programs. For simplicity, we only do intra-procedural analysis. You need to output the results for both CHA and RTA. You can first perform CHA, and then perform RTA based on the results of CHA.
- Analyzing C++ program is different from analyzing C program as we do in previous homework. In C++ programs, function names are mangled. Name mangling solves the problem of overloaded identifiers in programming languages, such as virtual functions. We should be careful when analyzing C++ programs. To ease your workload, I have already add code help with the analysis in the presence of name mangling.
- If you have time, you can try to implement VTA on our code template, it is optional.
- You can generate the bitcode file by the following command or use the .ll file provided, the LLVM version is 10.0.0.
- Command:
clang -S -O0 -fno-discard-value-names -g -emit-llvm simple.cpp
Benchmark
Sample Output
Code Template
- We provide a simple script to help your running, you need to modify the
PATH and LLVM_HOME variables to your own paths. You can also use your own script.
- I have completed many parts for you, you need to understand these code and complete the whole program.
- The missing parts are tagged with
//TODO.
- LLVM uses
StructType* to represent class type, you can use Module.getTypeByName(class_name) to get the corresponding type pointer.
- We only need to analyze the main function.
control-flow.tar.gz
Submission
- For each program, output a .txt file as the result, named as H9_progName_StuFstName_StuID.txt, e.g.
H9_simple_ZhouAn_20639948.txt.