From UML to ANSI-C - An Eclipse-Based Code Generation Framework

Mathias Funk, Alexander Nyßen, Horst LichterIcsoft (se/muse/gsdca) 2008

TL;DR

This paper presents an Eclipse-based framework for generating ANSI-C code from UML models, specifically addressing the needs of small embedded and real-time systems. It tackles the limitations of existing UML tools that often generate C++ or proprietary code, offering a flexible and customizable solution for generating standard C code crucial for resource-constrained environments.

What Problem Does This Paper Address?

Model-Driven Engineering (MDE) has gained traction for developing embedded and real-time systems, with UML becoming a dominant modeling language. However, current MDE tools often fall short when it comes to generating code for small embedded and real-time systems. These systems have strict time and space constraints, making them incompatible with C++ or proprietary code generated by many tools. Instead, plain ANSI-C is the preferred language due to its efficiency and widespread compiler support. The core problem is the lack of flexible and customizable tools that can reliably generate ANSI-C code from UML models for these specific, resource-constrained domains. Existing commercial tools are often inflexible, and academic approaches have largely overlooked this niche.

Methods

The authors propose a two-step code generation framework built on the Eclipse platform:

  1. Model-to-Model Transformation: A logical transformation maps UML model elements to an intermediate ANSI-C meta-model. This step separates the "what" (language constructs) from the "how" (code generation), allowing for easier customization of the transformation logic without affecting the code generation itself.
  2. Model-to-Text Generation: The intermediate ANSI-C model is then transformed into actual C code files.

This approach leverages Eclipse's EMF (Eclipse Modeling Framework) for handling meta-models and OAW (openArchitectureWare) for implementing the transformation and generation scripts (using xTend for model-to-model and xPand for model-to-text). The framework is designed to be modular, allowing for the integration of custom transformation and generation components. A key feature is the use of "ProtectedRegionAnnotations" within the ANSI-C meta-model, which allows developers to insert custom code that will be preserved across regeneration cycles, enhancing practical usability.

Datasets

Not discussed in the paper. The paper focuses on a framework and its evaluation using a platform-specific generator, rather than on training or evaluating against large datasets.

Key Insights and Ideas

  • The Two-Step Approach is Crucial: Separating the logical UML-to-ANSI-C mapping from the physical code generation significantly improves flexibility, maintainability, and testability.
  • Intermediate Meta-Model is Key: An ANSI-C meta-model acts as a stable target, ensuring generated code is ANSI-conformant and simplifying the model-to-text generation.
  • Eclipse Ecosystem is a Strong Foundation: Leveraging Eclipse, EMF, and OAW provides a mature and extensible platform, enabling seamless integration with existing development tools.
  • Customization is Paramount for Embedded: The ability to insert custom code (via ProtectedRegionAnnotations) is essential for the practical adoption of MDE in embedded systems, where specific hardware interactions or optimizations are often required.
  • Bridging the Academic-Industry Gap: The framework aims to address the perceived disconnect between academic research and the real-world needs of embedded systems development.

Key Results

The paper demonstrates the framework's concept through a platform-dependent code generator for the Renesas M16C target. This generator produces customized ANSI-C code from UML structure diagrams. The evaluation highlights:

  • Customizability: The separation of concerns allowed customization to affect only the transformation part, leaving the reference generation unit untouched.
  • Reduced Effort: Delegating generation details to the reference unit significantly reduced implementation effort compared to standalone development.
  • Maintainability: The modular design and clear separation of concerns contribute to improved maintainability.

While quantitative results like specific code size reduction or execution speedup are not detailed, the qualitative results emphasize the framework's effectiveness in providing a flexible and usable solution for ANSI-C code generation from UML.

Limitations and Future Work

  • Initial Learning Effort: The authors acknowledge that implementing the transformation logic requires an initial learning effort, both for developing OAW xTend scripts and for understanding the ANSI-C meta-model structure.
  • Generalizability of Evaluation: Statements about quality, performance, or maintainability of the generated code are limited to the specific evaluation setup and cannot be generalized to the framework itself without further testing.
  • Future Work: The paper implies that further development and adoption of custom transformation units by end-users are expected. The framework itself is made available as part of the ViPER platform, encouraging its use and further development.

Summary updated

BibTeX
@inproceedings{funk2008from,
  author = {Mathias Funk and Alexander Nyßen and Horst Lichter},
  title = {{From UML to ANSI-C - An Eclipse-Based Code Generation Framework}},
  booktitle = {Icsoft (se/muse/gsdca)},
  year = {2008},
}
Figure