Coverage for pyEDAA/IPXACT/Component.py: 29%

223 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-17 01:13 +0000

1# ==================================================================================================================== # 

2# _____ ____ _ _ ___ ______ __ _ ____ _____ # 

3# _ __ _ _| ____| _ \ / \ / \ |_ _| _ \ \/ / / \ / ___|_ _| # 

4# | '_ \| | | | _| | | | |/ _ \ / _ \ | || |_) \ / / _ \| | | | # 

5# | |_) | |_| | |___| |_| / ___ \ / ___ \ _ | || __// \ / ___ \ |___ | | # 

6# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)___|_| /_/\_\/_/ \_\____| |_| # 

7# |_| |___/ # 

8# ==================================================================================================================== # 

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

13# ==================================================================================================================== # 

14# Copyright 2017-2024 Patrick Lehmann - Bötzingen, Germany # 

15# Copyright 2016-2016 Patrick Lehmann - Dresden, Germany # 

16# # 

17# Licensed under the Apache License, Version 2.0 (the "License"); # 

18# you may not use this file except in compliance with the License. # 

19# You may obtain a copy of the License at # 

20# # 

21# http://www.apache.org/licenses/LICENSE-2.0 # 

22# # 

23# Unless required by applicable law or agreed to in writing, software # 

24# distributed under the License is distributed on an "AS IS" BASIS, # 

25# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

26# See the License for the specific language governing permissions and # 

27# limitations under the License. # 

28# # 

29# SPDX-License-Identifier: Apache-2.0 # 

30# ==================================================================================================================== # 

31# 

32from textwrap import dedent 

33 

34from pyTooling.Decorators import export 

35 

36from pyEDAA.IPXACT import RootElement, __DEFAULT_SCHEMA__ 

37 

38 

39@export 

40class Component(RootElement): 

41 """Represents an IP-XACT components.""" 

42 

43 def __init__(self, vlnv, description): 

44 super().__init__(vlnv) 

45 

46 self._description = description 

47 self._busInterfaces = [] 

48 self._indirectInterfaces = [] 

49 self._channels = [] 

50 self._remapStates = [] 

51 self._addressSpaces = [] 

52 self._memoryMaps = [] 

53 self._model = None 

54 self._componentGenerators = [] 

55 self._choices = [] 

56 self._fileSets = [] 

57 self._whiteboxElements = [] 

58 self._cpus = [] 

59 self._otherClockDrivers = [] 

60 self._resetTypes = [] 

61 self._parameters = [] 

62 self._assertions = [] 

63 

64 def Settem(self, item): 

65 if isinstance(item, Model): self._model = item 

66 else: 

67 raise ValueError() 

68 

69 def AddItem(self, item) -> None: 

70 if isinstance(item, BusInterface): self._busInterfaces.append(item) 

71 elif isinstance(item, IndirectInterface): self._indirectInterfaces.append(item) 

72 elif isinstance(item, Channel): self._channels.append(item) 

73 elif isinstance(item, RemapState): self._remapStates.append(item) 

74 elif isinstance(item, AddressSpace): self._addressSpaces.append(item) 

75 elif isinstance(item, MemoryMap): self._memoryMaps.append(item) 

76 elif isinstance(item, ComponentGenerator): self._componentGenerators.append(item) 

77 elif isinstance(item, Choice): self._choices.append(item) 

78 elif isinstance(item, FileSet): self._fileSets.append(item) 

79 elif isinstance(item, WhiteboxElement): self._whiteboxElements.append(item) 

80 elif isinstance(item, Cpu): self._cpus.append(item) 

81 elif isinstance(item, OtherClockDriver): self._otherClockDrivers.append(item) 

82 elif isinstance(item, ResetType): self._resetTypes.append(item) 

83 elif isinstance(item, Parameter): self._parameters.append(item) 

84 elif isinstance(item, Assertion): self._assertions.append(item) 

85 else: 

86 raise ValueError() 

87 

88 def ToXml(self) -> str: 

89 """Converts the object's data into XML format.""" 

90 

91 buffer = dedent("""\ 

92 <?xml version="1.0" encoding="UTF-8"?> 

93 <{xmlns}:component 

94 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

95 xmlns:{xmlns}="{schemaUri}" 

96 xsi:schemaLocation="{schemaUri} {schemaUrl}"> 

97 {versionedIdentifier} 

98 <{xmlns}:description>{description}</{xmlns}:description> 

99 """).format( 

100 xmlns=__DEFAULT_SCHEMA__.NamespacePrefix, 

101 schemaUri=__DEFAULT_SCHEMA__.SchemaUri, 

102 schemaUrl=__DEFAULT_SCHEMA__.SchemaUrl, 

103 versionedIdentifier=self._vlnv.ToXml(isVersionedIdentifier=True), 

104 description=self._description 

105 ) 

