A MIPS decompiler.
Given some MIPS assembly, this program will attempt to convert it to C. The goal is that eventually the output will be well-formed C, and eventually after that, byte-equivalent C.
Right now the decompiler is fairly functional, though it sometimes generates suboptimal code (especially for loops), and sometimes crashes. See the
tests/directory for some example output.
Make sure you have Python 3.6 or later installed, then do
python3 -m pip install --upgrade attrs pycparser.
You might need to install
pipfirst; on Ubuntu this can be done with:
bash sudo apt update sudo apt install python3-pip
python3 mips_to_c.py [options]
--helpto see which options are available.
There is much low-hanging fruit still. Take a look at the issues if you want to help out.
blackto auto-format our code. We recommend using
pre-committo ensure only auto-formatted code is committed. To set these up, run:
bash pip install pre-commit black pre-commit install
Your commits will then be automatically formatted per commit. You can also manually run
blackon the command-line.
There is a small test suite, which works as follows: - As you develop your commit, occasionally run
./run_tests.pyto see if any tests have changed output. These tests run the decompiler on a small corpus of IRIX 5.3-compiled MIPS assembly. - Before pushing your commit, run
./run_tests.py --overwriteto write changed tests to disk, and commit resultant changes.
You are encouraged to add new tests using the
./tests/add_test.pyscript. Make sure to
./run_tests.pyafter adding new tests.
Type annotations are used for all Python code.
mypy mips_to_c.pyshould pass without any errors.
To get pretty graph visualizations, install
pipand globally on your system (e.g.
sudo apt install graphviz), and pass the