-
Notifications
You must be signed in to change notification settings - Fork 270
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
1 parent
9718ffe
commit 90056c9
Showing
16 changed files
with
644 additions
and
212 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 |
---|---|---|
|
@@ -2,11 +2,16 @@ | |
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
# Copyright (c) 2014-2024, Lars Asplund [email protected] | ||
|
||
from pathlib import Path | ||
from vunit import VUnit | ||
from vunit.python_pkg import compile_vhpi_application, compile_fli_application, compile_vhpidirect_nvc_application | ||
from vunit.python_pkg import ( | ||
compile_vhpi_application, | ||
compile_fli_application, | ||
compile_vhpidirect_nvc_application, | ||
compile_vhpidirect_ghdl_application, | ||
) | ||
|
||
|
||
def hello_world(): | ||
|
@@ -65,7 +70,6 @@ def main(): | |
vu.add_vhdl_builtins() | ||
vu.add_python() | ||
vu.add_random() | ||
vu.enable_location_preprocessing() | ||
simulator_name = vu.get_simulator_name() | ||
|
||
if simulator_name in ["rivierapro", "activehdl"]: | ||
|
@@ -76,6 +80,8 @@ def main(): | |
compile_fli_application(root, vu) | ||
elif simulator_name == "nvc": | ||
compile_vhpidirect_nvc_application(root, vu) | ||
elif simulator_name == "ghdl": | ||
compile_vhpidirect_ghdl_application(root, vu) | ||
|
||
lib = vu.add_library("lib") | ||
lib.add_source_files(root / "*.vhd") | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
-- Copyright (c) 2014-2024, Lars Asplund [email protected] | ||
|
||
library vunit_lib; | ||
context vunit_lib.vunit_context; | ||
|
@@ -51,8 +51,18 @@ begin | |
exec("from sys import prefix"); | ||
exec("from pathlib import Path"); | ||
exec("old_environ = environ"); | ||
exec("environ['TCL_LIBRARY'] = str(Path(prefix) / 'tcl' / 'tcl8.6')"); | ||
exec("environ['TK_LIBRARY'] = str(Path(prefix) / 'tcl' / 'tk8.6')"); | ||
exec( | ||
"if (Path(prefix) / 'lib' / 'tcl8.6').exists():" + | ||
" environ['TCL_LIBRARY'] = str(Path(prefix) / 'lib' / 'tcl8.6')" + | ||
"else:" + | ||
" environ['TCL_LIBRARY'] = str(Path(prefix) / 'tcl' / 'tcl8.6')" | ||
); | ||
exec( | ||
"if (Path(prefix) / 'lib' / 'tk8.6').exists():" + | ||
" environ['TK_LIBRARY'] = str(Path(prefix) / 'lib' / 'tk8.6')" + | ||
"else:" + | ||
" environ['TK_LIBRARY'] = str(Path(prefix) / 'tcl' / 'tk8.6')" | ||
); | ||
end; | ||
|
||
procedure unset_tcl_installation is | ||
|
@@ -209,7 +219,7 @@ begin | |
test_input := eval("test_input"); -- test_input is a variable of integer_vector_ptr_t type | ||
check(length(test_input) >= 1); | ||
check(length(test_input) <= 100); | ||
-- | ||
|
||
elsif run("Test run script functions") then | ||
-- As we've seen we can define Python functions with exec (fibonacci) and we can import functions from | ||
-- Python packages. Writing large functions in exec strings is not optimal since we don't | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
# Copyright (c) 2014-2024, Lars Asplund [email protected] | ||
|
||
""" | ||
Temporary helper module to compile C-code used by python_pkg. | ||
|
@@ -212,3 +212,59 @@ def compile_vhpidirect_nvc_application(run_script_root, vu): | |
print(proc.stdout) | ||
print(proc.stderr) | ||
raise RuntimeError("Failed to link NVC VHPIDIRECT application") | ||
|
||
|
||
def compile_vhpidirect_ghdl_application(run_script_root, vu): # pylint: disable=unused-argument | ||
""" | ||
Compile VHPIDIRECT application for GHDL. | ||
""" | ||
# TODO: Avoid putting in root | ||
path_to_shared_lib = (run_script_root).resolve() | ||
if not path_to_shared_lib.exists(): | ||
path_to_shared_lib.mkdir(parents=True, exist_ok=True) | ||
shared_lib = path_to_shared_lib / "python.so" | ||
path_to_python_include = ( | ||
Path(sys.executable).parent.parent.resolve() / "include" / f"python{sys.version_info[0]}.{sys.version_info[1]}" | ||
) | ||
path_to_python_libs = Path(sys.executable).parent.parent.resolve() / "bin" | ||
python_shared_lib = f"libpython{sys.version_info[0]}.{sys.version_info[1]}" | ||
path_to_python_pkg = Path(__file__).parent.resolve() / "vhdl" / "python" / "src" | ||
|
||
c_file_names = ["python_pkg_vhpidirect_ghdl.c", "python_pkg.c"] | ||
|
||
for c_file_name in c_file_names: | ||
args = [ | ||
"gcc", | ||
"-c", | ||
"-I", | ||
str(path_to_python_include), | ||
str(path_to_python_pkg / c_file_name), | ||
"-o", | ||
str(path_to_shared_lib / (c_file_name[:-1] + "o")), | ||
] | ||
|
||
proc = subprocess.run(args, capture_output=True, text=True, check=False, cwd=str(path_to_shared_lib / "..")) | ||
if proc.returncode != 0: | ||
print(proc.stdout) | ||
print(proc.stderr) | ||
raise RuntimeError("Failed to compile GHDL VHPIDIRECT application") | ||
|
||
args = [ | ||
"gcc", | ||
"-shared", | ||
"-fPIC", | ||
"-o", | ||
str(shared_lib), | ||
str(path_to_shared_lib / "python_pkg.o"), | ||
str(path_to_shared_lib / "python_pkg_vhpidirect_ghdl.o"), | ||
"-l", | ||
python_shared_lib, | ||
"-L", | ||
str(path_to_python_libs), | ||
] | ||
|
||
proc = subprocess.run(args, capture_output=True, text=True, check=False, cwd=str(path_to_shared_lib / "..")) | ||
if proc.returncode != 0: | ||
print(proc.stdout) | ||
print(proc.stderr) | ||
raise RuntimeError("Failed to link GHDL VHPIDIRECT application") |
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 |
---|---|---|
|
@@ -2,11 +2,18 @@ | |
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
# Copyright (c) 2014-2024, Lars Asplund [email protected] | ||
|
||
import sys | ||
from os import environ | ||
from pathlib import Path | ||
from vunit import VUnit | ||
from vunit.python_pkg import compile_vhpi_application, compile_fli_application, compile_vhpidirect_nvc_application | ||
from vunit.python_pkg import ( | ||
compile_vhpi_application, | ||
compile_fli_application, | ||
compile_vhpidirect_nvc_application, | ||
compile_vhpidirect_ghdl_application, | ||
) | ||
|
||
|
||
def remote_test(): | ||
|
@@ -15,7 +22,6 @@ def remote_test(): | |
|
||
def main(): | ||
root = Path(__file__).parent | ||
|
||
vu = VUnit.from_argv() | ||
vu.add_vhdl_builtins() | ||
vu.add_python() | ||
|
@@ -29,6 +35,8 @@ def main(): | |
compile_fli_application(root, vu) | ||
elif simulator_name == "nvc": | ||
compile_vhpidirect_nvc_application(root, vu) | ||
elif simulator_name == "ghdl": | ||
compile_vhpidirect_ghdl_application(root, vu) | ||
|
||
lib = vu.add_library("lib") | ||
lib.add_source_files(root / "test" / "*.vhd") | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
-- Copyright (c) 2014-2024, Lars Asplund [email protected] | ||
|
||
context python_context is | ||
library vunit_lib; | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
-- Copyright (c) 2014-2024, Lars Asplund [email protected] | ||
|
||
use work.python_ffi_pkg.all; | ||
use work.path.all; | ||
|
@@ -49,11 +49,6 @@ package python_pkg is | |
end package; | ||
|
||
package body python_pkg is | ||
function ssin (v : real) return real is | ||
begin | ||
assert false severity failure; | ||
end; | ||
|
||
-- @formatter:off | ||
procedure import_module_from_file(module_path, as_module_name : string) is | ||
constant spec_name : string := "__" & as_module_name & "_spec"; | ||
|
@@ -64,7 +59,7 @@ package body python_pkg is | |
spec_name & " = spec_from_file_location('" & as_module_name & "', str(Path('" & module_path & "')))" & LF & | ||
as_module_name & " = module_from_spec(" & spec_name & ")" & LF & | ||
"sys.modules['" & as_module_name & "'] = " & as_module_name & LF & | ||
spec_name & ".loader.exec_module(" & as_module_name & ")"; | ||
spec_name & ".loader.exec_module(" & as_module_name & ")"; | ||
begin | ||
exec(code); | ||
end; | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
-- Copyright (c) 2014-2024, Lars Asplund [email protected] | ||
|
||
use std.textio.all; | ||
|
||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
-- Copyright (c) 2014-2024, Lars Asplund [email protected] | ||
|
||
use std.textio.all; | ||
|
||
|
Oops, something went wrong.