TerosTechnology / vscode-terosHDL

VHDL and Verilog/SV IDE: state machine viewer, linter, documentation, snippets... and more!
https://terostechnology.github.io/terosHDLdoc/
GNU General Public License v3.0
570 stars 46 forks source link

Error schematic generation if top units more than one on VHDL files #614

Open ila-embsys opened 6 months ago

ila-embsys commented 6 months ago

Describing the bug

By pressing the 'Schematic Viewer' button on the 'Dependency Tree' panel, the Schematic Viewer window shows a blank page.

In the same time, the Output page for 'TerosHDL: Global' shows the log like that:

[info] yosys -m ghdl -p "ghdl --std=08 -fsynopsys a.vhd b.vhd tb_1.vhd tb_2.vhd -e; hierarchy -top tb_1; proc;  ; write_json teroshdl_yosys_output.json; stat"
[info] Yosys 0.33
-- Running command
1. Executing GHDL.
[info] error: no top unit found
ERROR: vhdl import failed.
[error] Yosys failed

The project, that produce error, contains two source files: tb_1.vhd and tb_2.vhd. Any of them could be set as a top file by pressing 'Select source as toplevel' on 'Sources' panel. That choosing changes the list of 'Dependency tree' and the list of 'Runs' panel. Also, that choosing reflects the '-top' argument value that passing to GHDL inside Yosys:

'ghdl --std=08 -fsynopsys a.vhd b.vhd tb_1.vhd tb_2.vhd -e; hierarchy -top tb_1; proc; ; write_json teroshdl_yosys_output.json; stat'

However, the command still produces error.

Investigating

To find where the error comes from, that generated command could be passed to Yosys CLI directly.

Run Yosys:

yosys -m ghdl

Then execute first part of generated command:

yosys> ghdl --std=08 -fsynopsys a.vhd b.vhd tb_1.vhd tb_2.vhd -e;

The error exactly here:

1. Executing GHDL.
error: no top unit found
ERROR: vhdl import failed.

GHDL internals

This error message no top unit found probably comes from here.

That Find_Top_Entity function, probably, here.

One of the conditions that the function could return nothing is top level files more than one:

if Top.Nbr_Top_Entities = 1 then
   return Top.First_Top_Entity;
else
   return Null_Iir;
end if;

Resolution

By trying to remove one of the tb files from the project 'sources' list, to left only one top file, the error disappears. 🎉 With the ability to choose any top file in the 'sources' list, not obvious that 'Schematic viewer' will not work if top file more then one.

I'm not sure my workflow is correct when I switch project's top file and run different 'Runs', but I tried and failed with 'Schematic Viewer'.

Possible resolve

An empty '-e' argument on the generated command "ghdl --std=08 -fsynopsys a.vhd b.vhd tb_1.vhd tb_2.vhd -e; hierarchy -top tb_1;" could be filled with the same value as for the flag '-top' on "hierarchy -top tb_1;". With that argument passing, that whole generated command works fine even with the multiple top files.

That '-e' probably comes from this line, but I don't know how it should work.


Environment information:

ila-embsys commented 6 months ago

Pretty sure the reasons of https://github.com/TerosTechnology/vscode-terosHDL/issues/381 is the same.

ila-embsys commented 5 months ago

This line which was added for the upcoming release probably will fix the issue.