Skip to content

Commit 4cc4cd9

Browse files
committed
add external packages through a builtin method
1 parent cc060e5 commit 4cc4cd9

4 files changed

Lines changed: 47 additions & 20 deletions

File tree

examples/vhdl/external_buffer/run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
ui = VUnit.from_argv(vhdl_standard=std)
1515

16+
ui.add_external_arrays([True])
17+
1618
src_path = join(dirname(__file__), "src")
1719

1820
lib = ui.add_library("lib")

vunit/builtins.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def add(name, deps=tuple()):
3232

3333
add("array_util")
3434
add("com")
35-
add("verification_components", ["com", "osvvm"])
35+
add("external_arrays")
36+
add("verification_components", ["com", "osvvm", "external_arrays"])
3637
add("osvvm")
3738
add("random", ["osvvm"])
3839
add("json4vhdl")
@@ -74,6 +75,42 @@ def _add_data_types(self):
7475
"""
7576
self._add_files(join(VHDL_PATH, "data_types", "src", "*.vhd"))
7677

78+
def _add_external_arrays(self, **args):
79+
"""
80+
Add sources corresponding to VHPIDIRECT arrays (or their placeholders)
81+
"""
82+
from vunit.test.common import simulator_check
83+
84+
packages = [False, False, False]
85+
implementations = [None, None, None]
86+
if args is not None:
87+
if 'packages' in args and args['packages'] is not None:
88+
packages = args["packages"]
89+
if 'implementations' in args and args["implementations"] is not None:
90+
implementations = args["implementations"]
91+
92+
files = [["external_byte_array-novhpi.vhd", "external_byte_array-body.vhd"]]
93+
94+
# files = [
95+
# ["external_byte_array-novhpi.vhd", "external_byte_array-body.vhd"],
96+
# ["external_integer_array-novhpi.vhd", "external_integer_array-body.vhd"],
97+
# ["external_memory-novhpi.vhd", "external_memory-body.vhd"]
98+
# ]
99+
100+
if not simulator_check(lambda simclass: simclass.supports_vhpi()):
101+
print("the selected simulator does not support VHPI; using non-VHPI packages...")
102+
else:
103+
for pkg in range(0, 1): # len(files)
104+
if packages[pkg]:
105+
if implementations[pkg] is not None:
106+
files[pkg] = implementations[pkg]
107+
else:
108+
files[pkg][0] = "external_byte_array-vhpi.vhd"
109+
110+
for pkg in range(0, 1): # len(files)
111+
for name in files[pkg]:
112+
self._add_files(join(VHDL_PATH, "data_types", "src", "external", name))
113+
77114
def _add_array_util(self):
78115
"""
79116
Add array utility
@@ -227,7 +264,7 @@ def _add_check(self, name, args=None):
227264
return False
228265

229266
old_args = self._already_added[name]
230-
if args != old_args:
267+
if args != old_args and name != "external_arrays":
231268
raise RuntimeError(
232269
"Optional builtin %r added with arguments %r has already been added with arguments %r"
233270
% (name, args, old_args))

vunit/project.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def __init__(self,
5252
self._manual_dependencies = []
5353
self._depend_on_package_body = depend_on_package_body
5454
self._builtin_libraries = set(["ieee", "std"])
55-
self.vhpi = False
5655

5756
def _validate_new_library_name(self, library_name):
5857
"""

vunit/ui.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ def set_objects(self, files):
469469
"""
470470
Set list of pre-built objects to be linked
471471
"""
472-
self._project.vhpi = True
473472
self.set_sim_option("ghdl.elab_flags", ["-Wl," + " ".join(files)])
474473

475474
def add_library(self, library_name, vhdl_standard=None, allow_duplicate=False):
@@ -881,20 +880,6 @@ def _main(self, post_run):
881880
all_ok = self._main_run(post_run)
882881
return all_ok
883882

884-
def _add_ext_pkg(self):
885-
"""
886-
Add sources corresponding to VHPIDIRECT arrays (or their placeholders)
887-
"""
888-
extmem = "ext_pkg-novhpi.vhd"
889-
if self._project.vhpi:
890-
# @TODO Check if the simulator supports VHPI-> simulator_if.supports_vhpi()
891-
extmem = "ext_pkg-vhpi.vhd"
892-
for name in [extmem, "ext_pkg-body.vhd"]:
893-
self.add_source_file(
894-
join(abspath(join(dirname(__file__), "vhdl")), "data_types", "src", "ext", name),
895-
"vunit_lib"
896-
)
897-
898883
def _create_simulator_if(self):
899884
"""
900885
Create new simulator instance
@@ -919,7 +904,6 @@ def _main_run(self, post_run):
919904
"""
920905
simulator_if = self._create_simulator_if()
921906
test_list = self._create_tests(simulator_if)
922-
self._add_ext_pkg()
923907
self._compile(simulator_if)
924908
print()
925909

@@ -1023,7 +1007,6 @@ def _main_compile_only(self):
10231007
Main function when only compiling
10241008
"""
10251009
simulator_if = self._create_simulator_if()
1026-
self._add_ext_pkg()
10271010
self._compile(simulator_if)
10281011
return True
10291012

@@ -1109,6 +1092,12 @@ def add_verification_components(self):
11091092
"""
11101093
self._builtins.add("verification_components")
11111094

1095+
def add_external_arrays(self, packages=None, implementations=None):
1096+
"""
1097+
Add sources corresponding to VHPIDIRECT arrays (or their placeholders)
1098+
"""
1099+
self._builtins.add("external_arrays", {'packages': packages, 'implementations': implementations})
1100+
11121101
def add_osvvm(self):
11131102
"""
11141103
Add osvvm library

0 commit comments

Comments
 (0)