forked from tum-ei-eda/etiss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
append_codeBlocks_with_examples.py
291 lines (264 loc) · 12.9 KB
/
append_codeBlocks_with_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#
# Copyright 2018 Infineon Technologies AG
#
# This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>
#
# The initial version of this software has been created with the funding support by the German Federal
# Ministry of Education and Research(BMBF) in the project EffektiV under grant 01IS13022.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
# the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and / or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
# Author: Chair of Electronic Design Automation, TUM
#
# Version 0.1
#
import sys
import os
import xml.etree.ElementTree as ET
# check param for file
if len(sys.argv) != 2:
print 'usage: python append_codeblocks_with_examples.py <cb_file>'
sys.exit()
cb_file = sys.argv[1]
if not os.path.exists(cb_file):
print 'File does not excist!'
sys.exit()
# xml string for target fault_injection
fault_injection = ET.fromstring(
' <Target title="fault_injection">\n\
<Option output="installed/examples/fault_injection_new/vp/build_dir/main" prefix_auto="0" extension_auto="0" />\n\
<Option working_dir="installed/examples/fault_injection_new/vp" />\n\
<Option object_output="installed/examples/fault_injection_new/vp/build_dir" />\n\
<Option type="1" />\n\
<Option compiler="gcc" />\n\
<Option parameters=" -iini/ETISS.ini -iini/OR1KVCPU.ini -iini/faultInjection.ini -ofaultInjection::sw_binary ../../SW/or1k/build/code.bin" />\n\
<Compiler>\n\
<Add option="-DETISS_DEBUG=0" />\n\
<Add option="-DSC_INCLUDE_DYNAMIC_PROCESSES" />\n\
</Compiler>\n\
<ExtraCommands>\n\
<Add before="make install" />\n\
<Add before="make install" />\n\
<Add before="cd installed/examples/SW/arm; make" />\n\
<Add before="cd installed/examples/SW/or1k; make" />\n\
<Add before="cd installed/examples/fault_injection_new/vp; make" />\n\
</ExtraCommands>\n\
<MakeCommands>\n\
<Build command="make -C "installed/examples/fault_injection_new/vp/build_dir/" main" />\n\
<CompileFile command="make -C "installed/examples/fault_injection_new/vp/build_dir/" VERBOSE=1 "$file"" />\n\
<Clean command="make -C "installed/examples/fault_injection_new/vp/build_dir/" VERBOSE=1 clean" />\n\
<AskRebuildNeeded command="make -q -C "installed/examples/fault_injection_new/vp/build_dir/" main" />\n\
<SilentBuild command="make -C "installed/examples/fault_injection_new/vp/build_dir" main > $(CMD_NULL)" />\n\
</MakeCommands>\n\
</Target>\n')
# xml string for target fault_injection
fault_injection_DualCPU = ET.fromstring(
' <Target title="fault_injection_DualCPU">\n\
<Option output="installed/examples/fault_injection_new/vp/build_dir/mainDualCPU" prefix_auto="0" extension_auto="0" />\n\
<Option working_dir="installed/examples/fault_injection_new/vp" />\n\
<Option object_output="installed/examples/fault_injection_new/vp/build_dir" />\n\
<Option type="1" />\n\
<Option compiler="gcc" />\n\
<Option parameters=" -iini/ETISS.ini -iini/OR1KVCPU.ini -iini/faultInjection.ini -ofaultInjection::sw_binary ../../SW/or1k/build/code.bin" />\n\
<Compiler>\n\
<Add option="-DETISS_DEBUG=0" />\n\
<Add option="-DSC_INCLUDE_DYNAMIC_PROCESSES" />\n\
</Compiler>\n\
<ExtraCommands>\n\
<Add before="make install" />\n\
<Add before="make install" />\n\
<Add before="cd installed/examples/SW/arm; make" />\n\
<Add before="cd installed/examples/SW/or1k; make" />\n\
<Add before="cd installed/examples/fault_injection_new/vp; make" />\n\
</ExtraCommands>\n\
<MakeCommands>\n\
<Build command="make -C "installed/examples/fault_injection_new/vp/build_dir/" mainDualCPU" />\n\
<CompileFile command="make -C "installed/examples/fault_injection_new/vp/build_dir/" VERBOSE=1 "$file"" />\n\
<Clean command="make -C "installed/examples/fault_injection_new/vp/build_dir/" VERBOSE=1 clean" />\n\
<AskRebuildNeeded command="make -q -C "installed/examples/fault_injection_new/vp/build_dir/" mainDualCPU" />\n\
<SilentBuild command="make -C "installed/examples/fault_injection_new/vp/build_dir/" mainDualCPU > $(CMD_NULL)" />\n\
</MakeCommands>\n\
</Target>\n')
# xml string for target bare_etiss_processor
bare_etiss_processor = ET.fromstring(
' <Target title="bare_etiss_processor">\n\
<Option output="installed/examples/bare_etiss_processor/build/main" prefix_auto="0" extension_auto="0" />\n\
<Option working_dir="installed/examples/bare_etiss_processor" />\n\
<Option object_output="installed/examples/bare_etiss_processor/build/" />\n\
<Option type="1" />\n\
<Option compiler="gcc" />\n\
<Option parameters=" -iETISS.ini " />\n\
<Compiler>\n\
<Add option="-DETISS_DEBUG=0" />\n\
<Add option="-DSC_INCLUDE_DYNAMIC_PROCESSES" />\n\
</Compiler>\n\
<ExtraCommands>\n\
<Add before="make install" />\n\
<Add before="make install" />\n\
<Add before="cd installed/examples/SW/arm; make" />\n\
<Add before="cd installed/examples/SW/or1k; make" />\n\
<Add before="cd installed/examples/bare_etiss_processor/build; cmake -DCMAKE_BUILD_TYPE=Debug .." />\n\
</ExtraCommands>\n\
<MakeCommands>\n\
<Build command="make -C "installed/examples/bare_etiss_processor/build/" ./main" />\n\
<CompileFile command="make -C "installed/examples/bare_etiss_processor/" VERBOSE=1 "$file"" />\n\
<Clean command="make -C "installed/examples/bare_etiss_processor/" VERBOSE=1 clean" />\n\
<AskRebuildNeeded command="make -q -C "installed/examples/bare_etiss_processor/build/" ./main" />\n\
<SilentBuild command="make -C "installed/examples/bare_etiss_processor/build/" ./main > $(CMD_NULL)" />\n\
</MakeCommands>\n\
</Target>\n')
# xml string for files in example fault_injection_new
AddPcTraceLoggerPlugin = ET.fromstring(
' <Unit filename="../examples/fault_injection_new/vp/ProjectSpecificPlugins/AddPcTraceLoggerPlugin.h">\n\
<Option target="fault_injection" />\n\
</Unit>\n')
BootAndInjectionCallbackPlugin = ET.fromstring(
' <Unit filename="../examples/fault_injection_new/vp/ProjectSpecificPlugins/BootAndInjectionCallbackPlugin.h">\n\
<Option target="fault_injection" />\n\
</Unit>')
ExitOnInfloopPlugin = ET.fromstring(
' <Unit filename="../examples/fault_injection_new/vp/ProjectSpecificPlugins/ExitOnInfloopPlugin.h">\n\
<Option target="fault_injection" />\n\
</Unit>')
SynchronizeCPUs_h = ET.fromstring(
' <Unit filename="./examples/fault_injection_new/vp/ProjectSpecificPlugins/SynchronizeCPUs.h">\n\
<Option target="fault_injection_DualCPU" />\n\
</Unit>')
SynchronizeCPUs_cpp = ET.fromstring(
' <Unit filename="./examples/fault_injection_new/vp/ProjectSpecificPlugins/SynchronizeCPUs.cpp">\n\
<Option target="fault_injection_DualCPU" />\n\
</Unit>')
InstructionCounterPlugin = ET.fromstring(
' <Unit filename="../examples/fault_injection_new/vp/ProjectSpecificPlugins/InstructionCounterPlugin.h">\n\
<Option target="fault_injection" />\n\
</Unit>')
fault_injection_new_main = ET.fromstring(
' <Unit filename="../examples/fault_injection_new/vp/main.cpp">\n\
<Option target="fault_injection" />\n\
</Unit>')
fault_injection_DualCPU_main = ET.fromstring(
' <Unit filename="../examples/fault_injection_new/vp/mainDualCPU.cpp">\n\
<Option target="fault_injection_DualCPU" />\n\
</Unit>')
# xml string for files in example bare_etiss_processor
bare_etiss_processor_main = ET.fromstring(
' <Unit filename="../examples/bare_etiss_processor/main.cpp">\n\
<Option target="fault_injection" />\n\
</Unit>')
# Open original file
cb_tree = ET.parse(cb_file)
cb_root = cb_tree.getroot()
# add example build target fault_injection_new
build = cb_root.find('Project').find('Build')
found = False
for target in build.findall("Target[@title='fault_injection']"):
print 'Target fault_injection already excists!'
found = True
if (not found):
print 'Added target fault_injection.'
build.append(fault_injection)
# add example build target fault_injection_new
found = False
for target in build.findall("Target[@title='fault_injection_DualCPU']"):
print 'Target fault_injection_DualCPU already excists!'
found = True
if (not found):
print 'Added target fault_injection_DualCPU.'
build.append(fault_injection_DualCPU)
# add example build target bare_etiss_processor
found = False
for target in build.findall("Target[@title='bare_etiss_processor']"):
print 'Target bare_etiss_processor already excists!'
found = True
if (not found):
print 'Added target bare_etiss_processor.'
build.append(bare_etiss_processor)
# add files of example fault_injection_new to project
project = cb_root.find('Project')
found = False
for unit in project.findall("Unit[@filename='../examples/fault_injection_new/vp/ProjectSpecificPlugins/AddPcTraceLoggerPlugin.h']"):
print 'Unit AddPcTraceLoggerPlugin.h already excists!'
found = True
if (not found):
print 'Added file AddPcTraceLoggerPlugin.h.'
project.append(AddPcTraceLoggerPlugin)
found = False
for unit in project.findall("Unit[@filename='../examples/fault_injection_new/vp/ProjectSpecificPlugins/BootAndInjectionCallbackPlugin.h']"):
print 'Unit BootAndInjectionCallbackPlugin.h already excists!'
found = True
if (not found):
print 'Added file BootAndInjectionCallbackPlugin.h.'
project.append(BootAndInjectionCallbackPlugin)
found = False
for unit in project.findall("Unit[@filename='../examples/fault_injection_new/vp/ProjectSpecificPlugins/ExitOnInfloopPlugin.h']"):
print 'Unit ExitOnInfloopPlugin.h already excists!'
found = True
if (not found):
print 'Added file ExitOnInfloopPlugin.h.'
project.append(ExitOnInfloopPlugin)
found = False
for unit in project.findall("Unit[@filename='../examples/fault_injection_new/vp/ProjectSpecificPlugins/SynchronizeCPUs.h']"):
print 'Unit SynchronizeCPUs.h already excists!'
found = True
if (not found):
print 'Added file SynchronizeCPUs.h.'
project.append(SynchronizeCPUs_h)
found = False
for unit in project.findall("Unit[@filename='../examples/fault_injection_new/vp/ProjectSpecificPlugins/SynchronizeCPUs.cpp']"):
print 'Unit SynchronizeCPUs.cpp already excists!'
found = True
if (not found):
print 'Added file SynchronizeCPUs.h.'
project.append(SynchronizeCPUs_cpp)
found = False
for unit in project.findall("Unit[@filename='../examples/fault_injection_new/vp/ProjectSpecificPlugins/InstructionCounterPlugin.h']"):
print 'Unit InstructionCounterPlugin.h already excists!'
found = True
if (not found):
print 'Added file InstructionCounterPlugin.h.'
project.append(InstructionCounterPlugin)
found = False
for unit in project.findall("Unit[@filename='../examples/fault_injection_new/vp/main.cpp']"):
print 'Unit fault_injection_new/vp/main.cpp already excists!'
found = True
if (not found):
print 'Added file main.cpp.'
project.append(fault_injection_new_main)
project.append(InstructionCounterPlugin)
found = False
for unit in project.findall("Unit[@filename='../examples/fault_injection_new/vp/mainDualCPU.cpp']"):
print 'Unit fault_injection_new/vp/mainDualCPU.cpp already excists!'
found = True
if (not found):
print 'Added file mainDualCPU.cpp.'
project.append(fault_injection_DualCPU_main)
# add files of example fault_injection_new to project
found = False
for unit in project.findall("Unit[@filename='../examples/bare_etiss_processor/main.cpp']"):
print 'Unit bare_etiss_processor/main.cpp already excists!'
found = True
if (not found):
project.append(bare_etiss_processor_main)
# Write back to file
#et.write('file.xml')
cb_tree.write(cb_file)