Coverage for pyVHDLModel/STD.py: 100%

82 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 22:13 +0000

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

2# __ ___ _ ____ _ __ __ _ _ # 

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

4# | '_ \| | | \ \ / /| |_| | | | | | | |\/| |/ _ \ / _` |/ _ \ | # 

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

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

7# |_| |___/ # 

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

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

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

14# Copyright 2017-2024 Patrick Lehmann - Boetzingen, Germany # 

15# Copyright 2016-2017 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# 

32"""This module contains library and package declarations for VHDL library ``STD``.""" 

33 

34from pyTooling.Decorators import export 

35 

36from pyVHDLModel.Base import Range, Direction 

37from pyVHDLModel.Name import SimpleName 

38from pyVHDLModel.Symbol import SimpleSubtypeSymbol 

39from pyVHDLModel.Expression import EnumerationLiteral, IntegerLiteral, PhysicalIntegerLiteral 

40from pyVHDLModel.Type import EnumeratedType, IntegerType, Subtype, PhysicalType, ArrayType 

41from pyVHDLModel.Predefined import PredefinedLibrary, PredefinedPackage, PredefinedPackageBody 

42 

43 

44@export 

45class Std(PredefinedLibrary): 

46 """ 

47 Predefined VHDL library ``std``. 

48 

49 The following predefined packages are in this library: 

50 

51 * :class:`~pyVHDLModel.STD.Standard` 

52 * :class:`~pyVHDLModel.STD.Env` 

53 * :class:`~pyVHDLModel.STD.TextIO` 

54 

55 .. seealso:: 

56 

57 Other predefined libraries: 

58 * Library :class:`~pyVHDLModel.IEEE.Ieee` 

59 """ 

60 

61 def __init__(self) -> None: 

62 super().__init__(PACKAGES) 

63 

64 

65@export 

66class Standard(PredefinedPackage): 

67 """ 

68 Predefined package ``std.standard``. 

69 

70 Predefined types: 

71 

72 * ``boolean``, ``boolean_vector`` 

73 * ``bit``, ``bit_vector`` 

74 * ``character``, ``string`` 

75 * ``integer``, ``integer_vector`` 

76 * ``natural``, ``positive`` 

77 * ``real``, ``real_vector`` 

78 * ``time``, ``time_vector`` 

79 * ``open_file_kind``, ``open_file_status`` 

80 

81 .. seealso:: 

82 

83 Matching :class:`Package Body <pyVHDLModel.STD.Standard_Body>` declaration. 

84 """ 

85 

86 def __init__(self) -> None: 

87 super().__init__() 

88 

89 boolean = EnumeratedType("boolean", (EnumerationLiteral("false"), EnumerationLiteral("true")), None) 

90 self._types[boolean._normalizedIdentifier] = boolean 

91 self._declaredItems.append(boolean) 

92 

93 bit = EnumeratedType("bit", (EnumerationLiteral("'0'"), EnumerationLiteral("'1'")), None) 

94 self._types[bit._normalizedIdentifier] = bit 

95 self._declaredItems.append(bit) 

96 

97 chars = \ 

98 "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "lf", "vt", "ff", "cr", "so", "si", "dle", "dc1", "dc2", "dc3",\ 

99 "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fsp", "gsp", "rsp", "usp", "' '", "'!'", "'\"'", "'#'", "'$'", "'%'", "'&'", "'''",\ 

100 "'('", "')'", "'*'", "'+'", "','", "'-'", "'.'", "'/'", "'0'", "'1'", "'2'", "'3'", "'4'", "'5'", "'6'", "'7'", "'8'", "'9'", "':'", "';'",\ 

101 "'<'", "'='", "'>'", "'?'", "'@'", "'A'", "'B'", "'C'", "'D'", "'E'", "'F'", "'G'", "'H'", "'I'", "'J'", "'K'", "'L'", "'M'", "'N'", "'O'",\ 

102 "'P'", "'Q'", "'R'", "'S'", "'T'", "'U'", "'V'", "'W'", "'X'", "'Y'", "'Z'", "'['", "'\'", "']'", "'^'", "'_'", "'`'", "'a'", "'b'", "'c'",\ 

103 "'d'", "'e'", "'f'", "'g'", "'h'", "'i'", "'j'", "'k'", "'l'", "'m'", "'n'", "'o'", "'p'", "'q'", "'r'", "'s'", "'t'", "'u'", "'v'", "'w'",\ 

104 "'x'", "'y'", "'z'", "'{'", "'|'", "'}'", "'~'", "del", "c128", "c129", "c130", "c131", "c132", "c133", "c134", "c135", "c136", "c137", "c138", "c139",\ 

105 "c140", "c141", "c142", "c143", "c144", "c145", "c146", "c147", "c148", "c149", "c150", "c151", "c152", "c153", "c154", "c155", "c156", "c157", "c158", "c159",\ 

106 "' '", "'¡'", "'¢'", "'£'", "'¤'", "'¥'", "'¦'", "'§'", "'¨'", "'©'", "'ª'", "'«'", "'¬'", "'­'", "'®'", "'¯'", "'°'", "'±'", "'²'", "'³'",\ 

107 "'´'", "'µ'", "'¶'", "'·'", "'¸'", "'¹'", "'º'", "'»'", "'¼'", "'½'", "'¾'", "'¿'", "'À'", "'Á'", "'Â'", "'Ã'", "'Ä'", "'Å'", "'Æ'", "'Ç'",\ 

108 "'È'", "'É'", "'Ê'", "'Ë'", "'Ì'", "'Í'", "'Î'", "'Ï'", "'Ð'", "'Ñ'", "'Ò'", "'Ó'", "'Ô'", "'Õ'", "'Ö'", "'×'", "'Ø'", "'Ù'", "'Ú'", "'Û'",\ 

109 "'Ü'", "'Ý'", "'Þ'", "'ß'", "'à'", "'á'", "'â'", "'ã'", "'ä'", "'å'", "'æ'", "'ç'", "'è'", "'é'", "'ê'", "'ë'", "'ì'", "'í'", "'î'", "'ï'",\ 

110 "'ð'", "'ñ'", "'ò'", "'ó'", "'ô'", "'õ'", "'ö'", "'÷'", "'ø'", "'ù'", "'ú'", "'û'", "'ü'", "'ý'", "'þ'", "'ÿ'" 

111 character = EnumeratedType("character", [EnumerationLiteral(char) for char in chars], None) 

112 self._types[character._normalizedIdentifier] = character 

113 self._declaredItems.append(character) 

114 

115 levels = "note", "warning", "error", "failure" 

116 severityLevel = EnumeratedType("severityLevel", [EnumerationLiteral(level) for level in levels], None) 

117 self._types[severityLevel._normalizedIdentifier] = severityLevel 

118 self._declaredItems.append(severityLevel) 

119 

120 integer = IntegerType("integer", Range(IntegerLiteral(-2**31), IntegerLiteral(2**31 - 1), Direction.To), None) 

121 self._types[integer._normalizedIdentifier] = integer 

122 self._declaredItems.append(integer) 

123 

124 # real 

125 

126 time = PhysicalType("time", Range(IntegerLiteral(-2**63), IntegerLiteral(2**63 - 1), Direction.To), primaryUnit="fs", units=( 

127 ("ps", PhysicalIntegerLiteral(1000, "fs")), 

128 ("ns", PhysicalIntegerLiteral(1000, "ps")), 

129 ("us", PhysicalIntegerLiteral(1000, "ns")), 

130 ("ms", PhysicalIntegerLiteral(1000, "us")), 

131 ("sec", PhysicalIntegerLiteral(1000, "ms")), 

132 ("min", PhysicalIntegerLiteral(60, "sec")), 

133 ("hr", PhysicalIntegerLiteral(60, "min")), 

134 ), parent=None) 

135 self._types[time._normalizedIdentifier] = time 

136 self._declaredItems.append(time) 

137 

138 # delay_length 

139 

140 # now 

141 

142 natural = Subtype("natural", SimpleSubtypeSymbol(SimpleName("integer")), None) 

143 natural._baseType = integer 

144 natural._range = Range(IntegerLiteral(0), IntegerLiteral(2**31 - 1), Direction.To) 

145 self._subtypes[natural._normalizedIdentifier] = natural 

146 self._declaredItems.append(natural) 

147 

148 positive = Subtype("positive", SimpleSubtypeSymbol(SimpleName("integer")), None) 

149 positive._baseType = integer 

150 positive._range = Range(IntegerLiteral(1), IntegerLiteral(2**31 - 1), Direction.To) 

151 self._subtypes[positive._normalizedIdentifier] = positive 

152 self._declaredItems.append(positive) 

153 

154 string = ArrayType("string", (SimpleSubtypeSymbol(SimpleName("positive")),), SimpleSubtypeSymbol(SimpleName("character")), None) 

155 self._types[string._normalizedIdentifier] = string 

156 self._declaredItems.append(string) 

157 

158 booleanVector = ArrayType("boolean_vector", (SimpleSubtypeSymbol(SimpleName("natural")),), SimpleSubtypeSymbol(SimpleName("boolean")), None) 

159 self._types[booleanVector._normalizedIdentifier] = booleanVector 

160 self._declaredItems.append(booleanVector) 

161 

162 bitVector = ArrayType("bit_vector", (SimpleSubtypeSymbol(SimpleName("natural")),), SimpleSubtypeSymbol(SimpleName("bit")), None) 

163 self._types[bitVector._normalizedIdentifier] = bitVector 

164 self._declaredItems.append(bitVector) 

165 

166 integerVector = ArrayType("integer_vector", (SimpleSubtypeSymbol(SimpleName("natural")),), SimpleSubtypeSymbol(SimpleName("integer")), None) 

167 self._types[integerVector._normalizedIdentifier] = integerVector 

168 self._declaredItems.append(integerVector) 

169 

170 # real_vector 

171 

172 timeVector = ArrayType("time_vector", (SimpleSubtypeSymbol(SimpleName("natural")),), SimpleSubtypeSymbol(SimpleName("time")), None) 

173 self._types[timeVector._normalizedIdentifier] = timeVector 

174 self._declaredItems.append(timeVector) 

175 

176 fileOpenKinds = "read_mode", "write_mode", "append_mode" 

177 openFileKind = EnumeratedType("open_file_kind", [EnumerationLiteral(kind) for kind in fileOpenKinds], None) 

178 self._types[openFileKind._normalizedIdentifier] = openFileKind 

179 self._declaredItems.append(openFileKind) 

180 

181 fileOpenStati = "open_ok", "status_error", "name_error", "mode_error" 

182 fileOpenStatus = EnumeratedType("open_file_status", [EnumerationLiteral(status) for status in fileOpenStati], None) 

183 self._types[fileOpenStatus._normalizedIdentifier] = fileOpenStatus 

184 self._declaredItems.append(fileOpenStatus) 

185 

186 # attribute foreign 

187 

188 

189@export 

190class Standard_Body(PredefinedPackageBody): 

191 """ 

192 Predefined package body of package ``std.standard``. 

193 

194 .. seealso:: 

195 

196 Matching :class:`Package <pyVHDLModel.STD.Standard>` declaration. 

197 """ 

198 

199 

200@export 

201class TextIO(PredefinedPackage): 

202 """ 

203 Predefined package ``std.textio``. 

204 

205 .. seealso:: 

206 

207 Matching :class:`Package Body <pyVHDLModel.STD.TextIO_Body>` declaration. 

208 """ 

209 

210 

211@export 

212class TextIO_Body(PredefinedPackageBody): 

213 """ 

214 Predefined package body of package ``std.textio``. 

215 

216 .. seealso:: 

217 

218 Matching :class:`Package <pyVHDLModel.STD.TextIO>` declaration. 

219 """ 

220 

221 

222@export 

223class Env(PredefinedPackage): 

224 """ 

225 Predefined package ``std.env``. 

226 

227 .. seealso:: 

228 

229 Matching :class:`Package Body <pyVHDLModel.STD.Env_Body>` declaration. 

230 """ 

231 

232 def __init__(self) -> None: 

233 super().__init__() 

234 

235 self._AddPackageClause(("work.textio.all",)) 

236 

237 

238@export 

239class Env_Body(PredefinedPackageBody): 

240 """ 

241 Predefined package body of package ``std.env``. 

242 

243 .. seealso:: 

244 

245 Matching :class:`Package <pyVHDLModel.STD.Env>` declaration. 

246 """ 

247 

248 

249PACKAGES = ( 

250 (Standard, Standard_Body), 

251 (TextIO, TextIO_Body), 

252 (Env, Env_Body), 

253)