Wiki source code of Kieler Compiler

Version 7.1 by cmot on 2014/03/16 22:26

Show last authors
1 = Kieler Compiler (KiCo) =
2
3 In order to integrate and be able to evaluate our compiler chain from SCCharts to C or VHDL code we use the KiCo project as a generic framework that allows to register setp-by-step transformations on EObjects. These can then be handled by the generic KIEM KiCo DataComponent.
4
5
6
7 {{toc/}}
8
9 == General ==
10
11 The KIELER Compiler (KiCo) project allows to register step-by-step model transformations on EObjects that could be written in Xtend or Java. These transformations are registered using an extension point provided (see below). After registering transformations these can be used by simply call the KielerCompiler compilation method as also explained further below.
12
13 [[image:attach:KiCo.jpg]]
14
15 == Extension Point ==
16
17 In order to add a transformation to KiCo you must follow these steps:
18
19 1. (((
20 Add dependency to
21
22 {{{de.cau.cs.kieler.kico}}}
23
24
25 )))
26 1. Add the extension
27
28
29 {{{de.cau.cs.kieler.kico.transformation}}}
30
31 Add one of the following
32
33 [[image:attach:KiCo2.jpg]]
34
35 |=(((
36 Extension Element
37 )))|=(((
38 Description
39 )))
40 |(((
41 transformationClass
42 )))|(((
43 The defined class must extend "de.cau.cs.kieler.kico.Transformation" and must implement the methods defined in "de.cau.cs.kieler.kico.ITransformation". These are
44
45 * getId(): Returns a unique String ID for this transformation. This is the ID the transformation will be referenced throughout KiCo.
46 * getName(): Optionally return a String name for this transformation. If null is returned here the ID will be used as a name.
47 * getDependencies(): Optionally return a List<String> of other transformation IDs that must run BEFORE this transformation. If null is returned then this means there are no dependencies.
48 * transform(EObject): Returns an EObject and does the central transformation.
49 )))
50 |(((
51 transformationMethod
52 )))|(((
53 The defined class can be freely chosen and does not need to extend or implement any other class or interface. Although you have to give more information in the extension element now:
54
55 * class: The class where the transform method is implemented in
56 * method: The name of the transformation method. Its signature must ensure that it returns an EObject an only take an EObject argument. Otherwise it cannot be found by KiCo.
57 * id: The unique String ID for this transformation. This is the ID the transformation will be referenced throughout KiCo.
58 * name: An optional String name for this transformation. If nothing is entered here the ID will be used as a name.
59 * dependencies: An optional String as comma separated list of other transformation IDs that must run BEFORE this transformation. If nothing is entered here then this means there are no dependencies.
60 )))
61 |(((
62 transformationGroup
63 )))|(((
64 Sometimes you may want to group other transformations and give this group a specific transformation ID as a kind of shortcut. You can do this by using the transformationGroup element giving the following information:
65
66 * id: The unique String ID for this transformation group. This is the ID the transformation group will be referenced throughout KiCo. It may also again be referenced by other transformation groups!
67 * dependencies: These are NOT optional for groups. Groups must specify their transformations as dependencies. Use a String as comma separated list of other transformation IDs or transformation group IDs that should represent this group. Note that the order will be implied by the referenced transformations itself although if there is a free degree of order it can be influenced by the order specified here in the group.
68 * name: An optional String name for this transformation. If nothing is entered here the ID will be used as a name.
69 )))
70
71 === Example ===
72
73 {{code title="plugin.xml"}}
74 <extension
75 point="de.cau.cs.kieler.kico.transformation">
76 <transformationGroup
77 id="NORMALIZE"
78 dependencies="TRIGGEREFFECT, SURFACEDEPTH"
79 name="Transform All Normalize">
80 </transformationGroup>
81 </extension>
82 <extension
83 point="de.cau.cs.kieler.kico.transformation">
84 <transformationMethod
85 class="de.cau.cs.kieler.sccharts.extensions.SCChartsCoreTransformation"
86 id="TRIGGEREFFECT"
87 method="transformTriggerEffect"
88 name="Transform Trigger and Effect">
89 </transformationMethod>
90 </extension>
91
92 <extension
93 point="de.cau.cs.kieler.kico.transformation">
94 <transformationMethod
95 class="de.cau.cs.kieler.sccharts.extensions.SCChartsCoreTransformation"
96 id="SURFACEDEPTH"
97 method="transformSurfaceDepth"
98 name="Transform Surface Depth">
99 </transformationMethod>
100 </extension>
101
102 <extension
103 point="de.cau.cs.kieler.kico.transformation">
104 <transformationGroup
105 id="ALL"
106 dependencies="CORE NORMALIZE"
107 name="Transform All">
108 </transformationGroup>
109 </extension>
110 {{/code}}
111
112
113
114 == Compilation ==
115
116 Once a bunch of model transformations are registered, these can simply be called using the KiCo central "KielerCompiler" class with its method compile(). This will be given a List<String> of transformation IDs or a comma separated String of transformation IDs as the first parameter. The second parameter is the EObject that is being transformed. It should meet the signature of the first model transformation called. Note that the actual model transformations that are done may vary because KiCo will automatically inspect the dependencies of each transformation requested (deep-recursively). If you do not like this to happen as an advanced user you can use a third parameter that will skip this autocompletion. Note that if you switch this off also NO transformation groups can be processed. Here is an overview and examples how to use the compile() method:
117
118 |=(((
119 Method
120 )))|=(((
121 Description
122 )))
123 |(((
124 \\
125
126 {{{EObject KielerCompiler.compile(List&#x3c;String&#x3e; transformationIDs, EObject eObject)}}}
127 )))|(((
128 * transformationIDs: List of Strings representing the transformation IDs and a pre-ordering. Note that KiCo may automatically modify the order to meet the dependencies of the referenced transformation IDs or transformation group IDs.
129 * eObject: The EObject that is the input to the compilation process.
130 * Returns: The EObject returned from the last model transformation called by KiCo.
131 )))
132 |(((
133 \\
134
135 {{{EObject KielerCompiler.compile(String transformationIDs, EObject eObject)}}}
136 )))|(((
137 This is a convenient method only which can be used to give transformation IDs or transformation group IDs as a comma separated String. For eObject and the return value see above.
138 )))
139 |(((
140
141 \\
142
143 {{{EObject KielerCompiler.compile(List&#x3c;String&#x3e; transformationIDs, EObject eObject, boolean autoexpand)}}}
144 )))|(((
145 This is an advanced compile method which can turn of auto-expansion with the last parameter. Use this with care! Note that if switching autoexpand off you cannot use transformation group IDs any more. Also no dependencies will be considered. The transformations will be applied straight forward in the order defined by the transformationIDs list.
146 )))
147
148 === Examples ===
149
150 {{code title="Java Code"}}
151 import de.cau.cs.kieler.kico.KielerCompiler;
152 ...
153 private MyEObjectClass myMethod(EObject eObject) {
154 ...
155 transformed = (MyEObjectClass) KielerCompiler.compile("ABORT, SIGNAL", eObject);
156 ...
157 return transformed
158 }
159 {{/code}}
160
161 {{code title="Xtend Code"}}
162 import de.cau.cs.kieler.kico.KielerCompiler
163 ...
164 def dispatch MyEObjectClass myMethod(EObject eObject) {
165 transformed = KielerCompiler.compile("ABORT, SIGNAL", eObject) as MyEObjectClass
166 ...
167 transformed
168 }
169
170
171
172
173 {{/code}}