Skip to content

Commit 3ad299e

Browse files
Merge pull request #3181 from verilog-to-routing/synlig_to_yosys_slang
Switching from Synlig to Yosys-Slang
2 parents bf921db + 3b2c0a8 commit 3ad299e

File tree

22 files changed

+226
-154
lines changed

22 files changed

+226
-154
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ jobs:
311311
name: 'Strong',
312312
suite: 'vtr_reg_strong'
313313
},
314+
{
315+
name: 'SystemVerilog',
316+
suite: 'vtr_reg_system_verilog'
317+
},
314318
{
315319
name: 'Valgrind Memory',
316320
suite: 'vtr_reg_valgrind_small'

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "libs/EXTERNAL/yosys"]
1414
path = libs/EXTERNAL/yosys
1515
url = https://github.com/YosysHQ/yosys.git
16+
[submodule "libs/EXTERNAL/yosys-slang"]
17+
path = libs/EXTERNAL/yosys-slang
18+
url = https://github.com/povik/yosys-slang.git

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ option(ODIN_SANITIZE "Enable building odin with sanitize flags" OFF)
5656

5757
# Allow the user to enable building Yosys
5858
option(WITH_PARMYS "Enable Yosys as elaborator and parmys-plugin as partial mapper" ON)
59-
option(SYNLIG_SYSTEMVERILOG "Enable building and installing Synlig SystemVerilog and UHDM plugins" OFF)
59+
option(SLANG_SYSTEMVERILOG "Enable building and installing Yosys-Slang plugin for parsing SystemVerilog" ON)
6060

6161
set(VTR_VERSION_MAJOR 9)
6262
set(VTR_VERSION_MINOR 0)
@@ -437,11 +437,12 @@ if(${WITH_ODIN})
437437
endif()
438438
endif()
439439

440-
# handle cmake params to compile Yosys SystemVerilog/UHDM plugins
441-
if(${SYNLIG_SYSTEMVERILOG})
442-
# avoid compiling plugins in case the Parmys frontend is not active
440+
# handle cmake params to compile yosys-slang plugin for Yosys
441+
if(${SLANG_SYSTEMVERILOG})
442+
# avoid compiling yosys-slang plugin in case the Parmys frontend is not active
443443
if(NOT ${WITH_PARMYS})
444-
message(SEND_ERROR "Utilizing SystemVerilog/UHDM plugins requires activating Parmys frontend. Please set WITH_PARMYS.")
444+
message(WARNING "Parmys is not enabled, disabling Yosys-Slang as well.")
445+
set(SLANG_SYSTEMVERILOG OFF)
445446
endif()
446447
endif()
447448

dev/vtr_test_suite_verifier/test_suites_info.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"name": "parmys_reg_basic",
1212
"ignored_tasks": []
1313
},
14+
{
15+
"name": "vtr_reg_system_verilog",
16+
"ignored_tasks": []
17+
},
1418
{
1519
"name": "vtr_reg_valgrind_small",
1620
"ignored_tasks": []

doc/src/vtr/run_vtr_flow.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,12 @@ The parser for these runs is considered the Yosys conventional Verilog/SystemVer
7373

7474
.. code-block:: bash
7575
76-
# Using the Synlig System_Verilog tool if installed, otherwise the Yosys conventional Verilog parser
77-
./run_vtr_flow <path/to/SystemVerilog/File> <path/to/arch/file> -parser system-verilog
78-
79-
# Using the Surelog plugin if installed, otherwise failure on the unsupported file type
80-
./run_vtr_flow <path/to/UHDM/File> <path/to/arch/file> -parser surelog
76+
# Using the Yosys-Slang plugin for Yosys, otherwise the Yosys conventional Verilog parser
77+
./run_vtr_flow <path/to/SystemVerilog/File> <path/to/arch/file> -parser slang
8178
82-
Running the default VTR flow using the Parmys standalone front-end.
83-
The Synlig HDL parser supports the (i.e., ``read_systemverilog``) and (i.e., ``read_uhdm``) commands. It utilizes Surelog for SystemVerilog 2017 processing and Yosys for synthesis.
84-
Enable Synlig tool with the ``-DSYNLIG_SYSTEMVERILOG=ON`` compile flag for the Parmys front-end.
79+
Will run the VTR flow (default configuration) with Yosys-Slang plugin for Yosys frontend using Parmys plugin as partial mapper.
80+
The Yosys-Slang SystemVerilog parser supports the (i.e., ``read_slang``) command. Yosys-Slang builds on top of the slang library to provide comprehensive SystemVerilog support.
81+
Enable the Yosys-Slang plugin with the ``-DSLANG_SYSTEMVERILOG=ON`` compile flag for the Parmys front-end.
8582

8683
.. code-block:: bash
8784
@@ -260,19 +257,24 @@ Detailed Command-line Options
260257

261258
.. option:: -parser <PARSER>
262259

263-
Specify a parser for the Yosys synthesizer [default (Verilog-2005), surelog (UHDM), system-verilog].
260+
Specify a parser for the Yosys synthesizer [default (Verilog-2005), slang (SystemVerilog)].
264261
The script uses the default conventional Verilog parser if this argument is not used.
265262

266263
**Default:** default
267264

268265
.. note::
269266

270-
Universal Hardware Data Model (UHDM) is a complete modeling of the IEEE SystemVerilog Object Model with VPI Interface, Elaborator, Serialization, Visitor and Listener.
271-
UHDM is used as a compiled interchange format in between SystemVerilog tools. Typical inputs to the UHDM flow are files with ``.v`` or ``.sv`` extensions.
272-
The ``system-verilog`` parser, which represents the ``read_systemverilog`` command, reads SystemVerilog files directly in Yosys.
273-
It executes Surelog with provided filenames and converts them (in memory) into UHDM file. Then, this UHDM file is converted into Yosys AST. `[Yosys-SystemVerilog] <https://github.com/antmicro/yosys-systemverilog#usage>`_
274-
On the other hand, the ``surelog`` parser, which uses the ``read_uhdm`` Yosys command, walks the design tree and converts its nodes into Yosys AST nodes using Surelog. `[UHDM-Yosys <https://github.com/chipsalliance/UHDM-integration-tests#uhdm-yosys>`_, `Surelog] <https://github.com/chipsalliance/Surelog#surelog>`_
267+
Yosys-Slang is a Yosys plugin that is built on top of the slang library to provide comprehensive SystemVerilog support.
268+
It supports the ``read_slang`` command, used with the ``-C`` command-line option to read include-files from a text file containing include-file names.
269+
It is used to read SystemVerilog files directly in Yosys.
270+
For more information on Yosys-Slang, see `[Yosys-Slang] <https://github.com/povik/yosys-slang.git>`_
275271

276272
.. note::
277273

278274
Parmys is a Yosys plugin which provides intelligent partial mapping features (inference, binding, and hard/soft logic trade-offs) from Odin-II for Yosys. For more information on available paramters see the `Parmys <https://github.com/CAS-Atlantic/parmys-plugin.git>`_ plugin page.
275+
276+
.. Universal Hardware Data Model (UHDM) is a complete modeling of the IEEE SystemVerilog Object Model with VPI Interface, Elaborator, Serialization, Visitor and Listener.
277+
.. UHDM is used as a compiled interchange format in between SystemVerilog tools. Typical inputs to the UHDM flow are files with ``.v`` or ``.sv`` extensions.
278+
.. The ``system-verilog`` parser, which represents the ``read_systemverilog`` command, reads SystemVerilog files directly in Yosys.
279+
.. It executes Surelog with provided filenames and converts them (in memory) into UHDM file. Then, this UHDM file is converted into Yosys AST. `[Yosys-SystemVerilog] <https://github.com/antmicro/yosys-systemverilog#usage>`_
280+
.. On the other hand, the ``surelog`` parser, which uses the ``read_uhdm`` Yosys command, walks the design tree and converts its nodes into Yosys AST nodes using Surelog. `[UHDM-Yosys <https://github.com/chipsalliance/UHDM-integration-tests#uhdm-yosys>`_, `Surelog] <https://github.com/chipsalliance/Surelog#surelog>`_

libs/EXTERNAL/CMakeLists.txt

Lines changed: 42 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
include(ExternalProject)
22
include(ProcessorCount)
33

4+
find_package(Git REQUIRED)
5+
46
#Manually synchronized external libraries
57
add_subdirectory(libpugixml)
68

@@ -10,7 +12,6 @@ add_subdirectory(libsdcparse)
1012
add_subdirectory(libblifparse)
1113
add_subdirectory(libtatum)
1214
add_subdirectory(libcatch2)
13-
#add_subdirectory(synlig)
1415
#add_subdirectory(parmys)
1516

1617
#Proc numbers
@@ -60,11 +61,11 @@ if (${WITH_PARMYS})
6061

6162
#Initialize yosys submodules
6263
execute_process(
63-
COMMAND git submodule update --init
64+
COMMAND ${GIT_EXECUTABLE} submodule update --init
6465
WORKING_DIRECTORY ${YOSYS_SRC_DIR}
6566
)
6667
execute_process(
67-
COMMAND ${GIT_EXECUTABLE} submodule foreach --recursive git\ submodule\ update\ --init
68+
COMMAND ${GIT_EXECUTABLE} submodule foreach --recursive ${GIT_EXECUTABLE}\ submodule\ update\ --init
6869
WORKING_DIRECTORY ${YOSYS_SRC_DIR}
6970
)
7071

@@ -73,104 +74,61 @@ if (${WITH_PARMYS})
7374
COMMAND ${MAKE_PROGRAM} -C ${YOSYS_SRC_DIR}
7475
ENABLE_ABC=0
7576
PREFIX=${CMAKE_BINARY_DIR}
76-
77+
> /dev/null 2>&1
7778
COMMAND ${MAKE_PROGRAM}
7879
-C ${YOSYS_SRC_DIR}
7980
install
8081
ENABLE_ABC=0
8182
PREFIX=${CMAKE_BINARY_DIR}
82-
83+
> /dev/null 2>&1
8384
WORKING_DIRECTORY ${YOSYS_SRC_DIR})
8485

8586
add_custom_target(yosys ALL DEPENDS ${YOSYS_BUILD_DIR})
8687

87-
if (${SYNLIG_SYSTEMVERILOG})
88-
89-
set(SURELOG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Surelog)
90-
set(SURELOG_BINARY_DIR ${SURELOG_SOURCE_DIR}/build)
91-
set(YOSYS_F4PGA_PLUGINS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/yosys-f4pga-plugins)
92-
93-
ExternalProject_Add(surelog
94-
# root directory for Surelog project
95-
PREFIX "surelog"
96-
97-
GIT_REPOSITORY https://github.com/chipsalliance/Surelog.git
98-
GIT_TAG v1.71
99-
GIT_PROGRESS TRUE
100-
GIT_SHALLOW TRUE
101-
102-
# setting source, build and install directories
103-
SOURCE_DIR "${SURELOG_SOURCE_DIR}"
104-
BUILD_IN_SOURCE FALSE
105-
INSTALL_DIR "${SURELOG_BINARY_DIR}"
106-
107-
# define Surelog cache values
108-
CMAKE_CACHE_ARGS
109-
"-DCMAKE_BUILD_TYPE:STRING=Release"
110-
"-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}"
111-
"-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON"
112-
"-DCMAKE_WARN_DEPRECATED:BOOL=OFF"
113-
114-
# redirect logs to a logfile
115-
LOG_BUILD ON
116-
LOG_UPDATE ON
117-
LOG_INSTALL ON
118-
LOG_CONFIGURE OFF
119-
LOG_OUTPUT_ON_FAILURE ON
120-
121-
# dependency
122-
DEPENDS yosys
123-
)
124-
125-
# Synlig integration (manages Surelog and UHDM internally)
126-
127-
# Synlig integration (manages Surelog and UHDM internally)
128-
set(SYNLIG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/synlig)
88+
if (${SLANG_SYSTEMVERILOG})
89+
set(SLANG_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/yosys-slang)
90+
set(SLANG_BUILD_DIR ${CMAKE_BINARY_DIR}/yosys-slang)
91+
#Initialize yosys-slang submodules
92+
execute_process(
93+
COMMAND ${GIT_EXECUTABLE} submodule update --init
94+
WORKING_DIRECTORY ${SLANG_SRC_DIR}
95+
)
96+
execute_process(
97+
COMMAND ${GIT_EXECUTABLE} submodule foreach --recursive ${GIT_EXECUTABLE}\ submodule\ update\ --init
98+
WORKING_DIRECTORY ${SLANG_SRC_DIR}
99+
)
100+
set(SLANG_FE "${SLANG_SRC_DIR}/src/slang_frontend.cc")
101+
ExternalProject_Add(
102+
yosys-slang
103+
SOURCE_DIR ${SLANG_SRC_DIR}
104+
BINARY_DIR ${SLANG_BUILD_DIR}
105+
106+
#Disabling UndrivenPass in slang_frontend.cc
107+
PATCH_COMMAND
108+
${CMAKE_COMMAND} -E echo "Patching slang_frontend.cc to disable UndrivenPass" &&
109+
${CMAKE_COMMAND} -DIN=${SLANG_FE} -P ${CMAKE_CURRENT_SOURCE_DIR}/patch_slang.cmake
110+
111+
CONFIGURE_COMMAND ""
112+
113+
# Sets location of yosys-config required by slang and suppresses warnings
114+
BUILD_COMMAND
115+
${CMAKE_COMMAND} -E env
116+
YOSYS_PREFIX=${CMAKE_BINARY_DIR}/bin/
117+
${MAKE_PROGRAM} -C ${SLANG_SRC_DIR}
118+
CMAKE_FLAGS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-w"
119+
install
129120

130-
# Clone Synlig repository and ensure submodules are synced before building
131-
ExternalProject_Add(synlig
132-
PREFIX "synlig"
121+
INSTALL_COMMAND ""
133122

134-
# Clone the Synlig repository
135-
GIT_REPOSITORY https://github.com/chipsalliance/synlig.git
136-
GIT_TAG main
137-
GIT_PROGRESS TRUE
138-
GIT_SHALLOW TRUE
123+
DEPENDS yosys
139124

140-
# Set source and build directories
141-
SOURCE_DIR "${SYNLIG_SOURCE_DIR}"
142-
BUILD_IN_SOURCE FALSE
143-
INSTALL_DIR " "
144-
145-
# Sync submodules after cloning
146-
147-
148-
UPDATE_COMMAND git submodule update --init --recursive third_party/surelog
149-
WORKING_DIRECTORY ${SYNLIG_SOURCE_DIR}
150-
151-
BUILD_COMMAND ${MAKE_PROGRAM} -C ${SYNLIG_SOURCE_DIR} install DESTDIR=${CMAKE_BINARY_DIR}/bin/synlig_install -j${PROCESSOR_COUNT}
152-
INSTALL_COMMAND ""
153-
CONFIGURE_COMMAND ""
154-
155-
# Pass necessary paths and set environment variables
156-
CMAKE_CACHE_ARGS
157-
"-DCMAKE_BUILD_TYPE:STRING=Release"
158-
"-DSURELOG_PATH=${CMAKE_BINARY_DIR}/surelog"
159-
"-DYOSYS_PATH=${CMAKE_BINARY_DIR}/yosys"
160-
"-DUHDM_INSTALL_DIR=${CMAKE_BINARY_DIR}"
161-
"-DBUILD_DIR=${CMAKE_BINARY_DIR}/synlig-build"
162-
"-DEXPORT_PATH=${CMAKE_BINARY_DIR}/synlig_install/usr/local/bin:$ENV{PATH}"
163-
164-
LOG_BUILD ON
125+
LOG_BUILD OFF
165126
LOG_UPDATE ON
166127
LOG_INSTALL ON
167128
LOG_CONFIGURE OFF
168129
LOG_OUTPUT_ON_FAILURE ON
169-
170-
# Ensure dependencies like Yosys are built first
171-
DEPENDS yosys # Ensure submodule sync runs before synlig build
130+
172131
)
173-
174132
endif ()
175133
endif ()
176134

libs/EXTERNAL/patch_slang.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Patch step for yosys-slang
2+
#
3+
# The variable 'IN' points to vtr_root/libs/EXTERNAL/yosys-slang/src/slang_frontend.cc
4+
# This file contains the UndrivenPass that we want to disable
5+
#
6+
# This patch step finds the line where the UndrivenPass is called and comments out that line
7+
#
8+
# The UndrivenPass needs to be disabled due to unsupported synchronous rules in vtr_primitives.v
9+
10+
if(NOT DEFINED IN)
11+
message(FATAL_ERROR "patch_slang.cmake: IN (SLANG_FE) variable not set.")
12+
endif()
13+
file(READ "${IN}" SLANG_FRONTEND_CONTENTS)
14+
string(REPLACE "call(design, \"undriven\");" "// call(design, \"undriven\");" SLANG_PATCHED "${SLANG_FRONTEND_CONTENTS}")
15+
if(NOT SLANG_FRONTEND_CONTENTS STREQUAL SLANG_PATCHED)
16+
message(STATUS "Patching slang_frontend.cc to disable UndrivenPass")
17+
file(WRITE "${IN}" "${SLANG_PATCHED}")
18+
endif()

libs/EXTERNAL/yosys-slang

Submodule yosys-slang added at 76b83eb
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Parameters:
2+
#
3+
# circuit_list - list of circuits passed into the flow
4+
# file_list - text file being written to that will contain
5+
# the names of circuits from circuit list.
6+
#
7+
#Function:
8+
#
9+
# Validates file extensions of input files and writes the names
10+
# of input files to the file list to be read by yosys-slang.
11+
12+
proc build_filelist { circuit_list file_list } {
13+
set fh [open $file_list "w"]
14+
foreach f $circuit_list {
15+
set ext [string tolower [file extension $f]]
16+
if {$ext == ".sv" || $ext == ".svh" || $ext == ".v" || $ext == ".vh"} {
17+
puts $fh $f
18+
} else {
19+
close $fh
20+
error "Unsupported file type. Yosys-Slang accepts .sv .svh .v .vh. File {$f}"
21+
}
22+
}
23+
close $fh
24+
}

0 commit comments

Comments
 (0)