A Compiler-Driven Approach for Static Dependency Injection in Embedded Software - Oliveira, Thiago Borges de; Costa, Ariadne de Andrade (Anais do Simpósio Brasileiro de Linguagens de Programação (SBLP); 2025: Anais do XXIX Simpósio Brasileiro de Linguagens de Programação, 2025)
Developing embedded software is challenging due to the need to strike a balance between writing loosely coupled and maintainable code while coping with the microcontroller’s limitations in memory, storage, and processing power. While object-oriented programming can lead to improved abstractions and cohesive, easier-to-maintain software, traditional low-level implementation of polymorphism often introduces runtime overhead that hinders its adoption. This paper proposes a compiler-driven dependency injection (DI) technique that enables the compiler to resolve dependencies and replace bound interfaces with concrete implementations in the AST tree to reduce the burden of virtual dispatch in embedded software. We compared five implementations of a breakout game written with object-oriented language features, C++20 concepts, and our proposed method. Results show that the language features allow clear interface definitions and centralized binding configurations, enhancing maintainability and portability. Furthermore, our compiler-driven approach enables optimizations beyond interface boundaries, improving code inlining, constant propagation, interprocedural optimization, and dead code elimination, producing 41.9% smaller and up to 73.3% faster firmware than equivalent versions with compile-time injection.