Skip to content

Commit 685eaa4

Browse files
committed
Add doctest examples to helperfuncs.py. Also:
* Remove documentation for `check_rtl_assertions` as it should only be used by `Simulation`. * Rearrange functions in documentation so discouraged functions appear later. * Make example output wire names more consistent. * Add more links.
1 parent 6359cd3 commit 685eaa4

File tree

5 files changed

+458
-308
lines changed

5 files changed

+458
-308
lines changed

docs/helpers.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ Control Flow Hardware
3939

4040
.. autofunction:: pyrtl.corecircuits.mux
4141
.. autofunction:: pyrtl.corecircuits.select
42-
.. autofunction:: pyrtl.corecircuits.bitfield_update
43-
.. autofunction:: pyrtl.corecircuits.bitfield_update_set
4442
.. autoclass:: pyrtl.helperfuncs.MatchedFields
4543
:members:
4644
:undoc-members:
4745
.. autofunction:: pyrtl.helperfuncs.match_bitpattern
46+
.. autofunction:: pyrtl.corecircuits.bitfield_update
47+
.. autofunction:: pyrtl.corecircuits.bitfield_update_set
4848

4949
Interpreting Vectors of Bits
5050
----------------------------
@@ -57,11 +57,11 @@ functions below do not create any hardware but rather help in the process of
5757
reasoning about bit vector representations of human understandable values.
5858

5959
.. autofunction:: pyrtl.helperfuncs.val_to_signed_integer
60-
.. autofunction:: pyrtl.helperfuncs.val_to_formatted_str
61-
.. autofunction:: pyrtl.helperfuncs.formatted_str_to_val
6260
.. autoclass:: pyrtl.helperfuncs.ValueBitwidthTuple
6361
:members: value, bitwidth
6462
.. autofunction:: pyrtl.helperfuncs.infer_val_and_bitwidth
63+
.. autofunction:: pyrtl.helperfuncs.val_to_formatted_str
64+
.. autofunction:: pyrtl.helperfuncs.formatted_str_to_val
6565
.. autofunction:: pyrtl.helperfuncs.log2
6666

6767
Debugging
@@ -70,7 +70,6 @@ Debugging
7070
.. autofunction:: pyrtl.core.set_debug_mode
7171
.. autofunction:: pyrtl.helperfuncs.probe
7272
.. autofunction:: pyrtl.helperfuncs.rtl_assert
73-
.. autofunction:: pyrtl.helperfuncs.check_rtl_assertions
7473

7574
Reductions
7675
----------

pyrtl/core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,16 +1039,19 @@ def temp_working_block():
10391039
return set_working_block(Block())
10401040

10411041

1042-
def set_debug_mode(debug=True):
1043-
""" Set the global debug mode.
1042+
def set_debug_mode(debug: bool = True):
1043+
"""Set the global debug mode.
10441044
1045-
:param bool debug: Optional boolean paramter to which debug mode will be set
1045+
Sets the debug mode to the specified ``debug`` value. Debug mode is off by default,
1046+
to improve performance. When debug mode is enabled, all temporary
1047+
:class:`WireVectors<.WireVector>` will be assigned names based on the line of code
1048+
on which they were created.
10461049
1047-
This function will set the debug mode to the specified value. Debug mode
1048-
is, by default, set to off to keep the performance of the system. With debug
1049-
mode set to true, all temporary WireVectors created will be given a name based
1050-
on the line of code on which they were created and a snapshot of the call-stack
1051-
for those WireVectors will be kept as well.
1050+
Each :class:`.WireVector` will also save a copy of its call stack when constructed.
1051+
These call stacks can be inspected as ``WireVector.init_call_stack``, and they will
1052+
appear in :meth:`Block.sanity_check` error messages.
1053+
1054+
:param debug: Optional boolean parameter to which the debug mode will be set.
10521055
"""
10531056
global debug_mode
10541057
global _setting_keep_wirevector_call_stack

pyrtl/corecircuits.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def concat(*args: WireVectorLike) -> WireVector:
171171
172172
.. note::
173173
174-
Consider using :func:`.wire_struct` or :func:`.wire_matrix` instead, which help
174+
Consider using :func:`.wire_struct` or :func:`.wire_matrix` instead, which helps
175175
with consistently disassembling, naming, and reassembling fields.
176176
177177
.. doctest only::
@@ -230,7 +230,7 @@ def concat_list(wire_list: list[WireVectorLike]) -> WireVector:
230230
231231
.. note::
232232
233-
Consider using :func:`.wire_struct` or :func:`.wire_matrix` instead, which help
233+
Consider using :func:`.wire_struct` or :func:`.wire_matrix` instead, which helps
234234
with consistently disassembling, naming, and reassembling fields.
235235
236236
.. doctest only::
@@ -285,15 +285,15 @@ def signed_add(a: WireVectorLike, b: WireVectorLike) -> WireVector:
285285
286286
>>> neg_three = pyrtl.Const(val=-3, signed=True, bitwidth=3)
287287
>>> neg_five = pyrtl.Const(val=-5, signed=True, bitwidth=5)
288-
>>> out = pyrtl.Output(name="out")
288+
>>> output = pyrtl.Output(name="output")
289289
290-
>>> out <<= pyrtl.signed_add(neg_three, neg_five)
291-
>>> out.bitwidth
290+
>>> output <<= pyrtl.signed_add(neg_three, neg_five)
291+
>>> output.bitwidth
292292
6
293293
294294
>>> sim = pyrtl.Simulation()
295295
>>> sim.step()
296-
>>> pyrtl.val_to_signed_integer(sim.inspect("out"), bitwidth=out.bitwidth)
296+
>>> pyrtl.val_to_signed_integer(sim.inspect("output"), bitwidth=output.bitwidth)
297297
-8
298298
299299
:param a: A :class:`.WireVector`, or any type that can be coerced to
@@ -327,15 +327,15 @@ def signed_sub(a: WireVectorLike, b: WireVectorLike) -> WireVector:
327327
328328
>>> neg_three = pyrtl.Const(val=-3, signed=True, bitwidth=3)
329329
>>> neg_five = pyrtl.Const(val=-5, signed=True, bitwidth=5)
330-
>>> out = pyrtl.Output(name="out")
330+
>>> output = pyrtl.Output(name="output")
331331
332-
>>> out <<= pyrtl.signed_sub(neg_three, neg_five)
333-
>>> out.bitwidth
332+
>>> output <<= pyrtl.signed_sub(neg_three, neg_five)
333+
>>> output.bitwidth
334334
6
335335
336336
>>> sim = pyrtl.Simulation()
337337
>>> sim.step()
338-
>>> pyrtl.val_to_signed_integer(sim.inspect("out"), bitwidth=out.bitwidth)
338+
>>> pyrtl.val_to_signed_integer(sim.inspect("output"), bitwidth=output.bitwidth)
339339
2
340340
341341
:param a: A :class:`.WireVector`, or any type that can be coerced to
@@ -374,15 +374,15 @@ def signed_mult(a: WireVectorLike, b: WireVectorLike) -> WireVector:
374374
375375
>>> neg_three = pyrtl.Const(val=-3, signed=True, bitwidth=3)
376376
>>> neg_five = pyrtl.Const(val=-5, signed=True, bitwidth=5)
377-
>>> out = pyrtl.Output(name="out")
377+
>>> output = pyrtl.Output(name="output")
378378
379-
>>> out <<= pyrtl.signed_mult(neg_three, neg_five)
380-
>>> out.bitwidth
379+
>>> output <<= pyrtl.signed_mult(neg_three, neg_five)
380+
>>> output.bitwidth
381381
8
382382
383383
>>> sim = pyrtl.Simulation()
384384
>>> sim.step()
385-
>>> pyrtl.val_to_signed_integer(sim.inspect("out"), bitwidth=out.bitwidth)
385+
>>> pyrtl.val_to_signed_integer(sim.inspect("output"), bitwidth=output.bitwidth)
386386
15
387387
388388
:param a: A :class:`.WireVector`, or any type that can be coerced to
@@ -416,15 +416,15 @@ def signed_lt(a: WireVectorLike, b: WireVectorLike) -> WireVector:
416416
417417
>>> neg_three = pyrtl.Const(val=-3, signed=True, bitwidth=3)
418418
>>> neg_five = pyrtl.Const(val=-5, signed=True, bitwidth=5)
419-
>>> out = pyrtl.Output(name="out")
419+
>>> output = pyrtl.Output(name="output")
420420
421-
>>> out <<= pyrtl.signed_lt(neg_three, neg_five)
422-
>>> out.bitwidth
421+
>>> output <<= pyrtl.signed_lt(neg_three, neg_five)
422+
>>> output.bitwidth
423423
1
424424
425425
>>> sim = pyrtl.Simulation()
426426
>>> sim.step()
427-
>>> sim.inspect("out")
427+
>>> sim.inspect("output")
428428
0
429429
430430
:param a: A :class:`.WireVector`, or any type that can be coerced to
@@ -454,15 +454,15 @@ def signed_le(a: WireVectorLike, b: WireVectorLike) -> WireVector:
454454
455455
>>> neg_three = pyrtl.Const(val=-3, signed=True, bitwidth=3)
456456
>>> neg_five = pyrtl.Const(val=-5, signed=True, bitwidth=5)
457-
>>> out = pyrtl.Output(name="out")
457+
>>> output = pyrtl.Output(name="output")
458458
459-
>>> out <<= pyrtl.signed_le(neg_three, neg_five)
460-
>>> out.bitwidth
459+
>>> output <<= pyrtl.signed_le(neg_three, neg_five)
460+
>>> output.bitwidth
461461
1
462462
463463
>>> sim = pyrtl.Simulation()
464464
>>> sim.step()
465-
>>> sim.inspect("out")
465+
>>> sim.inspect("output")
466466
0
467467
468468
:param a: A :class:`.WireVector`, or any type that can be coerced to
@@ -493,15 +493,15 @@ def signed_gt(a: WireVectorLike, b: WireVectorLike) -> WireVector:
493493
494494
>>> neg_three = pyrtl.Const(val=-3, signed=True, bitwidth=3)
495495
>>> neg_five = pyrtl.Const(val=-5, signed=True, bitwidth=5)
496-
>>> out = pyrtl.Output(name="out")
496+
>>> output = pyrtl.Output(name="output")
497497
498-
>>> out <<= pyrtl.signed_gt(neg_three, neg_five)
499-
>>> out.bitwidth
498+
>>> output <<= pyrtl.signed_gt(neg_three, neg_five)
499+
>>> output.bitwidth
500500
1
501501
502502
>>> sim = pyrtl.Simulation()
503503
>>> sim.step()
504-
>>> sim.inspect("out")
504+
>>> sim.inspect("output")
505505
1
506506
507507
:param a: A :class:`.WireVector`, or any type that can be coerced to
@@ -531,15 +531,15 @@ def signed_ge(a: WireVectorLike, b: WireVectorLike) -> WireVector:
531531
532532
>>> neg_three = pyrtl.Const(val=-3, signed=True, bitwidth=3)
533533
>>> neg_five = pyrtl.Const(val=-5, signed=True, bitwidth=5)
534-
>>> out = pyrtl.Output(name="out")
534+
>>> output = pyrtl.Output(name="output")
535535
536-
>>> out <<= pyrtl.signed_ge(neg_three, neg_five)
537-
>>> out.bitwidth
536+
>>> output <<= pyrtl.signed_ge(neg_three, neg_five)
537+
>>> output.bitwidth
538538
1
539539
540540
>>> sim = pyrtl.Simulation()
541541
>>> sim.step()
542-
>>> sim.inspect("out")
542+
>>> sim.inspect("output")
543543
1
544544
545545
:param a: A :class:`.WireVector`, or any type that can be coerced to
@@ -580,13 +580,13 @@ def shift_right_arithmetic(bits_to_shift: WireVector,
580580
581581
>>> neg_forty = pyrtl.Const(val=-40, signed=True, bitwidth=7)
582582
>>> shift_amount = pyrtl.Input(name="shift_amount", bitwidth=3)
583-
>>> out = pyrtl.Output(name="out")
583+
>>> output = pyrtl.Output(name="output")
584584
585-
>>> out <<= pyrtl.shift_right_arithmetic(neg_forty, shift_amount)
585+
>>> output <<= pyrtl.shift_right_arithmetic(neg_forty, shift_amount)
586586
587587
>>> sim = pyrtl.Simulation()
588588
>>> sim.step(provided_inputs={"shift_amount": 3})
589-
>>> pyrtl.val_to_signed_integer(sim.inspect("out"), bitwidth=out.bitwidth)
589+
>>> pyrtl.val_to_signed_integer(sim.inspect("output"), bitwidth=output.bitwidth)
590590
-5
591591
>>> int(-40 / 2 ** 3)
592592
-5
@@ -622,13 +622,13 @@ def shift_left_logical(bits_to_shift: WireVector,
622622
623623
>>> three = pyrtl.Const(val=3, bitwidth=6)
624624
>>> shift_amount = pyrtl.Input(name="shift_amount", bitwidth=3)
625-
>>> out = pyrtl.Output(name="out")
625+
>>> output = pyrtl.Output(name="output")
626626
627-
>>> out <<= pyrtl.shift_left_logical(three, shift_amount)
627+
>>> output <<= pyrtl.shift_left_logical(three, shift_amount)
628628
629629
>>> sim = pyrtl.Simulation()
630630
>>> sim.step(provided_inputs={"shift_amount": 3})
631-
>>> sim.inspect("out")
631+
>>> sim.inspect("output")
632632
24
633633
>>> 3 * 2 ** 3
634634
24
@@ -668,13 +668,13 @@ def shift_right_logical(bits_to_shift: WireVector,
668668
669669
>>> forty = pyrtl.Const(val=40, bitwidth=6)
670670
>>> shift_amount = pyrtl.Input(name="shift_amount", bitwidth=3)
671-
>>> out = pyrtl.Output(name="out")
671+
>>> output = pyrtl.Output(name="output")
672672
673-
>>> out <<= pyrtl.shift_right_logical(forty, shift_amount)
673+
>>> output <<= pyrtl.shift_right_logical(forty, shift_amount)
674674
675675
>>> sim = pyrtl.Simulation()
676676
>>> sim.step(provided_inputs={"shift_amount": 3})
677-
>>> sim.inspect("out")
677+
>>> sim.inspect("output")
678678
5
679679
>>> int(40 / 2 ** 3)
680680
5
@@ -846,7 +846,7 @@ def bitfield_update(w: WireVectorLike, range_start: int, range_end: int, newvalu
846846
847847
.. note::
848848
849-
Consider using :func:`.wire_struct` or :func:`.wire_matrix` instead, which help
849+
Consider using :func:`.wire_struct` or :func:`.wire_matrix` instead, which helps
850850
with consistently disassembling, naming, and reassembling fields.
851851
852852
:param w: A :class:`.WireVector`, or any type that can be coerced to
@@ -909,7 +909,7 @@ def bitfield_update_set(w: WireVectorLike,
909909
910910
.. note::
911911
912-
Consider using :func:`.wire_struct` or :func:`.wire_matrix` instead, which help
912+
Consider using :func:`.wire_struct` or :func:`.wire_matrix` instead, which helps
913913
with consistently disassembling, naming, and reassembling fields.
914914
915915
:param w: A :class:`.WireVector`, or any type that can be coerced to

0 commit comments

Comments
 (0)