Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPI: Adding vpiPort detection (Corrects regression introduced by #753) #762

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/building/gcc/GNULinux-GNAT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GCC Backend on GNU/Linux with GCC/GNAT
--disable-bootstrap --disable-lto --disable-multilib --disable-libssp \
--disable-libgomp --disable-libquadmath
$ make -j2 && make install
$ cd /path/to/ghdl/source/dir
$ cd /path/to/ghdl/source/dir/build
$ make ghdllib
$ make install

Expand Down
2 changes: 1 addition & 1 deletion doc/ghdl.texi
Original file line number Diff line number Diff line change
Expand Up @@ -3883,7 +3883,7 @@ $ /path/to/gcc/source/dir/configure --prefix=/usr/local --enable-languages=c,vhd
--disable-bootstrap --disable-lto --disable-multilib --disable-libssp \
--disable-libgomp --disable-libquadmath
$ make -j2 && make install
$ cd /path/to/ghdl/source/dir
$ cd /path/to/ghdl/source/dir/build
$ make ghdllib
$ make install
@end example
Expand Down
126 changes: 114 additions & 12 deletions src/grt/grt-vpi.adb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ package body Grt.Vpi is
Trace ("vpiModule");
when vpiNet =>
Trace ("vpiNet");
when vpiPort =>
Trace ("vpiPort");
when vpiDirection =>
Trace ("vpiDirection");
when vpiParameter =>
Trace ("vpiParameter");
when vpiScope =>
Expand Down Expand Up @@ -345,7 +349,7 @@ package body Grt.Vpi is
Error : AvhpiErrorT;
begin
case aType is
when vpiNet =>
when vpiPort | vpiNet =>
Rel := VhpiDecls;
when vpiModule =>
if Ref = null then
Expand Down Expand Up @@ -485,6 +489,17 @@ package body Grt.Vpi is
Res := Vpi_Get_Size (Ref);
when vpiVector =>
Res := Boolean'Pos (Vpi_Get_Vector (Ref));
when vpiDirection =>
case Vhpi_Get_Mode (Ref.Ref) is
when VhpiInMode =>
Res := vpiInput;
when VhpiOutMode =>
Res := vpiOutput;
when VhpiInoutMode =>
Res := vpiInout;
when others =>
Res := vpiNoDirection;
end case;
when others =>
dbgPut_Line ("vpi_get: unknown property");
Res := 0;
Expand Down Expand Up @@ -513,8 +528,16 @@ package body Grt.Vpi is
| VhpiForGenerateK
| VhpiCompInstStmtK =>
return vpiModule;
when VhpiPortDeclK
| VhpiSigDeclK =>
when VhpiPortDeclK =>
declare
Info : Verilog_Wire_Info;
begin
Get_Verilog_Wire (Res, Info);
if Info.Vtype /= Vcd_Bad then
return vpiPort;
end if;
end;
when VhpiSigDeclK =>
declare
Info : Verilog_Wire_Info;
begin
Expand Down Expand Up @@ -548,6 +571,9 @@ package body Grt.Vpi is
when vpiNet =>
return new struct_vpiHandle'(mType => vpiNet,
Ref => Res);
when vpiPort =>
return new struct_vpiHandle'(mType => vpiPort,
Ref => Res);
when vpiParameter =>
return new struct_vpiHandle'(mType => vpiParameter,
Ref => Res);
Expand All @@ -560,7 +586,7 @@ package body Grt.Vpi is
-- vpiHandle vpi_scan(vpiHandle iter)
-- Scan the Verilog HDL hierarchy for objects with a one-to-many
-- relationship.
-- see IEEE 1364-2001, chapter 27.36, page 709
-- see IEEE Std 1800-2017, chapter 38.40, page 1109
function Vpi_Scan_Internal (Iter: vpiHandle) return vpiHandle
is
Res : VhpiHandleT;
Expand Down Expand Up @@ -592,6 +618,8 @@ package body Grt.Vpi is
when vpiInternalScope
| vpiModule =>
Expected_Kind := vpiModule;
when vpiPort =>
Expected_Kind := vpiPort;
when vpiNet =>
Expected_Kind := vpiNet;
when others =>
Expand All @@ -603,7 +631,8 @@ package body Grt.Vpi is
exit when Error /= AvhpiErrorOk;

Kind := Vhpi_Handle_To_Vpi_Prop (Res);
if Kind /= vpiUndefined and then Kind = Expected_Kind then
if Kind /= vpiUndefined and then (Kind = Expected_Kind or
(Kind = vpiPort and Expected_Kind = vpiNet)) then
return Build_vpiHandle (Res, Kind);
end if;
end loop;
Expand Down Expand Up @@ -632,14 +661,83 @@ package body Grt.Vpi is

------------------------------------------------------------------------
-- char *vpi_get_str(int property, vpiHandle ref)
-- see IEEE 1364-2001, page xxx
-- see IEEE Std 1800-2017, page 1061
Tmpstring2 : String (1 .. 1024);
function Vpi_Get_Str_Internal (Property : Integer; Ref : vpiHandle)
return Ghdl_C_String
is
Prop : VhpiStrPropertyT;
Len : Natural;
Res : Ghdl_C_String;

procedure Copy_VpiType_CString is
R : String renames Tmpstring2;
procedure Add (C : Character) is
begin
Len := Len + 1;
if Len <= R'Last then
R (Len) := C;
end if;
end Add;

procedure Add (Str : String) is
begin
for I in Str'Range loop
Add (Str (I));
end loop;
end Add;

begin
Len := 0;
case Vhpi_Handle_To_Vpi_Prop(Ref.Ref) is
when vpiUndefined =>
Add ("vpiUndefined");
when vpiType =>
Add ("vpiType");
when vpiName =>
Add ("vpiName");
when vpiFullName =>
Add ("vpiFullName");
when vpiSize =>
Add ("vpiSize");
when vpiTimePrecision =>
Add ("vpiTimePrecision");
when vpiScalar =>
Add ("vpiScalar");
when vpiVector =>
Add ("vpiVector");
when vpiModule =>
Add ("vpiModule");
when vpiDefFile =>
Add ("vpiDefFile");
when vpiNet =>
Add ("vpiNet");
when vpiPort =>
Add ("vpiPort");
when vpiDirection =>
Add ("vpiDirection");
when vpiParameter =>
Add ("vpiParameter");
when vpiScope =>
Add ("vpiScope");
when vpiInternalScope =>
Add ("vpiInternalScope");
when vpiLeftRange =>
Add ("vpiLeftRange");
when vpiRightRange =>
Add ("vpiRightRange");
when vpiStop =>
Add ("vpiStop");
when vpiFinish =>
Add ("vpiFinish");
when vpiReset =>
Add ("vpiReset");
when others =>
return;
end case;
R (Len + 1) := NUL;
end Copy_VpiType_CString;

begin
if Ref = null then
return null;
Expand All @@ -650,9 +748,15 @@ package body Grt.Vpi is
Prop := VhpiFullNameP;
when vpiName =>
Prop := VhpiNameP;
when vpiDefFile =>
Prop := VhpiFileNameP;
when vpiType =>
Tmpstring2 (1 .. 4) := "???" & NUL;
return To_Ghdl_C_String (Tmpstring2'Address);
Copy_VpiType_CString;
if Len = 0 then
return null;
else
return To_Ghdl_C_String (Tmpstring2'Address);
end if;
when others =>
dbgPut_Line ("vpi_get_str: unhandled property");
return null;
Expand Down Expand Up @@ -722,7 +826,7 @@ package body Grt.Vpi is
when vpiRightRange
| vpiLeftRange =>
case Ref.mType is
when vpiNet =>
when vpiPort| vpiNet =>
Res := new struct_vpiHandle (aType);
Res.Ref := Ref.Ref;
return Res;
Expand Down Expand Up @@ -804,10 +908,9 @@ package body Grt.Vpi is

case Info.Vtype is
when Vcd_Bad
| Vcd_Enum8
| Vcd_Float64 =>
return null;
when Vcd_Integer32 =>
when Vcd_Integer32 | Vcd_Enum8 =>
declare
V : Ghdl_U32;
begin
Expand Down Expand Up @@ -1090,7 +1193,6 @@ package body Grt.Vpi is
dbgPut_Line ("vpi_put_value: vpiObjTypeVal");
when vpiBinStrVal =>
Ii_Vpi_Put_Value_Bin_Str (Info, Len, aValue.Str);
-- dbgPut_Line ("vpi_put_value: vpiBinStrVal");
when vpiOctStrVal =>
dbgPut_Line ("vpi_put_value: vpiNet, vpiOctStrVal");
when vpiDecStrVal =>
Expand Down
18 changes: 18 additions & 0 deletions src/grt/grt-vpi.ads
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,32 @@ package Grt.Vpi is
vpiName: constant integer := 2;
vpiFullName: constant integer := 3;
vpiSize: constant integer := 4;
vpiFile: constant integer := 5;
vpiLineNo: constant integer := 6;
vpiTopModule: constant integer := 7;
vpiCellInstance: constant integer := 8;
vpiDefName: constant integer := 9;
vpiProtected: constant integer := 10;
vpiTimeUnit: constant integer := 11;
vpiTimePrecision: constant integer := 12;
vpiDefNetType: constant integer := 13;
vpiDefFile: constant integer := 15;

vpiScalar: constant integer := 17;
vpiVector: constant integer := 18;

-- object codes, see vpi_user.h
vpiModule: constant integer := 32;
vpiNet: constant integer := 36;
vpiPort: constant integer := 44;
--
vpiDirection: constant integer := 20;
vpiInput: constant integer := 1;
vpiOutput: constant integer := 2;
vpiInout: constant integer := 3;
vpiMixedIO: constant integer := 4;
vpiNoDirection: constant integer := 5;

vpiParameter: constant integer := 41;
vpiLeftRange: constant integer := 79;
vpiRightRange: constant integer := 83;
Expand Down
Loading