Skip to content

Commit

Permalink
Merge pull request #5 from benoitdenkinger/doc_update
Browse files Browse the repository at this point in the history
HAL C++ implementation and documentation update
  • Loading branch information
Risto97 authored Apr 6, 2024
2 parents 1ee34dc + bd61e7e commit 755c68a
Show file tree
Hide file tree
Showing 55 changed files with 28,787 additions and 11,156 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ instance/
.scrapy

# Sphinx documentation
docs/_build/
docs/*build
docs/deps/_deps

# PyBuilder
.pybuilder/
Expand All @@ -82,6 +83,9 @@ target/
profile_default/
ipython_config.py

# VS code
.vscode

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ It is based on C++ 17<br/>

#### For installation instruction click [here](https://risto97.github.io/PeakRDL-halcpp/docs/getting_started/installation).
#### For an instruction on how to run a simple example click [here](https://risto97.github.io/PeakRDL-halcpp/docs/getting_started/example)

93 changes: 93 additions & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

cmake_minimum_required(VERSION 3.25)

project(PeakRDL-halcpp-Documentation
VERSION 0.4.0
)

# This is needed to create the python venv for CMinx
include("deps/deps.cmake")

find_program(
SPHINX_APIDOC
NAMES sphinx-apidoc
HINTS ${Python3_VIRTUAL_ENV}/bin
REQUIRED
)
# This prints a message saying the executables are found
include(FindPackageHandleStandardArgs)
# find_package_handle_standard_args(Sphinx-build DEFAULT_MSG SPHINX_BUILD)
find_package_handle_standard_args(Sphinx-apidoc DEFAULT_MSG SPHINX_APIDOC)


# Create the API documentation target
set(API_DOC_INPUT_DIR "${PROJECT_SOURCE_DIR}/../src/")
set(API_SPHINX_SRC_DIR "${PROJECT_BINARY_DIR}/api/sphinx_docs/")
set(API_SPHINX_BUILD_DIR "${API_SPHINX_SRC_DIR}/_build/")
# Default location in conf.py
set(SPHINX_TMPL_DIR "${API_SPHINX_SRC_DIR}/_templates/")

# Sphinx is used to convert PeakRDL-halcpp method comments into rST format later transformed to a
# static html documentation using again sphinx
set(API_DOC_RST_CMD ${SPHINX_APIDOC} --full --module-first -a -H ${PROJECT_NAME} -A CERN -R ${PROJECT_VERSION} --templatedir=${SPHINX_TMPL_DIR} -o ${API_SPHINX_SRC_DIR} ${API_DOC_INPUT_DIR})
# This command trigger the rST to html conversion (internally using sphinx-build command)
set(API_DOC_HTML_CMD make -C ${API_SPHINX_SRC_DIR} html)
# This file creates an automatic triggering for the documentation update
set(API_INDEX_HTML_FILE "${API_SPHINX_BUILD_DIR}/html/index.html")

add_custom_command(
OUTPUT ${API_SPHINX_SRC_DIR}
COMMAND "${CMAKE_COMMAND}" -E make_directory "${API_SPHINX_SRC_DIR}"
COMMENT "Create documentation output directory."
)

add_custom_command(
OUTPUT ${API_INDEX_HTML_FILE}
COMMAND ${API_DOC_RST_CMD}
COMMAND ${API_DOC_HTML_CMD}
DEPENDS ${API_SPHINX_SRC_DIR}
COMMENT "Generating the PeakRDL-halcpp API rST documentation."
)
# This will trigger the above command through the dependency
add_custom_target(
api_doc
DEPENDS ${API_INDEX_HTML_FILE}
)

# Generated files based on cmake configuration/template file (.in files)
# Only @MY_VAR@ format is replaced to avoid replacing structure like ${MY_VAR} which are used in other
# languages or file format (e.g., in Makefiles).
configure_file(${PROJECT_SOURCE_DIR}/sphinx_config/conf.py.in ${SPHINX_TMPL_DIR}/conf.py_t @ONLY)

# This template is not used by sphinx-apidoc for unknwown reason so it is also copied directly to
# the source file. No change is expected from sphinx-apidoc as cmake already takes care of this.
configure_file(${PROJECT_SOURCE_DIR}/sphinx_config/Makefile.in ${SPHINX_TMPL_DIR}/Makefile_t @ONLY)
configure_file(${PROJECT_SOURCE_DIR}/sphinx_config/Makefile.in ${API_SPHINX_SRC_DIR}/Makefile @ONLY)

# Now build the docusaurus documentation using npm
find_program(NPM_EXECUTABLE npm)
find_package_handle_standard_args(npm DEFAULT_MSG NPM_EXECUTABLE)

set(DOCUSAURUS_OUT_DIR ${PROJECT_BINARY_DIR}/docusaurus)
file(MAKE_DIRECTORY ${DOCUSAURUS_OUT_DIR})
set(DOCUSAURUS_STAMP_FILE ${DOCUSAURUS_OUT_DIR}/stamp.stamp)
add_custom_command(
OUTPUT ${DOCUSAURUS_STAMP_FILE}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND touch ${DOCUSAURUS_STAMP_FILE}
COMMAND ${NPM_EXECUTABLE} install docusaurus
COMMAND ${NPM_EXECUTABLE} run build ${PROJECT_SOURCE_DIR} -- --out-dir ${DOCUSAURUS_OUT_DIR}
COMMAND cp -r ${API_SPHINX_BUILD_DIR}/html ${DOCUSAURUS_OUT_DIR}/api_html
# API static html is copied and added as a simple link (didn't find a nicer solution yet)
DEPENDS api_doc
COMMENT "Installing and Building Docusaurus"
)
add_custom_target(docusaurus_doc
DEPENDS ${DOCUSAURUS_STAMP_FILE}
COMMENT "Installing and Building Docusaurus"
)

add_custom_target(docusaurus_start
DEPENDS docusaurus_doc
COMMAND ${NPM_EXECUTABLE} run serve ${PROJECT_SOURCE_DIR} -- --dir ${DOCUSAURUS_OUT_DIR}
)
26 changes: 26 additions & 0 deletions docs/api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Generate the html static documention with sphinx from the rST files generated with cminx and copy
# them to the static folder used by docusaurus.
html_api: html
cp -r build/html/* ../static/api_html/
.PHONY: html_api

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20 changes: 20 additions & 0 deletions docs/api/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = @DOC_OUTPUT_DIR@
BUILDDIR = @HTML_SPHINX_OUTPUT_DIR@

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
71 changes: 71 additions & 0 deletions docs/api/conf.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join('..', '..', 'src')))
print(os.path.abspath(os.path.join('..', '..', 'src')))

# -- Project information -----------------------------------------------------

project = 'PeakRDL-halcpp'
copyright = '2024, CERN'
author = 'CERN'

# The full version, including alpha/beta/rc tags
release = '@PROJECT_VERSION@'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx.ext.graphviz',
'sphinx.ext.inheritance_diagram',
]

inheritance_node_attrs = dict(
color='"#6AB0DE"',
fillcolor='"#E7F2FA"',
style='"rounded, filled"'
)

inheritance_graph_attrs = dict(rankdir="TB")

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
# 'include',
# 'templates'
]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
7 changes: 7 additions & 0 deletions docs/deps/deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Options for the virtual env creation
option(UPDATE_PYTHON_DEPS "Force update dependencies" OFF)
option(DEPS_USE_VENV "Create a Python virtual environment and install dependencies locally" ON)
option(UPDATE_DEPS "Update all of the dependencies, CPM packages and Python" OFF)
# This script creates the virtual env if it is not existing
include("${CMAKE_CURRENT_LIST_DIR}/venv.cmake")
3 changes: 3 additions & 0 deletions docs/deps/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx==7.2.6
sphinx-rtd-theme==2.0.0
systemrdl-compiler==1.27.3
40 changes: 40 additions & 0 deletions docs/deps/venv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
if(DEPS_USE_VENV)
# Create the python virtual environment if not already done
# Set an environment variable as activating a virtual env would do
set(ENV{VIRTUAL_ENV} "${CMAKE_CURRENT_LIST_DIR}/_deps/venv")
# The previous coommand tricks find_package() to look for a python interpreter under the
# VIRUTAL_ENV path. Note that if the venv is deleted, the Python3_EXECUTABLE is still cached so it
# generates an error (in this case delete the CMakeCache.txt)
find_package(Python3 COMPONENTS Interpreter)
# Check if the virtual env path is inside the found python3 executable
string(FIND "${Python3_EXECUTABLE}" $ENV{VIRTUAL_ENV}/bin/python IN_VENV)
if(NOT IN_VENV EQUAL 0)
# If no venv exist, create one
execute_process (COMMAND "${Python3_EXECUTABLE}" -m venv "${CMAKE_CURRENT_LIST_DIR}/_deps/venv")
# The virtual environment is used before any other standard paths to look-up for the interpreter
set(Python3_FIND_VIRTUALENV FIRST)
# Remove the python executable to search for the venv one
unset(Python3_EXECUTABLE)
find_package (Python3 COMPONENTS Interpreter)
# For the update of the deps for a newly created venv
set(__UPDATE_PYTHON_DEPS TRUE)
endif()

# Cache the string for simpler access (this causes the problem above, so maybe it is not the best)
set(Python3_EXECUTABLE ${Python3_EXECUTABLE} CACHE STRING "Python3_EXECUTABLE")
# Cache the virtual env path to use package more easily
set(Python3_VIRTUAL_ENV $ENV{VIRTUAL_ENV} CACHE STRING "Python3_VIRTUAL_ENV")

# If requested by the user or the script, update the deps
if((NOT DEFINED UPDATE_PYTHON_DEPS) OR UPDATE_PYTHON_DEPS OR __UPDATE_PYTHON_DEPS OR UPDATE_DEPS)
execute_process(COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade pip)
execute_process(COMMAND ${Python3_EXECUTABLE} -m pip install -r ${CMAKE_CURRENT_LIST_DIR}/requirements.txt)
# Disable and unset the triggering variables otherwise it will always be executed
set(UPDATE_PYTHON_DEPS OFF CACHE STRING "Force update python dependencies")
# Is this really needed?
unset(__UPDATE_PYTHON_DEPS)
endif()
else()
# Use the global python installation
find_package (Python3 COMPONENTS Interpreter)
endif()
8 changes: 8 additions & 0 deletions docs/docs/api_documentation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
sidebar_position: 2
---

# API documentation

*LINK TO BE ADDED*

9 changes: 4 additions & 5 deletions docs/docs/getting_started/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar_position: 3
```
peakrdl halcpp [-h] [-I INCDIR] [-t TOP] [--rename INST_NAME]
[-P PARAMETER=VALUE] -o OUTPUT [--ext [EXT [EXT ...]]]
[--list-files] [--keep-buses] [-f FILE] [--peakrdl-cfg CFG]
[--list-files] [--skip-buses] [-f FILE] [--peakrdl-cfg CFG]
FILE [FILE ...]
```

Expand All @@ -27,7 +27,7 @@ peakrdl halcpp [-h] [-I INCDIR] [-t TOP] [--rename INST_NAME]
|[`-o`](#_o) |Option | 1|exporter args |
|[`--ext`](#__ext) |Option |* |exporter args |
|[`--list-files`](#__list_files) |Option | 0|exporter args |
|[`--keep-buses`](#__keep_buses) |Option | 0|exporter args |
|[`--skip-buses`](#__skip_buses) |Option | 0|exporter args |


### `-h` `--help` {#_h___help}
Expand Down Expand Up @@ -70,8 +70,7 @@ list of addrmap modules that have implemented {name}_EXT class in {name}_ext.h h

Dont generate files, but instead just list the files that will be generated, and external files that need to be included

### `--keep-buses` {#__keep_buses}

If there is an addrmap containing only addrmaps, not registers, by default it will be ommited in hierarchy, it is possible to keep it by passing --keep-buses flag
### `--skip-buses` {#__skip_buses}

By default the SystemRDL hierarchy is preserved but it can be simplified by removing buses (i.e., addrmap containing only addrmaps, not registers). This is achieved by passing the --skip-buses flag.

1 change: 1 addition & 0 deletions docs/docs/hierarchy/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ They can be found in [src/include](https://github.com/Risto97/PeakRDL-halcpp/tre

There you can find the following base template classes:
* [AddrmapNode](/docs/hierarchy/nodes/addrmap)
* [RegfileNode](/docs/hierarchy/nodes/regfile)
* [RegNode](/docs/hierarchy/nodes/reg)
* [FieldNode](/docs/hierarchy/nodes/field)
* [MemNode](/docs/hierarchy/nodes/mem)
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/hierarchy/nodes/addrmap/addrmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 4
# AddrmapNode

`AddrmapNode` is a template class that represents an `addrmap` component in SystemRDL.<br/>
`AddrmapNode` can contain `RegNodes`, `MemNodes`, `RegFileNodes` (TODO) and other `AddrmapNodes`, but `AddrmapNode` can only be contained within another `AddrmapNode` or can be a top `AddrmapNode`.
`AddrmapNode` can contain `RegNodes`, `MemNodes`, `RegFileNodes` and other `AddrmapNodes`, but an `AddrmapNode` can only be contained within another `AddrmapNode` or can be a top `AddrmapNode`.

## `AddrmapNode`

Expand All @@ -16,7 +16,7 @@ The following template is a general `AddrmapNode` which expect to be contained w
In case of `read`, `write` requests to this node, the requests will be forwarded to the containing node, as this node does not implement memory IO operations.

This template expects 2 parameters:
* `BASE` is a address offset within containing `AddrmapNode`.
* `BASE` is an address offset within containing `AddrmapNode`.
* `PARENT_TYPE` is a type of the parent `AddrmapNode`, a specialization of the `AddrmapNode` where `PARENT_TYPE==void` is provided [below](#top_addrmap).

```cpp
Expand All @@ -37,5 +37,5 @@ class AddrmapNode <BASE, void> : public ArchIoNode;
As you can see it is a specialization of `AddrmapNode` where the `PARENT_TYPE==void`.
The `BASE` parameter is the same.
An addition here is that it inherits an [`ArchIoNode`](/docs/hierarchy/nodes/arch_io), which is a class that provides memory IO operations of the platform.<br/>
In addition, the top `AddrmapNode` inherits an [`ArchIoNode`](/docs/hierarchy/nodes/arch_io), which is a class that provides memory IO operations of the platform.<br/>
`ArchIoNode` is expected to implement `write32()` and `read32()` methods.
4 changes: 2 additions & 2 deletions docs/docs/hierarchy/nodes/arch_io/arch_io.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The default node provides a typical memory IO operations for a CPU.
However it is possible to override this node in cases of:
* Using generated halcpp drivers as a `UVM-RAL` for `SystemC-UVM` or `C++` testbenches.
* For debugging, where you might want to replace memory IO with console prints
* For Emulation, where you might want to model memory IO operations its side effects in the platform.
* For Emulation, where you might want to model memory IO operations and side effects in the platform.
* Or Simply if the provided `ArchIoNode` is not adequate.

## Overriding `ArchIoNode`
Expand All @@ -32,4 +32,4 @@ public:
```
The easiest solution is to define macro `_ARCH_IO_H_` before including the HAL driver header file (in this case `soc_hal.h`).
After that you need to provide your custom implemetnation for ArchIoNode.
After that you need to provide your custom implementation for ArchIoNode.
Loading

0 comments on commit 755c68a

Please sign in to comment.