20090109 Dsl2cpp Md Workbench
-
Upload
azubi -
Category
News & Politics
-
view
85 -
download
0
Transcript of 20090109 Dsl2cpp Md Workbench
Ander Zubizarreta 9/1/2009
DSL to C++
Sysdef code generation using MDWorkbench
Problem Definition
• We have a source XML file describing a system, according to a XML Schema metamodel
• System has many elements of the type Controllable
• The goal is to generate a cpp implementation for each Controllable type element
Problem definition
XML Model
Model to Text transformation
C++ code
XSD
Problem Definition
Source• XML file
– The XML file describes a system– The system has many
controllables– Each controllable has inputs,
outputs, params, faults…
Target• .h and .cpp file for each Controllable
– The generation of the .H file is straightforward
– The generation of the .CPP file comprises several RuleSets
• Locals:– For each
input/output/param/fault/timer » define a local of that type
• doInit – \\ initialize each local variable– \\ by getting its value (using
mappings in wtsl)
We’ll use MDWorkbench for that purpose
WHY IS USED?
MDWorkbench
• MDWorkbench is a model-driven engineering development environment to build:– Source code and text generators– Word documentation– Model transformers
• Eclipse-based IDE– Java code may be used in MDWorkbench projects
• Developed by Sodius SAS
MDWorkbench
Solution
Model
Metamodel
Rules Templates
C++ code
Steps
1. Import the metamodel to MDWorkbench
2. Browse the model using MDWorkbench
3. Create the rulesets and templates for code generation
4. Run the generator
1. Importing a metamodel
• MDWorkbench natively allows to work with Ecore, Relational or UML models
• New metamodels can be imported, allowing to work with different kind of models
• Importing a metamodel consists in creating an Eclipse plugin which will be used by MDWorkbench
• Our metamodel is defined using XML Schema
1. Importing a metamodel1
2
3
Select the specific
file
4
1. Importing a metamodelCreating Plugin
• We now have to export the created project as a plugin
• When we restart MDWorkbench the new metamodel will be available
2. Browsing the model
• Once the metamodel has been imported we can open the model in MDWorkbench and browse it
3. Writing the generators
• Rulesets, text templates and scripts can be used to generate code– Rulesets are written in MQL– Templates ar written in TGL– Scripts can be written in MQL, TGL or Java
• First sketch of the solution:– Two code templates: one for .h files and other for .cpp files– A ruleset: to apply the templates to each controllable in the model– Scripts: we’ll call to some scrpits from the templates to get the
elements of the controllable
3. Writing the generators
• Ruleset:– cppGenerator.mqr
• Templates:– hGen.tgt– cppGen.tgt
• Scripts:– doGetInitializations()– doGetLocalsDefinitions()
3. Writing the generatorshGen.tgt
Refer to “20081202_MDWorkbench_Tool.ppt” for a detailed overview
of Templates
3. Writing the generatorscppGen.Tgt (call to script)
Refer to “20081202_MDWorkbench_Tool.ppt”
for a detailed overview of Templates
3. Writing the generatorsScripts
Refer to “20081202_MDWorkbench_Tool.ppt”
for a detailed overview of Scripts
3. Writing the generatorsRuleset
• cppGeneration.mqr: applies the text templates to each controllable
Refer to “20081202_MDWorkbench_Tool.ppt”
for a detailed overview of Rulesets
4. Running the generatorRun configuration
• Select the ruleset as the main element we want to run and the input model
4. Running the generatorOutput
• Console output: • Report:
4. Running the generatorOutput
• Part of a generated .cpp file: