question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor of handle objects

See original GitHub issue

Handles (in handle.py) support dot syntax for traversal of the HDL object hierarchy, but they also contain a number of attributes for using the value. These namespaces are known to collide and there currently is no mechanism to work around this issue. And to some degree it is unavoidable, Python objects have a number of builtin attributes (usually starting and ending with 2 underscores).

To solve this I recommend we split the traversal and analysis of HDL objects into two. Object traversal objects will only be able to be used to traverse the hierarchy. We can then obtain a HDLValue object which will contain all the other expected and useful behavior. One would obtain this value with an attribute that will not collide with valid identifiers in Verilog, VHDL or Python: use is a keyword in both languages and not a keyword in Python.

type(dut.input)  # -> child of SimHandleBase
int(dut.input)  # -> Error
type(dut.input.use)  # -> HDLValue
int(dut.input.use)  # -> 0

Alternatively, since we should already mention Python builtin attributes names (__{name}__) will not work we could put such a function in a similar name (e.g. __value__), and provide a free function (or constructor) for access.

type(HDLValue(dut.input))  # -> HDLValue
int(HDLValue(dut.input))  # -> 0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Mar 18, 2020

operator: still valid Verilog identifiers, but unfortunately unavoidable

Not true, because python operators only cares about type(dut).__operator__, we’re free to replace dut.__operator__ via type(dut).__getattribute__.

1reaction
ktbarrettcommented, Mar 18, 2020

I have run into .value before, it’s the biggest offender. In that case the solution was to rename the object 😕 This may not be easy depending upon the user. Formal verification processes are extremely bureaucratic, turn around time on a rename might be over a week. But every attribute on those classes is a valid Verilog identifier (VHDL identifiers can’t start with _) and has the potential to collide.

  • setimmediatevalue, drivers, loads, and value: valid Verilog and VHDL identifiers
  • _thing: while they are “private”, they are still valid Verilog identitifers
  • __operator__: still valid Verilog identifiers, but unfortunately unavoidable

I just made this issue to highlight an implementation flaw that might one day be worked and poll for potential solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduce Parameter Object - Refactoring.Guru
In the method that you want to refactor, use Add Parameter, which is where your parameter object will be passed. In all method...
Read more >
How to refactor the God object class antipattern | TheServerSide
Here's a look at how to refactor your God object and simplify your object-oriented design for future development.
Read more >
How to refactor my project to have less mutable objects?
In summary, I understood 1-introduce dependencies in constructor and don't change them. 2- avoid public mutable variables, and tendency to ...
Read more >
What's the best way to refactor a method that has too many (6+ ...
"Introduce Parameter Object" refactoring. See the Refactoring Catalog. ... is when a class really does need to deal with multiple logical things, ...
Read more >
JavaScript Refactoring — Objects and Values - Level Up Coding
If we have magic numbers, we should replace them with named constants. We should add getters and setter methods for class fields so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found