vunit-python-bridge 0.4.0__py3-none-any.whl → 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vunit_python_bridge/bin/vunit_python_bridge-cp310-win_amd64.dll +0 -0
- vunit_python_bridge/bin/vunit_python_bridge-cp311-win_amd64.dll +0 -0
- vunit_python_bridge/bin/vunit_python_bridge-cp312-win_amd64.dll +0 -0
- vunit_python_bridge/bin/vunit_python_bridge-cp313-win_amd64.dll +0 -0
- vunit_python_bridge/bin/vunit_python_bridge-cp314-win_amd64.dll +0 -0
- vunit_python_bridge/bin/vunit_python_bridge-cp315-win_amd64.dll +0 -0
- vunit_python_bridge/bridge.py +13 -0
- vunit_python_bridge/hdl/src/python_bridge_pkg.vhd.in +24 -19
- vunit_python_bridge/hdl/src/python_ffi_pkg_bridge.vhd +98 -28
- vunit_python_bridge/runtime.py +85 -26
- {vunit_python_bridge-0.4.0.dist-info → vunit_python_bridge-0.4.1.dist-info}/METADATA +1 -1
- {vunit_python_bridge-0.4.0.dist-info → vunit_python_bridge-0.4.1.dist-info}/RECORD +15 -15
- {vunit_python_bridge-0.4.0.dist-info → vunit_python_bridge-0.4.1.dist-info}/WHEEL +0 -0
- {vunit_python_bridge-0.4.0.dist-info → vunit_python_bridge-0.4.1.dist-info}/licenses/LICENSE +0 -0
- {vunit_python_bridge-0.4.0.dist-info → vunit_python_bridge-0.4.1.dist-info}/top_level.txt +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
vunit_python_bridge/bridge.py
CHANGED
|
@@ -118,6 +118,7 @@ def setup(
|
|
|
118
118
|
front_end = "fli" if is_fli else "vhpi" if is_vhpi else None
|
|
119
119
|
library_file = _prepare_library(Path(simulator_prefix) if front_end else None, front_end)
|
|
120
120
|
run_script_dir = str(Path.cwd() if run_script_path is None else Path(run_script_path).resolve().parent)
|
|
121
|
+
_make_pythonpath_absolute()
|
|
121
122
|
# The configuration belongs to the project, the library may be shared. The simulator
|
|
122
123
|
# hooks tell the library where the configuration is.
|
|
123
124
|
config_file = root / CONFIG_FILE_NAME
|
|
@@ -208,6 +209,18 @@ def _check_attributes(name: str, interface, hooks) -> None:
|
|
|
208
209
|
)
|
|
209
210
|
|
|
210
211
|
|
|
212
|
+
def _make_pythonpath_absolute() -> None:
|
|
213
|
+
"""
|
|
214
|
+
Resolve relative PYTHONPATH entries against the current directory, as python does. VUnit
|
|
215
|
+
starts vsim (Questa/ModelSim, Riviera-PRO) in the test output directory, where they would
|
|
216
|
+
resolve differently.
|
|
217
|
+
"""
|
|
218
|
+
# Not covered: a relative PYTHONPATH set after add_package, which needs the cwd in the config
|
|
219
|
+
value = os.environ.get("PYTHONPATH")
|
|
220
|
+
if value:
|
|
221
|
+
os.environ["PYTHONPATH"] = os.pathsep.join(os.path.abspath(entry) for entry in value.split(os.pathsep))
|
|
222
|
+
|
|
223
|
+
|
|
211
224
|
def _prepare_library(simulator_prefix: Optional[Path], front_end: Optional[str]) -> Path:
|
|
212
225
|
"""
|
|
213
226
|
Prepare the library in the library directory, failing with a pointer to the variable
|
|
@@ -16,76 +16,81 @@
|
|
|
16
16
|
--
|
|
17
17
|
-- Only scalars and constrained arrays cross the foreign interface since their
|
|
18
18
|
-- ABI is identical for NVC and GHDL on all platforms and is translated to the
|
|
19
|
-
-- FLI parameter passing conventions by native/fli.c.
|
|
19
|
+
-- FLI parameter passing conventions by native/fli.c. The integers are c_int32_t,
|
|
20
|
+
-- which is the int32_t of the native library whatever the width of integer:
|
|
21
|
+
-- integer can be 64 bits with VHDL-2019, and its results then cross as two
|
|
22
|
+
-- halves, see python_ffi_pkg.
|
|
20
23
|
|
|
21
24
|
package python_bridge_pkg is
|
|
22
25
|
constant chunk_length : positive := 1024;
|
|
23
26
|
subtype string_chunk_t is string(1 to chunk_length);
|
|
24
|
-
|
|
27
|
+
type c_int32_t is range -2147483647 - 1 to 2147483647;
|
|
28
|
+
type c_int32_vector_t is array (natural range <>) of c_int32_t;
|
|
29
|
+
subtype integer_chunk_t is c_int32_vector_t(0 to chunk_length - 1);
|
|
25
30
|
subtype real_chunk_t is real_vector(0 to chunk_length - 1);
|
|
26
31
|
|
|
27
32
|
-- Start the interpreter. Idempotent.
|
|
28
|
-
impure function vpy_setup return
|
|
33
|
+
impure function vpy_setup return c_int32_t;
|
|
29
34
|
attribute foreign of vpy_setup : function is "{foreign:vpy_setup}";
|
|
30
35
|
|
|
31
36
|
-- Flush Python's streams and drop the last result and the staged values.
|
|
32
37
|
-- The interpreter is not finalized: later operations keep working.
|
|
33
|
-
impure function vpy_cleanup return
|
|
38
|
+
impure function vpy_cleanup return c_int32_t;
|
|
34
39
|
attribute foreign of vpy_cleanup : function is "{foreign:vpy_cleanup}";
|
|
35
40
|
|
|
36
|
-
impure function vpy_buffer_clear return
|
|
41
|
+
impure function vpy_buffer_clear return c_int32_t;
|
|
37
42
|
attribute foreign of vpy_buffer_clear : function is "{foreign:vpy_buffer_clear}";
|
|
38
43
|
|
|
39
|
-
impure function vpy_buffer_append(chunk : string_chunk_t; length :
|
|
44
|
+
impure function vpy_buffer_append(chunk : string_chunk_t; length : c_int32_t) return c_int32_t;
|
|
40
45
|
attribute foreign of vpy_buffer_append : function is "{foreign:vpy_buffer_append}";
|
|
41
46
|
|
|
42
47
|
-- Start an operation in the session named by the buffer ("default" is __main__).
|
|
43
|
-
impure function vpy_begin return
|
|
48
|
+
impure function vpy_begin return c_int32_t;
|
|
44
49
|
attribute foreign of vpy_begin : function is "{foreign:vpy_begin}";
|
|
45
50
|
|
|
46
51
|
-- Execute the buffer as Python source (is_file = 0) or as a file name (is_file = 1).
|
|
47
|
-
impure function vpy_execute(is_file :
|
|
52
|
+
impure function vpy_execute(is_file : c_int32_t) return c_int32_t;
|
|
48
53
|
attribute foreign of vpy_execute : function is "{foreign:vpy_execute}";
|
|
49
54
|
|
|
50
55
|
-- Evaluate the buffer as a Python expression and convert the value to the
|
|
51
56
|
-- VHDL type given by kind. width is the length of a std_ulogic_vector,
|
|
52
57
|
-- signed or unsigned result, -1 when it is not known.
|
|
53
|
-
impure function vpy_eval(kind, width :
|
|
58
|
+
impure function vpy_eval(kind, width : c_int32_t) return c_int32_t;
|
|
54
59
|
attribute foreign of vpy_eval : function is "{foreign:vpy_eval}";
|
|
55
60
|
|
|
56
|
-
impure function vpy_push_array(length, width, height, depth, bit_width, is_signed :
|
|
61
|
+
impure function vpy_push_array(length, width, height, depth, bit_width, is_signed : c_int32_t) return c_int32_t;
|
|
57
62
|
attribute foreign of vpy_push_array : function is "{foreign:vpy_push_array}";
|
|
58
63
|
|
|
59
|
-
impure function vpy_array_write(chunk : integer_chunk_t; length :
|
|
64
|
+
impure function vpy_array_write(chunk : integer_chunk_t; length : c_int32_t) return c_int32_t;
|
|
60
65
|
attribute foreign of vpy_array_write : function is "{foreign:vpy_array_write}";
|
|
61
66
|
|
|
62
67
|
-- Stage the pushed array and return its id (>= 1), -1 on error. Python
|
|
63
68
|
-- source code refers to the value as __vunit__.staged(<id>).
|
|
64
|
-
impure function vpy_stage return
|
|
69
|
+
impure function vpy_stage return c_int32_t;
|
|
65
70
|
attribute foreign of vpy_stage : function is "{foreign:vpy_stage}";
|
|
66
71
|
|
|
67
|
-
impure function vpy_result_integer return
|
|
72
|
+
impure function vpy_result_integer return c_int32_t;
|
|
68
73
|
attribute foreign of vpy_result_integer : function is "{foreign:vpy_result_integer}";
|
|
69
74
|
|
|
70
75
|
impure function vpy_result_real return real;
|
|
71
76
|
attribute foreign of vpy_result_real : function is "{foreign:vpy_result_real}";
|
|
72
77
|
|
|
73
|
-
impure function vpy_result_meta(idx :
|
|
78
|
+
impure function vpy_result_meta(idx : c_int32_t) return c_int32_t;
|
|
74
79
|
attribute foreign of vpy_result_meta : function is "{foreign:vpy_result_meta}";
|
|
75
80
|
|
|
76
|
-
impure function vpy_error_length return
|
|
81
|
+
impure function vpy_error_length return c_int32_t;
|
|
77
82
|
attribute foreign of vpy_error_length : function is "{foreign:vpy_error_length}";
|
|
78
83
|
|
|
79
|
-
procedure vpy_result_read_string(chunk : out string_chunk_t; offset, length :
|
|
84
|
+
procedure vpy_result_read_string(chunk : out string_chunk_t; offset, length : c_int32_t);
|
|
80
85
|
attribute foreign of vpy_result_read_string : procedure is "{foreign:vpy_result_read_string}";
|
|
81
86
|
|
|
82
|
-
procedure vpy_result_read_integers(chunk : out integer_chunk_t; offset, length :
|
|
87
|
+
procedure vpy_result_read_integers(chunk : out integer_chunk_t; offset, length : c_int32_t);
|
|
83
88
|
attribute foreign of vpy_result_read_integers : procedure is "{foreign:vpy_result_read_integers}";
|
|
84
89
|
|
|
85
|
-
procedure vpy_result_read_reals(chunk : out real_chunk_t; offset, length :
|
|
90
|
+
procedure vpy_result_read_reals(chunk : out real_chunk_t; offset, length : c_int32_t);
|
|
86
91
|
attribute foreign of vpy_result_read_reals : procedure is "{foreign:vpy_result_read_reals}";
|
|
87
92
|
|
|
88
|
-
procedure vpy_error_read(chunk : out string_chunk_t; offset, length :
|
|
93
|
+
procedure vpy_error_read(chunk : out string_chunk_t; offset, length : c_int32_t);
|
|
89
94
|
attribute foreign of vpy_error_read : procedure is "{foreign:vpy_error_read}";
|
|
90
95
|
end package;
|
|
91
96
|
|
|
@@ -252,14 +252,14 @@ package body python_ffi_pkg is
|
|
|
252
252
|
-- Transfers through the bridge
|
|
253
253
|
-----------------------------------------------------------------------------
|
|
254
254
|
impure function p_error_text return string is
|
|
255
|
-
constant len : natural := vpy_error_length;
|
|
255
|
+
constant len : natural := integer(vpy_error_length);
|
|
256
256
|
variable result : string(1 to len);
|
|
257
257
|
variable chunk : string_chunk_t;
|
|
258
258
|
variable offset, n : natural := 0;
|
|
259
259
|
begin
|
|
260
260
|
while offset < len loop
|
|
261
261
|
n := minimum(chunk_length, len - offset);
|
|
262
|
-
vpy_error_read(chunk, offset, n);
|
|
262
|
+
vpy_error_read(chunk, c_int32_t(offset), c_int32_t(n));
|
|
263
263
|
result(offset + 1 to offset + n) := chunk(1 to n);
|
|
264
264
|
offset := offset + n;
|
|
265
265
|
end loop;
|
|
@@ -277,17 +277,51 @@ package body python_ffi_pkg is
|
|
|
277
277
|
return false;
|
|
278
278
|
end;
|
|
279
279
|
|
|
280
|
+
-- The width of integer: 32 bits, or 64 bits as with VHDL-2019. The
|
|
281
|
+
-- foreign interface is 32 bits, so a 64-bit integer result crosses it as two
|
|
282
|
+
-- halves, see _integer_halves in runtime.py.
|
|
283
|
+
constant p_integer_width : positive := 32 + 32 * boolean'pos(integer'high > 2147483647);
|
|
284
|
+
|
|
285
|
+
-- A 64-bit integer from its halves, low taken as unsigned. Only called with a
|
|
286
|
+
-- 64-bit integer since 2**32 does not fit in a 32-bit one.
|
|
287
|
+
function p_from_halves(low, high : c_int32_t) return integer is
|
|
288
|
+
variable half_range : integer := 2**16;
|
|
289
|
+
begin
|
|
290
|
+
half_range := half_range * half_range;
|
|
291
|
+
if low < 0 then
|
|
292
|
+
return integer(high) * half_range + (integer(low) + half_range);
|
|
293
|
+
end if;
|
|
294
|
+
return integer(high) * half_range + integer(low);
|
|
295
|
+
end;
|
|
296
|
+
|
|
297
|
+
-- The width vpy_eval takes: the width of integer for an integer, integer_vector
|
|
298
|
+
-- or dict_t result, else the width of the result
|
|
299
|
+
function p_result_width(kind, width : integer) return integer is
|
|
300
|
+
begin
|
|
301
|
+
if kind = p_kind_integer or kind = p_kind_integer_vector or kind = p_kind_dict then
|
|
302
|
+
return p_integer_width;
|
|
303
|
+
end if;
|
|
304
|
+
return width;
|
|
305
|
+
end;
|
|
306
|
+
|
|
307
|
+
impure function p_succeeded(
|
|
308
|
+
status : c_int32_t; operation : string; logger : logger_t := python_logger
|
|
309
|
+
) return boolean is
|
|
310
|
+
begin
|
|
311
|
+
return p_succeeded(integer(status), operation, logger);
|
|
312
|
+
end;
|
|
313
|
+
|
|
280
314
|
impure function p_send(text : string) return integer is
|
|
281
315
|
alias normalized : string(1 to text'length) is text;
|
|
282
316
|
variable chunk : string_chunk_t;
|
|
283
317
|
variable offset, n : natural := 0;
|
|
284
318
|
variable status : integer;
|
|
285
319
|
begin
|
|
286
|
-
status := vpy_buffer_clear;
|
|
320
|
+
status := integer(vpy_buffer_clear);
|
|
287
321
|
while offset < text'length and status = 0 loop
|
|
288
322
|
n := minimum(chunk_length, text'length - offset);
|
|
289
323
|
chunk(1 to n) := normalized(offset + 1 to offset + n);
|
|
290
|
-
status := vpy_buffer_append(chunk, n);
|
|
324
|
+
status := integer(vpy_buffer_append(chunk, c_int32_t(n)));
|
|
291
325
|
offset := offset + n;
|
|
292
326
|
end loop;
|
|
293
327
|
return status;
|
|
@@ -313,7 +347,7 @@ package body python_ffi_pkg is
|
|
|
313
347
|
begin
|
|
314
348
|
return p_begin(session, operation)
|
|
315
349
|
and p_succeeded(p_send(text), operation, logger)
|
|
316
|
-
and p_succeeded(vpy_execute(is_file), operation, logger);
|
|
350
|
+
and p_succeeded(vpy_execute(c_int32_t(is_file)), operation, logger);
|
|
317
351
|
end;
|
|
318
352
|
|
|
319
353
|
impure function p_exec_file(
|
|
@@ -334,15 +368,24 @@ package body python_ffi_pkg is
|
|
|
334
368
|
begin
|
|
335
369
|
return p_begin(session, operation)
|
|
336
370
|
and p_succeeded(p_send(expr), operation, logger)
|
|
337
|
-
and p_succeeded(vpy_eval(kind, width), operation, logger);
|
|
371
|
+
and p_succeeded(vpy_eval(c_int32_t(kind), c_int32_t(p_result_width(kind, width))), operation, logger);
|
|
338
372
|
end;
|
|
339
373
|
|
|
340
374
|
-----------------------------------------------------------------------------
|
|
341
375
|
-- Results
|
|
342
376
|
-----------------------------------------------------------------------------
|
|
377
|
+
-- With a 64-bit integer, the high half is the first metadata value
|
|
343
378
|
impure function p_result_integer return integer is
|
|
344
379
|
begin
|
|
345
|
-
|
|
380
|
+
if p_integer_width = 64 then
|
|
381
|
+
return p_from_halves(vpy_result_integer, vpy_result_meta(0));
|
|
382
|
+
end if;
|
|
383
|
+
return integer(vpy_result_integer);
|
|
384
|
+
end;
|
|
385
|
+
|
|
386
|
+
impure function p_result_meta(idx : natural) return integer is
|
|
387
|
+
begin
|
|
388
|
+
return integer(vpy_result_meta(c_int32_t(idx)));
|
|
346
389
|
end;
|
|
347
390
|
|
|
348
391
|
impure function p_result_real return real is
|
|
@@ -351,44 +394,52 @@ package body python_ffi_pkg is
|
|
|
351
394
|
end;
|
|
352
395
|
|
|
353
396
|
impure function p_result_string return string is
|
|
354
|
-
constant len : natural :=
|
|
397
|
+
constant len : natural := p_result_meta(0);
|
|
355
398
|
variable result : string(1 to len);
|
|
356
399
|
variable chunk : string_chunk_t;
|
|
357
400
|
variable offset, n : natural := 0;
|
|
358
401
|
begin
|
|
359
402
|
while offset < len loop
|
|
360
403
|
n := minimum(chunk_length, len - offset);
|
|
361
|
-
vpy_result_read_string(chunk, offset, n);
|
|
404
|
+
vpy_result_read_string(chunk, c_int32_t(offset), c_int32_t(n));
|
|
362
405
|
result(offset + 1 to offset + n) := chunk(1 to n);
|
|
363
406
|
offset := offset + n;
|
|
364
407
|
end loop;
|
|
365
408
|
return result;
|
|
366
409
|
end;
|
|
367
410
|
|
|
411
|
+
-- With a 64-bit integer, an element is its low and high halves
|
|
368
412
|
impure function p_result_integer_vector return integer_vector is
|
|
369
|
-
constant len : natural :=
|
|
413
|
+
constant len : natural := p_result_meta(0);
|
|
414
|
+
constant halves : positive := p_integer_width / 32;
|
|
370
415
|
variable result : integer_vector(0 to len - 1);
|
|
371
416
|
variable chunk : integer_chunk_t;
|
|
372
417
|
variable offset, n : natural := 0;
|
|
373
418
|
begin
|
|
374
419
|
while offset < len loop
|
|
375
|
-
n := minimum(chunk_length, len - offset);
|
|
376
|
-
vpy_result_read_integers(chunk, offset, n);
|
|
377
|
-
|
|
420
|
+
n := minimum(chunk_length / halves, len - offset);
|
|
421
|
+
vpy_result_read_integers(chunk, c_int32_t(offset * halves), c_int32_t(n * halves));
|
|
422
|
+
for idx in 0 to n - 1 loop
|
|
423
|
+
if halves = 2 then
|
|
424
|
+
result(offset + idx) := p_from_halves(chunk(2 * idx), chunk(2 * idx + 1));
|
|
425
|
+
else
|
|
426
|
+
result(offset + idx) := integer(chunk(idx));
|
|
427
|
+
end if;
|
|
428
|
+
end loop;
|
|
378
429
|
offset := offset + n;
|
|
379
430
|
end loop;
|
|
380
431
|
return result;
|
|
381
432
|
end;
|
|
382
433
|
|
|
383
434
|
impure function p_result_real_vector return real_vector is
|
|
384
|
-
constant len : natural :=
|
|
435
|
+
constant len : natural := p_result_meta(0);
|
|
385
436
|
variable result : real_vector(0 to len - 1);
|
|
386
437
|
variable chunk : real_chunk_t;
|
|
387
438
|
variable offset, n : natural := 0;
|
|
388
439
|
begin
|
|
389
440
|
while offset < len loop
|
|
390
441
|
n := minimum(chunk_length, len - offset);
|
|
391
|
-
vpy_result_read_reals(chunk, offset, n);
|
|
442
|
+
vpy_result_read_reals(chunk, c_int32_t(offset), c_int32_t(n));
|
|
392
443
|
result(offset to offset + n - 1) := chunk(0 to n - 1);
|
|
393
444
|
offset := offset + n;
|
|
394
445
|
end loop;
|
|
@@ -396,22 +447,22 @@ package body python_ffi_pkg is
|
|
|
396
447
|
end;
|
|
397
448
|
|
|
398
449
|
impure function p_result_integer_array return integer_array_t is
|
|
399
|
-
constant len : natural :=
|
|
450
|
+
constant len : natural := p_result_meta(0);
|
|
400
451
|
variable result : integer_array_t := new_3d(
|
|
401
|
-
width =>
|
|
402
|
-
height =>
|
|
403
|
-
depth =>
|
|
404
|
-
bit_width =>
|
|
405
|
-
is_signed =>
|
|
452
|
+
width => p_result_meta(1),
|
|
453
|
+
height => p_result_meta(2),
|
|
454
|
+
depth => p_result_meta(3),
|
|
455
|
+
bit_width => p_result_meta(4),
|
|
456
|
+
is_signed => p_result_meta(5) /= 0
|
|
406
457
|
);
|
|
407
458
|
variable chunk : integer_chunk_t;
|
|
408
459
|
variable offset, n : natural := 0;
|
|
409
460
|
begin
|
|
410
461
|
while offset < len loop
|
|
411
462
|
n := minimum(chunk_length, len - offset);
|
|
412
|
-
vpy_result_read_integers(chunk, offset, n);
|
|
463
|
+
vpy_result_read_integers(chunk, c_int32_t(offset), c_int32_t(n));
|
|
413
464
|
for idx in 0 to n - 1 loop
|
|
414
|
-
set(result, offset + idx, chunk(idx));
|
|
465
|
+
set(result, offset + idx, integer(chunk(idx)));
|
|
415
466
|
end loop;
|
|
416
467
|
offset := offset + n;
|
|
417
468
|
end loop;
|
|
@@ -435,8 +486,27 @@ package body python_ffi_pkg is
|
|
|
435
486
|
);
|
|
436
487
|
return -1;
|
|
437
488
|
end if;
|
|
489
|
+
-- The elements cross as 32 bits, which a 64-bit integer, and so an
|
|
490
|
+
-- integer_array_t with a bit_width of 32, can exceed
|
|
491
|
+
if p_integer_width = 64 then
|
|
492
|
+
for idx in 0 to len - 1 loop
|
|
493
|
+
if get(arr, idx) < integer(c_int32_t'low) or get(arr, idx) > integer(c_int32_t'high) then
|
|
494
|
+
failure(
|
|
495
|
+
python_logger,
|
|
496
|
+
operation & " failed:" & LF &
|
|
497
|
+
"Element " & integer'image(idx) & " (" & integer'image(get(arr, idx)) & ") of the integer_array_t " &
|
|
498
|
+
"does not fit in 32 bits (" & integer'image(integer(c_int32_t'low)) & " to " &
|
|
499
|
+
integer'image(integer(c_int32_t'high)) & ")."
|
|
500
|
+
);
|
|
501
|
+
return -1;
|
|
502
|
+
end if;
|
|
503
|
+
end loop;
|
|
504
|
+
end if;
|
|
438
505
|
if not p_succeeded(
|
|
439
|
-
vpy_push_array(
|
|
506
|
+
vpy_push_array(
|
|
507
|
+
c_int32_t(len), c_int32_t(width(arr)), c_int32_t(height(arr)), c_int32_t(depth(arr)),
|
|
508
|
+
c_int32_t(bit_width(arr)), c_int32_t(boolean'pos(is_signed(arr)))
|
|
509
|
+
),
|
|
440
510
|
operation
|
|
441
511
|
) then
|
|
442
512
|
return -1;
|
|
@@ -445,15 +515,15 @@ package body python_ffi_pkg is
|
|
|
445
515
|
while offset < len loop
|
|
446
516
|
n := minimum(chunk_length, len - offset);
|
|
447
517
|
for idx in 0 to n - 1 loop
|
|
448
|
-
chunk(idx) := get(arr, offset + idx);
|
|
518
|
+
chunk(idx) := c_int32_t(get(arr, offset + idx));
|
|
449
519
|
end loop;
|
|
450
|
-
if not p_succeeded(vpy_array_write(chunk, n), operation) then
|
|
520
|
+
if not p_succeeded(vpy_array_write(chunk, c_int32_t(n)), operation) then
|
|
451
521
|
return -1;
|
|
452
522
|
end if;
|
|
453
523
|
offset := offset + n;
|
|
454
524
|
end loop;
|
|
455
525
|
|
|
456
|
-
staged_id := vpy_stage;
|
|
526
|
+
staged_id := integer(vpy_stage);
|
|
457
527
|
if staged_id < 1 then
|
|
458
528
|
failure(python_logger, operation & " failed:" & LF & p_error_text);
|
|
459
529
|
return -1;
|
|
@@ -485,7 +555,7 @@ package body python_ffi_pkg is
|
|
|
485
555
|
impure function eval_integer(expr : string; session : python_session_t := default_session) return integer is
|
|
486
556
|
begin
|
|
487
557
|
if p_eval(expr, p_kind_integer, -1, p_eval_operation(expr, session), session) then
|
|
488
|
-
return
|
|
558
|
+
return p_result_integer;
|
|
489
559
|
end if;
|
|
490
560
|
return integer'low;
|
|
491
561
|
end;
|
vunit_python_bridge/runtime.py
CHANGED
|
@@ -59,6 +59,11 @@ VHDL_TYPE_NAMES = {
|
|
|
59
59
|
STD_ULOGIC_VALUES = frozenset("UX01ZWLH-")
|
|
60
60
|
INTEGER_LOW = -(2**31)
|
|
61
61
|
INTEGER_HIGH = 2**31 - 1
|
|
62
|
+
# The width of VHDL integer: 32 bits, or 64 bits as with VHDL-2019. VHDL
|
|
63
|
+
# gives it as the width of an integer, integer_vector or dict_t result, -1 meaning
|
|
64
|
+
# 32. A 64-bit integer crosses the foreign interface as two int32 halves, see
|
|
65
|
+
# _integer_halves.
|
|
66
|
+
INTEGER_WIDTHS = (32, 64)
|
|
62
67
|
TEXT_ENCODING = "utf-8"
|
|
63
68
|
TEXT_ERRORS = "surrogateescape"
|
|
64
69
|
|
|
@@ -583,24 +588,68 @@ class Runtime: # pylint: disable=too-many-instance-attributes
|
|
|
583
588
|
if kind == KIND_INTEGER_ARRAY:
|
|
584
589
|
return self._array_result(value, array_meta)
|
|
585
590
|
if kind == KIND_DICT:
|
|
586
|
-
return self._dict_result(value, array_meta)
|
|
591
|
+
return self._dict_result(value, array_meta, width)
|
|
587
592
|
if kind not in VHDL_TYPE_NAMES:
|
|
588
593
|
raise RuntimeError(f"Internal error: unknown result kind {kind}")
|
|
589
594
|
converter = "bits" if kind in (KIND_SIGNED, KIND_UNSIGNED) else VHDL_TYPE_NAMES[kind]
|
|
590
595
|
return getattr(self, f"_{converter}_result")(kind, value, width)
|
|
591
596
|
|
|
592
597
|
@staticmethod
|
|
593
|
-
def
|
|
598
|
+
def _integer_width(width):
|
|
594
599
|
"""
|
|
595
|
-
|
|
600
|
+
The width of VHDL integer given by VHDL, see INTEGER_WIDTHS.
|
|
601
|
+
"""
|
|
602
|
+
if width == -1:
|
|
603
|
+
return 32
|
|
604
|
+
if width not in INTEGER_WIDTHS:
|
|
605
|
+
raise RuntimeError(f"Internal error: unsupported width of VHDL integer {width}")
|
|
606
|
+
return width
|
|
607
|
+
|
|
608
|
+
@staticmethod
|
|
609
|
+
def _integer_range(width):
|
|
610
|
+
"""
|
|
611
|
+
The range of VHDL integer of a width.
|
|
612
|
+
"""
|
|
613
|
+
if width == 64:
|
|
614
|
+
return -(2**63), 2**63 - 1
|
|
615
|
+
return INTEGER_LOW, INTEGER_HIGH
|
|
616
|
+
|
|
617
|
+
@staticmethod
|
|
618
|
+
def _integer_halves(value):
|
|
619
|
+
"""
|
|
620
|
+
The low and high int32 halves of a 64-bit integer, low as a signed int32.
|
|
621
|
+
VHDL computes the value as high * 2**32 + low, low taken as unsigned.
|
|
622
|
+
"""
|
|
623
|
+
low = value & 0xFFFFFFFF
|
|
624
|
+
return low - (1 << 32) if low & 0x80000000 else low, value >> 32
|
|
625
|
+
|
|
626
|
+
def _integer_result(self, kind, value, width):
|
|
627
|
+
"""
|
|
628
|
+
Convert an int result. With a 64-bit integer, the high half is the first
|
|
629
|
+
metadata value.
|
|
596
630
|
"""
|
|
597
631
|
if not _is_integer(value):
|
|
598
632
|
raise _type_error(kind, value, "int")
|
|
633
|
+
width = self._integer_width(width)
|
|
634
|
+
low, high = self._integer_range(width)
|
|
599
635
|
value = int(value)
|
|
600
|
-
if not
|
|
601
|
-
raise OverflowError(f"{value} is outside the range of VHDL integer ({
|
|
636
|
+
if not low <= value <= high:
|
|
637
|
+
raise OverflowError(f"{value} is outside the range of VHDL integer ({low} to {high})")
|
|
638
|
+
if width == 64:
|
|
639
|
+
value, high_half = self._integer_halves(value)
|
|
640
|
+
return (value, 0.0, b"", (high_half,))
|
|
602
641
|
return (value, 0.0, b"", ())
|
|
603
642
|
|
|
643
|
+
def _integer_vector_data(self, integers, width):
|
|
644
|
+
"""
|
|
645
|
+
integer_vector data: native int32, or with a 64-bit integer the low and
|
|
646
|
+
high int32 halves of each element.
|
|
647
|
+
"""
|
|
648
|
+
if width == 64:
|
|
649
|
+
halves = [half for value in integers for half in self._integer_halves(value)]
|
|
650
|
+
return struct.pack(f"={len(halves)}i", *halves)
|
|
651
|
+
return struct.pack(f"={len(integers)}i", *integers)
|
|
652
|
+
|
|
604
653
|
@staticmethod
|
|
605
654
|
def _real_result(kind, value, _width):
|
|
606
655
|
"""
|
|
@@ -688,11 +737,13 @@ class Runtime: # pylint: disable=too-many-instance-attributes
|
|
|
688
737
|
raise _type_error(kind, value, "a list or tuple")
|
|
689
738
|
return value
|
|
690
739
|
|
|
691
|
-
def _integer_vector_result(self, kind, value,
|
|
740
|
+
def _integer_vector_result(self, kind, value, width):
|
|
692
741
|
"""
|
|
693
|
-
Convert a list/tuple of int to integer_vector data
|
|
742
|
+
Convert a list/tuple of int to integer_vector data, see _integer_vector_data.
|
|
694
743
|
"""
|
|
695
744
|
values = self._sequence(kind, value)
|
|
745
|
+
width = self._integer_width(width)
|
|
746
|
+
integer_low, integer_high = self._integer_range(width)
|
|
696
747
|
integers = []
|
|
697
748
|
for index, element in enumerate(values):
|
|
698
749
|
if not _is_integer(element):
|
|
@@ -701,14 +752,13 @@ class Runtime: # pylint: disable=too-many-instance-attributes
|
|
|
701
752
|
f"a {_type_name(element)} ({element!r:.100}), to a VHDL integer; expected int"
|
|
702
753
|
)
|
|
703
754
|
element = int(element)
|
|
704
|
-
if not
|
|
755
|
+
if not integer_low <= element <= integer_high:
|
|
705
756
|
raise OverflowError(
|
|
706
757
|
f"Element {index} ({element}) is outside the range of VHDL integer "
|
|
707
|
-
f"({
|
|
758
|
+
f"({integer_low} to {integer_high})"
|
|
708
759
|
)
|
|
709
760
|
integers.append(element)
|
|
710
|
-
|
|
711
|
-
return (0, 0.0, data, (len(integers),))
|
|
761
|
+
return (0, 0.0, self._integer_vector_data(integers, width), (len(integers),))
|
|
712
762
|
|
|
713
763
|
def _real_vector_result(self, kind, value, _width):
|
|
714
764
|
"""
|
|
@@ -729,15 +779,15 @@ class Runtime: # pylint: disable=too-many-instance-attributes
|
|
|
729
779
|
data = struct.pack(f"={len(reals)}d", *reals)
|
|
730
780
|
return (0, 0.0, data, (len(reals),))
|
|
731
781
|
|
|
732
|
-
def _dict_result(self, value, array_meta):
|
|
782
|
+
def _dict_result(self, value, array_meta, width):
|
|
733
783
|
"""
|
|
734
784
|
Convert a dict and keep its entries for VHDL to fetch, see dict_kinds.
|
|
735
|
-
The result is the handle of the dict.
|
|
785
|
+
The result is the handle of the dict. width is the width of VHDL integer.
|
|
736
786
|
"""
|
|
737
787
|
self._dicts = []
|
|
738
|
-
return (self._convert_dict(value, array_meta), 0.0, b"", ())
|
|
788
|
+
return (self._convert_dict(value, array_meta, self._integer_width(width)), 0.0, b"", ())
|
|
739
789
|
|
|
740
|
-
def _convert_dict(self, value, array_meta):
|
|
790
|
+
def _convert_dict(self, value, array_meta, width):
|
|
741
791
|
"""
|
|
742
792
|
Convert the entries of a dict, and of its nested dicts, and return its handle.
|
|
743
793
|
"""
|
|
@@ -747,18 +797,28 @@ class Runtime: # pylint: disable=too-many-instance-attributes
|
|
|
747
797
|
for key, item in value.items():
|
|
748
798
|
if not isinstance(key, str):
|
|
749
799
|
raise TypeError(f"Cannot convert the dict key {key!r:.100}, a {_type_name(key)}; expected str")
|
|
750
|
-
entries.append((key,) + self._dict_value(key, item, array_meta))
|
|
800
|
+
entries.append((key,) + self._dict_value(key, item, array_meta, width))
|
|
751
801
|
self._dicts.append(entries)
|
|
752
802
|
return len(self._dicts) - 1
|
|
753
803
|
|
|
754
|
-
def _dict_value(self, key, item, array_meta):
|
|
804
|
+
def _dict_value(self, key, item, array_meta, width):
|
|
755
805
|
"""
|
|
756
806
|
The result kind and the converted value of a dict entry.
|
|
757
807
|
"""
|
|
758
808
|
if _is_bool(item):
|
|
759
809
|
return KIND_BOOLEAN, (int(bool(item)), 0.0, b"", ())
|
|
760
810
|
if _is_integer(item):
|
|
761
|
-
|
|
811
|
+
value = self._dict_integer(key, item, width)
|
|
812
|
+
if not INTEGER_LOW <= value <= INTEGER_HIGH:
|
|
813
|
+
# set_integer encodes the value in 32 bits whatever the width of integer
|
|
814
|
+
raise OverflowError(
|
|
815
|
+
f"{value} of dict key {key!r:.100} is outside the range of a dict_t integer, which VUnit "
|
|
816
|
+
f"stores in 32 bits ({INTEGER_LOW} to {INTEGER_HIGH})"
|
|
817
|
+
)
|
|
818
|
+
if width == 64:
|
|
819
|
+
low, high = self._integer_halves(value)
|
|
820
|
+
return KIND_INTEGER, (low, 0.0, b"", (high,))
|
|
821
|
+
return KIND_INTEGER, (value, 0.0, b"", ())
|
|
762
822
|
if _is_float(item):
|
|
763
823
|
if not math.isfinite(item):
|
|
764
824
|
raise ValueError(f"{item} of dict key {key!r:.100} cannot be represented as VHDL real")
|
|
@@ -766,27 +826,26 @@ class Runtime: # pylint: disable=too-many-instance-attributes
|
|
|
766
826
|
if isinstance(item, str):
|
|
767
827
|
return KIND_STRING, self._string_result(KIND_STRING, item, -1)
|
|
768
828
|
if isinstance(item, dict):
|
|
769
|
-
return KIND_DICT, (self._convert_dict(item, array_meta), 0.0, b"", ())
|
|
829
|
+
return KIND_DICT, (self._convert_dict(item, array_meta, width), 0.0, b"", ())
|
|
770
830
|
if isinstance(item, numpy.ndarray):
|
|
771
831
|
try:
|
|
772
832
|
return KIND_INTEGER_ARRAY, self._array_result(item, array_meta)
|
|
773
833
|
except (TypeError, ValueError, OverflowError) as error:
|
|
774
834
|
raise type(error)(f"dict key {key!r:.100}: {error}") from None
|
|
775
835
|
if isinstance(item, list) and all(_is_integer(element) for element in item):
|
|
776
|
-
integers = [self._dict_integer(key, element) for element in item]
|
|
777
|
-
return KIND_INTEGER_VECTOR, (0, 0.0,
|
|
836
|
+
integers = [self._dict_integer(key, element, width) for element in item]
|
|
837
|
+
return KIND_INTEGER_VECTOR, (0, 0.0, self._integer_vector_data(integers, width), (len(integers),))
|
|
778
838
|
raise TypeError(
|
|
779
839
|
f"Cannot convert the value of dict key {key!r:.100}, a {_type_name(item)} ({item!r:.100}); "
|
|
780
840
|
"expected int, float, str, bool, a list of int, a NumPy array of integers or a dict"
|
|
781
841
|
)
|
|
782
842
|
|
|
783
|
-
|
|
784
|
-
|
|
843
|
+
def _dict_integer(self, key, value, width):
|
|
844
|
+
low, high = self._integer_range(width)
|
|
785
845
|
value = int(value)
|
|
786
|
-
if not
|
|
846
|
+
if not low <= value <= high:
|
|
787
847
|
raise OverflowError(
|
|
788
|
-
f"{value} of dict key {key!r:.100} is outside the range of VHDL integer "
|
|
789
|
-
f"({INTEGER_LOW} to {INTEGER_HIGH})"
|
|
848
|
+
f"{value} of dict key {key!r:.100} is outside the range of VHDL integer ({low} to {high})"
|
|
790
849
|
)
|
|
791
850
|
return value
|
|
792
851
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
vunit_python_bridge/__init__.py,sha256=3YLbTXiMC0KSBhayw_q2rXNi3O1GMaviINSAnHi7EeU,3036
|
|
2
|
-
vunit_python_bridge/bridge.py,sha256=
|
|
2
|
+
vunit_python_bridge/bridge.py,sha256=MrbyRVbZhuyWUQmFtMaQ1kokjzs4ciirVSMj5ESb5xI,13347
|
|
3
3
|
vunit_python_bridge/file_base.py,sha256=yWWN-z7GWPnWMLuqIyUMSRWfax_6W0i92pA0nrh2qTY,4730
|
|
4
4
|
vunit_python_bridge/native_library.py,sha256=DUH4MYaPSHO-FtvX7_1UsVIpgLSWArPOU8Urv1rGa20,25340
|
|
5
|
-
vunit_python_bridge/runtime.py,sha256=
|
|
5
|
+
vunit_python_bridge/runtime.py,sha256=07RCnOGHt7ZXe8V1Y0Yq-77EYew2QYLPEoIBf9gF4II,35598
|
|
6
6
|
vunit_python_bridge/simulator_hooks.py,sha256=syBITFpv5pE7ZKbHIM4vTwo8wGhF9AfhNa-Obs0xNdI,7599
|
|
7
7
|
vunit_python_bridge/vunit_pkg.toml,sha256=8AO9wJFWqIGbWU8FLWAHL8vtfeYuD3D0FllilXVXmVE,660
|
|
8
|
-
vunit_python_bridge/bin/vunit_python_bridge-cp310-win_amd64.dll,sha256=
|
|
9
|
-
vunit_python_bridge/bin/vunit_python_bridge-cp311-win_amd64.dll,sha256=
|
|
10
|
-
vunit_python_bridge/bin/vunit_python_bridge-cp312-win_amd64.dll,sha256
|
|
11
|
-
vunit_python_bridge/bin/vunit_python_bridge-cp313-win_amd64.dll,sha256=
|
|
12
|
-
vunit_python_bridge/bin/vunit_python_bridge-cp314-win_amd64.dll,sha256=
|
|
13
|
-
vunit_python_bridge/bin/vunit_python_bridge-cp315-win_amd64.dll,sha256=
|
|
14
|
-
vunit_python_bridge/hdl/src/python_bridge_pkg.vhd.in,sha256=
|
|
8
|
+
vunit_python_bridge/bin/vunit_python_bridge-cp310-win_amd64.dll,sha256=zvdj_6TOozIp_MOMzAG35BiobSZcWKumcWfmNdM1bDA,26624
|
|
9
|
+
vunit_python_bridge/bin/vunit_python_bridge-cp311-win_amd64.dll,sha256=gMreqwiChLm81bb_vJZb7CORikEvI-RxuwjDraCcZdU,26624
|
|
10
|
+
vunit_python_bridge/bin/vunit_python_bridge-cp312-win_amd64.dll,sha256=a6aL02meAWdpBZr_rXXd5e4hVziYdehub6eiXYJgqFY,26624
|
|
11
|
+
vunit_python_bridge/bin/vunit_python_bridge-cp313-win_amd64.dll,sha256=_0iBkCjm5dFO264nzNiiAd337kYg3k8n0kHN61spTHo,26624
|
|
12
|
+
vunit_python_bridge/bin/vunit_python_bridge-cp314-win_amd64.dll,sha256=4OY1LIWqFB3wmKk-lS_r-KpDNdMo0O6RDYsTnYHkSUA,26624
|
|
13
|
+
vunit_python_bridge/bin/vunit_python_bridge-cp315-win_amd64.dll,sha256=fOw-XZpwOPSiItxJUU8bWO1OED9Sja87r8f8zMGj_qY,26624
|
|
14
|
+
vunit_python_bridge/hdl/src/python_bridge_pkg.vhd.in,sha256=cykEPH0A0asOWPHkZ-xClYzMHm9sQFG4065MmkygaGI,5194
|
|
15
15
|
vunit_python_bridge/hdl/src/python_context.vhd,sha256=IE9dVRfPiA9tDVPW82hYltu5z3ZUczJIC4S3Hk_z9z4,522
|
|
16
|
-
vunit_python_bridge/hdl/src/python_ffi_pkg_bridge.vhd,sha256=
|
|
16
|
+
vunit_python_bridge/hdl/src/python_ffi_pkg_bridge.vhd,sha256=kvJFEs5hhLf3q_3tQKKIKa3NxwkJ85owBf9XFYBbpB8,22889
|
|
17
17
|
vunit_python_bridge/hdl/src/python_object_pkg.vhd,sha256=rvKiOMf2YZbjUssbbBGbUUsXi_Wc5y_aO77lgVx95WQ,34182
|
|
18
18
|
vunit_python_bridge/hdl/src/python_pkg.vhd,sha256=GvF7LUZk7lu8a_nMI-dNJ5FkQaXxW1FcSLeRhF2nJJE,56242
|
|
19
19
|
vunit_python_bridge/hdl/tools/generate_python_pkg.py,sha256=l_YPDW22TxGORH_ydefvKJ-HUXPfBYvOdczWxVf549Q,22731
|
|
@@ -27,8 +27,8 @@ vunit_python_bridge/native/fli.c,sha256=Half7fS8BA9X3n1jjpRAsUOoNDWEqhUT4WVfn_d-
|
|
|
27
27
|
vunit_python_bridge/native/interpreter.c,sha256=Ey6S6NZdCGs32G43jnOnAoS04RhSwJZoGGFGlaG0CBw,8222
|
|
28
28
|
vunit_python_bridge/native/operations.c,sha256=8hDC4iHcYOcy9Ijh564OKEx80eoJ7GDnlbPJX4hII1g,7271
|
|
29
29
|
vunit_python_bridge/native/vhpi.c,sha256=jnoHXIavPWC8wmAZwUvM-w7sDiptXxlHWlntVgmie2s,9208
|
|
30
|
-
vunit_python_bridge-0.4.
|
|
31
|
-
vunit_python_bridge-0.4.
|
|
32
|
-
vunit_python_bridge-0.4.
|
|
33
|
-
vunit_python_bridge-0.4.
|
|
34
|
-
vunit_python_bridge-0.4.
|
|
30
|
+
vunit_python_bridge-0.4.1.dist-info/licenses/LICENSE,sha256=Pz2eACSxkhsGfW9_iN60pgy-enjnbGTj8df8O3ebnQQ,16726
|
|
31
|
+
vunit_python_bridge-0.4.1.dist-info/METADATA,sha256=YGNrArKETqspCKDczuEzGycYPTtsBCj6KeOjdiScM0I,5741
|
|
32
|
+
vunit_python_bridge-0.4.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
33
|
+
vunit_python_bridge-0.4.1.dist-info/top_level.txt,sha256=abj4noIVQMKaPr2m8kPPxH6RSYadeXKc0Ho2uilmlEg,20
|
|
34
|
+
vunit_python_bridge-0.4.1.dist-info/RECORD,,
|
|
File without changes
|
{vunit_python_bridge-0.4.0.dist-info → vunit_python_bridge-0.4.1.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|