Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 1.81 KB

README.md

File metadata and controls

41 lines (35 loc) · 1.81 KB

SDCC 8051 dead code elimination tool

This is a dead code optimization tool for SDCC mcs51 port (aka 8051 family). Took inspiration from sdccrm, a dead code optimization tool for sdcc stm8 port.

How it works

The tool takes in two argument types:

  • A directory, using option -d, containing all assembly files of a project. Assumed that all asm files are generated by sdcc for mcs51 port.

  • By default, the tool assumed that main is the only entry point in the entire project.
    Optionally, the user can provides additional entry points for ISRs by using option -e.

The brief execution order is:

  1. The tool then scan the whole dir for .asm files, find all functions in each .asm files.
  2. Next, it build function call trees, with the trunks are the entry points.
  3. All orphan functions are then removed from the .asm files.
    Finally, output files are saved with the name <org_name>.asm.mod.

Example:

./sdcc_MCS51_rm.py -d ./blink_timer -e Timer0_ISR

Important

The tool was tested with SDCC version 4.3.x and 4.4.0.

Caution

1. The tool might misidentifies some functions, especially functions called using pointer, as orphan function.
If that happens, you'll get this message during link:

sdcc: Calling linker...
sdcc: sdld -nf blink_timer.lk
?ASlink-Warning-Undefined Global '_send_char' referenced by module 'main'

You can mark that function as an entry point as a dirty work-around. I haven't find out the reason why yet.

./sdcc_MCS51_rm.py -d ./test -e send_char

2. Sometimes, the tool can't remove local variable initialization codes for several orphan functions. You can remove it by hand, or again, just mark its function as entry point for a lazy fix.