pyEDAA.IPXACT.Component

pyEDAA/IPXACT/Component.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# ==================================================================================================================== #
#              _____ ____    _        _      ___ ______  __    _    ____ _____                                         #
#  _ __  _   _| ____|  _ \  / \      / \    |_ _|  _ \ \/ /   / \  / ___|_   _|                                        #
# | '_ \| | | |  _| | | | |/ _ \    / _ \    | || |_) \  /   / _ \| |     | |                                          #
# | |_) | |_| | |___| |_| / ___ \  / ___ \ _ | ||  __//  \  / ___ \ |___  | |                                          #
# | .__/ \__, |_____|____/_/   \_\/_/   \_(_)___|_|  /_/\_\/_/   \_\____| |_|                                          #
# |_|    |___/                                                                                                         #
# ==================================================================================================================== #
# Authors:                                                                                                             #
#   Patrick Lehmann                                                                                                    #
#                                                                                                                      #
# License:                                                                                                             #
# ==================================================================================================================== #
# Copyright 2017-2024 Patrick Lehmann - Bötzingen, Germany                                                             #
# Copyright 2016-2016 Patrick Lehmann - Dresden, Germany                                                               #
#                                                                                                                      #
# Licensed under the Apache License, Version 2.0 (the "License");                                                      #
# you may not use this file except in compliance with the License.                                                     #
# You may obtain a copy of the License at                                                                              #
#                                                                                                                      #
#   http://www.apache.org/licenses/LICENSE-2.0                                                                         #
#                                                                                                                      #
# Unless required by applicable law or agreed to in writing, software                                                  #
# distributed under the License is distributed on an "AS IS" BASIS,                                                    #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                                             #
# See the License for the specific language governing permissions and                                                  #
# limitations under the License.                                                                                       #
#                                                                                                                      #
# SPDX-License-Identifier: Apache-2.0                                                                                  #
# ==================================================================================================================== #
#
from textwrap           import dedent

from pyTooling.Decorators import export

from pyEDAA.IPXACT      import RootElement, __DEFAULT_SCHEMA__


@export
class Component(RootElement):
	"""Represents an IP-XACT components."""

	def __init__(self, vlnv, description):
		super().__init__(vlnv)

		self._description =         description
		self._busInterfaces =       []
		self._indirectInterfaces =  []
		self._channels =            []
		self._remapStates =         []
		self._addressSpaces =       []
		self._memoryMaps =          []
		self._model =               None
		self._componentGenerators = []
		self._choices =             []
		self._fileSets =            []
		self._whiteboxElements =    []
		self._cpus =                []
		self._otherClockDrivers =   []
		self._resetTypes =          []
		self._parameters =          []
		self._assertions =          []

	def Settem(self, item):
		if isinstance(item, Model):                 self._model = item
		else:
			raise ValueError()

	def AddItem(self, item) -> None:
		if isinstance(item, BusInterface):          self._busInterfaces.append(item)
		elif isinstance(item, IndirectInterface):   self._indirectInterfaces.append(item)
		elif isinstance(item, Channel):             self._channels.append(item)
		elif isinstance(item, RemapState):          self._remapStates.append(item)
		elif isinstance(item, AddressSpace):        self._addressSpaces.append(item)
		elif isinstance(item, MemoryMap):           self._memoryMaps.append(item)
		elif isinstance(item, ComponentGenerator):  self._componentGenerators.append(item)
		elif isinstance(item, Choice):              self._choices.append(item)
		elif isinstance(item, FileSet):             self._fileSets.append(item)
		elif isinstance(item, WhiteboxElement):     self._whiteboxElements.append(item)
		elif isinstance(item, Cpu):                 self._cpus.append(item)
		elif isinstance(item, OtherClockDriver):    self._otherClockDrivers.append(item)
		elif isinstance(item, ResetType):           self._resetTypes.append(item)
		elif isinstance(item, Parameter):           self._parameters.append(item)
		elif isinstance(item, Assertion):           self._assertions.append(item)
		else:
			raise ValueError()

	def ToXml(self) -> str:
		"""Converts the object's data into XML format."""

		buffer = dedent("""\
			<?xml version="1.0" encoding="UTF-8"?>
			<{xmlns}:component
				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
				xmlns:{xmlns}="{schemaUri}"
				xsi:schemaLocation="{schemaUri} {schemaUrl}">
			{versionedIdentifier}
				<{xmlns}:description>{description}</{xmlns}:description>
			""").format(
				xmlns=__DEFAULT_SCHEMA__.NamespacePrefix,
				schemaUri=__DEFAULT_SCHEMA__.SchemaUri,
				schemaUrl=__DEFAULT_SCHEMA__.SchemaUrl,
				versionedIdentifier=self._vlnv.ToXml(isVersionedIdentifier=True),
				description=self._description
			)

		if self._busInterfaces:
			buffer += "\t<{xmlns}:busInterfaces>\n"
			for busInterface in self._busInterfaces:
				buffer += busInterface.ToXml(2)
			buffer += "\t</{xmlns}:busInterfaces>\n"

		if self._indirectInterfaces:
			buffer += "\t<{xmlns}:indirectInterfaces>\n"
			for indirectInterface in self._indirectInterfaces:
				buffer += indirectInterface.ToXml(2)
			buffer += "\t</{xmlns}:indirectInterfaces>\n"

		if self._channels:
			buffer += "\t<{xmlns}:channels>\n"
			for channel in self._channels:
				buffer += channel.ToXml(2)
			buffer += "\t</{xmlns}:channels>\n"

		if self._remapStates:
			buffer += "\t<{xmlns}:remapStates>\n"
			for remapState in self._remapStates:
				buffer += remapState.ToXml(2)
			buffer += "\t</{xmlns}:remapStates>\n"

		if self._addressSpaces:
			buffer += "\t<{xmlns}:addressSpaces>\n"
			for addressSpace in self._addressSpaces:
				buffer += addressSpace.ToXml(2)
			buffer += "\t</{xmlns}:addressSpaces>\n"

		if self._memoryMaps:
			buffer += "\t<{xmlns}:memoryMaps>\n"
			for memoryMap in self._memoryMaps:
				buffer += memoryMap.ToXml(2)
			buffer += "\t</{xmlns}:memoryMaps>\n"

		if self._model:
			buffer += "\t<{xmlns}:model>\n"
			buffer += self._model.ToXml(2)
			buffer += "\t</{xmlns}:model>\n"

		if self._componentGenerators:
			buffer += "\t<{xmlns}:componentGenerators>\n"
			for componentGenerator in self._componentGenerators:
				buffer += componentGenerator.ToXml(2)
			buffer += "\t</{xmlns}:componentGenerators>\n"

		if self._choices:
			buffer += "\t<{xmlns}:choices>\n"
			for choice in self._choices:
				buffer += choice.ToXml(2)
			buffer += "\t</{xmlns}:choices>\n"

		if self._fileSets:
			buffer += "\t<{xmlns}:fileSets>\n"
			for fileSet in self._fileSets:
				buffer += fileSet.ToXml(2)
			buffer += "\t</{xmlns}:fileSets>\n"

		if self._whiteboxElements:
			buffer += "\t<{xmlns}:whiteboxElements>\n"
			for whiteboxElement in self._whiteboxElements:
				buffer += whiteboxElement.ToXml(2)
			buffer += "\t</{xmlns}:whiteboxElements>\n"

		if self._cpus:
			buffer += "\t<{xmlns}:cpus>\n"
			for cpu in self._cpus:
				buffer += cpu.ToXml(2)
			buffer += "\t</{xmlns}:cpus>\n"

		if self._otherClockDrivers:
			buffer += "\t<{xmlns}:otherClockDrivers>\n"
			for otherClockDriver in self._otherClockDrivers:
				buffer += otherClockDriver.ToXml(2)
			buffer += "\t</{xmlns}:otherClockDrivers>\n"

		if self._resetTypes:
			buffer += "\t<{xmlns}:resetTypes>\n"
			for resetType in self._resetTypes:
				buffer += resetType.ToXml(2)
			buffer += "\t</{xmlns}:resetTypes>\n"

		if self._parameters:
			buffer += "\t<{xmlns}:parameters>\n"
			for parameter in self._parameters:
				buffer += parameter.ToXml(2)
			buffer += "\t</{xmlns}:parameters>\n"

		if self._assertions:
			buffer += "\t<{xmlns}:assertions>\n"
			for assertion in self._assertions:
				buffer += assertion.ToXml(2)
			buffer += "\t</{xmlns}:assertions>\n"

		buffer += dedent("""\
				</{xmlns}:component>
				""")

		return buffer.format(xmlns=__DEFAULT_SCHEMA__.NamespacePrefix)


@export
class BusInterface:
	"""Represents an IP-XACT bus interface."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class IndirectInterface:
	"""Represents an IP-XACT indirect interface."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class Channel:
	"""Represents an IP-XACT channel."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class RemapState:
	"""Represents an IP-XACT remap state."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class AddressSpace:
	"""Represents an IP-XACT address space."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class MemoryMap:
	"""Represents an IP-XACT memory map."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class Model:
	"""Represents an IP-XACT model."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class ComponentGenerator:
	"""Represents an IP-XACT component generator."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class Choice:
	"""Represents an IP-XACT choice."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class FileSet:
	"""Represents an IP-XACT fileset."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class WhiteboxElement:
	"""Represents an IP-XACT whitebos element."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class Cpu:
	"""Represents an IP-XACT cpu."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class OtherClockDriver:
	"""Represents an IP-XACT *other* clock driver."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class ResetType:
	"""Represents an IP-XACT reset type."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class Parameter:
	"""Represents an IP-XACT parameter."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""


@export
class Assertion:
	"""Represents an IP-XACT assertion."""

	def __init__(self) -> None:
		pass

	def ToXml(self, indent=0):
		"""Converts the object's data into XML format."""

		return ""