Skip to content

Commit fb024c4

Browse files
authored
Merge pull request #5135 from YosysHQ/emil/ast-ownership
ast, read_verilog: ownership in AST, use C++ styles for parser and lexer
2 parents 407d425 + 642e041 commit fb024c4

28 files changed

+3720
-3639
lines changed

.github/actions/setup-build-env/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ runs:
88
shell: bash
99
run: |
1010
sudo apt-get update
11-
sudo apt-get install gperf build-essential bison flex libreadline-dev gawk tcl-dev libffi-dev git graphviz xdot pkg-config python3 libboost-system-dev libboost-python-dev libboost-filesystem-dev zlib1g-dev libbz2-dev
11+
sudo apt-get install gperf build-essential bison flex libfl-dev libreadline-dev gawk tcl-dev libffi-dev git graphviz xdot pkg-config python3 libboost-system-dev libboost-python-dev libboost-filesystem-dev zlib1g-dev libbz2-dev
1212
1313
- name: Install macOS Dependencies
1414
if: runner.os == 'macOS'

.github/workflows/extra-builds.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ jobs:
2727
with:
2828
submodules: true
2929
persist-credentials: false
30+
- run: sudo apt-get install libfl-dev
3031
- name: Build
3132
run: make vcxsrc YOSYS_VER=latest
3233
- uses: actions/upload-artifact@v4
3334
with:
3435
name: vcxsrc
3536
path: yosys-win32-vcxsrc-latest.zip
36-
37+
3738
vs-build:
3839
name: Visual Studio build
3940
runs-on: windows-latest
4041
needs: [vs-prep, pre_job]
4142
if: needs.pre_job.outputs.should_skip != 'true'
42-
steps:
43+
steps:
4344
- uses: actions/download-artifact@v4
4445
with:
4546
name: vcxsrc
@@ -68,9 +69,20 @@ jobs:
6869
WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz
6970
if ! [ -d ${WASI_SDK} ]; then curl -L ${WASI_SDK_URL} | tar xzf -; fi
7071
72+
FLEX_VER=2.6.4
73+
FLEX=flex-${FLEX_VER}
74+
FLEX_URL=https://github.com/westes/flex/releases/download/v${FLEX_VER}/${FLEX}.tar.gz
75+
if ! [ -d ${FLEX} ]; then curl -L ${FLEX_URL} | tar xzf -; fi
76+
77+
mkdir -p flex-build
78+
(cd flex-build &&
79+
../${FLEX}/configure --prefix=$(pwd)/../flex-prefix &&
80+
make &&
81+
make install)
82+
7183
mkdir -p build
7284
cat > build/Makefile.conf <<END
73-
export PATH := $(pwd)/${WASI_SDK}/bin:${PATH}
85+
export PATH := $(pwd)/${WASI_SDK}/bin:$(pwd)/flex-prefix/bin:${PATH}
7486
WASI_SYSROOT := $(pwd)/${WASI_SDK}/share/wasi-sysroot
7587
7688
CONFIG := wasi
@@ -80,6 +92,8 @@ jobs:
8092
ENABLE_READLINE := 0
8193
ENABLE_PLUGINS := 0
8294
ENABLE_ZLIB := 0
95+
96+
CXXFLAGS += -I$(pwd)/flex-prefix/include
8397
END
8498
8599
make -C build -f ../Makefile CXX=clang -j$(nproc)

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ ifeq ($(ENABLE_PYOSYS),1)
132132
CXXFLAGS += -I$(BREW_PREFIX)/boost/include
133133
LINKFLAGS += -L$(BREW_PREFIX)/boost/lib -L$(BREW_PREFIX)/boost-python3/lib
134134
endif
135-
CXXFLAGS += -I$(BREW_PREFIX)/readline/include
136-
LINKFLAGS += -L$(BREW_PREFIX)/readline/lib
135+
CXXFLAGS += -I$(BREW_PREFIX)/readline/include -I$(BREW_PREFIX)/flex/include
136+
LINKFLAGS += -L$(BREW_PREFIX)/readline/lib -L$(BREW_PREFIX)/flex/lib
137137
PKG_CONFIG_PATH := $(BREW_PREFIX)/libffi/lib/pkgconfig:$(PKG_CONFIG_PATH)
138138
PKG_CONFIG_PATH := $(BREW_PREFIX)/tcl-tk/lib/pkgconfig:$(PKG_CONFIG_PATH)
139139
export PATH := $(BREW_PREFIX)/bison/bin:$(BREW_PREFIX)/gettext/bin:$(BREW_PREFIX)/flex/bin:$(PATH)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ recommended) and some standard tools such as GNU Flex, GNU Bison, and GNU Make.
8080
TCL, readline and libffi are optional (see ``ENABLE_*`` settings in Makefile).
8181
Xdot (graphviz) is used by the ``show`` command in yosys to display schematics.
8282

83-
For example on Ubuntu Linux 16.04 LTS the following commands will install all
83+
For example on Ubuntu Linux 22.04 LTS the following commands will install all
8484
prerequisites for building yosys:
8585

86-
$ sudo apt-get install build-essential clang lld bison flex \
86+
$ sudo apt-get install build-essential clang lld bison flex libfl-dev \
8787
libreadline-dev gawk tcl-dev libffi-dev git \
8888
graphviz xdot pkg-config python3 libboost-system-dev \
8989
libboost-python-dev libboost-filesystem-dev zlib1g-dev

docs/source/getting_started/installation.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ Build prerequisites
8888
^^^^^^^^^^^^^^^^^^^
8989

9090
A C++ compiler with C++17 support is required as well as some standard tools
91-
such as GNU Flex, GNU Bison, Make and Python. Some additional tools: readline,
92-
libffi, Tcl and zlib; are optional but enabled by default (see
91+
such as GNU Flex, GNU Bison (>=3.8), Make, and Python (>=3.11). Some additional
92+
tools: readline, libffi, Tcl and zlib; are optional but enabled by default (see
9393
:makevar:`ENABLE_*` settings in Makefile). Graphviz and Xdot are used by the
9494
`show` command to display schematics.
9595

96-
Installing all prerequisites for Ubuntu 20.04:
96+
Installing all prerequisites for Ubuntu 22.04:
9797

9898
.. code:: console
9999
100-
sudo apt-get install gperf build-essential bison flex \
101-
libreadline-dev gawk tcl-dev libffi-dev git graphviz \
102-
xdot pkg-config python3 libboost-system-dev \
100+
sudo apt-get install gperf build-essential clang lld bison flex libfl-dev \
101+
libreadline-dev gawk tcl-dev libffi-dev git \
102+
graphviz xdot pkg-config python3 libboost-system-dev \
103103
libboost-python-dev libboost-filesystem-dev zlib1g-dev
104104
105105
Installing all prerequisites for macOS 13 (with Homebrew):
@@ -137,8 +137,9 @@ For Cygwin use the following command to install all prerequisites, or select the
137137
minimum required version of Python is 3.11. This means that Cygwin is not
138138
compatible with many of the Python-based frontends. While this does not
139139
currently prevent Yosys itself from working, no guarantees are made for
140-
continued support. It is instead recommended to use Windows Subsystem for
141-
Linux (WSL) and follow the instructions for Ubuntu.
140+
continued support. You may also need to specify `CXXSTD=gnu++17` to resolve
141+
missing `strdup` function when using gcc. It is instead recommended to use
142+
Windows Subsystem for Linux (WSL) and follow the instructions for Ubuntu.
142143

143144
..
144145
For MSYS2 (MINGW64):

docs/source/yosys_internals/flow/verilog_frontend.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ be found in :file:`frontends/verilog/verilog_lexer.l` in the Yosys source tree.
4747
The lexer does little more than identifying all keywords and literals recognised
4848
by the Yosys Verilog frontend.
4949

50-
The lexer keeps track of the current location in the Verilog source code using
51-
some global variables. These variables are used by the constructor of AST nodes
52-
to annotate each node with the source code location it originated from.
50+
The lexer keeps track of the current location in the Verilog source code with
51+
a ``VerilogLexer::out_loc`` and uses it to construct parser-defined
52+
symbol objects.
5353

5454
Finally the lexer identifies and handles special comments such as "``// synopsys
5555
translate_off``" and "``// synopsys full_case``". (It is recommended to use
@@ -178,21 +178,22 @@ properties:
178178
179179
- | Source code location
180180
| Each ``AST::AstNode`` is automatically annotated with the current source
181-
code location by the ``AST::AstNode`` constructor. It is stored in the
182-
``std::string filename`` and ``int linenum`` member variables.
181+
code location by the ``AST::AstNode`` constructor. The ``location`` type
182+
is a manual reimplementation of the bison-provided location type. This
183+
type is defined at ``frontends/verilog/verilog_location.h``.
183184
184-
The ``AST::AstNode`` constructor can be called with up to two child nodes that
185-
are automatically added to the list of child nodes for the new object. This
185+
The ``AST::AstNode`` constructor can be called with up to 4 child nodes. This
186186
simplifies the creation of AST nodes for simple expressions a bit. For example
187187
the bison code for parsing multiplications:
188188

189189
.. code:: none
190-
:number-lines:
190+
:number-lines:
191191
192-
basic_expr '*' attr basic_expr {
193-
$$ = new AstNode(AST_MUL, $1, $4);
194-
append_attr($$, $3);
195-
} |
192+
basic_expr TOK_ASTER attr basic_expr {
193+
$$ = std::make_unique<AstNode>(AST_MUL, std::move($1), std::move($4));
194+
SET_AST_NODE_LOC($$.get(), @1, @4);
195+
append_attr($$.get(), $3);
196+
} |
196197
197198
The generated AST data structure is then passed directly to the AST frontend
198199
that performs the actual conversion to RTLIL.
@@ -204,7 +205,7 @@ tree respectively.
204205
Transforming AST to RTLIL
205206
-------------------------
206207

207-
The AST Frontend converts a set of modules in AST representation to modules in
208+
The AST frontend converts a set of modules in AST representation to modules in
208209
RTLIL representation and adds them to the current design. This is done in two
209210
steps: simplification and RTLIL generation.
210211

0 commit comments

Comments
 (0)