Skip to content

Commit 8dd0fa3

Browse files
authored
Merge pull request #335 from pllab/typos-and-docs
Adding documentation, fixing typos
2 parents 543df55 + 8ca0ce9 commit 8dd0fa3

16 files changed

+179
-166
lines changed

pyrtl/compilesim.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class DllMemInspector(collections.Mapping):
24-
"""Dictionary-like access to a hashmap in a CompiledSimulation."""
24+
""" Dictionary-like access to a hashmap in a CompiledSimulation. """
2525

2626
def __init__(self, sim, mem):
2727
self._aw = mem.addrwidth
@@ -229,10 +229,10 @@ def _sort_tuple(t):
229229
file.flush()
230230

231231
def run(self, inputs):
232-
"""Run many steps of the simulation.
232+
""" Run many steps of the simulation.
233233
234234
:param inputs: A list of input mappings for each step;
235-
its length is the number of steps to be executed.
235+
its length is the number of steps to be executed.
236236
"""
237237
steps = len(inputs)
238238
# create i/o arrays of the appropriate length
@@ -288,7 +288,7 @@ def run(self, inputs):
288288
self.tracer.trace[name].extend(res)
289289

290290
def _traceable(self, wv):
291-
"""Check if wv is able to be traced
291+
""" Check if wv is able to be traced.
292292
293293
If it is traceable due to a probe, record that probe in _probe_mapping.
294294
"""
@@ -301,7 +301,7 @@ def _traceable(self, wv):
301301
return False
302302

303303
def _remove_untraceable(self):
304-
"""Remove from the tracer those wires that CompiledSimulation cannot track.
304+
""" Remove from the tracer those wires that CompiledSimulation cannot track.
305305
306306
Create _probe_mapping for wires only traceable via probes.
307307
"""
@@ -312,7 +312,7 @@ def _remove_untraceable(self):
312312
self.tracer.trace.__init__(wvs)
313313

314314
def _create_dll(self):
315-
"""Create a dynamically-linked library implementing the simulation logic."""
315+
""" Create a dynamically-linked library implementing the simulation logic. """
316316
self._dir = tempfile.mkdtemp()
317317
with open(path.join(self._dir, 'pyrtlsim.c'), 'w') as f:
318318
self._create_code(lambda s: f.write(s + '\n'))
@@ -334,19 +334,19 @@ def _create_dll(self):
334334
self._mem_lookup.restype = ctypes.POINTER(ctypes.c_uint64)
335335

336336
def _limbs(self, w):
337-
"""Number of 64-bit words needed to store value of wire."""
337+
""" Number of 64-bit words needed to store value of wire. """
338338
return (w.bitwidth + 63) // 64
339339

340340
def _makeini(self, w, v):
341-
"""C initializer string for a wire with a given value."""
341+
""" C initializer string for a wire with a given value. """
342342
pieces = []
343343
for _ in range(self._limbs(w)):
344344
pieces.append(hex(v & ((1 << 64) - 1)))
345345
v >>= 64
346346
return ','.join(pieces).join('{}')
347347

348348
def _romwidth(self, m):
349-
"""Bitwidth of integer type sufficient to hold rom entry.
349+
""" Bitwidth of integer type sufficient to hold rom entry.
350350
351351
On large memories, returns 64; an array will be needed.
352352
"""
@@ -369,18 +369,18 @@ def _makemask(self, dest, res, pos):
369369
return ''
370370

