Skip to content

Commit

Permalink
add external packages through a builtin method
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Apr 19, 2019
1 parent cc060e5 commit 4cc4cd9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
2 changes: 2 additions & 0 deletions examples/vhdl/external_buffer/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

ui = VUnit.from_argv(vhdl_standard=std)

ui.add_external_arrays([True])

src_path = join(dirname(__file__), "src")

lib = ui.add_library("lib")
Expand Down
41 changes: 39 additions & 2 deletions vunit/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def add(name, deps=tuple()):

add("array_util")
add("com")
add("verification_components", ["com", "osvvm"])
add("external_arrays")
add("verification_components", ["com", "osvvm", "external_arrays"])
add("osvvm")
add("random", ["osvvm"])
add("json4vhdl")
Expand Down Expand Up @@ -74,6 +75,42 @@ def _add_data_types(self):
"""
self._add_files(join(VHDL_PATH, "data_types", "src", "*.vhd"))

def _add_external_arrays(self, **args):
"""
Add sources corresponding to VHPIDIRECT arrays (or their placeholders)
"""
from vunit.test.common import simulator_check

packages = [False, False, False]
implementations = [None, None, None]
if args is not None:
if 'packages' in args and args['packages'] is not None:
packages = args["packages"]
if 'implementations' in args and args["implementations"] is not None:
implementations = args["implementations"]

files = [["external_byte_array-novhpi.vhd", "external_byte_array-body.vhd"]]

# files = [
# ["external_byte_array-novhpi.vhd", "external_byte_array-body.vhd"],
# ["external_integer_array-novhpi.vhd", "external_integer_array-body.vhd"],
# ["external_memory-novhpi.vhd", "external_memory-body.vhd"]
# ]

if not simulator_check(lambda simclass: simclass.supports_vhpi()):
print("the selected simulator does not support VHPI; using non-VHPI packages...")
else:
for pkg in range(0, 1): # len(files)
if packages[pkg]:
if implementations[pkg] is not None:
files[pkg] = implementations[pkg]
else:
files[pkg][0] = "external_byte_array-vhpi.vhd"

for pkg in range(0, 1): # len(files)
for name in files[pkg]:
self._add_files(join(VHDL_PATH, "data_types", "src", "external", name))

def _add_array_util(self):
"""
Add array utility
Expand Down Expand Up @@ -227,7 +264,7 @@ def _add_check(self, name, args=None):
return False

old_args = self._already_added[name]
if args != old_args:
if args != old_args and name != "external_arrays":
raise RuntimeError(
"Optional builtin %r added with arguments %r has already been added with arguments %r"
% (name, args, old_args))
Expand Down
1 change: 0 additions & 1 deletion vunit/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def __init__(self,
self._manual_dependencies = []
self._depend_on_package_body = depend_on_package_body
self._builtin_libraries = set(["ieee", "std"])
self.vhpi = False

def _validate_new_library_name(self, library_name):
"""
Expand Down
23 changes: 6 additions & 17 deletions vunit/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ def set_objects(self, files):
"""
Set list of pre-built objects to be linked
"""
self._project.vhpi = True
self.set_sim_option("ghdl.elab_flags", ["-Wl," + " ".join(files)])

def add_library(self, library_name, vhdl_standard=None, allow_duplicate=False):
Expand Down Expand Up @@ -881,20 +880,6 @@ def _main(self, post_run):
all_ok = self._main_run(post_run)
return all_ok

def _add_ext_pkg(self):
"""
Add sources corresponding to VHPIDIRECT arrays (or their placeholders)
"""
extmem = "ext_pkg-novhpi.vhd"
if self._project.vhpi:
# @TODO Check if the simulator supports VHPI-> simulator_if.supports_vhpi()
extmem = "ext_pkg-vhpi.vhd"
for name in [extmem, "ext_pkg-body.vhd"]:
self.add_source_file(
join(abspath(join(dirname(__file__), "vhdl")), "data_types", "src", "ext", name),
"vunit_lib"
)

def _create_simulator_if(self):
"""
Create new simulator instance
Expand All @@ -919,7 +904,6 @@ def _main_run(self, post_run):
"""
simulator_if = self._create_simulator_if()
test_list = self._create_tests(simulator_if)
self._add_ext_pkg()
self._compile(simulator_if)
print()

Expand Down Expand Up @@ -1023,7 +1007,6 @@ def _main_compile_only(self):
Main function when only compiling
"""
simulator_if = self._create_simulator_if()
self._add_ext_pkg()
self._compile(simulator_if)
return True

Expand Down Expand Up @@ -1109,6 +1092,12 @@ def add_verification_components(self):
"""
self._builtins.add("verification_components")

def add_external_arrays(self, packages=None, implementations=None):
"""
Add sources corresponding to VHPIDIRECT arrays (or their placeholders)
"""
self._builtins.add("external_arrays", {'packages': packages, 'implementations': implementations})

def add_osvvm(self):
"""
Add osvvm library
Expand Down

0 comments on commit 4cc4cd9

Please sign in to comment.