Skip to content

Commit 3053880

Browse files
committed
0.6.0
- (#115) Correct an issue with Jupyter notebooks and inability to obtain source information - (#59) Add environment-variable support for controlling enhanced diagnostic messages, and add documentation Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
1 parent 96283b6 commit 3053880

File tree

13 files changed

+115
-17
lines changed

13 files changed

+115
-17
lines changed

doc/Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
## 0.6.0
3+
- (#115) Correct an issue with Jupyter notebooks and inability
4+
to obtain source information
5+
- (#59) Add environment-variable support for controlling
6+
enhanced diagnostic messages, and add documentation
7+
28
## 0.5.9
39
- (#107) Added a new randomization approach that deals better
410
with bit conflicts.

etc/ivpm.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
name=pyvsc
3-
version=0.5.9
3+
version=0.6.0
44

src/vsc/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from ucis.ucdb.ucdb_factory import UcdbFactory
4343
from ucis.ucdb.ucdb_ucis import UcdbUCIS
4444
from vsc import profile
45+
from vsc.impl.ctor import glbl_debug, glbl_solvefail_debug
4546

4647

4748
def get_coverage_report(details=False)->str:
@@ -148,3 +149,12 @@ def vsc_static_init():
148149

149150
#vsc_static_init()
150151

152+
def vsc_debug(val):
153+
global glbl_debug
154+
glbl_debug = val
155+
156+
def vsc_solvefail_debug(val):
157+
global glbl_solvefail_debug
158+
glbl_solvefail_debug = val
159+
160+

src/vsc/coverage.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,12 @@ def configure_options(self, *args, **kwargs):
269269
raise Exception("Covergroup inheritance is not currently supported")
270270

271271
# Store declaration information on the type
272-
file = inspect.getsourcefile(T)
273-
lineno = inspect.getsourcelines(T)[1]
272+
if hasattr(T, "__file__"):
273+
file = inspect.getsourcefile(T)
274+
lineno = inspect.getsourcelines(T)[1]
275+
else:
276+
file = "<unknown>"
277+
lineno = -1
274278
setattr(T, "_srcinfo_decl", SourceInfo(file, lineno))
275279

276280
# This is the interposer class that wraps a user-defined

src/vsc/impl/ctor.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,54 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
from vsc.impl.coverage_registry import CoverageRegistry
18-
1917
'''
2018
Created on Jul 23, 2019
2119
2220
@author: ballance
2321
'''
2422

23+
import os
24+
25+
from vsc.impl.coverage_registry import CoverageRegistry
2526
from vsc.model.constraint_expr_model import ConstraintExprModel
2627

28+
2729
rand_obj_type_m = {}
2830
constraint_scope_stack = []
2931
expr_l = []
3032
foreach_arr_s = []
3133

34+
if "VSC_CAPTURE_SRCINFO" in os.environ.keys() and os.environ["VSC_CAPTURE_SRCINFO"] != "":
35+
try:
36+
glbl_capture_srcinfo = int(os.environ["VSC_CAPTURE_SRCINFO"])
37+
except Exception:
38+
print("Note: VSC_CAPTURE_SRCINFO must be numeric, not %s" %
39+
os.environ["VSC_CAPTURE_SRCINFO"])
40+
glbl_capture_srcinfo = 0
41+
else:
42+
glbl_capture_srcinfo = 0
43+
44+
if "VSC_DEBUG" in os.environ.keys() and os.environ["VSC_DEBUG"] != "":
45+
try:
46+
glbl_debug = int(os.environ["VSC_DEBUG"])
47+
except Exception:
48+
print("Note: VSC_DEBUG must be numeric, not %s" %
49+
os.environ["VSC_DEBUG"])
50+
glbl_debug = 0
51+
else:
52+
glbl_debug = 0
53+
54+
if "VSC_SOLVEFAIL_DEBUG" in os.environ.keys() and os.environ["VSC_SOLVEFAIL_DEBUG"] != "":
55+
try:
56+
glbl_solvefail_debug = int(os.environ["VSC_SOLVEFAIL_DEBUG"])
57+
except Exception:
58+
print("Note: VSC_SOLVEFAIL_DEBUG must be numeric, not %s" %
59+
os.environ["VSC_SOLVEFAIL_DEBUG"])
60+
glbl_solvefail_debug = 0
61+
else:
62+
glbl_solvefail_debug = 0
63+
64+
3265
# Tracks whether srcinfo should be collected for a type
3366
srcinfo_mode_s = []
3467

@@ -62,7 +95,11 @@ def push_srcinfo_mode(m):
6295
srcinfo_mode_s.append(m)
6396

6497
def in_srcinfo_mode():
65-
return len(srcinfo_mode_s) > 0 and srcinfo_mode_s[-1]
98+
global glbl_capture_srcinfo
99+
if glbl_capture_srcinfo > 0:
100+
return True
101+
else:
102+
return len(srcinfo_mode_s) > 0 and srcinfo_mode_s[-1]
66103

67104
def pop_srcinfo_mode():
68105
if len(srcinfo_mode_s) > 0:

src/vsc/impl/vscobj_int.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class VscObjInt(object):
88

99
def __init__(self):
1010
self.ctor_level = 0
11+
self.srcinfo = False
1112

src/vsc/model/randomizer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
from pip._internal.cli.cmdoptions import src
6161
from vsc.model.solvegroup_swizzler_range import SolveGroupSwizzlerRange
6262
from vsc.model.solvegroup_swizzler_partsel import SolveGroupSwizzlerPartsel
63+
from vsc.impl.ctor import glbl_debug, glbl_solvefail_debug
6364

6465

6566
class Randomizer(RandIF):
@@ -71,8 +72,14 @@ def __init__(self, debug=0, lint=0, solve_fail_debug=0, solve_info=None):
7172
self.pretty_printer = ModelPrettyPrinter()
7273
self.solve_info = solve_info
7374
self.debug = debug
75+
if glbl_debug > 0 and glbl_debug > debug:
76+
self.debug = glbl_debug
77+
7478
self.lint = lint
7579
self.solve_fail_debug = solve_fail_debug
80+
if glbl_solvefail_debug > 0 and glbl_solvefail_debug > solve_fail_debug:
81+
self.solve_fail_debug = glbl_solvefail_debug
82+
7683
# self.swizzler = SolveGroupSwizzlerRange(solve_info)
7784
self.swizzler = SolveGroupSwizzlerPartsel(solve_info)
7885

src/vsc/rand_obj.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class randobj_interposer(T):
5959

6060
def __init__(self, *args, **kwargs):
6161
ro_i = self._get_ro_int()
62+
ro_i.srcinfo = srcinfo
6263

6364
# Capture the instantiation location
6465
frame = inspect.stack()[1]
@@ -230,15 +231,18 @@ def _get_ro_int(self):
230231
return self._ro_int
231232

232233
def __enter__(self):
234+
ro_i = self._get_ro_int()
233235
enter_expr_mode()
234236
self.get_model() # Ensure model is constructed
237+
push_srcinfo_mode(ro_i.srcinfo)
235238
push_constraint_scope(ConstraintBlockModel("inline"))
236239
return self
237240

238241
def __exit__(self, t, v, tb):
239242
frame = inspect.stack()[1]
240243
c = pop_constraint_scope()
241244
leave_expr_mode()
245+
pop_srcinfo_mode()
242246
model = self.get_model() # Ensure model is constructed
243247
try:
244248
Randomizer.do_randomize(

src/vsc/types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from vsc.model.field_const_array_model import FieldConstArrayModel
4444
from vsc.model.field_scalar_model import FieldScalarModel
4545
from vsc.model.unary_expr_type import UnaryExprType
46-
from vsc.model.value_scalar import ValueScalar
46+
from vsc.model.value_scalar import ValueScalar, ValueInt
4747

4848

4949
from vsc.impl.expr_mode import get_expr_mode, expr_mode, is_expr_mode
@@ -295,16 +295,16 @@ def to_expr(t):
295295
# This expression is already on the stack
296296
# push_expr(t.em)
297297
return t
298-
elif type(t) == int:
299-
return expr(ExprLiteralModel(t, True, 32))
298+
elif type(t) == int or type(t) == ValueInt:
299+
return expr(ExprLiteralModel(int(t), True, 32))
300300
elif isinstance(type(t), (EnumMeta,IntEnum)):
301301
return expr(EnumInfo.get(type(t)).e2e(t))
302302
elif hasattr(t, "to_expr"):
303303
return t.to_expr()
304304
elif callable(t):
305305
raise Exception("TODO: support lambda references")
306306
else:
307-
raise Exception("Element \"" + str(t) + "\" isn't recognized, and doesn't provide to_expr")
307+
raise Exception("Element \"" + str(t) + "\" isn't recognized, and doesn't provide to_expr (type=%s)" % str(type(t)))
308308

309309

310310
class field_info(object):

ve/unit/test_constraint_expr.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ def __init__(self):
1616
self.b = vsc.rand_uint8_t()
1717

1818
my_i = my_c()
19-
with my_i.randomize_with() as it:
20-
it.a == it.b
21-
self.assertEqual(my_i.a, my_i.b)
19+
for i in range(2):
20+
with my_i.randomize_with() as it:
21+
it.a == it.b
22+
self.assertEqual(my_i.a, my_i.b)
2223

2324
def test_ne(self):
2425
@vsc.randobj

0 commit comments

Comments
 (0)