Papyrus-RT/Developer/Design/0.8/Codegen High Level Overview
High-level view of the general transformation architecture
The code generator is implemented in XTend as a set of model to model transformations. The input model is an instance of a UML model with the UML-RT profile applied. The output model is an instance of a C++ language model. There is a set of specialized intermediate models where needed. The C++ language model writes itself to source code files which can then be compiled.
The code generator will provide a mechanism for overriding and customizing certain parts of the transformation algorithm.
Input Model and Toolset API
The code generator is implemented as a set of plugins that run within Eclipse. Papyrus-RT invokes the code generator with a function call, passing in the model elements to be generated.
More detail is provided in the Code Generator API
Intermediate models are a partial representation of a specific portion of the input model. The goal of an intermediate model is to allow a separation of concerns between the input model structure and generation of the source code.
Intermediate models are an optional component in generator. If portions of the input model can be directly converted to the output model then there is no need to create an intermediate model for that aspect of generation.
For example, consider generation of connectors. If an input model has a connection that passes through a relay port then the code pattern will likely specify that the relay port be removed so that the end ports are directly connected. In this case we may choose to create a Port and Connector intermediate model as shown here.
Customizing the Code Generator
Intermediate models are also be useful when end users customize the code generation pattern. We should eventually create a customization debugger where the end users can visualize the intermediate model in order to observe the impact of their changes.
= Output Model =
The output model is the end of the model transformation pipeline. Other intermediate models are stages in the ultimate goal, which is to produce source code. The output model contains the logic to create source code files from the model elements.
The output model is useful for all source code languages, but it is especially useful for languages that generate the same information in multiple places. In C++ for example, member function signatures are generated in the header file and the implementation file. The end-user creates a single model element and the language model contains the logic for creating multiple files with the same content.
The output model implements file generation in a way that only modifies files when there is new content. This allows make-based builds to use the timestamp of the file to avoid compilation when the content has not changed.
Want to know more?
Check out our the detailed description of the transformation architecture.