-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
194 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "extern/pybind11"] | ||
path = pysv/extern/pybind11 | ||
url = https://github.com/pybind/pybind11 | ||
[submodule "pysv/extern/vlstd"] | ||
path = pysv/extern/vlstd | ||
url = https://github.com/Kuree/vlstd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "svdpi.h" | ||
|
||
py::memoryview to_buffer(const svOpenArrayHandle array_handle) { | ||
ssize_t element_size = sizeof(int32_t); | ||
void *base_ptr = nullptr; | ||
std::vector<ssize_t> sizes = {}; | ||
std::vector<ssize_t> strides = {}; | ||
|
||
// we try to query the underlying representation | ||
base_ptr = svGetArrayPtr(array_handle); | ||
if (!base_ptr) { | ||
throw std::runtime_error("Array type does not have native C representation"); | ||
} | ||
auto dim = svDimensions(array_handle); | ||
for (auto i = 0; i < dim; i++) { | ||
auto s = svSize(array_handle, i); | ||
sizes.emplace_back(s); | ||
} | ||
// assumes row major ordering | ||
ssize_t stride = element_size; | ||
strides = std::vector<ssize_t>(dim, element_size); | ||
for (int i = 0; i < dim - 1; i++) { | ||
stride *= sizes[i]; | ||
strides[i] = stride; | ||
} | ||
|
||
return py::memoryview::from_buffer( | ||
base_ptr, /* Pointer to buffer */ | ||
element_size, /* Size of one scalar */ | ||
py::format_descriptor<int32_t>::value, /* Python struct-style format descriptor */ | ||
sizes, /* Buffer dimensions */ | ||
strides /* Strides (in bytes) for each index */ | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "Vtest_verilator_array.h" | ||
#include "test_verilator_array.hh" | ||
#include <exception> | ||
#include <random> | ||
#include <iostream> | ||
|
||
int main () { | ||
Vtest_verilator_array vtop; | ||
vtop.eval(); | ||
|
||
// tear down the runtime | ||
pysv_finalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
`include "pysv_pkg.sv" | ||
|
||
module test_verilator_array(); | ||
|
||
import pysv::*; | ||
|
||
int a[3:0]; | ||
|
||
initial begin | ||
for (int i = 0; i < 4; i++) begin | ||
a[i] = 2; | ||
end | ||
set_value(a); | ||
$display("%0d", a[2]); | ||
end | ||
|
||
endmodule |