A Compiler-Driven Approach for Static Dependency Injection in Embedded Software
Abstract: 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.
Keywords: Compiler-driven dependency injection; Embedded software; Hardware Abstraction; Optimization.
Citation: Thiago Borges de Oliveira; Ariadne de Andrade Costa. A Compiler-Driven Approach for Static Dependency Injection in Embedded Software. In: Simpósio Brasileiro de Linguagens de Programação (SBLP), Recife, PE, Brasil, 2025, pp. 19-27.
Copy citation in bibtex format.