106 

107 if self._busInterfaces: 

108 buffer += "\t<{xmlns}:busInterfaces>\n" 

109 for busInterface in self._busInterfaces: 

110 buffer += busInterface.ToXml(2) 

111 buffer += "\t</{xmlns}:busInterfaces>\n" 

112 

113 if self._indirectInterfaces: 

114 buffer += "\t<{xmlns}:indirectInterfaces>\n" 

115 for indirectInterface in self._indirectInterfaces: 

116 buffer += indirectInterface.ToXml(2) 

117 buffer += "\t</{xmlns}:indirectInterfaces>\n" 

118 

119 if self._channels: 

120 buffer += "\t<{xmlns}:channels>\n" 

121 for channel in self._channels: 

122 buffer += channel.ToXml(2) 

123 buffer += "\t</{xmlns}:channels>\n" 

124 

125 if self._remapStates: 

126 buffer += "\t<{xmlns}:remapStates>\n" 

127 for remapState in self._remapStates: 

128 buffer += remapState.ToXml(2) 

129 buffer += "\t</{xmlns}:remapStates>\n" 

130 

131 if self._addressSpaces: 

132 buffer += "\t<{xmlns}:addressSpaces>\n" 

133 for addressSpace in self._addressSpaces: 

134 buffer += addressSpace.ToXml(2) 

135 buffer += "\t</{xmlns}:addressSpaces>\n" 

136 

137 if self._memoryMaps: 

138 buffer += "\t<{xmlns}:memoryMaps>\n" 

139 for memoryMap in self._memoryMaps: 

140 buffer += memoryMap.ToXml(2) 

141 buffer += "\t</{xmlns}:memoryMaps>\n" 

142 

143 if self._model: 

144 buffer += "\t<{xmlns}:model>\n" 

145 buffer += self._model.ToXml(2) 

146 buffer += "\t</{xmlns}:model>\n" 

147 

148 if self._componentGenerators: 

149 buffer += "\t<{xmlns}:componentGenerators>\n" 

150 for componentGenerator in self._componentGenerators: 

151 buffer += componentGenerator.ToXml(2) 

152 buffer += "\t</{xmlns}:componentGenerators>\n" 

153 

154 if self._choices: 

155 buffer += "\t<{xmlns}:choices>\n" 

156 for choice in self._choices: 

157 buffer += choice.ToXml(2) 

158 buffer += "\t</{xmlns}:choices>\n" 

159 

160 if self._fileSets: 

161 buffer += "\t<{xmlns}:fileSets>\n" 

162 for fileSet in self._fileSets: 

163 buffer += fileSet.ToXml(2) 

164 buffer += "\t</{xmlns}:fileSets>\n" 

165 

166 if self._whiteboxElements: 

167 buffer += "\t<{xmlns}:whiteboxElements>\n" 

168 for whiteboxElement in self._whiteboxElements: 

169 buffer += whiteboxElement.ToXml(2) 

170 buffer += "\t</{xmlns}:whiteboxElements>\n" 

171 

172 if self._cpus: 

173 buffer += "\t<{xmlns}:cpus>\n" 

174 for cpu in self._cpus: 

175 buffer += cpu.ToXml(2) 

176 buffer += "\t</{xmlns}:cpus>\n" 

177 

178 if self._otherClockDrivers: 

179 buffer += "\t<{xmlns}:otherClockDrivers>\n" 

180 for otherClockDriver in self._otherClockDrivers: 

181 buffer += otherClockDriver.ToXml(2) 

182 buffer += "\t</{xmlns}:otherClockDrivers>\n" 

183 

184 if self._resetTypes: 

185 buffer += "\t<{xmlns}:resetTypes>\n" 

186 for resetType in self._resetTypes: 

187 buffer += resetType.ToXml(2) 

188 buffer += "\t</{xmlns}:resetTypes>\n" 

189 

190 if self._parameters: 

191 buffer += "\t<{xmlns}:parameters>\n" 

192 for parameter in self._parameters: 

193 buffer += parameter.ToXml(2) 

194 buffer += "\t</{xmlns}:parameters>\n" 

195 

196 if self._assertions: 

197 buffer += "\t<{xmlns}:assertions>\n" 

198 for assertion in self._assertions: 

199 buffer += assertion.ToXml(2) 

200 buffer += "\t</{xmlns}:assertions>\n" 

201 

202 buffer += dedent("""\ 

203 </{xmlns}:component> 

204 """) 

205 

206 return buffer.format(xmlns=__DEFAULT_SCHEMA__.NamespacePrefix) 