371371
def _getarglimb(self, arg, n):
372-
"""Get the nth limb of the given wire.
372+
""" Get the nth limb of the given wire.
373373
374374
Returns '0' when the wire does not have sufficient limbs.
375375
"""
376376
return '{vn}[{n}]'.format(vn=self.varname[arg], n=n) if arg.bitwidth > 64 * n else '0'
377377

378378
def _clean_name(self, prefix, obj):
379-
"""Create a C variable name with the given prefix based on the name of obj."""
379+
""" Create a C variable name with the given prefix based on the name of obj. """
380380
return '{}{}_{}'.format(prefix, self._uid(), ''.join(c for c in obj.name if c.isalnum()))
381381

382382
def _uid(self):
383-
"""Get an auto-incrementing number suitable for use as a unique identifier."""
383+
""" Get an auto-incrementing number suitable for use as a unique identifier. """
384384
x = self._uid_counter
385385
self._uid_counter += 1
386386
return x

pyrtl/conditional.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959

6060
def currently_under_condition():
61-
"""Returns True if execution is currently in the context of a _ConditionalAssignment."""
61+
""" Returns True if execution is currently in the context of a _ConditionalAssignment. """
6262
return _depth > 0
6363

6464

@@ -67,7 +67,7 @@ def currently_under_condition():
6767
# instances (hopefully the only and unchanging instances) of the following two types.
6868

6969
class _ConditionalAssignment(object):
70-
""" helper type of global "conditional_assignment". """
70+
""" Helper type of global "conditional_assignment". """
7171
def __enter__(self):
7272
global _depth
7373
_check_no_nesting()
@@ -83,7 +83,7 @@ def __exit__(self, *exc_info):
8383

8484

8585
class _Otherwise(object):
86-
""" helper type of global "otherwise". """
86+
""" Helper type of global "otherwise". """
8787
def __enter__(self):
8888
_push_condition(otherwise)
8989

@@ -92,7 +92,7 @@ def __exit__(self, *exc_info):
9292

9393

9494
def _reset_conditional_state():
95-
"""Set or reset all the module state required for conditionals."""
95+
""" Set or reset all the module state required for conditionals. """
9696
global _conditions_list_stack
9797
global _conflicts_map
9898
global _predicate_map

pyrtl/core.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ def wirevector_subset(self, cls=None, exclude=tuple()):
370370
If no cls is specified, the full set of wirevectors associated with the Block are
371371
returned. If cls is a single type, or a tuple of types, only those wirevectors of
372372
the matching types will be returned. This is helpful for getting all inputs, outputs,
373-
or registers of a block for example."""
373+
or registers of a block for example.
374+
"""
374375
if cls is None:
375376
initial_set = self.wirevector_set
376377
else:
@@ -384,7 +385,8 @@ def logic_subset(self, op=None):
384385
"""Return set of logicnets, filtered by the type(s) of logic op provided as op.
385386
386387
If no op is specified, the full set of logicnets associated with the Block are
387-
returned. This is helpful for getting all memories of a block for example."""
388+
returned. This is helpful for getting all memories of a block for example.
389+
"""
388390
if op is None:
389391
return self.logic
390392
else:
@@ -395,7 +397,8 @@ def get_wirevector_by_name(self, name, strict=False):
395397
396398
By fallthrough, if a matching wirevector cannot be found the value None is
397399
returned. However, if the argument strict is set to True, then this will
398-
instead throw a PyrtlError when no match is found."""
400+
instead throw a PyrtlError when no match is found.
401+
"""
399402
if name in self.wirevector_by_name:
400403
return self.wirevector_by_name[name]
401404
elif strict:
@@ -468,7 +471,8 @@ def __iter__(self):
468471
Note: this method will throw an error if there are loops in the
469472
logic that do not involve registers.
470473
Also, the order of the nets is not guaranteed to be the same
471-
over multiple iterations"""
474+
over multiple iterations.
475+
"""
472476
from .wire import Input, Const, Register
473477
src_dict, dest_dict = self.net_connections()
474478
to_clear = self.wirevector_subset((Input, Const, Register))
@@ -498,7 +502,8 @@ def sanity_check(self):
498502
""" Check block and throw PyrtlError or PyrtlInternalError if there is an issue.
499503
500504
Should not modify anything, only check data structures to make sure they have been
501-
built according to the assumptions stated in the Block comments."""
505+
built according to the assumptions stated in the Block comments.
506+
"""
502507

503508
# TODO: check that the wirevector_by_name is sane
504509
from .wire import Input, Const, Output
@@ -724,7 +729,7 @@ def sanity_check_net(self, net):
724729

725730
class PostSynthBlock(Block):
726731
""" This is a block with extra metadata required to maintain the
727-
pre synthesis interface post synthesis
732+
pre-synthesis interface during post-synthesis.
728733
"""
729734

730735
def __init__(self):
@@ -758,7 +763,8 @@ def _get_debug_mode():
758763

759764

760765
def _get_useful_callpoint_name():
761-
""" Attempts to find the lowest user-level call into the pyrtl module
766+
""" Attempts to find the lowest user-level call into the PyRTL module.
767+
762768
:return (string, int) or None: the file name and line number respectively
763769
764770
This function walks back the current frame stack attempting to find the
@@ -815,10 +821,10 @@ def reset_working_block():
815821

816822
class set_working_block(object):
817823
""" Set the working block to be the block passed as argument.
818-
Compatible with the 'with' statement
824+
Compatible with the 'with' statement.
819825
820-
Sanity checks will only be run if the new block is different
821-
from the original block
826+
Sanity checks will only be run if the new block is different
827+
from the original block.
822828
"""
823829

824830
@staticmethod
@@ -844,8 +850,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
844850

845851
def temp_working_block():
846852
""" Set the working block to be new temporary block.
847-
If used with the 'with' statement the block will be reset to the
848-
original value (at the time of call) at exit of the context.
853+
854+
If used with the 'with' statement the block will be reset to the
855+
original value (at the time of call) at exit of the context.
849856
"""
850857
return set_working_block(Block())
851858

@@ -864,13 +871,13 @@ def set_debug_mode(debug=True):
864871

865872

866873
class _NameIndexer(object):
867-
""" Provides internal names that are based on a prefix and an index"""
874+
""" Provides internal names that are based on a prefix and an index. """
868875
def __init__(self, internal_prefix='_sani_temp'):
869876
self.internal_prefix = internal_prefix
870877
self.internal_index = 0
871878

872879
def make_valid_string(self):
873-
"""Build a valid string based on the prefix and internal index"""
880+
""" Build a valid string based on the prefix and internal index. """
874881
return self.internal_prefix + str(self.next_index())
875882

876883
def next_index(self):
@@ -880,9 +887,8 @@ def next_index(self):
880887

881888

882889
class _NameSanitizer(_NameIndexer):
883-
"""
884-
Sanitizes the names so that names can be used in places that don't allow
885-
for arbitrary names while not mangling valid names
890+
""" Sanitizes the names so that names can be used in places that don't allow
891+
for arbitrary names while not mangling valid names.
886892
887893
Put the values you want to validate into make_valid_string the first time
888894
you want to sanitize a particular string (or before the first time), and
@@ -902,7 +908,7 @@ def __init__(self, identifier_regex_str, internal_prefix='_sani_temp',
902908
super(_NameSanitizer, self).__init__(internal_prefix)
903909

904910
def __getitem__(self, item):
905-
""" Get a value from the sanitizer"""
911+
""" Get a value from the sanitizer """
906912
if not self.map_valid and self.is_valid_str(item):
907913
return item
908914
return self.val_map[item]
@@ -911,7 +917,7 @@ def is_valid_str(self, string):
911917
return self.identifier.match(string) and self.extra_checks(string)
912918

913919
def make_valid_string(self, string=''):
914-
""" Inputting a value for the first time """
920+
""" Inputting a value for the first time. """
915921
if not self.is_valid_str(string):
916922
if string in self.val_map and not self.allow_dups:
917923
raise IndexError("Value {} has already been given to the sanitizer".format(string))
@@ -925,7 +931,7 @@ def make_valid_string(self, string=''):
925931

926932

927933
class _PythonSanitizer(_NameSanitizer):
928-
""" Name Sanitizer specifically built for Python identifers"""
934+
""" Name Sanitizer specifically built for Python identifers. """
929935
def __init__(self, internal_prefix='_sani_temp', map_valid_vals=True):
930936
super(_PythonSanitizer, self).__init__(_py_regex, internal_prefix, map_valid_vals)
931937
self.extra_checks = lambda s: not keyword.iskeyword(s)

0 commit comments

Comments
 (0)