Skip to content

Commit 6f527c4

Browse files
committed
feat: add external models to string_ptr; add byte_vector* as an alias
1 parent 82f5d55 commit 6f527c4

12 files changed

Lines changed: 850 additions & 215 deletions

vunit/builtins.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,55 @@ def _add_files(self, pattern):
6868

6969
self._vunit_lib.add_source_file(file_name)
7070

71-
def _add_data_types(self):
71+
def _add_data_types(self, use_external=None, impls=None):
7272
"""
7373
Add data types packages
74+
75+
:param use_external: list of a single Boolean, to select whether to enable external models for string.
76+
:param impls: optional list of lists containing alternative implementations for external models.
7477
"""
7578
self._add_files(join(VHDL_PATH, "data_types", "src", "types", "*.vhd"))
7679
self._add_files(join(VHDL_PATH, "data_types", "src", "*.vhd"))
7780

81+
# Add sources corresponding to VHPIDIRECT arrays (or their placeholders)
82+
83+
from vunit.test.common import simulator_check
84+
85+
use_ext = [False]
86+
files = [None]
87+
88+
if use_external is not None:
89+
for ind, val in enumerate(use_external):
90+
use_ext[ind] = val
91+
if impls is not None:
92+
for ind, val in enumerate(impls):
93+
files[ind] = val
94+
95+
for val in use_ext:
96+
if val and simulator_check(lambda simclass: not simclass.supports_vhpi()):
97+
raise RuntimeError("the selected simulator does not support VHPI; must use non-VHPI packages...")
98+
99+
ext_path = join(VHDL_PATH, "data_types", "src", "external")
100+
101+
def default_pkg(cond, type_str):
102+
"""
103+
Return name of VHDL file with default VHPIDIRECT foreign declarations.
104+
"""
105+
nostr = 'no'
106+
if cond:
107+
nostr = ''
108+
return join(ext_path, 'external_' + type_str + '-' + nostr + 'vhpi.vhd')
109+
110+
if not files[0]:
111+
files[0] = [
112+
default_pkg(use_ext[0], 'string'),
113+
join(ext_path, "external_string-body.vhd")
114+
]
115+
116+
for _, flist in enumerate(files):
117+
for name in flist:
118+
self._add_files(name)
119+
78120
def _add_array_util(self):
79121
"""
80122
Add array utility
@@ -168,11 +210,14 @@ def add_verilog_builtins(self):
168210
"""
169211
self._vunit_lib.add_source_files(join(VERILOG_PATH, "vunit_pkg.sv"))
170212

171-
def add_vhdl_builtins(self):
213+
def add_vhdl_builtins(self, use_external=None, impls=None):
172214
"""
173215
Add vunit VHDL builtin libraries
216+
217+
:param use_external: list of a single Boolean, to select whether to enable external models for string.
218+
:param impls: optional list of lists containing alternative implementations for external models.
174219
"""
175-
self._add_data_types()
220+
self._add_data_types(use_external=use_external, impls=impls)
176221
self._add_files(join(VHDL_PATH, "*.vhd"))
177222
for path in ("core", "logging", "string_ops", "check", "dictionary", "run", "path"):
178223
self._add_files(join(VHDL_PATH, path, "src", "*.vhd"))

vunit/ui.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
A list of PLI file names.
119119
120120
``ghdl.flags``
121-
Extra arguments passed to ``ghdl --elab-run`` command *before* executable specific flags. Must be a list of strings.
121+
Extra arguments passed to ``ghdl --elab-run`` command *before* executable specific flags.
122122
Must be a list of strings.
123123
124124
``incisive.irun_sim_flags``
@@ -290,12 +290,16 @@ class VUnit(object): # pylint: disable=too-many-instance-attributes, too-many-p
290290
"""
291291

292292
@classmethod
293-
def from_argv(cls, argv=None, compile_builtins=True, vhdl_standard=None):
293+
def from_argv(cls, argv=None, compile_builtins=True, vhdl_standard=None, use_external=None, impls=None):
294294
"""
295295
Create VUnit instance from command line arguments.
296296
297297
:param argv: Use explicit argv instead of actual command line argument
298298
:param compile_builtins: Do not compile builtins. Used for VUnit internal testing.
299+
:param vhdl_standard: The VHDL standard used to compile files into this library,
300+
if None the VUNIT_VHDL_STANDARD environment variable is used
301+
:param use_external: list of a single Boolean, to select whether to enable external models for string.
302+
:param impls: optional list of lists containing alternative implementations for external models
299303
:returns: A :class:`.VUnit` object instance
300304
301305
:example:
@@ -307,10 +311,16 @@ def from_argv(cls, argv=None, compile_builtins=True, vhdl_standard=None):
307311
308312
"""
309313
args = VUnitCLI().parse_args(argv=argv)
310-
return cls.from_args(args, compile_builtins=compile_builtins, vhdl_standard=vhdl_standard)
314+
return cls.from_args(
315+
args,
316+
compile_builtins=compile_builtins,
317+
vhdl_standard=vhdl_standard,
318+
use_external=use_external,
319+
impls=impls
320+
)
311321

312322
@classmethod
313-
def from_args(cls, args, compile_builtins=True, vhdl_standard=None):
323+
def from_args(cls, args, compile_builtins=True, vhdl_standard=None, use_external=None, impls=None):
314324
"""
315325
Create VUnit instance from args namespace.
316326
Intended for users who adds custom command line options.
@@ -319,12 +329,22 @@ def from_args(cls, args, compile_builtins=True, vhdl_standard=None):
319329
320330
:param args: The parsed argument namespace object
321331
:param compile_builtins: Do not compile builtins. Used for VUnit internal testing.
332+
:param vhdl_standard: The VHDL standard used to compile files into this library,
333+
if None the VUNIT_VHDL_STANDARD environment variable is used
334+
:param use_external: list of a single Boolean, to select whether to enable external models for string.
335+
:param impls: optional list of lists containing alternative implementations for external models
322336
:returns: A :class:`.VUnit` object instance
323-
"""
324337
325-
return cls(args, compile_builtins=compile_builtins, vhdl_standard=vhdl_standard)
338+
"""
339+
return cls(
340+
args,
341+
compile_builtins=compile_builtins,
342+
vhdl_standard=vhdl_standard,
343+
use_external=use_external,
344+
impls=impls
345+
)
326346

327-
def __init__(self, args, compile_builtins=True, vhdl_standard=None):
347+
def __init__(self, args, compile_builtins=True, vhdl_standard=None, use_external=None, impls=None):
328348
self._args = args
329349
self._configure_logging(args.log_level)
330350
self._output_path = abspath(args.output_path)
@@ -371,8 +391,9 @@ def test_filter(name, attribute_names):
371391
self._test_bench_list = TestBenchList(database=database)
372392

373393
self._builtins = Builtins(self, self._vhdl_standard, simulator_class)
394+
self._compile_builtins = compile_builtins
374395
if compile_builtins:
375-
self.add_builtins()
396+
self.add_builtins(use_external=use_external, impls=impls)
376397

377398
def _create_database(self):
378399
"""
@@ -858,7 +879,6 @@ def _main(self, post_run):
858879
"""
859880
Base vunit main function without performing exit
860881
"""
861-
862882
if self._args.export_json is not None:
863883
return self._main_export_json(self._args.export_json)
864884

@@ -1056,11 +1076,14 @@ def _run_test(self, test_cases, report):
10561076
no_color=self._args.no_color)
10571077
runner.run(test_cases)
10581078

1059-
def add_builtins(self):
1079+
def add_builtins(self, use_external=None, impls=None):
10601080
"""
10611081
Add vunit VHDL builtin libraries
1082+
1083+
:param use_external: list of a single Boolean, to select whether to enable external models for string.
1084+
:param impls: optional list of lists containing alternative implementations for external models.
10621085
"""
1063-
self._builtins.add_vhdl_builtins()
1086+
self._builtins.add_vhdl_builtins(use_external=use_external, impls=impls)
10641087

10651088
def add_com(self):
10661089
"""
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com
6+
--
7+
-- The purpose of this package is to provide a byte vector access type (pointer)
8+
-- that can itself be used in arrays and returned from functions unlike a
9+
-- real access type. This is achieved by letting the actual value be a handle
10+
-- into a singleton datastructure of string access types.
11+
--
12+
13+
use work.byte_vector_pkg.all;
14+
use work.string_ptr_pkg.all;
15+
16+
package byte_vector_ptr_pkg is
17+
18+
alias byte_vector_ptr_t is string_ptr_t;
19+
alias null_byte_vector_ptr is null_string_ptr;
20+
21+
alias new_byte_vector_ptr is new_string_ptr[natural, integer, val_t return ptr_t];
22+
alias new_byte_vector_ptr is new_string_ptr[natural, integer, natural return ptr_t];
23+
alias new_byte_vector_ptr is new_string_ptr[string, integer return ptr_t];
24+
25+
alias is_external is is_external[ptr_t return boolean];
26+
alias deallocate is deallocate[ptr_t];
27+
alias length is length[ptr_t return integer];
28+
alias set is set[ptr_t, natural, natural];
29+
alias get is get[ptr_t, natural return natural];
30+
alias reallocate is reallocate[ptr_t, natural, natural];
31+
alias resize is resize[ptr_t, natural, natural, natural];
32+
33+
-- alias write_byte is write_char;
34+
-- alias read_byte is read_char;
35+
-- alias byte_vector_access_t is string_access_t;
36+
37+
end package;

vunit/vhdl/data_types/src/data_types_context.vhd

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

77
context data_types_context is
88
library vunit_lib;
9+
use vunit_lib.byte_vector_pkg.all;
10+
use vunit_lib.byte_vector_ptr_pkg.all;
911
use vunit_lib.integer_vector_ptr_pkg.all;
1012
use vunit_lib.integer_vector_ptr_pool_pkg.all;
1113
use vunit_lib.integer_array_pkg.all;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com
6+
7+
package body external_string_pkg is
8+
procedure
9+
write_char(
10+
id : integer;
11+
i : integer;
12+
v : character
13+
)is begin
14+
assert false report "VHPI write_char" severity failure;
15+
end;
16+
17+
impure function
18+
read_char(
19+
id : integer;
20+
i : integer
21+
) return character is begin
22+
assert false report "VHPI read_char" severity failure;
23+
end;
24+
25+
impure function
26+
get_ptr(
27+
id : integer
28+
) return extstring_access_t is begin
29+
assert false report "VHPI get_string_ptr" severity failure;
30+
end;
31+
end package body;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com
6+
7+
use work.string_pkg.all;
8+
9+
package external_string_pkg is
10+
procedure
11+
write_char(
12+
id : integer;
13+
i : integer;
14+
v : character
15+
);
16+
17+
impure function
18+
read_char(
19+
id : integer;
20+
i : integer
21+
) return character;
22+
23+
impure function
24+
get_ptr(
25+
id : integer
26+
) return extstring_access_t;
27+
end package;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com
6+
7+
use work.string_pkg.all;
8+
9+
package external_string_pkg is
10+
procedure
11+
write_char(
12+
id : integer;
13+
i : integer;
14+
v : character
15+
);
16+
attribute foreign of write_char : procedure is "VHPIDIRECT write_char";
17+
18+
impure function
19+
read_char(
20+
id : integer;
21+
i : integer
22+
) return character;
23+
attribute foreign of read_char : function is "VHPIDIRECT read_char";
24+
25+
impure function
26+
get_ptr(
27+
id : integer
28+
) return extstring_access_t;
29+
attribute foreign of get_ptr : function is "VHPIDIRECT get_string_ptr";
30+
end package;

0 commit comments

Comments
 (0)