207 

208 

209@export 

210class BusInterface: 

211 """Represents an IP-XACT bus interface.""" 

212 

213 def __init__(self) -> None: 

214 pass 

215 

216 def ToXml(self, indent=0): 

217 """Converts the object's data into XML format.""" 

218 

219 return "" 

220 

221 

222@export 

223class IndirectInterface: 

224 """Represents an IP-XACT indirect interface.""" 

225 

226 def __init__(self) -> None: 

227 pass 

228 

229 def ToXml(self, indent=0): 

230 """Converts the object's data into XML format.""" 

231 

232 return "" 

233 

234 

235@export 

236class Channel: 

237 """Represents an IP-XACT channel.""" 

238 

239 def __init__(self) -> None: 

240 pass 

241 

242 def ToXml(self, indent=0): 

243 """Converts the object's data into XML format.""" 

244 

245 return "" 

246 

247 

248@export 

249class RemapState: 

250 """Represents an IP-XACT remap state.""" 

251 

252 def __init__(self) -> None: 

253 pass 

254 

255 def ToXml(self, indent=0): 

256 """Converts the object's data into XML format.""" 

257 

258 return "" 

259 

260 

261@export 

262class AddressSpace: 

263 """Represents an IP-XACT address space.""" 

264 

265 def __init__(self) -> None: 

266 pass 

267 

268 def ToXml(self, indent=0): 

269 """Converts the object's data into XML format.""" 

270 

271 return "" 

272 

273 

274@export 

275class MemoryMap: 

276 """Represents an IP-XACT memory map.""" 

277 

278 def __init__(self) -> None: 

279 pass 

280 

281 def ToXml(self, indent=0): 

282 """Converts the object's data into XML format.""" 

283 

284 return "" 

285 

286 

287@export 

288class Model: 

289 """Represents an IP-XACT model.""" 

290 

291 def __init__(self) -> None: 

292 pass 

293 

294 def ToXml(self, indent=0): 

295 """Converts the object's data into XML format.""" 

296 

297 return "" 

298 

299 

300@export 

301class ComponentGenerator: 

302 """Represents an IP-XACT component generator.""" 

303 

304 def __init__(self) -> None: 

305 pass 

306 

307 def ToXml(self, indent=0): 

308 """Converts the object's data into XML format.""" 

309 

310 return "" 

311 

312 

313@export 

314class Choice: 

315 """Represents an IP-XACT choice.""" 

316 

317 def __init__(self) -> None: 

318 pass 

319 

320 def ToXml(self, indent=0): 

321 """Converts the object's data into XML format.""" 

322 

323 return "" 

324 

325 

326@export 

327class FileSet: 

328 """Represents an IP-XACT fileset.""" 

329 

330 def __init__(self) -> None: 

331 pass 

332 

333 def ToXml(self, indent=0): 

334 """Converts the object's data into XML format.""" 

335 

336 return "" 

337 

338 

339@export 

340class WhiteboxElement: 

341 """Represents an IP-XACT whitebos element.""" 

342 

343 def __init__(self) -> None: 

344 pass 

345 

346 def ToXml(self, indent=0): 

347 """Converts the object's data into XML format.""" 

348 

349 return "" 

350 

351 

352@export 

353class Cpu: 

354 """Represents an IP-XACT cpu.""" 

355 

356 def __init__(self) -> None: 

357 pass 

358 

359 def ToXml(self, indent=0): 

360 """Converts the object's data into XML format.""" 

361 

362 return "" 

363 

364 

365@export 

366class OtherClockDriver: 

367 """Represents an IP-XACT *other* clock driver.""" 

368 

369 def __init__(self) -> None: 

370 pass 

371 

372 def ToXml(self, indent=0): 

373 """Converts the object's data into XML format.""" 

374 

375 return "" 

376 

377 

378@export 

379class ResetType: 

380 """Represents an IP-XACT reset type.""" 

381 

382 def __init__(self) -> None: 

383 pass 

384 

385 def ToXml(self, indent=0): 

386 """Converts the object's data into XML format.""" 

387 

388 return "" 

389 

390 

391@export 

392class Parameter: 

393 """Represents an IP-XACT parameter.""" 

394 

395 def __init__(self) -> None: 

396 pass 

397 

398 def ToXml(self, indent=0): 

399 """Converts the object's data into XML format.""" 

400 

401 return "" 

402 

403 

404@export 

405class Assertion: 

406 """Represents an IP-XACT assertion.""" 

407 

408 def __init__(self) -> None: 

409 pass 

410 

411 def ToXml(self, indent=0): 

412 """Converts the object's data into XML format.""" 

413 

414 return ""