-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Poke Instance Values #15
Comments
I can think of two ways to do it. Both approach has some advantages and drawbacks. Pure DPI-based approachThe DPI defined by LRM does support pass by reference. Here is an example to set values from C: import "DPI-C" function void set(output int a);
module top;
logic [31:0] a;
initial begin
set(a);
$display("value is: %0d", a);
end
endmodule void set(int *a) { *a = 42; } If you run the code, you will see logic The issue is that Python doesn't support pass by reference, so there needs a translation to bridge the gap. One simple way I can think of is adding another return type such as @py(a=Int32, b=Int16, return_type=Reference(c=Int32, d=Int32, e=Int16))
def foo(a, b):
return a + b, a, b Then it will be translated into the following C signature void foo(int32_t a, int16_t b, int32_t *c, int32_t *d, int16_t *e); Then in SV you do the following: logic[31:0] a, c, d;
logic[15:0] b, e;
initial begin
foo(a, b, c, d, e); // c, d, e will be set in the C function
end I haven't tested this out with Verilator, but I suspect this should work as well. The issue with that is the downstream tools like VPI-based approachSetting values is much easier to do in
$drive_signals(top); where However, I'm a little bit reluctant to do it via API that due to the following reasons:
Please let me know what you think. |
I think the DPI approach should work if it's simpler, let me brainstorm about the interface, perhaps there's some alternative to just returning the reference values that's a bit more natural |
Actually we might be able to just handle the references at the fault level. So a user in fault could say something like |
Are you referring to a) primitive as return type or b) reference/class object as return type? |
I think reference is required since that's how you supply the names for each return value? |
Got it. I'm going to implement that. |
Should be working now. Feel free to reopen or open another issue if it doesn't work with fault. |
I'm interested in adding support for a
pysv
style driver where the input stimuli are generated by a Python class. The difficulty here is transferring the values from Python to SV. We could call separate methods for each port value (with each method returning a value), but that seems a bit convoluted. Is there any possibility of having the Python code somehow poke values in the simulation? It seems like we'd need some DPI support for this to work, but maybe if we could pass a handle to an instance, we could set the values of ports.The text was updated successfully, but these errors were encountered: