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

Provide initial skeleton for libghdl documentation. #1445

Closed
wants to merge 0 commits into from

Conversation

m-kru
Copy link
Contributor

@m-kru m-kru commented Aug 25, 2020

Reopen of #1441

@eine eine added Documentation: General General documentation issues. Documentation: Restructured Text Related to documentation written in Restructured Text (ReST). Interface: Python Question labels Aug 25, 2020
@eine
Copy link
Collaborator

eine commented Aug 25, 2020

FTR, I believe this is the most simple (and single) example available using libghdl: https://github.com/ghdl/ghdl/tree/master/testsuite/python/units01

AST Traversing
##############

If someone wants to use `libghdl`, then he probably wants to know how to traverse the AST to get the information about nodes of design units.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are examples of traverse functions in pyutils.py. The function nodes_iter is a visitor on all nodes, while declarations_iter and concurrent_stmts_iter are more selective.

##############

If someone wants to use `libghdl`, then he probably wants to know how to traverse the AST to get the information about nodes of design units.
It would be really nice to provide an example showing how to traverse the tree.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a look at vhdl_langserver/symbols.py to see how symbols are gathered from a vhdl file. Or references.py.

In the `vhdl_ls` Load_File function is used to parse the file and get the tree root.
The return value is an integer.

* What does this integer represent?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not an integer, but a reference to a node (which is an index so indeed an integer). In Ada the fact that this is an integer is almost hidden, but that is clear in the low-level binding. (Hence a reason why we should have a high-level and more pythonic API).

The value, if not null, represents an Iir_Kind_Design_File.

The return value is an integer.

* What does this integer represent?
* How to use this integer to traverse the AST and get information about nodes?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can call the various iterators defined in pyutils.py


To be able to use `libghdl`, it first must be initialized.

* Why does it must be initialized?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many data that must be set up, like the name table. You cannot do anything useful without it. And then there are also some higher levels constructs that should also be initialized, like the content of the ieee library.


* Why does it must be initialized?
* What does the initialization do?
* Is there any use case where someone would want to use libghdl without initialization?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think so.

* Why does it must be initialized?
* What does the initialization do?
* Is there any use case where someone would want to use libghdl without initialization?
* If no, then why it does not initialize itself automatically?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One reason is because it is a low-level binding. The other reason is because some initialization (like which ieee library is loaded) depends on some options.


.. code-block:: python

libghdl.libghdl_init()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one does Ada elaboration. Nothing visible and could be automatic (but that would make the build infrastructure more complex).

.. code-block:: python

libghdl.libghdl_init()
libghdl.libghdl__set_hooks_for_analysis()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, it defines the back-end, which is invoked when a unit is analyzed.


# Set the prefix in order to locate the vhdl libraries.
libghdl.libghdl__set_exec_prefix(
*_to_char_p(dirname(dirname(_libghdl_path)).encode('utf-8')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the comment is not clear enough, please tell me.

But this is 'just' the start of the initialization. If you look at vhdl_langsever/workspace.py you will see the remaining (in __init__):

  • redirecting errors
  • setting flags and options
  • end of initialization (load libraries).


Here we should write superficially how `libghdl` works.

* Does it return structures such as AST to the calling code, or does it store them internally?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AST are always internally stored. The reason is that a unit may reference another unit.
At some point, we may want to introduce a notion of context that would contain all the global variables.

Here we should write superficially how `libghdl` works.

* Does it return structures such as AST to the calling code, or does it store them internally?
* Is it thread safe?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No!

@eine
Copy link
Collaborator

eine commented Oct 19, 2020

@m-kru, did you close this on purpose? Or was it an undesired effect of updating your master branch?

@m-kru
Copy link
Contributor Author

m-kru commented Oct 19, 2020

@eine ehhh, again undesired effect.

@eine
Copy link
Collaborator

eine commented Oct 19, 2020

Do you know how to get it back? git checkout -b doc/libghdl cc416a50e817fbdaaa5579420051dffa258a40bf might work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: General General documentation issues. Documentation: Restructured Text Related to documentation written in Restructured Text (ReST). Interface: Python Question
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants