34
34
:copyright: Copyright 2021-2023 Patrick Lehmann - Bötzingen, Germany
35
35
:license: Apache License, Version 2.0
36
36
"""
37
- from enum import unique , Enum
37
+ from enum import unique , Enum
38
38
from typing import Dict , Union
39
39
40
40
from pyTooling .Decorators import export
44
44
__email__ = "Paebbels@gmail.com"
45
45
__copyright__ = "2021-2023, Patrick Lehmann"
46
46
__license__ = "Apache License, Version 2.0"
47
- __version__ = "0.3.6"
48
-
49
-
50
- @export
51
- @unique
52
- class VerilogVersion (Enum ):
53
- Any = - 1
54
- Verilog95 = 95
55
- Verilog2001 = 2001
56
- Verilog2005 = 2005
57
-
58
- __VERSION_MAPPINGS__ : Dict [Union [int , str ], Enum ] = {
59
- 95 : Verilog95 ,
60
- 1 : Verilog2001 ,
61
- 5 : Verilog2005 ,
62
- 1995 : Verilog95 ,
63
- 2001 : Verilog2001 ,
64
- 2005 : Verilog2005 ,
65
- "Any" : Any ,
66
- "95" : Verilog95 ,
67
- "01" : Verilog2001 ,
68
- "05" : Verilog2005 ,
69
- "1995" : Verilog95 ,
70
- "2001" : Verilog2001 ,
71
- "2005" : Verilog2005 ,
72
- }
73
-
74
- def __init__ (self , * _ ):
75
- """Patch the embedded MAP dictionary"""
76
- for k , v in self .__class__ .__VERSION_MAPPINGS__ .items ():
77
- if (not isinstance (v , self .__class__ )) and (v == self .value ):
78
- self .__class__ .__VERSION_MAPPINGS__ [k ] = self
79
-
80
- @classmethod
81
- def Parse (cls , value ):
82
- try :
83
- return cls .__VERSION_MAPPINGS__ [value ]
84
- except KeyError :
85
- ValueError ("Value '{0!s}' cannot be parsed to member of {1}." .format (value , cls .__name__ ))
86
-
87
- def __lt__ (self , other ):
88
- return self .value < other .value
89
-
90
- def __le__ (self , other ):
91
- return self .value <= other .value
92
-
93
- def __gt__ (self , other ):
94
- return self .value > other .value
95
-
96
- def __ge__ (self , other ):
97
- return self .value >= other .value
98
-
99
- def __ne__ (self , other ):
100
- return self .value != other .value
101
-
102
- def __eq__ (self , other ):
103
- if (self is self .__class__ .Any ) or (other is self .__class__ .Any ):
104
- return True
105
- else :
106
- return self .value == other .value
107
-
108
- def __str__ (self ):
109
- return "Verilog'" + str (self .value )[- 2 :]
110
-
111
- def __repr__ (self ):
112
- return str (self .value )
47
+ __version__ = "0.4.0"
113
48
114
49
115
50
@export
116
51
@unique
117
52
class SystemVerilogVersion (Enum ):
118
53
Any = - 1
54
+
55
+ Verilog95 = 95
56
+ Verilog2001 = 1
57
+ Verilog2005 = 5
58
+
119
59
SystemVerilog2005 = 2005
120
60
SystemVerilog2009 = 2009
121
61
SystemVerilog2012 = 2012
122
62
SystemVerilog2017 = 2017
123
63
124
64
__VERSION_MAPPINGS__ : Dict [Union [int , str ], Enum ] = {
125
- 5 : SystemVerilog2005 ,
65
+ - 1 : Any ,
66
+ 95 : Verilog95 ,
67
+ 1 : Verilog2001 ,
68
+ 5 : Verilog2005 ,
69
+ # 5: SystemVerilog2005, # prefer Verilog on numbers below 2000
126
70
9 : SystemVerilog2009 ,
127
71
12 : SystemVerilog2012 ,
128
72
17 : SystemVerilog2017 ,
73
+ 1995 : Verilog95 ,
74
+ 2001 : Verilog2001 ,
75
+ # 2005: Verilog2005, # prefer SystemVerilog on numbers above 2000
129
76
2005 : SystemVerilog2005 ,
130
77
2009 : SystemVerilog2009 ,
131
78
2012 : SystemVerilog2012 ,
132
79
2017 : SystemVerilog2017 ,
133
80
"Any" : Any ,
134
- "05" : SystemVerilog2005 ,
81
+ "95" : Verilog95 ,
82
+ "01" : Verilog2001 ,
83
+ "05" : Verilog2005 ,
84
+ # "05": SystemVerilog2005, # prefer Verilog on numbers below 2000
135
85
"09" : SystemVerilog2009 ,
136
86
"12" : SystemVerilog2012 ,
137
87
"17" : SystemVerilog2017 ,
88
+ "1995" : Verilog95 ,
89
+ "2001" : Verilog2001 ,
90
+ # "2005": Verilog2005, # prefer SystemVerilog on numbers above 2000
138
91
"2005" : SystemVerilog2005 ,
139
92
"2009" : SystemVerilog2009 ,
140
93
"2012" : SystemVerilog2012 ,
@@ -148,35 +101,43 @@ def __init__(self, *_):
148
101
self .__class__ .__VERSION_MAPPINGS__ [k ] = self
149
102
150
103
@classmethod
151
- def Parse (cls , value ) :
104
+ def Parse (cls , value : Union [ int , str ]) -> "SystemVerilogVersion" :
152
105
try :
153
106
return cls .__VERSION_MAPPINGS__ [value ]
154
107
except KeyError :
155
- ValueError ("Value '{0!s}' cannot be parsed to member of {1}." .format (value , cls .__name__ ))
108
+ raise ValueError ("Value '{0!s}' cannot be parsed to member of {1}." .format (value , cls .__name__ ))
156
109
157
- def __lt__ (self , other ):
110
+ def __lt__ (self , other ) -> bool :
158
111
return self .value < other .value
159
112
160
- def __le__ (self , other ):
113
+ def __le__ (self , other ) -> bool :
161
114
return self .value <= other .value
162
115
163
- def __gt__ (self , other ):
116
+ def __gt__ (self , other ) -> bool :
164
117
return self .value > other .value
165
118
166
- def __ge__ (self , other ):
119
+ def __ge__ (self , other ) -> bool :
167
120
return self .value >= other .value
168
121
169
- def __ne__ (self , other ):
122
+ def __ne__ (self , other ) -> bool :
170
123
return self .value != other .value
171
124
172
- def __eq__ (self , other ):
125
+ def __eq__ (self , other ) -> bool :
173
126
if (self is self .__class__ .Any ) or (other is self .__class__ .Any ):
174
127
return True
175
128
else :
176
129
return self .value == other .value
177
130
178
- def __str__ (self ):
179
- return "SV'" + str (self .value )[- 2 :]
131
+ def __str__ (self ) -> str :
132
+ if self .value == - 1 :
133
+ return "SV'Any"
134
+ elif self .value < self .SystemVerilog2005 .value :
135
+ return "Verilog'" + str (self .value )[- 2 :]
136
+ else :
137
+ return "SV'" + str (self .value )[- 2 :]
180
138
181
- def __repr__ (self ):
182
- return str (self .value )
139
+ def __repr__ (self ) -> str :
140
+ if self .value == - 1 :
141
+ return "Any"
142
+ else :
143
+ return str (self .value )
0 commit comments