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

GHDL: a complete VHDL parser #111

Closed
eine opened this issue Jul 2, 2016 · 47 comments
Closed

GHDL: a complete VHDL parser #111

eine opened this issue Jul 2, 2016 · 47 comments

Comments

@eine
Copy link
Collaborator

eine commented Jul 2, 2016

I've been thinking long about having some multiplatform (windows and gnu/linux), free (libre), lightweight and standalone tool to analize large bodies of VHDL 2008 code at block/RTL level. That tool would provide a hierarchy browser of the compiled/synthetized design, so that all the parameterized types and components are resolved. Ideally, the info in the hierarchy would be enough to build a command line tool to draw diagrams with different levels of abstraction (entities, processes and concurrent black boxes) for documentation purposes. As a dream, a GUI could be built with linked references between diagrams and sources.

Among those features, hierarchy browsers are already available in all the big (and heavy) EDA tools and simulators; diagrams and linked references are also supported by most of the big editors. However, most of those tools require several GB to be installed, since they provide lower levels of abstraction and many other utilities. On top of that, the heavy GUIs must be launched even to just analize the hierarchy.

The closest alternative I am aware of is RTLVision. It seems to be very complete technically, it is supported in multiple platforms (windows/linux/solaris), and accepts VHDL, Verilog and System Verilog. Moreover, the engine can be used in many GUI environments. Indeed, I believe it is used by some of the big players in the industry. It is not specified which the supported versions of the standard are, but I believe it should be quite complete for 2008, since they use Verific's parser. However, I don't know how fast it is, given that it accepts multiple languages, and that it includes a waveform viewer to allow signal tracing. In any case, it is neither libre nor free or open source.

There are some projects from academia, such as VHDLVisualizer and HDLVisualizer; and even web solutions: vhdltolatex.mamikon.net. But all of them lack proper language support. Is worth referring to VisualHDL even though its input is THDL++ and outputs VHDL.


A a result, I realized that the starting point should be a reliable VHDL parser. So I searched for free alternatives:

Since I found no valid candidate, I had to accept that parsing VHDL is not straightforward. Some others reached the same conclusion before: Parsing VHDL is [very] hard , A Note on the Parsing of Complete VHDL-2002.

Then, even though ANTLR4 could be the least bad starting point, maybe parsing VHDL with a general purpose engine is not the way to go.

EDIT 2017-12-07 >
Since this first message was posted, I have been informed about new projects:

  • Nic30/hdlConvertor is an implementation using ANTLR4 for VHDL2002, which uses this grammar, along with the one at antlr/grammars-v4.
  • kevinpt/hdlparse, a simple package implementing a rudimentary parser for VHDL and Verilog. It is not capable of fully parsing the entire language.
  • Paebbels/pyVHDLParser is a "different kind" of parser. There are several characteristics that make this project specially interesting:
    • It is explicitly meant to support VHDL-2008 and (hopefully) VHDL-2018.
    • The author and maintainer (@Paebbels):
      • Is activaly participating in the evolution of the language and pushing towards the integration of new features. I.e., his knowledge about corner cases and how hard parsing VHDL can be is far beyond any average or even advanced user/developer.
      • Is also involved in the development of GHDL (he is one of the 3 most active developers) and is currently in the maintainers group.
      • Has recently stated that his objective is to use GHDL professionally for training: Project Systems Engineering #469 (comment) . Therfore, I expect him to push pyVHDLParser to be as strict at conforming the standard as GHDL is.
    • Some python integration is being added to GHDL, which will expectedly allow better integration between both projects.

I think that pyVHDLParser is the best bet. Indeed, if I were to start this thread right now, I would focus on understanding what the differences between GHDL's built-in features and pyVHDLParser are:

  • Will they always be split projects?
  • Can part/all of pyVHDLParser be embedded in GHDL?
  • Can some of the features in pyVHDLParser be externalized to GHDL?
  • Does it make sense to use GHDL as a preprocessor (i.e. get the hierarchy)

@tgindold 2016-07-03
In fact you want more than a vhdl parser: you also want a vhdl
elaborator to get access to all instantiated units, signals and connections.

GHDL has all these data, at least internally. The options --disp-tree
can be used to dump some of them and vpi/vhpi could also be used to get
more details. However, this won't be as complete as RTL view, as ghdl
is not a synthetizer and doesn't create a netlist.

Generating a dot/graphviz connection net shouldn't be very difficult.

NOTE: the rest of this comment are old thoughts, comments and questions that lead to the conclusion above. They are kept because technical details are discussed, which are useful on the path to understand the questions above.
EDIT 2017-12-07 <


Since GHDL is a compiler, it actually parses at least part of the code. It's fast, lightweight, multiplatform, standalone and free. Moreover, it is known for being strict at conforming the standard. I think this is the most valuable feature, given that there already exist multiple incomplete projects which are not expected to be ever improved to this extent.

However, I know nothing about Ada and less about how compilers work. I don't know how much of the structure of the design has to be explicitly known by the GHDL core in order to generate machine code; i.e., whether blocks of VHDL code can be fed directly into an Ada compiler. Anyway, I have analized the content of a library file:

  package pkg at 1( 0) + 0 on 11;
  package body pkg at 6( 93) + 0 on 12;
  package mygpkg at 13( 232) + 0 on 13;
  entity ent at 17( 293) + 0 on 14;
  architecture arch of ent at 23( 400) + 0 on 15;

It seems that I could build a hierarchy view of the packages, entities and architectures defined in each file. On top of that, the pretty print command and the cross-reference command syntax highlight every word; the second one also links every identifier (packages, entities, architectures, types, signals...) to it's declaration. Then, although I have not found explicit references in the user guide about how the html is generated, I would say that GHDL could be a good candidate. Nevertheless, the interfacing to other languages section of the user guide explains how to import subprograms, but not how to access to information about the design. I would say that the only choice at now is AVHPI, which is a very light and slightly adapted version of VHPI. I suppose that it is a very first step forward to something similar to Aldec's VHPI Applications.

In the end, the questions:

  • @tgingold, is GHDL suitable for this purposes, or is it focused on generating executable machine code?

@tgindold 2016-07-02
Yes, it is suitable. GHDL is able to parse and analyze vhdl sources and uses an AST as an internal representation of vhdl source. This part is clearly separated from the code generation and simulation part.
For example, the cross-reference only uses the parser and analyzer, but not at all the code generation part.

  • Is Ada the only language which can be used to extract information of the elaborated design from GHDL?

@tgindold 2016-07-02
No. The AST representation (documented in iirs.ads) could be read from any language. It shouldn't be very hard to have a python interface for example.

  • Which are the supported VHPI functions and objects?

@tgindold 2016-07-02
Far from being complete. VHPI is only supported for the simulation aspect, and just complete enough to support cocotb.

  • Given the actual status, how much effort would be needed to print the complete hierarchy of a design (top entity, ports, signals, processes, generate blocks, instantiated modules...) in any format (ascii tree to stdout, json, xml...).

@tgindold 2016-07-02
It is already possible to display the hierarchy using the --disp-tree option. The output is an ascii tree, but it wouldn't be that difficult to generate a json file.

Although I don't feel confident enough to dive into the sources of GHDL, I wouldn't mind to give Ada a try someweek in the next months. I'd like to have a big picture, to have a better reference of how much time it would require.

@tgingold
Copy link
Member

tgingold commented Jul 2, 2016

On 02/07/16 07:52, 1138-4EB wrote:

I've been thinking long about having some multiplatform (windows and
gnu/linux), free (libre), lightweight and standalone tool to analize
large bodies of VHDL 2008 code at block/RTL level. That tool would
provide a hirarchy browser of the compiled/synthetized design, so that
all the parameterized types and components are resolved. Ideally, the
info in the hierarchy would be enough to build a command line tool to
draw diagrams with different levels of abstraction (entities, processes
and concurrent black boxes) for documentation purposes. As a dream, a
GUI could be built with linked references between diagrams and sources.

Among those features, hierarchy browsers are already available in all
the big (and heavy) EDA tools and simulators; diagrams and linked
references are also supported by most of the big editors. However, most
of those tools require several GB to be installed, since they provide
lower levels of abstraction and many other utilities. On top of that,
the heavy GUIs must be launched even to just analize the hierarchy.

The closest alternative I am aware of is RTLVision
http://www.concept.de/nlview.html#FAMILY. It seems
http://www.concept.de/flash/RTL_basic.swf to be very complete
technically, it is supported in multiple platforms
(windows/linux/solaris), and accepts VHDL, Verilog and System Verilog.
Moreover, the engine http://www.concept.de/nlview.html#FAMILY can be
used in many GUI environments. Indeed, I believe it is used by some of
the big players in the industry. It is not specified which the supported
versions of the standard are, but I believe it should be quite complete
for 2008, since they use http://www.concept.de/nlview.html#FAMILY
Verific http://www.verific.com/'s parser. However, I don't know how
fast it is, given that it accepts multiple languages, and that it
includes a waveform viewer to allow signal tracing. In any case, it is
neither libre nor free or open source.

There are some projects from academia, such as VHDLVisualizer
http://www2.fiit.stuba.sk/%7Emacko/VHDLVisualizer/ and HDLVisualizer
http://labss2.fiit.stuba.sk/TeamProject/2011/team05pkss/docs/; and
even web solutions: vhdltolatex.mamikon.net
http://vhdltolatex.mamikon.net/. But all of them lack proper language
support. Is worth referring to VisualHDL
http://visualhdl.sysprogs.org/ even though its input is THDL++ and
outputs VHDL.

A a result, I realized that the starting point should be a reliable VHDL
parser. So I searched for free alternatives:

  • Many grammars and parsers for VHDL 1993 (or version not specified)
    [tams.informatik.uni-hamburg.de/vhdl
    https://tams.informatik.uni-hamburg.de/vhdl/index.php?content=07-tools#grammar]
  • Not complete VHDL 2008 grammar for Coco/R
    [github.com/wltr/coco-vhdl-2008
    https://github.com/wltr/coco-vhdl-2008]
  • Handmade prototype of parser based on regexps
    [bitbucket.org/AngelEzquerra/vhdl_analyzer
    https://bitbucket.org/AngelEzquerra/vhdl_analyzer].
  • Parser for Perl last updated in 2002
    [cpan.org/~gslondon/Hardware-Vhdl-Parser-0.12
    http://search.cpan.org/%7Egslondon/Hardware-Vhdl-Parser-0.12/]
  • Grammar for Lex-Yacc (version not specified)
    [vhdlverif.sourceforge.net
    http://vhdlverif.sourceforge.net/index.html]
  • Not complete VHDL 2008 AST
    [github.com/grwlf/vsim/blob/master/grammar/vhdl-grammar
    https://github.com/grwlf/vsim/blob/master/grammar/vhdl-grammar]
  • ANTLR4 grammars [github.com/antlr/grammars-v4
    https://github.com/antlr/grammars-v4]

Since I found no valid candidate, I had to accept that parsing VHDL is
not straightforward. Some others reached the same conclusion before:
Parsing VHDL is [very] hard
http://eli.thegreenplace.net/2009/05/19/parsing-vhdl-is-very-hard, A
Note on the Parsing of Complete VHDL-2002
http://ceur-ws.org/Vol-255/paper11.pdf.

Then, even though ANTLR4 could be the least bad starting point, maybe
parsing VHDL with a general purpose engine is not the way to go. Since
GHDL is a compiler, it actually parses at least part of the code. It's
fast, lightweight, multiplatform, standalone and free. Moreover, it is
known for being strict at conforming the standard. However, I know
nothing about Ada and less about how compilers work. I don't know how
much of the structure of the design has to be explicitly known by the
GHDL core in order to generate machine code; i.e., whether blocks of
VHDL code can be fed directly into an Ada compiler. Anyway, I have
analized the content of a library file:

|package pkg at 1( 0) + 0 on 11; package body pkg at 6( 93) + 0 on 12;
package mygpkg at 13( 232) + 0 on 13; entity ent at 17( 293) + 0 on 14;
architecture arch of ent at 23( 400) + 0 on 15; |

It seems that I could build a hierarchy view of the packages, entities
and architectures defined in each file. On top of that, the pretty print
command
http://ghdl.readthedocs.io/en/latest/Invoking_GHDL.html#pretty-print-command
and the cross-reference command
http://ghdl.readthedocs.io/en/latest/Invoking_GHDL.html#cross-reference-command
syntax highlight every word; the second one also links every identifier
(packages, entities, architectures, types, signals...) to it's
declaration. Then, although I have not found explicit references in the
user guide, I would say that GHDL could be a good candidate.
Nevertheless, the interfacing to other languages
http://ghdl.readthedocs.io/en/latest/GHDL_implementation_of_VHDL.html#interfacing-to-other-languages
section of the user guide explains how to import subprograms, but not
how to access to information about the design. I would say that the only
choice at now is |AVHPI|, which is /a very light and slightly adapted
version of VHPI/. I suppose that it is a very first step forward to
something similar to Aldec's VHPI Applications
https://www.aldec.com/en/support/resources/documentation/articles/1457.

Wow, a lot of references. I haven't yet read all these pages, but I can
still try to answer to your questions.

In the end, the questions:

Yes, it is suitable. GHDL is able to parse and analyze vhdl sources and
uses an AST as an internal representation of vhdl source. This part is
clearly separated from the code generation and simulation part.
For example, the cross-reference only uses the parser and analyzer, but
not at all the code generation part.

  • Is Ada the only language which can be used to extract information of
    the elaborated design from GHDL?

No. The AST representation (documented in iirs.ads) could be read from
any language. It shouldn't be very hard to have a python interface
for example.

  • Which are the supported VHPI functions and objects?

Far from being complete. VHPI is only supported for the simulation
aspect, and just complete enough to support cocotb.

  • Given the actual status, how much effort would be needed to print
    the complete hierarchy of a design (top entity, ports, signals,
    processes, generate blocks, instantiated modules...) in any format
    (ascii tree to stdout, json, xml...).

It is already possible to display the hierarchy using the --disp-tree
option. The output is an ascii tree, but it wouldn't be that difficult
to generate a json file.

I will comment on the first part of your message later.

Tristan.

@tgingold
Copy link
Member

tgingold commented Jul 3, 2016

On 02/07/16 07:52, 1138-4EB wrote:

I've been thinking long about having some multiplatform (windows and
gnu/linux), free (libre), lightweight and standalone tool to analize
large bodies of VHDL 2008 code at block/RTL level. That tool would
provide a hirarchy browser of the compiled/synthetized design, so that
all the parameterized types and components are resolved. Ideally, the
info in the hierarchy would be enough to build a command line tool to
draw diagrams with different levels of abstraction (entities, processes
and concurrent black boxes) for documentation purposes. As a dream, a
GUI could be built with linked references between diagrams and sources.

Among those features, hierarchy browsers are already available in all
the big (and heavy) EDA tools and simulators; diagrams and linked
references are also supported by most of the big editors. However, most
of those tools require several GB to be installed, since they provide
lower levels of abstraction and many other utilities. On top of that,
the heavy GUIs must be launched even to just analize the hierarchy.

The closest alternative I am aware of is RTLVision
http://www.concept.de/nlview.html#FAMILY. It seems
http://www.concept.de/flash/RTL_basic.swf to be very complete
technically, it is supported in multiple platforms
(windows/linux/solaris), and accepts VHDL, Verilog and System Verilog.
Moreover, the engine http://www.concept.de/nlview.html#FAMILY can be
used in many GUI environments. Indeed, I believe it is used by some of
the big players in the industry. It is not specified which the supported
versions of the standard are, but I believe it should be quite complete
for 2008, since they use http://www.concept.de/nlview.html#FAMILY
Verific http://www.verific.com/'s parser. However, I don't know how
fast it is, given that it accepts multiple languages, and that it
includes a waveform viewer to allow signal tracing. In any case, it is
neither libre nor free or open source.

There are some projects from academia, such as VHDLVisualizer
http://www2.fiit.stuba.sk/%7Emacko/VHDLVisualizer/ and HDLVisualizer
http://labss2.fiit.stuba.sk/TeamProject/2011/team05pkss/docs/; and
even web solutions: vhdltolatex.mamikon.net
http://vhdltolatex.mamikon.net/. But all of them lack proper language
support. Is worth referring to VisualHDL
http://visualhdl.sysprogs.org/ even though its input is THDL++ and
outputs VHDL.

A a result, I realized that the starting point should be a reliable VHDL
parser. So I searched for free alternatives:

  • Many grammars and parsers for VHDL 1993 (or version not specified)
    [tams.informatik.uni-hamburg.de/vhdl
    https://tams.informatik.uni-hamburg.de/vhdl/index.php?content=07-tools#grammar]
  • Not complete VHDL 2008 grammar for Coco/R
    [github.com/wltr/coco-vhdl-2008
    https://github.com/wltr/coco-vhdl-2008]
  • Handmade prototype of parser based on regexps
    [bitbucket.org/AngelEzquerra/vhdl_analyzer
    https://bitbucket.org/AngelEzquerra/vhdl_analyzer].
  • Parser for Perl last updated in 2002
    [cpan.org/~gslondon/Hardware-Vhdl-Parser-0.12
    http://search.cpan.org/%7Egslondon/Hardware-Vhdl-Parser-0.12/]
  • Grammar for Lex-Yacc (version not specified)
    [vhdlverif.sourceforge.net
    http://vhdlverif.sourceforge.net/index.html]
  • Not complete VHDL 2008 AST
    [github.com/grwlf/vsim/blob/master/grammar/vhdl-grammar
    https://github.com/grwlf/vsim/blob/master/grammar/vhdl-grammar]
  • ANTLR4 grammars [github.com/antlr/grammars-v4
    https://github.com/antlr/grammars-v4]

Since I found no valid candidate, I had to accept that parsing VHDL is
not straightforward. Some others reached the same conclusion before:
Parsing VHDL is [very] hard
http://eli.thegreenplace.net/2009/05/19/parsing-vhdl-is-very-hard, A
Note on the Parsing of Complete VHDL-2002
http://ceur-ws.org/Vol-255/paper11.pdf.

Then, even though ANTLR4 could be the least bad starting point, maybe
parsing VHDL with a general purpose engine is not the way to go. Since
GHDL is a compiler, it actually parses at least part of the code. It's
fast, lightweight, multiplatform, standalone and free. Moreover, it is
known for being strict at conforming the standard. However, I know
nothing about Ada and less about how compilers work. I don't know how
much of the structure of the design has to be explicitly known by the
GHDL core in order to generate machine code; i.e., whether blocks of
VHDL code can be fed directly into an Ada compiler. Anyway, I have
analized the content of a library file:

|package pkg at 1( 0) + 0 on 11; package body pkg at 6( 93) + 0 on 12;
package mygpkg at 13( 232) + 0 on 13; entity ent at 17( 293) + 0 on 14;
architecture arch of ent at 23( 400) + 0 on 15; |

It seems that I could build a hierarchy view of the packages, entities
and architectures defined in each file. On top of that, the pretty print
command
http://ghdl.readthedocs.io/en/latest/Invoking_GHDL.html#pretty-print-command
and the cross-reference command
http://ghdl.readthedocs.io/en/latest/Invoking_GHDL.html#cross-reference-command
syntax highlight every word; the second one also links every identifier
(packages, entities, architectures, types, signals...) to it's
declaration. Then, although I have not found explicit references in the
user guide, I would say that GHDL could be a good candidate.
Nevertheless, the interfacing to other languages
http://ghdl.readthedocs.io/en/latest/GHDL_implementation_of_VHDL.html#interfacing-to-other-languages
section of the user guide explains how to import subprograms, but not
how to access to information about the design. I would say that the only
choice at now is |AVHPI|, which is /a very light and slightly adapted
version of VHPI/. I suppose that it is a very first step forward to
something similar to Aldec's VHPI Applications
https://www.aldec.com/en/support/resources/documentation/articles/1457.

In fact you want more than a vhdl parser: you also want a vhdl
elaborator to get access to all instantiated units, signals and connections.

GHDL has all these data, at least internally. The options --disp-tree
can be used to dump some of them and vpi/vhpi could also be used to get
more details. However, this won't be as complete as RTL view, as ghdl
is not a synthetizer and doesn't create a netlist.

Generating a dot/graphviz connection net shouldn't be very difficult.

Tristan.

@tgingold
Copy link
Member

tgingold commented Jul 6, 2016

I close this issue as this was just a question.
But do not hesitate to continue the discussion.

Tristan.

@flip111
Copy link
Contributor

flip111 commented Jul 21, 2016

@1138-4eb

Nice idea, i had something similar in mind. Perhaps you can leave your e-mail address to stay in touch? So i will comment with what i know, point by point.

  • Lightweight .. seems a bit of odd requirement. Performant seems more relevant.
  • Block level visualization .. this is a problem of placing a graph in a 2D space. Ideally with the least amount of crossing edges, this can be done by algorithms that performs "Planarization". This package looked interesting http://www.ogdf.net/doku.php
  • RTL level visualization .. this could be a flowchart per process. Possibly also a flowchart of concurrent processes.
  • Parser .. yes you need one.
  • Elaborator .. this is basically an analysis on the Abstract Syntax Tree. The parser can only detect syntax errors, but after analysis of the AST it can also detect logic errors. For example a signal assignment on a variable. It doesn't have to be a complete elaborator, some pretty simple analysis can already provide pretty useful information.

I'm doing the parser and hopefully later the elaborator. I'm building this in haskell and the progress is slow but steady. I haven't started on the problem of Planarization so this area is still wide open. I decided to start with parsing because this would already be useful, and other tools build on top of it. For visualization javascript would be preferred because it plays well with html documents, publication on the web and atom editor.

I was planning to leverage ghdl to provide values of signals at a point in time. Or even to solve small snippets of logic. For example, given the following code:

variable A, B, C, D : boolean;
if notA && (B or C) then
  D := '1';
else
  D := '0';
end if;
  • The parser could figure out that notA is a typo.
  • The elaborator could figure out that '1' is not a valid value for type boolean.
  • The RTL visualizer could draw a flowchart of this piece of logic.
  • The RTL simulator (such as GHDL) can figure what will happen. Given the values of A, B and C what will be the result of expression not A && (B or C).

Too bad i was unable to install ghdl, now i'm looking to interface with modelsim, but this is also not an easy thing to do. Have you got ghdl working?

However, this won't be as complete as RTL view, as ghdl is not a synthetizer and doesn't create a netlist.

I'm not sure if a synthesis step would actually make it "more complete" ... after synthesis a lot of information is actually gone.

@tgingold
Copy link
Member

On 21/07/16 17:19, flip111 wrote:

[...]

Too bad i was unable to install ghdl, now i'm looking to interface with
modelsim, but this is also not an easy thing to do. Have you got ghdl
working?

Can you clarify why you were unable to install ghdl ? We do provide
binaries and building it from scratch is not that difficult.

Tristan.

@flip111
Copy link
Contributor

flip111 commented Jul 22, 2016

@tgingold i wrote about the gcc install here #52

@tgingold
Copy link
Member

On 22/07/16 19:55, flip111 wrote:

@tgingold https://github.com/tgingold i wrote about the gcc install
here #52 #52

Ah, ok I remember. But you should try the llvm or mcode backend instead
of the gcc one.

@jgjverheij
Copy link

jgjverheij commented Jul 22, 2016

@flip111

I'm doing the parser and hopefully later the elaborator. I'm building this in haskell and the progress is slow but steady. I haven't started on the problem of Planarization so this area is still wide open. I decided to start with parsing because this would already be useful, and other tools build on top of it.

I am trying to make co-simulation between CλaSH and Verilog/VHDL; CλaSH is actually just Haskell code... Co-simulation with Icarus-Verilog and Modelsim works currently. Simulation can be done with source-files or with quasiquoters, in which the module is used as string (written to file) currently. A future idea is to use a parser within Haskell to for example splice Haskell values in the DSL.

Will your Haskell parser be freely available? If yes, can your parser be used in this context?

After I installed Icarus Verilog on a clean Ubuntu 16.04, I installed GHDL with the following commands:

sudo apt-get install zlib1g-dev
sudo apt-get install llvm-3.5
sudo apt-get install clang
sudo apt-get install libedit-dev

--# GNAT GPL 2016
wget http://mirrors.cdn.adacore.com/art/5739cefdc7a447658e0b016b
tar xf 5739cefdc7a447658e0b016b
cd gnat-gpl-2016-x86_64-linux-bin/
sudo ./doinstall
PATH="/usr/gnat/bin:$PATH"; export PATH

--# GHDL
git clone https://github.com/tgingold/ghdl
cd ghdl
./configure --with-llvm-config=/usr/bin/llvm-config-3.5
make
sudo "PATH=$PATH" make install

@flip111
Copy link
Contributor

flip111 commented Jul 22, 2016

@jgjverheij you can not simulate CλaSH code directly as far as i know. CλaSH code compiles to vhdl or verilog. If you wanted to simulate CλaSH code with existing designs in RTL then you can generate RTL code first and just port map it like usual.

Thanks for the installation instructions ... it installed. While elaborating it seems a file was not installed properly.

ghdl -e pattern_recognizer
gcc: error: /usr/local/lib/ghdl/v93/std/std_standard.o: No such file or directory
ghdl: compilation error
ll /usr/local/lib/ghdl/v93/std/
total 72K
-rw-r--r-- 1 root root  297 jul 22 22:47 std-obj93.cf
-rw-r--r-- 1 root root  59K jul 22 22:47 textio_body.o
-rw-r--r-- 1 root root 4,6K jul 22 22:47 textio.o

This std_standard.o file is still in /home/flip111/Downloads/ghdl/

@jgjverheij
Copy link

@flip111 currently it is correct that is not possible to simulate CλaSH code with existing designs in RTL. That is why I am implementing co-simulation to make this possible.

Hereby a small Verilog example:

verilog_square :: (t ~ Signed 1000) => Signal t -> Signal t
verilog_square x    = coSim source "mult" x x
    where
        source      = [vsim| 
                                module mult (Out, Left, Right);              

                                parameter data_width = 1000;

                                input  signed [0:data_width-1] Left;  
                                input  signed [0:data_width-1] Right;                                                       
                                output signed [0:data_width-1] Out;                          

                                assign Out = Left * Right;                        

                                endmodule                                       
                      |]

Which gives the following result:

λ> sampleN 10 $ verilog_square $ fromList [1..]
[1,4,9,16,25,36,49,64,81,100]

To splice Haskell (CλaSH) values into this module, for example to create this:

......
                                assign Out = $(x) * $(x);  
......

...a parser has to be created (in this case Verilog). When you said you are building a VHDL parser in Haskell, it got my attention, because that is something I can use to give more possibilities within the co-simulation.

@flip111
Copy link
Contributor

flip111 commented Nov 13, 2017

@jgjverheij Sorry for not gettin back to this earlier. Congratz on getting your verilog/clash interface repo up! I haven't checked tried to run it though as i am just interested in VHDL for the moment.

Simulation can be done with source-files or with quasiquoters, in which the module is used as string (written to file) currently.

A future idea is to use a parser within Haskell to for example splice Haskell values in the DSL.

Both these sentences i don't understand what you're getting at.

Unfortunately work on the VHDL parser is stalled because i'm lacking the appropriate haskell skills to finish it (after already many attempts). The state of it is that i have ~4500 lines of code ... all the rules are implemented (but not working) in VHDL 1993. Got basic machinery up for testing and pretty printing. For the moment the following rules are working:

  • Grammar Level 0 (terminals only): AddingOperator, BaseSpecifier, BasedLiteral, BitValue, CharacterLiteral, DecimalLiteral, Direction, EntityClass, Exponent, ExtendedDigit, Identifier, Mode, MultiplyingOperator, RelationalOperator, ShiftOperator, Sign, SignalKind, StringLiteral, SubprogramKind
  • Grammar Level 1 (all rules that can be constructed from terminal rules): AbstractLiteral, BaseUnitDeclaration, BitStringLiteral, EntityClassEntry, EnumerationLiteral, IdentifierList, IncompleteTypeDeclaration, Label, LogicalName, OperatorSymbol, SimpleName
  • Grammar Level 2 (all rules that can be constructed with level 0 and 1): AliasDesignator, AttributeDesignator, Designator, EntityClassEntryList, EntityTag, EnumerationTypeDefinition, InstantiationList, LogicalNameList, NullStatement, Suffix
  • Grammar Level 3: GroupTemplateDeclaration, LibraryClause

That's it ... the top rule designFile is on level 33 so still a long way to go. The concrete problems i'm facing are (in level 4):

  • I used lookahead in the terminal definition to check if the subsequent character is in the set &'()*+,-./:;<=>|[] in which case a space is not needed. This works fine but now i have problems generating my Arbitrary instances which don't have the lookahead possibility.
  • I also have rules ahead for which i need to start keeping State so that i can figure out how to interpret syntax based on earlier findings (see the article @1138-4eb linked)

@Nic30
Copy link

Nic30 commented Nov 15, 2017

Hello,
did you know that there are verilog/vhdl grammars for ANTLR4 hdlConvertor.
It is possible to generate parser from them.
I do not know GHDL code, I just saying it may be useful for you...

@Paebbels
Copy link
Member

As far as I know, there is no free working VHDL-2008 grammar available on the internet.

The grammar you are pointing to is GPL 3.0 license so it prohibits a lot of use cases... It also contains no special case handling rules for all the corner cases in the VHDL language. As far as I know, the ANTLR4 grammar needs a lot of additional manual handling to get it working with VHDL.

That's why I started my own Python implementation of a special kind of VHDL parser: pyVHDLParser.

@flip111
Copy link
Contributor

flip111 commented Nov 15, 2017

@Paebbels i'm still looking for a library that can display entities and connections visually, do you know a good one?

@Paebbels
Copy link
Member

Paebbels commented Nov 15, 2017

@flip111
No, not really. For entity instance dependencies or for port to signal mappings?

@flip111
Copy link
Contributor

flip111 commented Nov 15, 2017

@Paebbels i mean a digital schematic as can be generated by for example Vivado. It would be nice to use parts of the schematic as images in documentation.

@Nic30
Copy link

Nic30 commented Nov 15, 2017

@flip111
I have some experimental "IDE" which does this thing, but it is not working because there is new D3.js library and i did only half of port.
It needs an implementation of algorithm form component placement from http://rtsys.informatik.uni-kiel.de/%7Ebiblio/downloads/theses/msp-dt.pdf p. 23.
I will do this on the end of semester.
screenshot from 2017-11-15 21-10-43

@flip111
Copy link
Contributor

flip111 commented Nov 15, 2017

@Nic30 whao that's very cool you found a good algorithm. I searched for this for a long time. So your solution is al javascript based with D3.js? That would be perfect.

@Nic30
Copy link

Nic30 commented Nov 15, 2017

Yes, D3.js is used for graph rendering, Angular is used for for data handling and flask is used as python server.

@eine
Copy link
Collaborator Author

eine commented Dec 7, 2017

@Nic30 , related to the topic, how do you get the structure of the modules? Do you use any parser?

@flip111
Copy link
Contributor

flip111 commented Dec 7, 2017

@1138-4eb Nic30 his software seems to be located here https://github.com/Nic30/hdlConvertor

I also want to mention https://github.com/Paebbels/pyVHDLParser which seems to be a nice parser which also supports VHDL 2008

Also found this https://kevinpt.github.io/hdlparse/ which is a newer library (between 2 and 7 months old) to generate documentation.

@Nic30
Copy link

Nic30 commented Dec 8, 2017

As @flip111 wrote. Also I am searching for cooperation. I am offering my help on similar project or anyone can help me. I am interested in everything which is related to HW especially HLS.

@eine
Copy link
Collaborator Author

eine commented Dec 9, 2017

@Nic30 I have a meaningful update to this thread in the oven. It is focused on trying to come up with a collaboration scheme so that we can try to integrate the pieces and proofs of concept we have been developing independently. As you can see, I already edited the first comment, to include explicit references to pyVHDLParser (which I knew about, but I had not given it the relevance I feel it has) and to your solution.

Just to be clear, I do think that ANTLR4 is a dead path for the matter at hand, in the sense that at some point (which can be quite late) it will be harder to 'hack' ANTLR, instead of going with a different concept (say pyVHDLParse and/or GHDL). However, don't take me wrong, I find the frontend part of your project very interesting and inspiring. Indeed, I am ok with using ANTLR as a quick input source to the frontend, as long as we use some intermediate format between the parser and the visualizer, which let's us swap either of them.


NOTE: the content below might be copied and/or moved to a different thread soon. See note at the end.


I somehow drafted that (JSON) format here which is an extended (and IMHO improved) version of the format used in icestudio, by taking ideas which are useful for a complete design flow (from edition, to simulation, synthesis, P&R and programming/configuration). In also considers the possibility to define data in a single or multiple files (this part is also above, but it is still in spanish). However, there might already exist a format which can be directly used. I'd like to hear about alternatives.

My proposal is to use this thread to discuss parsing. Since this is the repo of GHDL, I would focus on how to use/enhance --disp-tree, --pp-html, --file-to-xml... to generate the 'intermediate format'. Also, because some python features are being added to GHDL, the relation between GHDL and pyVHDLParser should also go here (see open questions in the updated first comment).

Then, I would open a different issue to discuss data requirements to build the visualization libraries/tools. We would discuss details about the intermediate format there, and set the minimum requirements which should be met by any parser in order to be usable (say GHDL, pyVHDLParser, ANTLR4). Note that the inputs can be not only parsers, but also 'documentation tools', such as Doxygen or VHDLDocL.

Last, I'd open a thread to talk about technical details to build the visualization libraries/tools. I like your approach using D3.js. Indeed, I considered using either that or three.js, but got quite stuck with graph theory. There is a JavaScript version of OGDF too. Other references that I'd like to bring to discussion are CodeMirror , Vue.js and wavedrom, tikz-timing... However, there are two alternatives (on top of the almost fully handmade solution) which deserve attention:


When i first found mxgraph a couple of years ago, it was not open source, but a paid library. Then, although it seemed promising, I discarded it. Moreover, I was convinced that a tool for hardware design had to be written in compiled languages (say Ada, C, C++, golang) because of performance. And this is/was Java and JavaScript. Well, both issues have changed now:

  • It is open source (Apache-2.0).
  • I learn't a little bit about how to use golang for the backend, javascript for the frontend and AJAX to implement basic APIs; how to use docker and the browser as a 'lightweight' replacement for nodejs; and how to automate the development with watchers/livereloades (say grunt-contrib-watch).

And... well... this is open source, free (as in free beer), and requires only 2.34MB. That's just one among multiple examples. The most exciting to me is wires. Note that adding a golang backend (10-20MB) and GHDL, we are talking about <30MB. Damn cool.


@Nic30 are you willing to consider the possibility to replace D3.js with mxgraph? I.e., use tha same ANTLR4 parser and layout algorithm you are using, but construct an XML/JSON you can provide as a model/input to mxgraph. I don't want to push you at all. Indeed, there are a couple of caveats:

  • Backend examples for mxgraph are written in Java and/or PHP. I'd say no, no. So porting those functions to a different backend language would be required. Note that these 'backend' functions are to save/load files. The examples are already functional client-side (with a plain web server providing html and js files). Although I have not tried it, I'd say that it would work even on GitHub Pages. This means that, shall parsers/layout algorithms be implemented in JavaScript, we could provide a full client-side IDE.
  • As stated previously, it is not reasonable to handle large projects composed of tens or hundreds of files in the browser. Therefore the possibilities to offload mxgraph should be explored to offer a performant solution. This applies to any solution. Just underlining here that I have not thoroughly analysed this yet.

NOTE: proceed with caution if you reply with quotes. Indeed, if any of these proposals is interesting to you and you agree on the proposed discussion plan, I'd encourage you not to hesitate to open a new thread. I am not sure about where should those be placed, tho. I think that @tgingold will be ok with this thread and the one considering a 'standard' data structure to construct visualizations of code bodies analized by GHDL. However, JavaScript, D3, three, mxgraph, jointjs... might be quite out of scope. In the end, we are trying to build an IDE around GHDL, but it might deserve it's own repo. Let it be Nic30/hdlConvertor, 1138-4EB/elide, Nic30/HWToolkit...

Related to #477, ideally I'd like to have a ghdl organization, where we could create ghdl/gui to integrate multiple possibilities. Not only the content discussed here, but also any general topics about using GHDL with GUI tools. For example: how to compile and simulate from Atom or how to set up linting tools.

However, in the end, I really don't mind at all. We are talking about 3-6 threads for now.


Last thought: keeping a modular approach, but thinking big, do not forget ghdlsynth-beta, icestorm, arachne-pnr, yosys...


@flip111 didn't forget about you. The message in the oven is a reply to you.

@Paebbels
Copy link
Member

Paebbels commented Dec 9, 2017

@1138-4eb

The main difference or disadvantage of GHDL is that it is not Python. I don't mean this in a case of how it is written, but more in a case that several free cloud services allow us to install Python packages and addons, but no binary code. I'm using a Python based chain of cloud services to do post processing of VHDL source files. I see no way to handle this with GHDL.

The second difference is that GHDL (as any compiler) removed comments. As a tool that extracts e.g. documentation from sources, GHDL can not be used.

pyVHDLParser e.g. has an generic and abstract description of language constructs. We can move this part to a separate repository so both (or more) projects can use this description.

pyVHDLParser does not create a classic AST (Abstract Syntax Tree) as an intermediate representation. It creates a CodeDOM (Code Document Object Model). So modelling does not start at tokens as classical use; it starts at the language model and goes backward to the characters in a file.

I think that the later processing steps in pyVHDLParser could use GHDL and pyVHDLParser "frontend" as an input.

@flip111
Copy link
Contributor

flip111 commented Dec 9, 2017

Parser applications

The selection of libraries (which were already mentioned) really depend on what you want to do. I see some cons and pros about every library. https://github.com/Nic30/hdlConvertor doesn't support VHDL 2008 but should be fast because it's written in C++. https://github.com/Paebbels/pyVHDLParser supports VHDL 2008 but it's written in python so we can expect it to be slower. (i didn't look into verilog because i'm not familiar with it, but it's also something to consider).

Having broad language support is always good to have in any situation (different flavors of vhdl, different flavors of verilig, systemC, clash, ...). But the required parsing speed depends on the application where the parser is used. From slowest (parsing speed doesn't matter much) to fastest (parsing speed is critical)

  • Generating documentation (both textual and generating schematics)
  • Generating schematics while editing your code (you are not gonna switch between code and schematic view every second so it's ok if you have to wait a little)
  • code linting / syntax checking on the command line (the context switch between CLI and editor will already be lower than with the schematic).
  • IDE/editor integration .. you need nearly instant feedback.

.. feel free to extend this list with more meaningful parser applications (i can list a few more but i wanted to limit this list to the most interesting once for the moment)

IDE

This means that, shall parsers/layout algorithms be implemented in JavaScript, we could provide a full client-side IDE.

In the end, we are trying to build an IDE around GHDL.

Since you say "build an IDE around GHDL" i assume that you want the IDE to contain a waveform viewer and not just use GHDL for parsing.

Ok let's consider building an IDE on top of javascript in two scenario's:

IDE in browser

You can't get around building a server-side app to interface with GHDL, python, C++ and various stuff. If you use any of them for the the critical parsing section you have to deal with additional latency of your HTTP request. For this reason editing code in the browser as a real IDE is already out of the window (a real IDE has code analyses on the fly like with vhdl-tool LSP). At best you can do something similar to github which is good enough to make very simple changes to your code.

offline IDE

You can still build a real IDE around javascript. The only sane way to do this is to latch onto already existing solutions, which are atom and vscode. I'm not a big fan of them because they are still slow. However it does work quite well and since there are big communities behind them it can only get better. The huge benefit here is that the javascript eco system makes it easy (compared to other solutions) to enhance these editors.

My conclusion is that the browser can never be good enough to offer serious IDE functionality (unless you host your server on the same machine of course). And atom/vscode are actually good enough. They are still slow editors but it's easy to push analytics to other tools like GHDL and dedicated parsers.

Documentation

For documentation i would say the browser is the preferred platform. Here you can have written documentation, display code snippets (no editing), display smaller or bigger schematics and sometimes it helps to show a waveform as well.

If the IDE solution still uses javascript for the most parts then there is real synergy between an IDE and a documentation viewer.

@Paebbels makes a good point here that it's important to be able to host on already existing infrastructure. Since maintaining infrastructure yourself is a day job on itself.

What is actually the benefit of GHDL for documentation? For the parsing there are other solutions in competition. So it's main advantage is actually what it was build for generating waveform (simulation). But i think it would be ok if the documentation writer can do the simulation offline and just upload the vcd file along with the documentation.

Visualization

In both IDE setting and documentation setting i think it would be useful to make visualizations in such a way that they allow you to explore the design. Of course a static image is already better than no image. But when doing things in the browser we can do better. I imagine looking at parts of your design and the clicking on the edges to start showing other parts they are connected to. If you want to do this the visualizing library needs to be fast enough for it so you don't have to wait long if your design gets big. I'm not sure which techniques have good hardware acceleration. All the libraries use either WebGL, canvas, SVG or HTML (this is the order i expect them to be fastest to slowest). Though for the moment it would be a waste of time to cook up a custom WebGL solution or something like that. Better go with an already existing solution (Nic30 d3.js or mxgraph or whatever). But it's interesting to see how these libraries respond when you load a big design into it.

But for really interesting visualizations let's move on to the next section ...

Data flow analysis

Data flow analysis is something compilers do for any language. In hardware design i think this is done in the elaboration phase (correct me if i'm wrong and it's actually in the analyzing phase). What is interesting about this for visualization (and actually also for when you are working with code) is that it gives more context to your signals.

I often see in VHDL code a lot of signals with std_logic (duh right?) .. but that means if (nearly) all of your signals have the same type that you have actually no type information. You don't know if it's a clock or a reset signal by looking at the type. Often things that could be (should be ?) in the type are pushed into the variable naming. Now variable names could be used by the computer to figure out what signal it is. Does the variable name contain clk or clock? But this approach gets hairy real quickly, especially when not something trivial as a clock name and you have a lot of renaming of signals going on (crossing entity boundaries and such).

What data flow analysis would give you is showing you drivers & readers from a signal (a term i picked up from modelsim). By this it would allow you to annotate your signal once on the top entity level "this signal is a clock" and then the data flow analysis would be able to infer all the signals which are derived from this clock. This solution is also not perfect because many drivers can converge on a single reader (using AND/OR gates) and one driver can diverge to many readers (just be the fact that they are connected). Suppose i have a <= b AND reset is a still a reset or is a control signal now? But still .. even with this problem it's a great thing to have because you get a lot of information for free.You could help the data flow analyzer on parts where it gets stuck by annotating (classifying) the signals yourself in the schematic. This annotating the data flow analyzer seems like extra work, but it is not in fact. Because if you drawing your own schematic from scratch you have to do all of the work (deciding which signals to draw in your schematic and how to classify them) without any help.

After the signal classification phase is done now you can do some really cool things. You can toggle to show a "type of signal" (i'm going to use type here now in the context of how they were classified by you and no longer the actual type in the code). Example "show/hide all clocks". Or maybe "color all clock lines green". Or "show me the data paths in my design".

I have actually never seen this done before in such a way so for me it's also a question how well this would work. The technically closest i have seen is modelsim dataflow window.

I don't think it's possible to get this information for GHDL at the moment ... but i know it's in there somewhere :P

ANTLR

I do think that ANTLR4 is a dead path for the matter at hand, in the sense that at some point (which can be quite late) it will be harder to 'hack' ANTLR

We don't need to "hack" ANTLR, the tool should be able to come up with dedicated parsers for your particular language. At the moment the following code generation targets are available: Java, C#, Python (2 and 3), JavaScript, Go, C++, Swift. From there it's up the the programmer to use these parsers in a tool. For example you could code for a vhdl and verilog parser, then use this code in a CLI tool with a command line option interface. Now you have a CLI tool that can syntax check both VHDL and verilog. The same for if you want to target javascript (in a github editing way scenario). ANTLR is one of the best tools to design parsers. That doesn't mean that there are no other good solutions available (all the parsers there are right now are good parsers). I'm not saying here we should go with ANTLR, i'm just saying that it's good software and it has it's own benefits too.

@Nic30
Copy link

Nic30 commented Dec 9, 2017

IDE

  • browser/electron solution will be best, because there are many great libraries for graphic in JS and it works everywhere. And many HW developers that I know, are working on servers because there are licenses installed. So client-server app makes perfect sense for them.
    (https://electronjs.org/ = offline version, server + chrome packed into executable)

  • D3.js is one of fastest graph libraries, http://bl.ocks.org/mjromper/95fef29a83c43cb116c3

    • I used current IDE for development of AXI4 DMAs, there were 16K+ endpoints and I did not suffered from lags.

Basic display of components is not a problem. Choice mxgraph/D3.js is invariant.
With mxgraph I did not solve following problems:

  • collapse and open internal structure of components
  • component/path keep out
  • diagrams with cyclic, self reference structures

I tried to use mxgraph json format but I did not found specification of it's json format back in times.

Data flow analysis

  • it is possible to discover clock etc, with lazy-loading and process analysis.
  • It is not generally possible to discover complex interfaces like Avalon/Axi4 ...

Without HLS meta-informations and platform-informations you are limited to just view hierarchy design and operator nets. But those informations can be provided by user in form of XDC/ucf... which user probably has.

@eine
Copy link
Collaborator Author

eine commented Dec 10, 2017

And can we move to some new issue? Or where already did to #477 and I just ignored it?

#477 is heavy WIP and content from there is being moved to different issues. This is one of them, but also 280, 377, 480... Therefore, content in #477 should not be overlapped with this thread. The only relation is that the possibility to create an organization is listed there, for now, and I'd like ghdl/gui to exist.

#477 is about using docker containers to build (GHDL, that tarballs for releases, ready-to-use images, web sites...). The conceptual IDE we are talking about in this thread will be available as a docker container (mostly because I don't install dev dependencies locally anymore), but I think that it should be deployable "standalone".

I use "standalone" because GHDL + python/C++ parser + python/golang webserver + python/golang/C++ backend + frontend sources (html, css, js) + (optional) gtkwave + (optional) vunit + (optional) doxygen + (dependency) python runtime is not exactly standalone, but... we get it.

About moving to some now issue to discuss GUI details, as commented above:

Indeed, if any of these proposals is interesting to you and you agree on the proposed discussion plan, I'd encourage you not to hesitate to open a new thread.

Go on!

@eine
Copy link
Collaborator Author

eine commented Dec 11, 2017

@flip111, @Nic30, I cleaned the wiki and the develop branch in 1138-4EB/elide. That will allow us to:

  • Edit all these notes in the wiki in a more structured way. Indeed, I moved some parts of this comment there already.
  • Have a site (1138-4EB.github.io/elide) to test full client-side viewers.
  • Put the examples and test outputs in a subdir:

@Nic30, @flip111, can we agree on a couple of examples and generate outputs for them with different tools? I mean --disp-tree, --pp-html... for GHDL; the abstract description @Paebbels mentioned for pyVHDLParser; the one used in hwtIde, etc.

@Nic30
@1138-4eb Yes, lets create library of examples with example outputs for each tool or desired format.

If you want, I can add both of you as collaborators.


I can't remember now if I stated somewhere my expectations when talking about IDEs: 1138-4EB/elide/wiki/Personal-expectations


flip111 2017-12-06
@1138-4eb Nic30 his software seems to be located here https://github.com/Nic30/hdlConvertor

Thanks @flip111, I didn't realize that @Nic30 is the same person who wrote about ANTLR4.

@flip111 2016-07-21
Lightweight .. seems a bit of odd requirement. Performant seems more relevant.

Let me elaborate: I don't like huge monolithic tools with heavy dependencies. At the same time, because VHDL projects can get so large and verbose, performance might be an issue. Therefore, I prefer to avoid interpreted languages, such as JavaScript, Python, Ruby... which is quite an issue because... you know...

At the same time, instead of very tightly coupled internal modules, I prefer to have some of those intermediate interfaces/APIs exposed so that some or all of the modules can be swapped with alternatives. Kind of 'build your own framework'. This is a compulsory requirement somehow, because we depend on external closed tools for synthesis, P&R and testing. Indeed, both VUnit and PoC are good examples of this approach.

As a result, 'lightweight' means to use (multiple) task-specific lightweight tools/libraries in Ada, C, C++, Golang... for the backend (analysis, elaboration, graph layout, waveform generation, waveform format conversion...). If all of these are given in a known format, the frontend can be as lightweight or heavy/performant as wanted. It can be as simple as a CLI or as heavy as a Eclipse mod.

Indeed, because VUnit, pyVHDLParser and GHDL are already cli tools, I would forget about the 'lightweight' feature for now, and focus on standard interfaces instead.

@tgingold:
GHDL has all these data, at least internally. The options --disp-tree
can be used to dump some of them and vpi/vhpi could also be used to get
more details. However, this won't be as complete as RTL view, as ghdl
is not a synthetizer and doesn't create a netlist.

Generating a dot/graphviz connection net shouldn't be very difficult.

Let's start here:

NOTE: these are open questions that I will try to respond myself and provide minimal working examples. Of course, I'd be glad to be helped, but I don't expect anyone to do it. As a first example, a full adder was tested with --disp-tree, --pp-html and --file-to-xml, along with getting the VCD. Outputs are available here.

  • Is the output of --disp-tree 'good' enough to generate a dot/graphviz connection?
  • Is the output of --disp-tree 'good' enough to generate a JSON object to be used for visualization?
    • GHDL already produces JSON with --psl-report<=FILENAME>
  • Can --pp-html be modified to generate a data structure instead of raw HTML, in order to allow using static site generators (say Jekyll, Hugo, Sphinx...) to apply templates and/or refactor the content?
    • Which format should be used? Is JSON valid? XML?
    • This feature is listed in the 'use cases' of pyVHDLParser. Should both GHDL and pyVHDLParser generate compatible data structures? Doing so would make the web generator compatible with both tools/libraries for parsing.
    • What is the relation between --disp-tree and --pp-html? Would the data structure generated by the latter be an extended version which includes all the info provided by the first?
  • What is the difference in the content generated by --pp-html and --file-to-xml? Seems that --file-to-xml is somehow what I propose in the previous point. However, the AST slightly changes from time to time (particularly when new nodes are added for new language features), so be liberal in what is allowed by your tool. Also, the XML can be quite large so consider it only during prototyping. and note that at this time there is no XML dump of the elaborated design.

So many questions. We need to set the requirements, to know if we can get it:

  • For example, I think GHDL is enough to produce diagrams as the ones generated by kevinpt/symbolator. It uses Pango, and Python bindings, so I expect it to be quite heavy. I'd say that a similar result can be obtained with the output of GHDL, a template and a preprocessor. A similar solution is vhdltolatex.
  • On the other end, this is a very personal and not complete list of desired features: https://github.com/1138-4EB/elide/wiki/(RTL)-IDE#desired-features
  • Nic30/hwtIde is somewhere in-between. The main feature is that it is meant for edition of the connections. I wonder if it allows to i) add/remove blocks, and/or ii) apply the visual modifications to the VHDL sources.

Parser

@flip111
I see some cons and pros about every library. https://github.com/Nic30/hdlConvertor doesn't support VHDL 2008 but should be fast because it's written in C++. https://github.com/Paebbels/pyVHDLParser supports VHDL 2008 but it's written in python so we can expect it to be slower.

For me (and I believe that other many will agree) a project started now must support VHDL 2008, and it must expect to support VHDL 2018 as well. I think that weight and performance can be traded, but language support is a must. Which way is faster/better?

  • Contribute to GHDL.
  • Contribute to pyVHDLParser.
  • Contribute to generate a free complete grammar for VHDL2008 that ANTLR4 can use.

@flip111
We don't need to "hack" ANTLR, the tool should be able to come up with dedicated parsers for your particular language.

I meant this:

@Paebbels
As far as I know, the ANTLR4 grammar needs a lot of additional manual handling to get it working with VHDL.


@flip111
(i didn't look into verilog because i'm not familiar with it, but it's also something to consider)

I'd drop this feature for now, and expect verilog users to convert their codebase to VHDL. Indeed, I think that VHDL93 or VHDL2002 should be used as standard "HDL netlists". This is somehow true already, since many higher abstraction languages generate VHDL: SpinalHDL/SpinalHDL, clash, myhdl...

Indeed, I remember asking @tgingold about using GHDL as a VHDL version conversion tool. That is, input VHDL 2008 codebase and get an equivalent VHDL 2002 or 1993 version. He pointed me to tgingold/ghdlsynth-beta, hence, I think that is the approach to use yosys for synthesis. I wonder how would the generic and abstract description mentioned by @Paebbels fit for this conversion task.

I believe this is the same as:

@Nic30

  • universal HDL parser API (same data as comp. viewer or doc gen)

Parser applications

Let's be more explicit about expected response times:

@flip111
Generating documentation (both textual and generating schematics)

Can take hours. We want it to take minutes. We'd love to have it done in seconds.

Note, it is not the same to generate HTML docs only, or to also generate a PDF with LaTeX in the background. It applies to both text and images.

@flip111
Generating schematics while editing your code (you are not gonna switch between code and schematic view every second so it's ok if you have to wait a little)

Must take seconds. We'd love to have it done in less than a second.

Indeed, I will :D. Won't switch between code and schematic every second, but have two screens, one showing the (hopefully interactive) schematic and the other with a text editor. Anyway, it can be triggered with a timeout, or a keyboard shortcut, no need for it to be on every file change.

@flip111
code linting / syntax checking on the command line (the context switch between CLI and editor will already be lower than with the schematic).

Can take minutes. We want it to take less than a second. We'd to have it done in milliseconds.

Using GHDL for formatting was discussed in #464.

eclipse/che, which is mentioned in #477, supports LSP. Adding this feature to GHDL is being discussed in #416.

VHDL Tool should be mentioned here, even though linting is a premium feature. Also, jeremiah-c-leary/vhdl-style-guide.

@flip111
IDE/editor integration .. you need nearly instant feedback.

As done above, I would set requirements for each feature, independently of having it in a IDE. I think that the IDE should be focused on visualization and automatization, no matter if tasks are fast or slow. I.e., I don't like instant linting, but prefer to use a keyboard shortcut to trigger it fast; hence, I am ok with it taking (tens of) seconds.

@flip111
.. feel free to extend this list with more meaningful parser applications (i can list a few more but i wanted to limit this list to the most interesting once for the moment)

If you don't mind, I think it is useful for all of us to have them listed as well. Doing so does not mean we need to integrate them, but allows to have a better big picture. We'll set priorities later, as it seems that each of us is most interested in certain parts of the concept.

@Nic30
duplicate code search
HW regex or query language

IDE

IDE in nodejs

1138-4EB/elide/wiki/IDE-in-nodejs-electron

IDE in browser

1138-4EB/elide/wiki/IDE-in-browser

Visualization modules/plugins

Interactive tree

1138-4EB/elide/wiki/Interactive-tree

(RTL) Schematic view

1138-4EB/elide/wiki/(RTL)-Schematic-view

@Nic30
With mxgraph I did not solve following problems:

  • collapse and open internal structure of components
  • component/path keep out
  • diagrams with cyclic, self reference structures

I tried to use mxgraph json format but I did not found specification of it's json format back in times.

For expansion/collapsing, did you see/use the 'container' blocks? In the example you can find them in the 'Advanced' section of shapes:

mxgraph_example

In the demo above I show some other fancy built-in features:

  • Floating outline view.
  • Optional Page View.
  • Optional grid.
  • Multiple visualization options: colors, line types, etc.
  • Hierarchical navigation as in Simulink. By default it is provided as a submenu in the main bar, but it can be easily added to the contextual (right-click) menu (it's a built-in option).

This last feature is the most interesting to me. Indeed, you can see in the demo that I tried it and forced it to fail by navigating into the container and making the content overflow the original size of the container. This is to show that it is not 'perfect' for our requirements, but it should be relatively easy to fix:

  • Show the limits when navigating inside.
  • Allow overflow and show scroll bars in the container.
  • Make the container fit the size of the content when navigating out.
  • Avoid the container showing the content when it does not fit. Show a placeholder/symbol/warning instead.

@Nic30 when you say that you didn't solve those problems, do you mean that those are not built-in features or that you couldn't dive into the code far enough to get it done?

@Nic30, leaving mxgraph apart, and focusing on your application, which features does it provide? I mean, did you implement every menu and action by hand, or are you using any library? A quick list of features:

  • Dragging.
  • Rotation.
  • Fixed connections.
  • Waypoints.
  • Styles for arrows, blocks, background, text...
  • Zoom.
  • Grid.
  • Outline.
  • Import xml/json.
  • Export to png/gif/jpg/pdf/svg/xml/json.
  • Copy & Paste.
  • Contextual (right-click) menu.
  • Tooltips.
  • Arrange (front/back).
  • Select layout algorithm.
  • Group elements in a container. Remove a container but leave elements connected to external blocks.
  • Hierarchical navigation.
  • Undo/Redo.
  • Add from library/list of shapes/modules.
  • Layers. Useful to add info not present in VHDL sources.

Note that not all of them are required. Indeed, some (such as group/ungrouping) can be difficult to translate to hardware. I am trying to guess which 'graphical edition' features you have implemented already.

Pipeline mapping and Gantt chart visualization

1138-4EB/elide/wiki/Pipeline-mapping-and-Gantt-chart-visualization

Waveform viewer

1138-4EB/elide/wiki/Waveform-viewer

Data flow analysis

1138-4EB/elide/wiki/Data-flow-analysis

Clocking analysis

1138-4EB/elide/wiki/Clocking-analysis

Documentation

1138-4EB/elide/wiki/Documentation

@Nic30
Copy link

Nic30 commented Dec 16, 2017

@1138-4eb , @flip111
I will respond after school projects and exams, my semester requires more time than was expected.

@Paebbels
Copy link
Member

@1138-4eb

pyVHDLParser is also a demonstrator. It's meant to allow easy adding and modification of VHDL language features. If the concepts of pyVHDLParser work out, it's possible to translate them e.g. C# There is no intention to be very fast. Being very fast requires heavy optimizations and thus disallows modifications for future language investigations.

Doxygen and similar documentation tools are not capable of handling the specifics of VHDL. They are limited to classes and methods. You can not transform VHDL to these paradigms. That's why I prefer e.g. Sphinx and Restructure Text. It can be extended to all needs of VHDL.

pyVHDLParser e.g. has an generic and abstract description of language constructs.

Where does that description fit in the flow?

pyVHDLParser provides a CodeDOM (semantic object model). It's a object-oriented model of the VHDL source code. It is not specific to any parser or compiler. Read the articles of Ken Beckett for more information.

If I don't get it wrong, GHDL, and every other 'normal' parser starts at the character level and goes up. Yours starts from the top and goes down to the details. Is it correct?

Yes.

Related to this, do pyVHDLParser and GHDL have any difference/advantage when it comes to recovering analysis?

As far as it feels with GHDL: It stops at the first error. pyVHDLParser is more tolerant, because it analyzes many thing in later steps, while more code was already analysed.

@eine
Copy link
Collaborator Author

eine commented Dec 18, 2017

Doxygen and similar documentation tools are not capable of handling the specifics of VHDL. They are limited to classes and methods. You can not transform VHDL to these paradigms. That's why I prefer e.g. Sphinx and Restructure Text. It can be extended to all needs of VHDL.

I think we are mixing concepts here. There are two different tasks: i) extract comments and metadata from sources and ii) generate a structured document (HTML and/or PDF) with the extracted info.

AFAIK, only Doxygen and similar tools (say VHDocL or gnatdoc) are capable of extracting specially decorated comments from sources. This is true for C-type languages, but also for python and (although buggy) VHDL.

A quite different issue is how to elaborate a HTML site or PDF from text-only structured documents. Sphinx, falls in this group, along with Pandoc, LaTeX, Hugo, Jekyll, wikis... Note that there is no relation to the sources, because text-only structured documents are written and updated manually.

Note: sphinx can behave as doxygen with python sources, which is what it was created for. It has been extended to support other languages, but the list is quite short compared to doxygen.

Then, any of the tools in this last group can be extended to all needs of VHDL, as long as a parser is used to generate intermediate formats (e.g. RestructureText/Markdown). Indeed, because Sphinx is lacking a VHDL domain, extending it is not very different from replacing vhdlparser with a more feature-rich parser.

This parser, say pyVHDLParser, needs some mechanism to decide which comments/components should be rendered in the final report and which are to be shown only in source listings. In the end, some syntax must be defined, which will likely conflict or replicate the conventions used by Doxygen. For example, VHDocL, can parse doxygen markup and come with a conversion script. There is also an extension for Sphinx to identify doxygen comments. What is your approach here?

Again, I think we should take into account in this thread that services as Travis exists, and can be used as a helper or a replacement for RTD. Is it possible for pyVHDLParser to output an intermediate XML instead of rst sources? With an 'XML to rst' parser it would still fit your workflow. At the same time, it would allow not python-limited environments to use different tools for rendering.

@Nic30
Copy link

Nic30 commented Feb 5, 2018

I am back from the dead. Thanks to overloaded semester I now have nearly semester free.
I did start working on netlist query language. I rewrite Nic30/hwtIde to use jgraph/mxgraph as it's dataformat. I have many other works, but first results can appear next week.

@flip111

what information would be most important to you and do you have any ideas to present them in the schematic? Perhaps it would be a nice idea to have a working document.

  • component/process level connections
  • expandable hierarchy
  • operand level connections on lowest level

I will allow to edit hwtIde wiki to all.

@1138-4eb
I have seen you wiki https://github.com/1138-4EB/elide/wiki and I agree with everything.
It may be useful to have edit rights.

Nic30/hwtIde - blocks are just hdl components they can be imported/exported etc.

(RTL) Schematic view - expanding blocks - I do not know if they can have ports but I will find out

when you say that you didn't solve those problems, do you mean that those are not built-in features or that you couldn't dive into the code far enough to get it done?

My worst problem was implementation of alg. for initial layout (place components form HDL somehow to have nice diagram with minimum nets crossing).
Current alg. is A* based, need to be reworked as mentioned, I found a paper which has right. alg. for this. But it is quite complex. (the problem is NP-hard, bit it is more like "NP^3")

For everything else there is JS lib which can do it.

leaving mxgraph apart, and focusing on your application, which features does it provide? I mean, did you implement every menu and action by hand, or are you using any library? A quick list of features:

Dragging.

D3.js

Rotation.

D3.js

Fixed connections.
Waypoints.

all connections are just json, components are placed by A* based alg. to have minimum crossing connections, these connections are just paths between route points rendered by D3.js

Styles for arrows, blocks, background, text...

css

Zoom.

D3.js

Grid.

simple JS

Outline.

D3.js

Import xml/json.

JS native

Export to png/gif/jpg/pdf/svg/xml/json.

in D3.js, not gui accessible yet

Copy & Paste.

simple JS

Contextual (right-click) menu.

none (not useful)

Tooltips.

D3.js plugin

Arrange (front/back).

possible in D3.js, not useful because components should not overlap

Select layout algorithm.

Select is done by D3.js and custom JS, it is easy.

Group elements in a container. Remove a container but leave elements connected to external blocks.

Containers are in very early prototype, renderer is just called on box, there is problem with shared history
and port placement.

Hierarchical navigation.

Done on file-browser level (needs to be on component diagram level)

Undo/Redo.

Done, custom JS, (actually back in time I had to completely rewrite IDE to support this)

Add from library/list of shapes/modules.

Modules are loaded from HDL or can be crafted in GUI, only rectangle shapes yet.

Layers. Useful to add info not present in VHDL sources.

Maybe it would be better to support only hierarchy based layers to keep things simple.

Also wires looks like good start.

@flip111
Copy link
Contributor

flip111 commented Feb 5, 2018

I found a paper which has right. alg. for this

care to link your source? Or are you referring to the paper from before?

@Nic30
Copy link

Nic30 commented Feb 6, 2018

@flip111
Yes, I was writing about algs. from http://rtsys.informatik.uni-kiel.de/%7Ebiblio/downloads/theses/msp-dt.pdf
(I did not found anything better.)

@eine
Copy link
Collaborator Author

eine commented Apr 10, 2018

I created a new repository a couple of days ago, where we can share/integrate the proofs of concept: https://github.com/1138-4EB/hwd-ide It started as a copy of the develop branch and the wiki of 1138-4EB/elide, but I thought it'd be better to use a new repo, because I have some personal unrelated content there. Now we can adapt/reorganize the content to fit the needs of different proofs.

@Nic30 and @flip111 were already added as collaborators. If any other wants to contribute, please let us know.

The wiki is public, so that anyone can contribute. Indeed, a couple of days ago @Paebbels also created awesome-vhdl. I believe that some of the references in the wiki might be moved there. The same applies to many resources mentioned in this issue. However, I am not sure about the "awesomeness" of all of them, since many are not under active development. @Paebbels, do you think that it would be interesting to add not active/complete projects to the awesome list? I would try to avoid mixing "really awesome" and "not so awesome, but really interesting" efforts, but I think it'd be required to somehow state the status/issues.


Right now, there is a single proof of concept that integrates filebrowser/filebrowser with ghdl/ext:vunit and ghdl/ext:vunit-gtkwave (see #477). This is a very basic web-based editor with GHDL, VUnit and (optional) GtkWave in the backend.

Travis CI is set up to execute two stages after each push to branch develop:

It is ready to start trying to put other stuff together!


I believe we can move the conversation here to the new repo. That way, we will produce less "noise" here, and we'll bother Tristan only when we need something related to GHDL. Feel free to open as many issues as you want, as we've talked about many different features.

PS: @flip111, @Nic30, I think that all the references here are already present in the wiki of the new repo, but don't hesitate to add any you might miss.

@kraigher
Copy link
Contributor

kraigher commented Nov 8, 2018

Regarding VHDL parser I have created a new parser project which might be of interest.
https://github.com/kraigher/rust_hdl

The current status is that a lot VHDL-2008 is parsed, enough to parse (VUnit, PoC, UVVM, OSVVM).
Good performance, it can parse 200k lines of code in 200 ms on my laptop which is 39 MB/s of parsing throughput.

@Nic30
Copy link

Nic30 commented Nov 8, 2018

@kraigher Good. Can you also setup ci (https://travis-ci.com/ etc.) and write some examples? I had 3min and I did not figure out how to use it.

@kraigher
Copy link
Contributor

kraigher commented Nov 8, 2018

@Nic30 I updated the readme on how to try it out. I will add CI soon.

@kraigher
Copy link
Contributor

kraigher commented Nov 8, 2018

@Nic30 You can also join the gitter channel https://gitter.im/rust_hdl/Lobby to ask questions and get support.

@kraigher
Copy link
Contributor

kraigher commented Nov 8, 2018

@Nic30 Now there is Travis CI as well.

@flip111
Copy link
Contributor

flip111 commented Nov 9, 2018

@kraigher what data structures are you using for symbol table?

@kraigher
Copy link
Contributor

kraigher commented Nov 9, 2018

@flip111 A hash table from name to unique_id. Since VHDL is case insensitive symbols that differ only in case get the same id. The id can be used for fast comparison.

The code is here:
https://github.com/kraigher/rust_hdl/blob/master/vhdl_parser/src/symbol_table.rs

@flip111
Copy link
Contributor

flip111 commented Nov 9, 2018

@kraigher i read elsewhere on the interwebz that vhdl is case insensitive so i don't doubt you about it, but i was curious how it was actually described in the standard. I had a quick look in the 1993 and 2008 standard but i couldn't find it, do you know? Perhaps it might just be so that people think VHDL is case insensitive because a lot of compilers are but it's not defined by the standard. Also with extended_identifier it seems strange to me if it were case insensitive because this is the special case of identifiers in which special characters can be used. So in this case it might also be interesting for the user to differentiate between lowercase and uppercase.

Is it already possible with the parser to lookup symbols from different scopes ?

@kraigher
Copy link
Contributor

kraigher commented Nov 9, 2018

@flip111
The parser currently only does the parsing into an AST. Semantic analysis is the next step and then symbol references will be resolved.

Regarding case in-sensitivity the standard does not use this terminology but rather say:

LRM 15.4.2 Basic identifiers

Basic identifiers differing only in the use of corresponding uppercase
and lowercase letters are considered the same.

Also regarding keywords

NOTE 1—Reserved words differing only in the use of corresponding uppercase and lowercase letters are considered as
the same (see 15.4.2)

LRM 15.4.3 Extended identifiers

Extended identifiers differing only in the use of corresponding uppercase and lowercase letters are distinct.
Moreover, every extended identifier is distinct from any basic identifier.
and lowercase letters are considered the same.

So normal identifiers are case insensitive but extended identifiers are not.
I currently treat extended identifiers as case in-sensitive so that is a bug. Good that you asked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants