21
Ander Zubizarreta 9/1/2009 DSL to C++ Sysdef code generation using MDWorkbench

20090109 Dsl2cpp Md Workbench

  • Upload
    azubi

  • View
    84

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 20090109 Dsl2cpp Md Workbench

Ander Zubizarreta 9/1/2009

DSL to C++

Sysdef code generation using MDWorkbench

Page 2: 20090109 Dsl2cpp Md Workbench

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

Page 3: 20090109 Dsl2cpp Md Workbench

Problem definition

XML Model

Model to Text transformation

C++ code

XSD

Page 4: 20090109 Dsl2cpp Md Workbench

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?

Page 5: 20090109 Dsl2cpp Md Workbench

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

Page 6: 20090109 Dsl2cpp Md Workbench

MDWorkbench

Page 7: 20090109 Dsl2cpp Md Workbench

Solution

Model

Metamodel

Rules Templates

C++ code

Page 8: 20090109 Dsl2cpp Md Workbench

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

Page 9: 20090109 Dsl2cpp Md Workbench

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

Page 10: 20090109 Dsl2cpp Md Workbench

1. Importing a metamodel1

2

3

Select the specific

file

4

Page 11: 20090109 Dsl2cpp Md Workbench

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

Page 12: 20090109 Dsl2cpp Md Workbench

2. Browsing the model

• Once the metamodel has been imported we can open the model in MDWorkbench and browse it

Page 13: 20090109 Dsl2cpp Md Workbench

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

Page 14: 20090109 Dsl2cpp Md Workbench

3. Writing the generators

• Ruleset:– cppGenerator.mqr

• Templates:– hGen.tgt– cppGen.tgt

• Scripts:– doGetInitializations()– doGetLocalsDefinitions()

Page 15: 20090109 Dsl2cpp Md Workbench

3. Writing the generatorshGen.tgt

Refer to “20081202_MDWorkbench_Tool.ppt” for a detailed overview

of Templates

Page 16: 20090109 Dsl2cpp Md Workbench

3. Writing the generatorscppGen.Tgt (call to script)

Refer to “20081202_MDWorkbench_Tool.ppt”

for a detailed overview of Templates

Page 17: 20090109 Dsl2cpp Md Workbench

3. Writing the generatorsScripts

Refer to “20081202_MDWorkbench_Tool.ppt”

for a detailed overview of Scripts

Page 18: 20090109 Dsl2cpp Md Workbench

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

Page 19: 20090109 Dsl2cpp Md Workbench

4. Running the generatorRun configuration

• Select the ruleset as the main element we want to run and the input model

Page 20: 20090109 Dsl2cpp Md Workbench

4. Running the generatorOutput

• Console output: • Report:

Page 21: 20090109 Dsl2cpp Md Workbench

4. Running the generatorOutput

• Part of a generated .cpp file: