3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-05-25 03:16:22 +00:00
This commit is contained in:
Catherine 2026-05-23 11:28:49 -04:00 committed by GitHub
commit 5293bc9164
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
236 changed files with 5488 additions and 2605 deletions

View file

@ -31,9 +31,9 @@ jobs:
echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT
fi
vs-prep:
name: Prepare Visual Studio build
runs-on: ubuntu-latest
vs-build:
name: Visual Studio build
runs-on: windows-latest
needs: [pre_job]
if: (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
steps:
@ -41,31 +41,31 @@ jobs:
with:
submodules: true
persist-credentials: false
- run: sudo apt-get install libfl-dev
- name: Build
run: make vcxsrc YOSYS_COMPILER="Visual Studio" VCX_DIR_NAME=yosys-win32-vcxsrc-latest
- uses: actions/upload-artifact@v7
with:
name: vcxsrc
path: yosys-win32-vcxsrc-latest.zip
vs-build:
name: Visual Studio build
runs-on: windows-latest
needs: [vs-prep, pre_job]
if: (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
steps:
- uses: actions/download-artifact@v8
with:
name: vcxsrc
path: .
- name: unzip
run: unzip yosys-win32-vcxsrc-latest.zip
- name: setup-msbuild
uses: microsoft/setup-msbuild@v2
- name: MSBuild
working-directory: yosys-win32-vcxsrc-latest
run: msbuild YosysVS.sln /p:PlatformToolset=v142 /p:Configuration=Release /p:WindowsTargetPlatformVersion=10.0.26100.0
- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1
- name: Install flex/bison
shell: pwsh
run: |
choco install winflexbison3 --no-progress
# Make tools visible to CMake
echo "C:\Program Files (x86)\GnuWin32\bin" | Out-File -Append -FilePath $env:GITHUB_PATH
echo "C:\ProgramData\chocolatey\lib\winflexbison3\tools" | Out-File -Append -FilePath $env:GITHUB_PATH
- name: Configure CMake
run: >
cmake -S . -B build
-A x64
-DCMAKE_BUILD_TYPE=Release
-DYOSYS_WITHOUT_ABC=ON
- name: Build
run: >
cmake --build build
--config Release
--parallel
wasi-build:
name: WASI build
@ -79,10 +79,11 @@ jobs:
persist-credentials: false
- name: Build
run: |
WASI_SDK=wasi-sdk-33.0-x86_64-linux
WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-33/wasi-sdk-33.0-x86_64-linux.tar.gz
WASI_VER=33
WASI_SDK=wasi-sdk-${WASI_VER}.0-x86_64-linux
WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VER}/${WASI_SDK}.tar.gz
if ! [ -d ${WASI_SDK} ]; then curl -L ${WASI_SDK_URL} | tar xzf -; fi
WASI_SDK_PATH=$(pwd)/${WASI_SDK}
FLEX_VER=2.6.4
FLEX=flex-${FLEX_VER}
FLEX_URL=https://github.com/westes/flex/releases/download/v${FLEX_VER}/${FLEX}.tar.gz
@ -94,24 +95,9 @@ jobs:
make &&
make install)
mkdir -p build
cat > build/Makefile.conf <<END
export PATH := $(pwd)/${WASI_SDK}/bin:$(pwd)/flex-prefix/bin:${PATH}
WASI_SYSROOT := $(pwd)/${WASI_SDK}/share/wasi-sysroot
CONFIG := wasi
PREFIX := /
ENABLE_TCL := 0
ENABLE_READLINE := 0
ENABLE_PLUGINS := 0
ENABLE_ZLIB := 0
CXXFLAGS += -I$(pwd)/flex-prefix/include
LINKFLAGS += -Wl,-z,stack-size=8388608 -Wl,--stack-first -Wl,--strip-all
END
make -C build -f ../Makefile CXX=clang -j$(nproc)
export PATH=${WASI_SDK_PATH}/bin:$(pwd)/flex-prefix/bin:${PATH}
cmake -B build -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-p1.cmake -DCMAKE_BUILD_TYPE=Release .
cmake --build build -j$(nproc)
nix-build:
name: "Build nix flake"

View file

@ -57,19 +57,20 @@ jobs:
- name: Build Yosys
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 1" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
echo "ENABLE_HELP_SOURCE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_ENABLE_HELP_SOURCE ON CACHE BOOL "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs
- name: Prepare docs
shell: bash
run:
make docs/prep -j$procs TARGETS= EXTRA_TARGETS=
cmake --build build --target docs-prepare -j$procs
- name: Upload artifact
uses: actions/upload-artifact@v4
@ -83,12 +84,12 @@ jobs:
- name: Install doc prereqs
shell: bash
run: |
make docs/reqs
make -C docs reqs
- name: Test build docs
shell: bash
run: |
make -C docs html -j$procs TARGETS= EXTRA_TARGETS=
cmake --build build --target docs-html -j$procs
- name: Trigger RTDs build
if: ${{ needs.check_docs_rebuild.outputs.docs_export == 'true' && github.repository == 'YosysHQ/yosys' }}

View file

@ -82,21 +82,20 @@ jobs:
- name: Build
shell: bash
run: |
mkdir build
cd build
make -f ../Makefile config-$CC
make -f ../Makefile -j$procs
make -f ../Makefile unit-test -j$procs
rm -rf build
cmake -B build . -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$procs
ctest --test-dir build/tests/unit
- name: Log yosys-config output
run: |
./yosys-config || true
./build/yosys-config || true
- name: Compress build
shell: bash
run: |
cd build
tar -cvf ../build.tar share/ yosys yosys-* libyosys.so
tar -cvf ../build.tar share/ yosys yosys-*
- name: Store build artifact
uses: actions/upload-artifact@v7
@ -136,17 +135,18 @@ jobs:
- name: Uncompress build
shell: bash
run:
tar -xvf build.tar
run: |
mkdir -p build
tar -xvf build.tar -C build
- name: Log yosys-config output
run: |
./yosys-config || true
./build/yosys-config || true
- name: Run tests
shell: bash
run: |
make -j$procs vanilla-test TARGETS= EXTRA_TARGETS= CONFIG=$CC
make -C tests -j$procs vanilla-test
- name: Report errors
if: ${{ failure() }}
@ -198,8 +198,6 @@ jobs:
runs-on: ${{ matrix.os }}
needs: [build-yosys, pre_docs_job]
if: needs.pre_docs_job.outputs.should_skip != 'true'
env:
CC: clang
strategy:
matrix:
os: [ubuntu-latest]
@ -224,12 +222,13 @@ jobs:
- name: Uncompress build
shell: bash
run:
tar -xvf build.tar
run: |
mkdir -p build
tar -xvf build.tar -C build
- name: Log yosys-config output
run: |
./yosys-config || true
./build/yosys-config || true
- name: Run tests
shell: bash
@ -258,20 +257,24 @@ jobs:
- name: Build Yosys
run: |
make config-clang
echo "ENABLE_CCACHE := 1" >> Makefile.conf
echo "ENABLE_HELP_SOURCE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_ENABLE_HELP_SOURCE ON CACHE BOOL "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs
- name: Install doc prereqs
shell: bash
run: |
make docs/reqs
make -C docs reqs
- name: Build docs
shell: bash
run: |
make docs DOC_TARGET=${{ matrix.docs-target }} -j$procs
cmake --build build --target docs-${{ matrix.docs-target }} -j$procs
- name: Store docs build artifact
uses: actions/upload-artifact@v4

View file

@ -37,7 +37,6 @@ jobs:
if: (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
env:
CXXFLAGS: ${{ startsWith(matrix.compiler, 'gcc') && '-Wp,-D_GLIBCXX_ASSERTIONS' || ''}}
CC_SHORT: ${{ startsWith(matrix.compiler, 'gcc') && 'gcc' || 'clang' }}
strategy:
matrix:
os:
@ -91,16 +90,18 @@ jobs:
- name: Build C++20
shell: bash
run: |
make config-$CC_SHORT
make -j$procs CXXSTD=c++20 compile-only
rm -rf build
cmake -B build -DCMAKE_CXX_STANDARD=20 . --fresh
cmake --build build --target yosys -j$procs
# maximum standard, only on newest compilers
- name: Build C++26
if: ${{ matrix.compiler == 'clang-22' || matrix.compiler == 'gcc-15' }}
shell: bash
run: |
make config-$CC_SHORT
make -j$procs CXXSTD=c++26 compile-only
rm -rf build
cmake -B build -DCMAKE_CXX_STANDARD=26 . --fresh
cmake --build build --target yosys -j$procs
test-compile-result:
runs-on: ubuntu-latest

View file

@ -38,7 +38,7 @@ jobs:
if: (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
env:
CC: clang
ASAN_OPTIONS: halt_on_error=1
ASAN_OPTIONS: halt_on_error=1 detect_container_overflow=0
UBSAN_OPTIONS: halt_on_error=1
strategy:
matrix:
@ -63,18 +63,20 @@ jobs:
- name: Build
shell: bash
run: |
make config-$CC
echo 'SANITIZER = ${{ matrix.sanitizer }}' >> Makefile.conf
make -j$procs
rm -rf build
cmake -B build . \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_BUILD_TYPE=Sanitize -DSANITIZE=${{ matrix.sanitizer }}
cmake --build build -j$procs
- name: Log yosys-config output
run: |
./yosys-config || true
./build/yosys-config || true
- name: Run tests
shell: bash
run: |
make -j$procs vanilla-test TARGETS= EXTRA_TARGETS=
make -C tests -j$procs vanilla-test
- name: Report errors
if: ${{ failure() }}

View file

@ -19,91 +19,77 @@ jobs:
- name: verific [SV]
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_SYSTEMVERILOG := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_VHDL := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_HIER_TREE := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 0" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_FEATURES "systemverilog" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs
- name: verific [VHDL]
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_SYSTEMVERILOG := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_VHDL := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_HIER_TREE := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 0" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_FEATURES "vhdl" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs
- name: verific [SV + VHDL]
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_SYSTEMVERILOG := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_VHDL := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_HIER_TREE := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 0" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_FEATURES "vhdl;systemverilog" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs
- name: verific [SV + HIER]
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_SYSTEMVERILOG := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_VHDL := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_HIER_TREE := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 0" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_FEATURES "systemverilog;hier_tree" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs
- name: verific [VHDL + HIER]
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_SYSTEMVERILOG := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_VHDL := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_HIER_TREE := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 0" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_FEATURES "vhdl;hier_tree" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs
- name: verific [SV + VHDL + HIER]
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_SYSTEMVERILOG := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_VHDL := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_HIER_TREE := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 0" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 0" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_FEATURES "systemverilog;vhdl;hier_tree" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs
- name: verific [SV + VHDL + HIER + EDIF + LIBERTY]
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_SYSTEMVERILOG := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_VHDL := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_HIER_TREE := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 0" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
make -j$procs
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_FEATURES "systemverilog;vhdl;hier_tree;edif;liberty" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build .
cmake --build build -j$procs

View file

@ -55,18 +55,19 @@ jobs:
- name: Build Yosys
run: |
make config-gcov
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 1" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
echo "ENABLE_FUNCTIONAL_TESTS := 1" >> Makefile.conf
make -j$procs ENABLE_LTO=1
rm -rf build Configuration.cmake
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_ENABLE_COVERAGE ON CACHE BOOL "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build . -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/.local -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j$procs
- name: Install Yosys
run: |
make install DESTDIR=${GITHUB_WORKSPACE}/.local PREFIX=
cmake --build build --target install
- name: Checkout SBY
uses: actions/checkout@v4
@ -81,7 +82,7 @@ jobs:
- name: Run Yosys tests
run: |
make -j$procs vanilla-test
make -C tests -j$procs vanilla-test
- name: Run Verific specific Yosys tests
run: |
@ -96,8 +97,8 @@ jobs:
- name: Run coverage
if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }}
run: |
make coverage
make clean_coverage
make -C tests coverage
make -C tests clean_coverage
- name: Push coverage
if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }}
@ -138,19 +139,20 @@ jobs:
- name: Build pyosys
run: |
make config-clang
echo "ENABLE_VERIFIC := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_EDIF := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_LIBERTY := 1" >> Makefile.conf
echo "ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 1" >> Makefile.conf
echo "ENABLE_CCACHE := 1" >> Makefile.conf
echo "ENABLE_PYOSYS := 1" >> Makefile.conf
echo "PYTHON_DESTDIR := /usr/lib/python3/site-packages" >> Makefile.conf
make -j$procs
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_WITH_PYTHON ON CACHE BOOL "")' >> Configuration.cmake
echo 'set(YOSYS_INSTALL_PYTHON ON CACHE BOOL "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build . \
-DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/.local \
-DYOSYS_INSTALL_PYTHON_SITEDIR=$GITHUB_WORKSPACE/.local/usr/lib/python3/site-packages
cmake --build build -j$procs
- name: Install pyosys
run: |
make install DESTDIR=${GITHUB_WORKSPACE}/.local PREFIX=
cmake --build build --target install
- name: Run pyosys tests
run: |

4
.gitignore vendored
View file

@ -49,7 +49,9 @@
/tests/unit/objtest/
/tests/ystests
/build
/build-*
/result
/result-*
/dist
# pyosys
@ -86,3 +88,5 @@ __pycache__
/qtcreator.creator
/qtcreator.creator.user
/compile_commands.json
/.direnv
/.envrc

View file

@ -12,3 +12,4 @@ brew "bash"
brew "llvm"
brew "lld"
brew "googletest"
brew "tcl-tk"

515
CMakeLists.txt Normal file
View file

@ -0,0 +1,515 @@
if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
set(rm "rm -rf")
if (WIN32)
set(rm "del /s /q")
endif()
message(FATAL_ERROR
"In-tree builds are not supported. Instead, run:\n"
"${rm} CMakeCache.txt CMakeFiles ; cmake -B build <options>"
)
endif()
cmake_minimum_required(VERSION 3.27)
project(yosys LANGUAGES C CXX)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
include(CMakeDependentOption)
include(FeatureSummary)
include(CheckPIESupported)
include(Condition)
include(CheckLibcFeatures)
include(PkgConfig)
include(PmgenCommand)
include(YosysVersion)
include(YosysInstallDirs)
include(YosysConfigScript)
include(YosysComponent)
include(YosysLinkTarget)
include(YosysAbc)
include(YosysAbcSubmodule)
include(YosysVerific)
# Build options.
set(YOSYS_COMPILER_LAUNCHER "" CACHE STRING "Compiler launcher (ccache, sccache)")
option(YOSYS_ENABLE_COVERAGE "Enable code coverage" OFF)
option(YOSYS_ENABLE_PROFILING "Enable instruction profiling" OFF)
set(YOSYS_PROGRAM_PREFIX "" CACHE STRING "Name prefix for programs, libraries, and data")
set(YOSYS_COMPONENTS "everything" CACHE STRING "List of components to build (use pass names)")
option(BUILD_SHARED_LIBS "Build libyosys as a shared library" ON)
option(YOSYS_DISABLE_THREADS "Disable threading" OFF)
set(YOSYS_ABC_EXECUTABLE "" CACHE FILEPATH
"Path to the ABC executable (empty for vendored, 'INTEGRATED-NOTFOUND' for in-process)")
option(YOSYS_WITHOUT_ABC "Disable ABC support (not recommended)" OFF)
option(YOSYS_WITHOUT_ZLIB "Disable zlib integration" OFF)
option(YOSYS_WITHOUT_LIBFFI "Disable libffi integration" OFF)
option(YOSYS_WITHOUT_READLINE "Disable readline integration" OFF)
option(YOSYS_WITHOUT_EDITLINE "Disable editline integration" OFF)
option(YOSYS_WITHOUT_TCL "Disable Tcl integration" OFF)
option(YOSYS_WITH_PYTHON "Enable Python integration" OFF)
set(YOSYS_VERIFIC_DIR "" CACHE FILEPATH "Path to the Verific source code (empty to disable)")
set(YOSYS_VERIFIC_COMPONENTS "" CACHE STRING
"List of Verific components to link (empty for autodetect)")
set(YOSYS_VERIFIC_FEATURES "" CACHE STRING
"List of Yosys Verific frontend features to enable (empty for autodetect)")
option(YOSYS_INSTALL_DRIVER "Install Yosys executable" ON)
option(YOSYS_INSTALL_LIBRARY "Install libyosys library" OFF)
cmake_dependent_option(YOSYS_INSTALL_PYTHON "Install Python extension module" OFF
YOSYS_WITH_PYTHON OFF)
set(YOSYS_INSTALL_PYTHON_SITEDIR "" CACHE STRING "Path to Python package installation directory")
option(YOSYS_ENABLE_HELP_SOURCE "Improve help text with source locations" OFF)
mark_as_advanced(YOSYS_ENABLE_HELP_SOURCE)
# Configure compiler.
set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
if (YOSYS_COMPILER_LAUNCHER)
set(CMAKE_C_COMPILER_LAUNCHER "${YOSYS_COMPILER_LAUNCHER}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${YOSYS_COMPILER_LAUNCHER}")
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
check_pie_supported() # opportunistically enable PIE
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -ggdb")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
set(CMAKE_CXX_FLAGS_SANITIZE "-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
if ("${SANITIZE}" MATCHES "memory")
set(CMAKE_CXX_FLAGS_SANITIZE "${CMAKE_CXX_FLAGS_SANITIZE} -fsanitize-memory-track-origins")
endif()
set(no_abc_options
"$<$<AND:$<NOT:$<BOOL:$<TARGET_PROPERTY:YOSYS_IS_ABC>>>,$<CONFIG:Sanitize>>:-fsanitize=${SANITIZE}>"
"$<$<NOT:$<BOOL:$<TARGET_PROPERTY:YOSYS_IS_ABC>>>:-Wall;-Wextra;-Werror=unused>"
)
add_compile_options("${no_abc_options}")
add_link_options("${no_abc_options}")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_DEBUG "/Od /DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /DEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL "/Os")
add_compile_options(/Zc:__cplusplus)
add_compile_definitions(
_CRT_NONSTDC_NO_DEPRECATE
_CRT_SECURE_NO_WARNINGS
)
else()
# We have to do this because CMake adds `-DNDEBUG` in release builds by default, and there's
# no particularly good way to prevent this without also erasing optimization flags.
# If you see this message, reproduce the block above with the flags supported by your compiler.
message(FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} compiler is not supported")
endif()
if (YOSYS_ENABLE_COVERAGE)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
else()
message(FATAL_ERROR "Code coverage is not supported on ${CMAKE_CXX_COMPILER_ID} compiler")
endif()
endif()
if (YOSYS_ENABLE_PROFILING)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
else()
message(FATAL_ERROR "Instruction profiling is not supported on ${CMAKE_CXX_COMPILER_ID} compiler")
endif()
endif()
if (NOT CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID)
message(FATAL_ERROR "C and C++ compilers must be provided by the same vendor")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
set(CMAKE_C_FLAGS_SANITIZE "${CMAKE_CXX_FLAGS_SANITIZE}")
if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
add_compile_options(
-fwasm-exceptions -mllvm -wasm-use-legacy-eh=false
-D_WASI_EMULATED_PROCESS_CLOCKS
)
add_link_options(
-fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -lunwind
-lwasi-emulated-process-clocks
-Wl,--stack-first,-z,stack-size=8388608
)
endif()
if (MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "16.0.0")
# GCC 15.2 sometimes refuses to construct an import directory for yosys.exe/libyosys.dll with:
# .../ld.exe: error: export ordinal too large: 67035
# The cause is unknown.
message(WARNING "MinGW GCC is supported starting with version 16.0.0")
endif()
# Required dependencies.
find_package(FLEX)
set_package_properties(FLEX PROPERTIES
URL "https://github.com/westes/flex"
DESCRIPTION "The Fast Lexical Analyzer"
PURPOSE "Compiling the Verilog lexer"
TYPE REQUIRED
)
find_package(BISON)
set_package_properties(BISON PROPERTIES
URL "https://www.gnu.org/software/bison/"
DESCRIPTION "The Yacc-compatible Parser Generator"
PURPOSE "Compiling the Verilog parser"
TYPE REQUIRED
)
find_package(Python3 3.7 COMPONENTS Interpreter)
set_package_properties(Python3 PROPERTIES
URL "https://www.python.org/"
DESCRIPTION "Dynamic programming language (Interpreter)"
PURPOSE "Generating data files\n Running external SMT2 solvers"
TYPE REQUIRED
)
# Optional dependencies.
check_glob()
check_system()
check_popen()
find_package(Threads QUIET)
check_pthread_create()
find_package(Dlfcn QUIET)
find_package(PkgConfig)
set_package_properties(PkgConfig PROPERTIES
URL "https://www.freedesktop.org/wiki/Software/pkg-config/"
DESCRIPTION "Library metadata manager"
PURPOSE "Discovering dependencies"
TYPE RECOMMENDED
)
pkg_config_import(zlib)
set_package_properties(zlib PROPERTIES
URL "https://github.com/madler/zlib"
DESCRIPTION "A massively spiffy yet delicately unobtrusive compression library"
PURPOSE "Handling Gzip and FST file formats"
)
pkg_config_import(libffi)
set_package_properties(libffi PROPERTIES
URL "https://sourceware.org/libffi/"
DESCRIPTION "A Portable Foreign Function Interface Library"
PURPOSE "Implementing Verilog DPI-C"
)
pkg_config_import(editline MODULES libedit)
set_package_properties(editline PROPERTIES
URL "https://www.thrysoee.dk/editline/"
DESCRIPTION "Line editing and history library (BSD)"
PURPOSE "Enhancing the command prompt"
TYPE RECOMMENDED
)
pkg_config_import(readline)
set_package_properties(readline PROPERTIES
URL "https://tiswww.case.edu/php/chet/readline/rltop.html"
DESCRIPTION "Line editing and history library (GPL)"
PURPOSE "Enhancing the command prompt"
TYPE RECOMMENDED
)
# See https://core.tcl-lang.org/tips/doc/trunk/tip/538.md
pkg_config_import(tcl MODULES tcl)
set_package_properties(tcl PROPERTIES
URL "https://www.tcl-lang.org/"
DESCRIPTION "Dynamic programming language"
PURPOSE "Parsing SDC constraint files\n Binding Yosys API"
)
if (tcl_FOUND)
get_target_property(tcl_options PkgConfig::tcl INTERFACE_COMPILE_OPTIONS)
if (tcl_options MATCHES "TCL_WITH_EXTERNAL_TOMMATH")
pkg_config_import(libtommath)
set_package_properties(libtommath PROPERTIES
URL "https://www.libtom.net/LibTomMath/"
DESCRIPTION "Multiple-precision integer library"
PURPOSE "Required by this build of Tcl"
TYPE REQUIRED
)
# Unfortunately the pkg-config file for Tcl includes libtommath as a private dependency,
# while it should be public since it is exposed in the public API and necessary for its use.
target_link_libraries(PkgConfig::tcl INTERFACE PkgConfig::libtommath)
else()
# Vendored within Tcl itself.
set(libtommath_FOUND TRUE)
endif()
endif()
if (YOSYS_WITH_PYTHON)
find_package(Python3Embed REQUIRED)
set_property(GLOBAL PROPERTY _CMAKE_Python3Embed_REQUIRED_VERSION "== ${Python3_VERSION}")
set_package_properties(Python3Embed PROPERTIES
URL "https://www.python.org/"
DESCRIPTION "Dynamic programming language (Embedding)"
PURPOSE "Binding Yosys API"
)
find_package(PyosysEnv REQUIRED)
set_package_properties(PyosysEnv PROPERTIES
DESCRIPTION "Pyosys wrapper generator environment"
PURPOSE "Either 'uv' or 'pybind11>3,<4 cxxheaderparser'"
)
endif()
find_package(GTest)
set_package_properties(GTest PROPERTIES
URL "https://google.github.io/googletest/"
DESCRIPTION "C++ testing and mocking framework by Google"
PURPOSE "Running unit tests"
TYPE RECOMMENDED
)
# Configure features based on dependency availability.
message(VERBOSE "Conditional features:")
condition(YOSYS_ENABLE_GLOB HAVE_GLOB)
condition(YOSYS_ENABLE_SPAWN HAVE_SYSTEM AND HAVE_POPEN)
condition(YOSYS_ENABLE_THREADS Threads_FOUND AND HAVE_PTHREAD_CREATE AND NOT YOSYS_DISABLE_THREADS)
condition(YOSYS_ENABLE_PLUGINS Dlfcn_FOUND)
condition(YOSYS_ENABLE_ABC NOT YOSYS_WITHOUT_ABC)
condition(YOSYS_ENABLE_ZLIB zlib_FOUND AND NOT YOSYS_WITHOUT_ZLIB)
condition(YOSYS_ENABLE_LIBFFI Dlfcn_FOUND AND libffi_FOUND AND NOT YOSYS_WITHOUT_LIBFFI)
condition(YOSYS_ENABLE_READLINE readline_FOUND AND NOT YOSYS_WITHOUT_READLINE)
condition(YOSYS_ENABLE_EDITLINE editline_FOUND AND NOT YOSYS_WITHOUT_EDITLINE AND NOT YOSYS_ENABLE_READLINE)
condition(YOSYS_ENABLE_TCL tcl_FOUND AND libtommath_FOUND AND NOT YOSYS_WITHOUT_TCL)
condition(YOSYS_ENABLE_PYTHON Python3Embed_FOUND AND PyosysEnv_FOUND AND YOSYS_WITH_PYTHON)
condition(YOSYS_ENABLE_VERIFIC YOSYS_VERIFIC_DIR AND zlib_FOUND)
# Describe dependencies and features
# CMake 4.0 would let us use proper conditions, but that's too new for now.
add_feature_info(have_glob YOSYS_ENABLE_GLOB "Glob expansion in filenames")
add_feature_info(have_spawn YOSYS_ENABLE_SPAWN "Passes that invoke external tools")
add_feature_info(have_threads YOSYS_ENABLE_THREADS "Multithreaded netlist operations")
add_feature_info(have_plugins YOSYS_ENABLE_PLUGINS "Dynamically loadable binary plugins")
add_feature_info(with_abc YOSYS_ENABLE_ABC "Production-quality logic synthesis flow")
add_feature_info(with_zlib YOSYS_ENABLE_ZLIB "Transparent Gzip decompression and FST file format support")
add_feature_info(with_libffi YOSYS_ENABLE_LIBFFI "Verilog DPI-C foreign function interface")
add_feature_info(with_readline YOSYS_ENABLE_READLINE "Using readline for prompt editing and history")
add_feature_info(with_editline YOSYS_ENABLE_EDITLINE "Using editline for prompt editing and history")
add_feature_info(with_tcl YOSYS_ENABLE_TCL "Tcl scripting and SDC parsing")
add_feature_info(with_python YOSYS_ENABLE_PYTHON "Python scripting and embedding")
add_feature_info(with_verific YOSYS_ENABLE_VERIFIC "Verific frontend integration")
message(STATUS "")
feature_summary(WHAT PACKAGES_FOUND
DEFAULT_DESCRIPTION)
feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND
DEFAULT_DESCRIPTION QUIET_ON_EMPTY FATAL_ON_MISSING_REQUIRED_PACKAGES
)
feature_summary(WHAT PACKAGES_NOT_FOUND
DEFAULT_DESCRIPTION QUIET_ON_EMPTY
)
feature_summary(WHAT ENABLED_FEATURES
DEFAULT_DESCRIPTION QUIET_ON_EMPTY)
feature_summary(WHAT DISABLED_FEATURES
DEFAULT_DESCRIPTION QUIET_ON_EMPTY)
# Describe project version.
yosys_extract_version()
# Describe ABC integration.
if (YOSYS_ENABLE_ABC AND NOT YOSYS_ENABLE_SPAWN AND NOT YOSYS_ABC_EXECUTABLE STREQUAL "INTEGRATED-NOTFOUND")
message(WARNING "ABC support on this platform forces -DYOSYS_ABC_EXECUTABLE=INTEGRATED-NOTFOUND")
set(YOSYS_ABC_EXECUTABLE "INTEGRATED-NOTFOUND" CACHE FILEPATH "" FORCE)
endif()
set(YOSYS_LINK_ABC 0)
if (YOSYS_ENABLE_ABC)
if (NOT YOSYS_SKIP_ABC_SUBMODULE_CHECK)
yosys_check_abc_submodule()
endif()
if (YOSYS_ABC_EXECUTABLE STREQUAL "INTEGRATED-NOTFOUND")
set(YOSYS_LINK_ABC 1)
message(STATUS "Building ABC: (integrated)")
elseif (YOSYS_ABC_EXECUTABLE STREQUAL "")
set(abc_filename ${YOSYS_PROGRAM_PREFIX}yosys-abc${CMAKE_EXECUTABLE_SUFFIX})
message(STATUS "Building ABC: ${YOSYS_INSTALL_FULL_BINDIR}/${abc_filename}")
else()
message(STATUS "External ABC: ${YOSYS_ABC_EXECUTABLE}")
endif()
endif()
# Ensure invalid dependencies fail at configuration time, not link time.
set(CMAKE_LINK_LIBRARIES_ONLY_TARGETS ON)
# Pseudo-library that injects common compilation options into every Yosys component.
add_library(yosys_common INTERFACE)
target_compile_definitions(yosys_common INTERFACE
_YOSYS_
$<$<CONFIG:Debug,RelWithDebInfo>:DEBUG>
)
target_include_directories(yosys_common INTERFACE
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
)
if (SANITIZE)
target_compile_options(yosys_common INTERFACE
${sanitize_options}
)
endif()
# Two pseudo-components used for dependency tracking only.
yosys_core(essentials BOOTSTRAP)
yosys_core(everything BOOTSTRAP)
# All of the source code.
add_subdirectory(libs)
add_subdirectory(kernel)
add_subdirectory(passes)
add_subdirectory(frontends)
add_subdirectory(backends)
add_subdirectory(techlibs)
if (YOSYS_ENABLE_PYTHON)
add_subdirectory(pyosys)
endif()
# ABC submodule.
if (YOSYS_ENABLE_ABC)
set(YOSYS_ABC_INSTALL NO)
if (YOSYS_ABC_EXECUTABLE STREQUAL "")
set(YOSYS_ABC_INSTALL YES)
endif()
yosys_abc_target(libyosys-abc yosys-abc
INCLUDE_IN_ALL_IF ${YOSYS_ABC_INSTALL}
)
endif()
# Compute a transitive closure of enabled components.
yosys_expand_components(library_components essentials ${YOSYS_COMPONENTS})
yosys_expand_components(driver_components driver ${YOSYS_COMPONENTS})
# Main Yosys executable (compiler driver).
yosys_cxx_executable(yosys
OUTPUT_NAME yosys
INCLUDE_IN_ALL_IF ${YOSYS_INSTALL_DRIVER}
)
yosys_link_components(yosys PRIVATE ${driver_components})
set_property(TARGET yosys PROPERTY ENABLE_EXPORTS ON)
if (MINGW)
target_link_options(yosys PRIVATE LINKER:--export-all-symbols)
set_target_properties(yosys PROPERTIES
# Final name: `yosys.exe.a` (linked to explicitly)
IMPORT_PREFIX ""
IMPORT_SUFFIX ".exe.a"
)
if (YOSYS_INSTALL_DRIVER)
install(FILES ${CMAKE_BINARY_DIR}/yosys.exe.a DESTINATION ${YOSYS_INSTALL_LIBDIR})
endif()
endif()
target_compile_options(yosys PRIVATE -fsanitize=undefined)
# Yosys components as a library.
if (BUILD_SHARED_LIBS)
set(libyosys_type SHARED)
else()
set(libyosys_type STATIC)
endif()
yosys_cxx_library(libyosys ${libyosys_type}
OUTPUT_NAME libyosys
INCLUDE_IN_ALL_IF ${YOSYS_INSTALL_LIBRARY}
)
yosys_link_components(libyosys PRIVATE ${library_components})
add_library(Yosys::libyosys ALIAS libyosys)
if (MINGW)
set_target_properties(libyosys PROPERTIES
# Final name: `libyosys.dll.a` (linked to via `-lyosys`)
IMPORT_PREFIX ""
)
endif()
# Yosys data files (mainly headers and technological libraries).
if (YOSYS_INSTALL_DRIVER OR YOSYS_INSTALL_LIBRARY)
yosys_install_component_data(${library_components} DESTINATION ${YOSYS_INSTALL_DATADIR})
endif()
# Python binary extension (for using Yosys as a Python library).
if (YOSYS_ENABLE_PYTHON)
yosys_cxx_library(pyosys SHARED
OUTPUT_NAME pyosys
INCLUDE_IN_ALL_IF ${YOSYS_INSTALL_PYTHON}
)
yosys_link_components(pyosys PRIVATE ${library_components})
if (YOSYS_INSTALL_PYTHON)
string(REPLACE "-" "_" PYOSYS_MODULE_PREFIX "${YOSYS_PROGRAM_PREFIX}")
if (YOSYS_INSTALL_PYTHON_SITEDIR STREQUAL "")
set(YOSYS_INSTALL_PYTHON_SITEDIR ${Python3_SITEARCH})
endif()
set(pyosys_install_dir ${YOSYS_INSTALL_PYTHON_SITEDIR}/${PYOSYS_MODULE_PREFIX}pyosys)
install(FILES pyosys/modinit.py
RENAME __init__.py
DESTINATION ${pyosys_install_dir}
)
install(FILES $<TARGET_FILE:pyosys>
RENAME libyosys${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${pyosys_install_dir}
)
if (YOSYS_ABC_EXECUTABLE STREQUAL "")
# If ABC is vendored it needs to be installed as a part of pyosys.
install(TARGETS yosys-abc
DESTINATION ${pyosys_install_dir}
)
endif()
yosys_install_component_data(${library_components} DESTINATION ${pyosys_install_dir}/share)
endif()
endif()
# Plugin build tool.
yosys_config_script(BUILD)
yosys_config_script(INSTALL)
# Tests.
add_subdirectory(tests/unit)
# TODO(cmake): other tests
# Docs.
add_custom_target(docs-prepare
COMMAND make -C ${CMAKE_SOURCE_DIR}/docs gen
BUILD_DIR=${CMAKE_BINARY_DIR}
PROGRAM_PREFIX=${YOSYS_PROGRAM_PREFIX}
YOSYS=$<TARGET_FILE:yosys>
)
foreach (format html latexpdf)
add_custom_target(docs-${format}
COMMAND make -C ${CMAKE_SOURCE_DIR}/docs ${format}
DEPENDS docs-prepare
)
endforeach()
# Utilities.
yosys_expand_components(all_components everything QUIET)
list(TRANSFORM all_components PREPEND "COMMAND;${CMAKE_COMMAND};-E;echo;" OUTPUT_VARIABLE echo_all_components)
add_custom_target(print-yosys-components
${echo_all_components}
VERBATIM
)
math(EXPR YOSYS_VERSION_MINOR_next "${YOSYS_VERSION_MINOR} + 1")
add_custom_target(increment-minor-version
COMMAND ${CMAKE_COMMAND} -E echo
"set(YOSYS_VERSION_MAJOR ${YOSYS_VERSION_MAJOR})"
> ${CMAKE_SOURCE_DIR}/cmake/YosysVersionData.cmake
COMMAND ${CMAKE_COMMAND} -E echo
"set(YOSYS_VERSION_MINOR ${YOSYS_VERSION_MINOR_next})"
>> ${CMAKE_SOURCE_DIR}/cmake/YosysVersionData.cmake
VERBATIM
)

1219
Makefile

File diff suppressed because it is too large Load diff

18
backends/CMakeLists.txt Normal file
View file

@ -0,0 +1,18 @@
add_subdirectory(aiger)
add_subdirectory(aiger2)
add_subdirectory(blif)
add_subdirectory(btor)
add_subdirectory(cxxrtl)
add_subdirectory(edif)
add_subdirectory(firrtl)
add_subdirectory(functional)
add_subdirectory(intersynth)
add_subdirectory(jny)
add_subdirectory(json)
add_subdirectory(rtlil)
add_subdirectory(simplec)
add_subdirectory(smt2)
add_subdirectory(smv)
add_subdirectory(spice)
add_subdirectory(table)
add_subdirectory(verilog)

View file

@ -0,0 +1,8 @@
yosys_backend(aiger
aiger.cc
REQUIRES
json11
)
yosys_backend(xaiger
xaiger.cc
)

View file

@ -1,4 +0,0 @@
OBJS += backends/aiger/aiger.o
OBJS += backends/aiger/xaiger.o

View file

@ -0,0 +1,5 @@
yosys_backend(aiger2
aiger.cc
PROVIDES
write_xaiger2
)

View file

@ -1 +0,0 @@
OBJS += backends/aiger2/aiger.o

View file

@ -0,0 +1,3 @@
yosys_backend(blif
blif.cc
)

View file

@ -1,3 +0,0 @@
OBJS += backends/blif/blif.o

View file

@ -0,0 +1,7 @@
yosys_backend(btor
btor.cc
REQUIRES
bmuxmap
demuxmap
bwmuxmap
)

View file

@ -1,3 +0,0 @@
OBJS += backends/btor/btor.o

View file

@ -0,0 +1,19 @@
yosys_backend(cxxrtl
cxxrtl_backend.cc
DATA_DIR
include/backends/cxxrtl
DATA_FILES
runtime/README.txt
runtime/cxxrtl/cxxrtl.h
runtime/cxxrtl/cxxrtl_vcd.h
runtime/cxxrtl/cxxrtl_time.h
runtime/cxxrtl/cxxrtl_replay.h
runtime/cxxrtl/capi/cxxrtl_capi.cc
runtime/cxxrtl/capi/cxxrtl_capi.h
runtime/cxxrtl/capi/cxxrtl_capi_vcd.cc
runtime/cxxrtl/capi/cxxrtl_capi_vcd.h
REQUIRES
hierarchy
flatten
proc
)

View file

@ -1,11 +0,0 @@
OBJS += backends/cxxrtl/cxxrtl_backend.o
$(eval $(call add_include_file,backends/cxxrtl/runtime/cxxrtl/cxxrtl.h))
$(eval $(call add_include_file,backends/cxxrtl/runtime/cxxrtl/cxxrtl_vcd.h))
$(eval $(call add_include_file,backends/cxxrtl/runtime/cxxrtl/cxxrtl_time.h))
$(eval $(call add_include_file,backends/cxxrtl/runtime/cxxrtl/cxxrtl_replay.h))
$(eval $(call add_include_file,backends/cxxrtl/runtime/cxxrtl/capi/cxxrtl_capi.cc))
$(eval $(call add_include_file,backends/cxxrtl/runtime/cxxrtl/capi/cxxrtl_capi.h))
$(eval $(call add_include_file,backends/cxxrtl/runtime/cxxrtl/capi/cxxrtl_capi_vcd.cc))
$(eval $(call add_include_file,backends/cxxrtl/runtime/cxxrtl/capi/cxxrtl_capi_vcd.h))

View file

@ -0,0 +1,3 @@
yosys_backend(edif
edif.cc
)

View file

@ -1,3 +0,0 @@
OBJS += backends/edif/edif.o

View file

@ -0,0 +1,8 @@
yosys_backend(firrtl
firrtl.cc
REQUIRES
pmuxtree
bmuxmap
demuxmap
bwmuxmap
)

View file

@ -1,3 +0,0 @@
OBJS += backends/firrtl/firrtl.o

View file

@ -0,0 +1,12 @@
yosys_backend(functional_cxx
cxx.cc
)
yosys_backend(functional_smt2
smtlib.cc
)
yosys_backend(functional_rosette
smtlib_rosette.cc
)
yosys_test_pass(generic
test_generic.cc
)

View file

@ -1,4 +0,0 @@
OBJS += backends/functional/cxx.o
OBJS += backends/functional/smtlib.o
OBJS += backends/functional/smtlib_rosette.o
OBJS += backends/functional/test_generic.o

View file

@ -0,0 +1,3 @@
yosys_backend(intersynth
intersynth.cc
)

View file

@ -1,3 +0,0 @@
OBJS += backends/intersynth/intersynth.o

View file

@ -0,0 +1,5 @@
yosys_backend(jny
jny.cc
PROVIDES
jny
)

View file

@ -1,2 +0,0 @@
OBJS += backends/jny/jny.o

View file

@ -0,0 +1,5 @@
yosys_backend(json
json.cc
PROVIDES
json
)

View file

@ -1,3 +0,0 @@
OBJS += backends/json/json.o

View file

@ -0,0 +1,11 @@
yosys_backend(rtlil
rtlil_backend.cc
rtlil_backend.h
PROVIDES
dump
DATA_DIR
include/backends/rtlil
DATA_FILES
rtlil_backend.h
ESSENTIAL
)

View file

@ -1,3 +0,0 @@
OBJS += backends/rtlil/rtlil_backend.o

View file

@ -0,0 +1,3 @@
yosys_backend(simplec
simplec.cc
)

View file

@ -1,3 +0,0 @@
OBJS += backends/simplec/simplec.o

View file

@ -0,0 +1,16 @@
yosys_backend(smt2
smt2.cc
REQUIRES
json11
DATA_DIR
python3
DATA_FILES
smtio.py
ywio.py
REQUIRES
bmuxmap
demuxmap
)
yosys_python_executable(yosys-smtbmc smtbmc.py)
yosys_python_executable(yosys-witness witness.py)

View file

@ -1,46 +0,0 @@
OBJS += backends/smt2/smt2.o
ifneq ($(CONFIG),mxe)
ifneq ($(CONFIG),emcc)
# MSYS targets support yosys-smtbmc, but require a launcher script
ifeq ($(CONFIG),$(filter $(CONFIG),msys2 msys2-64))
TARGETS += $(PROGRAM_PREFIX)yosys-smtbmc.exe $(PROGRAM_PREFIX)yosys-smtbmc-script.py
TARGETS += $(PROGRAM_PREFIX)yosys-witness.exe $(PROGRAM_PREFIX)yosys-witness-script.py
# Needed to find the Python interpreter for yosys-smtbmc scripts.
# Override if necessary, it is only used for msys2 targets.
PYTHON := $(shell cygpath -w -m $(PREFIX)/bin/python3)
$(PROGRAM_PREFIX)yosys-smtbmc-script.py: backends/smt2/smtbmc.py
$(P) sed -e 's|##yosys-sys-path##|sys.path += [os.path.dirname(os.path.realpath(__file__)) + p for p in ["/share/python3", "/../share/$(PROGRAM_PREFIX)yosys/python3"]]|;' \
-e "s|#!/usr/bin/env python3|#!$(PYTHON)|" < $< > $@
$(PROGRAM_PREFIX)yosys-witness-script.py: backends/smt2/witness.py
$(P) sed -e 's|##yosys-sys-path##|sys.path += [os.path.dirname(os.path.realpath(__file__)) + p for p in ["/share/python3", "/../share/$(PROGRAM_PREFIX)yosys/python3"]]|;' \
-e "s|#!/usr/bin/env python3|#!$(PYTHON)|" < $< > $@
$(PROGRAM_PREFIX)yosys-smtbmc.exe: misc/launcher.c $(PROGRAM_PREFIX)yosys-smtbmc-script.py
$(P) $(CXX) -DGUI=0 -O -s -o $@ $<
$(PROGRAM_PREFIX)yosys-witness.exe: misc/launcher.c $(PROGRAM_PREFIX)yosys-witness-script.py
$(P) $(CXX) -DGUI=0 -O -s -o $@ $<
# Other targets
else
TARGETS += $(PROGRAM_PREFIX)yosys-smtbmc $(PROGRAM_PREFIX)yosys-witness
$(PROGRAM_PREFIX)yosys-smtbmc: backends/smt2/smtbmc.py
$(P) sed 's|##yosys-sys-path##|sys.path += [os.path.dirname(os.path.realpath(__file__)) + p for p in ["/share/python3", "/../share/$(PROGRAM_PREFIX)yosys/python3"]]|;' < $< > $@.new
$(Q) chmod +x $@.new
$(Q) mv $@.new $@
$(PROGRAM_PREFIX)yosys-witness: backends/smt2/witness.py
$(P) sed 's|##yosys-sys-path##|sys.path += [os.path.dirname(os.path.realpath(__file__)) + p for p in ["/share/python3", "/../share/$(PROGRAM_PREFIX)yosys/python3"]]|;' < $< > $@.new
$(Q) chmod +x $@.new
$(Q) mv $@.new $@
endif
$(eval $(call add_share_file,share/python3,backends/smt2/smtio.py))
$(eval $(call add_share_file,share/python3,backends/smt2/ywio.py))
endif
endif

4
backends/smt2/smtbmc.py Normal file → Executable file
View file

@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!@PYTHON_SHEBANG@
#
# yosys -- Yosys Open SYnthesis Suite
#
@ -18,7 +18,7 @@
#
import os, sys, getopt, re, bisect, json
##yosys-sys-path##
sys.path += [os.path.dirname(os.path.realpath(__file__)) + p for p in ["/share/python3", "/../share/@YOSYS_PROGRAM_PREFIX@yosys/python3"]]
from smtio import SmtIo, SmtOpts, MkVcd
from ywio import ReadWitness, WriteWitness, WitnessValues
from collections import defaultdict

4
backends/smt2/witness.py Normal file → Executable file
View file

@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!@PYTHON_SHEBANG@
#
# yosys -- Yosys Open SYnthesis Suite
#
@ -18,7 +18,7 @@
#
import os, sys, itertools, re
##yosys-sys-path##
sys.path += [os.path.dirname(os.path.realpath(__file__)) + p for p in ["/share/python3", "/../share/@YOSYS_PROGRAM_PREFIX@yosys/python3"]]
import json
import click

View file

@ -0,0 +1,7 @@
yosys_backend(smv
smv.cc
REQUIRES
bmuxmap
demuxmap
bwmuxmap
)

View file

@ -1,3 +0,0 @@
OBJS += backends/smv/smv.o

View file

@ -0,0 +1,3 @@
yosys_backend(spice
spice.cc
)

View file

@ -1,3 +0,0 @@
OBJS += backends/spice/spice.o

View file

@ -0,0 +1,3 @@
yosys_backend(table
table.cc
)

View file

@ -1,3 +0,0 @@
OBJS += backends/table/table.o

View file

@ -0,0 +1,8 @@
yosys_backend(verilog
verilog_backend.cc
verilog_backend.h
REQUIRES
bmuxmap
demuxmap
clean_zerowidth
)

View file

@ -1,3 +0,0 @@
OBJS += backends/verilog/verilog_backend.o

View file

@ -0,0 +1,40 @@
include(CMakePushCheckState)
include(CheckSourceCompiles)
include(CheckCXXSymbolExists)
function(check_glob)
check_cxx_symbol_exists(glob "glob.h" HAVE_GLOB)
return (PROPAGATE HAVE_BLOB)
endfunction()
function(check_pthread_create)
if (Threads_FOUND)
# On WASI, `pthread_create()` is always available, but always fails on triples without threading
# support. Probe for it while requesting the stub implementation to be hidden, otherwise we will
# end up always crashing at runtime on thread creation.
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_DEFINITIONS -D_WASI_STRICT_PTHREAD)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
check_source_compiles(CXX [[
#include <pthread.h>
int main() {
pthread_create(0, 0, 0, 0);
}
]] HAVE_PTHREAD_CREATE)
cmake_pop_check_state()
endif()
return (PROPAGATE HAVE_PTHREAD_CREATE)
endfunction()
function(check_system)
check_cxx_symbol_exists(system "stdlib.h" HAVE_SYSTEM)
endfunction()
function(check_popen)
check_cxx_symbol_exists(popen "stdio.h" HAVE_POPEN)
if (NOT HAVE_POPEN)
unset(HAVE_POPEN CACHE)
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/popen-wpopen
check_cxx_symbol_exists(_popen "stdio.h" HAVE_POPEN)
endif()
endfunction()

35
cmake/Condition.cmake Normal file
View file

@ -0,0 +1,35 @@
# Syntax:
#
# condition(<var> <expr>...)
#
# If `<expr>...` is truthful (evaluated as in `if()`) then assigns 1 to `<var>`, else assigns 0.
# The assigned value is `0`/`1` rather than `TRUE`/`FALSE` for ease of use in generator expressions.
# Note that `<expr>...` *must* be unquoted.
#
# To understand how a certain outcome is reached, reconfigure the project with `--log-level VERBOSE`.
#
# Believe it or not, CMake doesn't have this built in!
#
macro(condition var)
if (${ARGN})
set(${var} 1)
else()
set(${var} 0)
endif()
set(_debug_expr)
foreach (token ${ARGN})
if (DEFINED ${token})
if (${${token}})
list(APPEND _debug_expr "${token}:1")
else()
list(APPEND _debug_expr "${token}:0")
endif()
else()
list(APPEND _debug_expr "${token}")
endif()
endforeach()
string(JOIN " " _debug_expr ${_debug_expr})
message(VERBOSE " ${var} = ${${var}} (${_debug_expr})")
unset(_debug_expr)
endmacro()

24
cmake/FindDlfcn.cmake Normal file
View file

@ -0,0 +1,24 @@
include(CMakePushCheckState)
include(CheckCXXSymbolExists)
include(FindPackageHandleStandardArgs)
if (WIN32 OR MSYS)
# Windows; dlopen is available via a polyfill `libs/dlfcn-win32`.
set(Dlfcn_LIBRARIES dlfcn)
else()
# Unix and Wasm; dlopen may or may not be available depending on platform.
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
check_cxx_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN)
cmake_pop_check_state()
if (HAVE_DLOPEN)
add_library(dlfcn INTERFACE)
target_link_libraries(dlfcn INTERFACE ${CMAKE_DL_LIBS})
set(Dlfcn_LIBRARIES dlfcn)
endif()
endif()
find_package_handle_standard_args(Dlfcn
REQUIRED_VARS Dlfcn_LIBRARIES
)

42
cmake/FindPyosysEnv.cmake Normal file
View file

@ -0,0 +1,42 @@
# We need a *third* `FindPython`-style call in this codebase because the host
# `Python3_EXECUTABLE` may not have pybind11 and cxxheaderparser installed,
# and installing it can be onerous. To work around this problem we try to detect
# whether the host interpreter has the necessary dependencies first, and if it
# does not, fall back to using `uv`.
foreach (strategy host uv fail)
if (strategy STREQUAL "host")
set(PyosysEnv_PYTHON Python3_EXECUTABLE)
elseif (strategy STREQUAL "uv")
set(PyosysEnv_PYTHON uv run --no-project --with pybind11>3,<4 --with cxxheaderparser python)
else()
set(PyosysEnv_PYTHON)
break()
endif()
execute_process(
COMMAND ${PyosysEnv_PYTHON} -m pybind11 --includes
RESULT_VARIABLE result
OUTPUT_VARIABLE output
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if (result EQUAL 0)
string(REGEX REPLACE " ?-I" ";" pybind11_INCLUDE_DIR "${output}")
list(FILTER pybind11_INCLUDE_DIR INCLUDE REGEX "/pybind11/")
execute_process(
COMMAND ${PyosysEnv_PYTHON} ${CMAKE_SOURCE_DIR}/pyosys/generator.py --help
RESULT_VARIABLE result
OUTPUT_QUIET
ERROR_QUIET
)
if (result EQUAL 0)
break()
endif()
endif()
endforeach()
find_package_handle_standard_args(PyosysEnv
REQUIRED_VARS PyosysEnv_PYTHON pybind11_INCLUDE_DIR
)

View file

@ -0,0 +1,16 @@
# Wrapper to improve behavior of `FindPython3` during cross-compilation.
# Does not entirely fix the problem; CMake 4.0 introduces `Python_ARTIFACTS_PREFIX`, which will.
# Stash the package found status
get_property(packages_found GLOBAL PROPERTY PACKAGES_FOUND)
get_property(packages_not_found GLOBAL PROPERTY PACKAGES_NOT_FOUND)
get_property(required_version GLOBAL PROPERTY _CMAKE_Python3_REQUIRED_VERSION)
# The `EXACT` specifier prevents the situation of `FindPython3` discovering a newer libpython-dev
# than the interpreter found in the past, rejecting it because it is too new, and giving up.
find_package(Python3 EXACT ${Python3_VERSION} COMPONENTS Development.Embed)
set(Python3Embed_FOUND ${Python3_Development.Embed_FOUND})
set_property(GLOBAL PROPERTY PACKAGES_FOUND "${packages_found}")
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND "${packages_not_found}")
set_property(GLOBAL PROPERTY _CMAKE_Python3_REQUIRED_VERSION "${required_version}")

43
cmake/PkgConfig.cmake Normal file
View file

@ -0,0 +1,43 @@
# Syntax:
#
# pkg_config_import(<package>)
#
# To use this command, `find_package(PkgConfig)` must be used beforehand, but it does
# not have to succeed. If the `PkgConfig` package is not found, all imports silently fail.
#
# Imports `<package>` as a CMake `IMPORTED` target `PkgConfig::<package>`.
# Updates the global `PACKAGES_FOUND` and `PACKAGES_NOT_FOUND` properties and defines
# the `<package>_FOUND` variable.
#
function(pkg_config_import arg_PREFIX)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "MODULES")
if (NOT arg_MODULES)
set(arg_MODULES ${arg_PREFIX})
endif()
if (PkgConfig_FOUND)
# Once CMake 4.1 is available, this call should be replaced with `cmake_pkg_config()`.
pkg_check_modules(${arg_PREFIX} IMPORTED_TARGET ${arg_MODULES})
if (${arg_PREFIX}_FOUND)
# We found the pkgconfig file, but is it actually a usable package?
# The main cause of failure here would be cross-compiling, which pkg-config does not
# handle very well (especially pre-`cmake_pkg_config()`).
try_compile(is_usable
SOURCE_FROM_CONTENT "main.cc" "int main() {}"
LINK_LIBRARIES PkgConfig::${arg_PREFIX}
LOG_DESCRIPTION "Checking if PkgConfig::${arg_PREFIX} is usable"
)
if (NOT is_usable)
message(STATUS "Modules '${arg_MODULES}' unusable (bad \$PKG_CONFIG_LIBDIR?)")
set(${arg_PREFIX}_FOUND 0)
endif()
endif()
endif()
if (${arg_PREFIX}_FOUND)
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND ${arg_PREFIX})
else()
set_property(GLOBAL APPEND PROPERTY PACKAGES_NOT_FOUND ${arg_PREFIX})
endif()
return (PROPAGATE ${arg_PREFIX}_FOUND)
endfunction()

60
cmake/PmgenCommand.cmake Normal file
View file

@ -0,0 +1,60 @@
# Syntax:
#
# pmgen_command(<output>
# [<input>...]
# [PREFIX <prefix>]
# [DEBUG]
# )
#
# Builds `<output>_pm.h` in the current binary directory from pmgen source files `<input>`, which must have
# the `*.pmg` extension. If `<input>...` contains more than one file, `<prefix>` must be provided.
#
# Defines the following variables:
# - `PMGEN_<output>_DEFINED`: Boolean indicating whether this command was successfully invoked.
# - `PMGEN_<output>_OUTPUT`: The header file generated by `pmgen`.
#
# Usage example:
#
# pmgen_command(my_dsp
# my_dsp.pmg
# )
# yosys_pass(my_dsp
# my_dsp.cc
# ${PMGEN_my_dsp_OUTPUT}
# )
#
# Usage example with multiple files:
#
# pmgen_command(my_dsp
# my_dsp_macc.pmg
# my_dsp_carry.pmg
# PREFIX
# my_dsp
# )
#
function(pmgen_command arg_NAME)
cmake_parse_arguments(PARSE_ARGV 1 arg "DEBUG" "PREFIX" "")
set(arg_INPUTS ${arg_UNPARSED_ARGUMENTS})
set(pmgen_script ${CMAKE_SOURCE_DIR}/passes/pmgen/pmgen.py)
set(pmgen_output ${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}_pm.h)
cmake_path(RELATIVE_PATH pmgen_output BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE pmgen_output_rel)
add_custom_command(
DEPENDS ${pmgen_script} ${arg_INPUTS}
OUTPUT ${pmgen_output}
COMMAND ${Python3_EXECUTABLE}
${pmgen_script}
"$<$<BOOL:${arg_DEBUG}>:-g>"
"$<$<BOOL:${arg_PREFIX}>:-p;${arg_PREFIX}>"
-o ${pmgen_output}
${arg_INPUTS}
COMMAND_EXPAND_LISTS
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
COMMENT "Compiling pattern matcher ${pmgen_output_rel}"
)
# The usage of this command is somewhat inspired by `flex_target()` and `bison_target()`.
set(PMGEN_${arg_NAME}_DEFINED TRUE)
set(PMGEN_${arg_NAME}_OUTPUT ${pmgen_output} PARENT_SCOPE)
endfunction()

96
cmake/YosysAbc.cmake Normal file
View file

@ -0,0 +1,96 @@
include(CheckCompilerFlag)
define_property(TARGET PROPERTY YOSYS_IS_ABC)
function(target_safe_compile_options target scope)
foreach (lang C CXX)
foreach (flag ${ARGN})
check_compiler_flag(${lang} ${flag} HAVE_${lang}_${flag})
if (HAVE_${lang}_${flag})
target_compile_options(${target} ${scope} $<$<COMPILE_LANGUAGE:${lang}>:${flag}>)
endif()
endforeach()
endforeach()
endfunction()
function(_yosys_abc_extract_makefile result vardecl filename)
# Parse a Makefile fragment and extracts the first matching variable assignment into
# a list of values.
file(READ ${filename} contents)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${filename})
if ("${contents}" MATCHES "${vardecl}(\\\\\n|[ \t])*(([^\\\\\n]|\\\\\n)+)")
string(REGEX REPLACE "(\\\\\n|[ \t])+" ";" ${result} "${CMAKE_MATCH_2}")
endif()
return (PROPAGATE ${result})
endfunction()
function(yosys_abc_target arg_LIBNAME arg_EXENAME)
cmake_parse_arguments(PARSE_ARGV 2 arg "" "INCLUDE_IN_ALL_IF" "")
# Instead of using either the ABC Make or CMake build system, we parse the source
# of truth: ABC's `module.make` files. This turns out to be quite trivial.
# This way, no assumptions about the environment are made, and Yosys can be compiled
# on Windows without MSYS as a result (while benefitting other platforms as well).
set(all_sources)
_yosys_abc_extract_makefile(module_files "MODULES :=" ${CMAKE_SOURCE_DIR}/abc/Makefile)
_yosys_abc_extract_makefile(module_files_cudd "MODULES \\+=" ${CMAKE_SOURCE_DIR}/abc/Makefile)
list(REMOVE_ITEM module_files "$(wildcard" "src/ext*)")
foreach (module_file ${module_files} ${module_files_cudd})
_yosys_abc_extract_makefile(module_sources "SRC \\+=" ${CMAKE_SOURCE_DIR}/abc/${module_file}/module.make)
list(APPEND all_sources ${module_sources})
endforeach()
list(TRANSFORM all_sources PREPEND abc/)
# Required to get `-DABC_NAMESPACE` below to work consistently.
set_source_files_properties(${all_sources} PROPERTIES LANGUAGE CXX)
set(main_source abc/src/base/main/main.c)
list(REMOVE_ITEM all_sources ${main_source})
find_package(Threads)
yosys_cxx_library(${arg_LIBNAME} STATIC
OUTPUT_NAME ${arg_LIBNAME}
)
target_sources(${arg_LIBNAME} PRIVATE ${all_sources})
target_include_directories(${arg_LIBNAME} PRIVATE abc/src)
target_compile_definitions(${arg_LIBNAME} PUBLIC
WIN32_NO_DLL
ABC_NAMESPACE=abc
ABC_USE_STDINT_H=1
ABC_USE_CUDD=1
ABC_NO_DYNAMIC_LINKING
$<${YOSYS_ENABLE_THREADS}:ABC_USE_PTHREADS>
$<${YOSYS_ENABLE_READLINE}:ABC_USE_READLINE>
ABC_NO_RLIMIT
)
target_safe_compile_options(${arg_LIBNAME} PRIVATE
-fpermissive
-fno-exceptions
-Wno-write-strings
-Wno-changes-meaning
-Wno-attributes
-Wno-deprecated-declarations
-Wno-deprecated-comma-subscript
-Wno-format
-Wno-constant-logical-operand
)
target_link_libraries(${arg_LIBNAME} PUBLIC
$<${YOSYS_ENABLE_THREADS}:Threads::Threads>
$<${YOSYS_ENABLE_READLINE}:PkgConfig::readline>
$<$<BOOL:${WIN32}>:-lshlwapi>
)
set_target_properties(${arg_LIBNAME} PROPERTIES
YOSYS_IS_ABC ON
)
yosys_cxx_executable(${arg_EXENAME}
OUTPUT_NAME ${arg_EXENAME}
INCLUDE_IN_ALL_IF "${arg_INCLUDE_IN_ALL_IF}"
)
target_sources(${arg_EXENAME} PRIVATE ${main_source})
target_include_directories(${arg_EXENAME} PRIVATE abc/src)
target_link_libraries(${arg_EXENAME} PRIVATE ${arg_LIBNAME})
set_target_properties(${arg_EXENAME} PROPERTIES
YOSYS_IS_ABC ON
)
endfunction()

View file

@ -0,0 +1,64 @@
# depends on YosysVersion.cmake
function(yosys_check_abc_submodule)
yosys_call_git(status)
set(yosys_status "tarball")
if (git_result EQUAL 0)
set(yosys_status "git")
endif()
yosys_call_git(submodule status abc)
set(git_commit)
if (EXISTS "${CMAKE_SOURCE_DIR}/abc/.gitcommit")
file(READ "${CMAKE_SOURCE_DIR}/abc/.gitcommit" git_commit)
string(STRIP "${git_commit}" git_commit)
endif()
set(abc_status "none")
if (git_result EQUAL 0 AND git_output MATCHES "^ ")
set(abc_status "git")
elseif (git_result EQUAL 0 AND git_output MATCHES "^\\+")
set(abc_status "git-changed")
elseif (git_result EQUAL 0 AND git_output MATCHES "^U")
set(abc_status "git-conflict")
elseif (git_commit MATCHES "^[0-9a-fA-F]+$")
set(abc_status "tarball")
elseif (git_commit MATCHES "\\$Format:%[hH]\\$")
set(abc_status "unknown")
endif()
if (abc_status STREQUAL "git" OR abc_status STREQUAL "tarball")
# Normal submodule or a tarball.
elseif (abc_status STREQUAL "git-changed")
message(FATAL_ERROR
"'abc' submodule does not match expected commit.\n"
"Run 'git submodule update' to check out the correct version.\n"
"Note: If testing a different version of ABC, call 'git commit abc' "
"in the Yosys source directory to update the expected commit.\n"
)
elseif (abc_status STREQUAL "git-conflict")
message(FATAL_ERROR
"'abc' submodule has merge conflicts.\n"
"Please resolve merge conflicts before continuing.\n"
)
elseif (abc_status STREQUAL "unknown") # OK
message(FATAL_ERROR
"Error: 'abc' is not configured as a git submodule.\n"
"To resolve this:\n"
"1. Back up your changes: Save any modifications from the 'abc' directory to another location.\n"
"2. Remove the existing 'abc' directory: Delete the 'abc' directory and all its contents.\n"
"3. Initialize the submodule: Run 'git submodule update --init' to set up 'abc' as a submodule.\n"
"4. Reapply your changes: Move your saved changes back to the 'abc' directory, if necessary.\n"
)
elseif (yosys_status STREQUAL "git") # OK
message(FATAL_ERROR
"Initialize the submodule: Run 'git submodule update --init' to set up 'abc' as a submodule.\n"
)
else() #
message(FATAL_ERROR
"${CMAKE_SOURCE_DIR} is not configured as a git repository, and 'abc' folder is missing.\n"
"If you already have ABC, set 'ABCEXTERNAL' make variable to point to ABC executable.\n"
"Otherwise, download release archive 'yosys.tar.gz' from https://github.com/YosysHQ/yosys/releases.\n"
" ('Source code' archive does not contain submodules.)\n"
)
endif()
endfunction()

321
cmake/YosysComponent.cmake Normal file
View file

@ -0,0 +1,321 @@
set(namespace "yosys")
# Properties internal to the component system.
define_property(TARGET PROPERTY YOSYS_COMPONENT)
define_property(TARGET PROPERTY YOSYS_PROVIDES)
define_property(TARGET PROPERTY YOSYS_REQUIRES)
define_property(TARGET PROPERTY YOSYS_DATA_FILES)
define_property(TARGET PROPERTY YOSYS_ENABLE_IF)
# Syntax:
#
# yosys_component(<prefix> <name> [INTERFACE]
# [<source>...]
# [DEFINITIONS <definition>...]
# [INCLUDE_DIRS <directory>...]
# [LIBRARIES <library>...]
# [PROVIDES <provided>...]
# [REQUIRES <required>...]
# [DATA_DIR <data_dir>]
# [DATA_FILES <data_file>...]
# [DATA_EXPLICIT [<dest_file> <src_file>]...]
# [ESSENTIAL]
# [ENABLE_IF "<condition>"]
# )
#
# Creates a target `yosys_<name>` (if `<prefix>` is empty) or `yosys_<prefix>_<name>` (if `<prefix>` is not empty).
# This target is an library target with some Yosys-specific behavior that simplifies partitioning the compiler
# into small pieces with explicitly defined compile-time and run-time dependency metadata. Circular dependencies
# between compilation units in different components are allowed.
#
# Parameter description:
# - `INTERFACE` should be specified for header-only libraries.
# - `<source>...` is a shortcut for `target_sources(PRIVATE)`.
# - `DEFINITIONS <definition>...` is a shortcut for `target_compile_definitions(PRIVATE)`.
# - `INCLUDE_DIRS <directory>...` is a shortcut for `target_include_directories(PRIVATE)`.
# - `LIBRARIES <library>...` is a shortcut for `target_link_libraries(PRIVATE)`.
# - `PROVIDES <provided>...` creates aliases to each `<provided>` component name.
# - `REQUIRES <required>...` ensures that if this target is linked into the Yosys binary, then every
# `<required>` component is also linked in.
# - `DATA_DIR <data_dir>` configures a base directory for installing data files; this directory
# is (relative to the root build directory or the installation prefix) `share/<data_dir>` if
# `DATA_DIR` is provided, and `share` if not.
# - `DATA_FILES <data_file>...` installs each of `<data_file>` as `share/<data_dir>/<path>/<name>`,
# where `<path>` is the directory name of `<data_file>` and `<name>` is the filename of `<data_file>`.
# - `DATA_EXPLICIT [<dest_file> <src_file>]...` installs each `<src_file>` as `share/<data_dir>/<dest_file>`.
# Where possible, `DATA_FILES` should be used instead.
# - `ESSENTIAL` ensures that this target is always linked into the Yosys binary.
# - `ENABLE_IF "<condition>"` marks the component as available only when `if(<condition>)` would run.
#
# Avoid using this function directly. Instead, use one of the wrappers below as follows:
# - to define a normal pass, use `yosys_pass(<name>)` to add a component called `<name>`.
# - to define a test pass, use `yosys_test_pass(<name>)` to add a component called `test_<name>`.
# - to define a frontend, use `yosys_frontend(<name>)` to add a component called `read_<name>`.
# - to define a backend, use `yosys_backend(<name>)` to add a component called `write_<name>`.
# - if the component sources define more than one pass, use `PROVIDES` with names of the other passes.
# - if the component uses `Pass::call()`, `Frontend::frontend_call()`, `Backend::backend_call()`, or other
# similar functions, use `REQUIRES` with names of all possibly needed passes.
# - if the component needs an essential pass, add the latter to `REQUIRES` anyway for completeness.
# - if the component subclasses a `ScriptPass`, build Yosys, then run `misc/script_pass_depends.py <pass>`
# to extract the names of all referenced passes.
# - in general, component names should be the same as corresponding pass names (as used in the REPL),
# but this is not a hard requirement and any suitable name can be used if desired.
#
function(yosys_component arg_PREFIX arg_NAME)
cmake_parse_arguments(PARSE_ARGV 2 arg
"INTERFACE;ESSENTIAL;BOOTSTRAP"
"DATA_DIR;ENABLE_IF"
"DEFINITIONS;INCLUDE_DIRS;LIBRARIES;DATA_FILES;DATA_EXPLICIT;PROVIDES;REQUIRES"
)
set(arg_SOURCES ${arg_UNPARSED_ARGUMENTS})
if ("${arg_ENABLE_IF}" STREQUAL "")
set(arg_ENABLE_IF TRUE)
endif()
if (arg_PREFIX STREQUAL "")
set(component "${arg_NAME}")
else()
set(component "${arg_PREFIX}_${arg_NAME}")
endif()
set(target "${namespace}_${component}")
list(TRANSFORM arg_PROVIDES PREPEND ${namespace}_ OUTPUT_VARIABLE provides_targets)
# An OBJECT library is used to allow for circular symbol dependencies between any source files.
# Unfortunately, public dependencies between OBJECT libraries aren't handled correctly, so we have
# to do it ourselves.
if (arg_SOURCES AND NOT arg_INTERFACE)
add_library(${target} EXCLUDE_FROM_ALL OBJECT)
target_sources(${target} PRIVATE ${arg_SOURCES})
target_include_directories(${target} PRIVATE ${arg_INCLUDE_DIRS})
target_compile_definitions(${target} PRIVATE ${arg_DEFINITIONS})
target_link_libraries(${target} PUBLIC yosys_common ${arg_LIBRARIES})
foreach (alias ${provides_targets})
add_library(${alias} ALIAS ${target})
endforeach()
else()
add_library(${target} EXCLUDE_FROM_ALL INTERFACE)
endif()
set_target_properties(${target} PROPERTIES
YOSYS_COMPONENT YES
YOSYS_PROVIDES "${arg_PROVIDES}"
YOSYS_REQUIRES "${arg_REQUIRES}"
YOSYS_DATA_FILES ""
YOSYS_ENABLE_IF "${arg_ENABLE_IF}"
)
set(share_file_pairs)
foreach (share_file ${arg_DATA_FILES})
list(APPEND share_file_pairs ${share_file} ${share_file})
endforeach()
list(APPEND share_file_pairs ${arg_DATA_EXPLICIT})
if (share_file_pairs)
set(data_depends)
set(share_root ${CMAKE_BINARY_DIR}/share)
while (share_file_pairs)
list(LENGTH share_file_pairs share_file_unpaired)
if (share_file_unpaired EQUAL 1)
message(FATAL_ERROR "Unpaired DATA_EXPLICIT argument: ${share_file_pairs}")
endif()
list(POP_FRONT share_file_pairs dst_file src_file)
cmake_path(ABSOLUTE_PATH src_file BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set(out_dir ${arg_DATA_DIR})
cmake_path(GET dst_file PARENT_PATH dst_parent)
cmake_path(APPEND out_dir ${dst_parent})
cmake_path(GET dst_file FILENAME dst_filename)
cmake_path(APPEND out_dir ${dst_filename} OUTPUT_VARIABLE out_file)
file(MAKE_DIRECTORY ${share_root}/${out_dir})
add_custom_command(
DEPENDS ${src_file}
OUTPUT ${share_root}/${out_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${share_root}/${out_file}
VERBATIM
COMMENT "Copying share/${out_file}"
)
set_property(TARGET ${target} APPEND PROPERTY YOSYS_DATA_FILES ${out_file})
list(APPEND data_depends ${share_root}/${out_file})
endwhile()
add_custom_target(${target}-data DEPENDS ${data_depends})
add_dependencies(${target} ${target}-data)
endif()
if (NOT arg_BOOTSTRAP)
set_property(TARGET yosys_everything APPEND PROPERTY YOSYS_REQUIRES ${component})
if (arg_ESSENTIAL)
set_property(TARGET yosys_essentials APPEND PROPERTY YOSYS_REQUIRES ${component})
endif()
endif()
endfunction()
# Syntax:
#
# yosys_core(<name> [<option>...])
# yosys_component("" <name> [<option>...])
#
# yosys_pass(<name> [<option>...])
# yosys_component("" <name> [<option>...])
#
# yosys_test_pass(<name> [<option>...])
# yosys_component("test" <name> [<option>...])
#
# yosys_frontend(<name> [<option>...])
# yosys_component("frontend" <name> [<option>...])
#
# yosys_backend(<name> [<option>...])
# yosys_component("backend" <name> [<option>...])
#
# See `yosys_component()` for details.
#
function(yosys_core)
yosys_component("" ${ARGV})
endfunction()
function(yosys_pass)
yosys_component("" ${ARGV})
endfunction()
function(yosys_test_pass)
yosys_component(test ${ARGV})
endfunction()
function(yosys_frontend)
yosys_component(read ${ARGV})
endfunction()
function(yosys_backend)
yosys_component(write ${ARGV})
endfunction()
# Syntax:
#
# yosys_expand_components(<variable> <component>...)
#
# Populates `<variable>` with the list of components required for linking every `<component>`,
# sorted by pre-order traversal.
#
function(yosys_expand_components arg_OUTPUT)
cmake_parse_arguments(PARSE_ARGV 1 arg "QUIET" "" "")
set(arg_COMPONENTS ${arg_UNPARSED_ARGUMENTS})
function(check_components context components)
set(error 0)
foreach (component ${components})
set(target "${namespace}_${component}")
if (NOT TARGET ${target})
message(SEND_ERROR "${context}Target ${target} does not exist")
set(error 1)
continue()
endif()
get_target_property(target_is_component ${target} YOSYS_COMPONENT)
if (NOT target_is_component)
message(SEND_ERROR "${context}Target ${target} is not a Yosys component")
set(error 1)
endif()
endforeach()
return (PROPAGATE error)
endfunction()
function(depth_first_search component visited_components required_components)
list(APPEND visited_components ${component})
get_target_property(component_requires "${namespace}_${component}" YOSYS_REQUIRES)
check_components("In REQUIRES of ${component}: " "${component_requires}")
foreach (requirement ${component_requires})
if (NOT requirement IN_LIST visited_components)
depth_first_search(${requirement} "${visited_components}" "${required_components}")
endif()
endforeach()
list(APPEND required_components ${component})
return (PROPAGATE visited_components required_components)
endfunction()
set(visited_components)
set(required_components)
check_components("" "${arg_COMPONENTS}")
foreach (component ${arg_COMPONENTS})
if (NOT component IN_LIST visited_components)
depth_first_search(${component} "${visited_components}" "${required_components}")
endif()
endforeach()
# If `everything` is in the component list, ignore disabled dependencies, else fail the build.
set(fail_if_disabled TRUE)
if (everything IN_LIST arg_COMPONENTS)
set(fail_if_disabled FALSE)
endif()
# ${required_components} are now sorted in pre-order (every component is visited before
# all of its dependents). Figure out which components are enabled and which components
# have disabled dependencies.
set(enabled_components)
if (NOT arg_QUIET)
message(TRACE "Resolving component dependencies:")
endif()
foreach (component ${required_components})
set(why_disabled "")
get_target_property(component_enable_if "${namespace}_${component}" YOSYS_ENABLE_IF)
if (${component_enable_if})
get_target_property(component_requires "${namespace}_${component}" YOSYS_REQUIRES)
foreach (requirement ${component_requires})
if (NOT requirement IN_LIST enabled_components)
set(why_disabled "dependency ${requirement}")
break()
endif()
endforeach()
else()
set(why_disabled "condition")
endif()
if ("${why_disabled}" STREQUAL "")
list(APPEND enabled_components ${component})
if (NOT arg_QUIET)
message(TRACE " Component ${component} enabled")
endif()
else()
if (NOT arg_QUIET)
message(TRACE " Component ${component} disabled (cause: ${why_disabled})")
endif()
if (fail_if_disabled)
message(FATAL_ERROR "Required component ${component} is disabled (cause: ${why_disabled})")
endif()
endif()
endforeach()
set(${arg_OUTPUT} ${enabled_components})
return(PROPAGATE ${arg_OUTPUT})
endfunction()
# Syntax:
#
# yosys_link_components(<target> {INTERFACE|PUBLIC|PRIVATE} <component>...)
#
# Link every `<component>` into `<target>`.
#
function(yosys_link_components arg_TARGET arg_SCOPE)
cmake_parse_arguments(PARSE_ARGV 2 arg "" "" "")
set(arg_COMPONENTS ${arg_UNPARSED_ARGUMENTS})
message(VERBOSE "Components for ${arg_TARGET}: ${arg_COMPONENTS}")
list(TRANSFORM arg_COMPONENTS PREPEND ${namespace}_ OUTPUT_VARIABLE linked_targets)
target_link_libraries(${arg_TARGET} ${arg_SCOPE} ${linked_targets})
endfunction()
# Syntax:
#
# yosys_install_component_data(<component>... DESTINATION <directory>)
#
# Install data files for every `<component>` into `<directory>`.
# Equivalent to copying `${CMAKE_BINARY_DIR}/share/.` to `<directory>/.` after a clean rebuild.
#
function(yosys_install_component_data)
cmake_parse_arguments(PARSE_ARGV 0 arg "" "DESTINATION" "")
set(arg_COMPONENTS ${arg_UNPARSED_ARGUMENTS})
if (NOT arg_DESTINATION)
message(FATAL_ERROR "Missing DESTINATION argument")
endif()
foreach (component ${arg_COMPONENTS})
get_target_property(data_files ${namespace}_${component} YOSYS_DATA_FILES)
foreach (data_file ${data_files})
cmake_path(GET data_file PARENT_PATH data_dir)
install(FILES ${CMAKE_BINARY_DIR}/share/${data_file} DESTINATION ${arg_DESTINATION}/${data_dir})
endforeach()
endforeach()
endfunction()

View file

@ -0,0 +1,60 @@
# Syntax:
#
# yosys_config_script({BUILD|INSTALL})
#
# Generates a `yosys-config` executable with embedded paths for in-tree builds or after installation.
#
function(yosys_config_script scope)
if (scope STREQUAL BUILD)
set(BINDIR ${CMAKE_BINARY_DIR})
set(LIBDIR ${CMAKE_BINARY_DIR})
set(DATDIR ${CMAKE_BINARY_DIR}/share)
set(suffix "")
elseif (scope STREQUAL INSTALL)
set(BINDIR ${YOSYS_INSTALL_FULL_BINDIR})
set(LIBDIR ${YOSYS_INSTALL_FULL_LIBDIR})
set(DATDIR ${YOSYS_INSTALL_FULL_DATADIR})
set(suffix ".install")
else()
message(FATAL_ERROR "Invalid scope ${scope}")
endif()
set(platform_link_flags)
set(platform_libs)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(platform_link_flags -undefined dynamic_lookup)
endif()
if (MINGW)
set(platform_libs -l:yosys.exe.a)
endif()
set(CXX ${CMAKE_CXX_COMPILER})
string(JOIN " " CXXFLAGS
-std=c++${CMAKE_CXX_STANDARD}
${CMAKE_CXX_FLAGS}
${CMAKE_CXX_COMPILE_OPTIONS_PIC}
-D_YOSYS_
"-DYOSYS_VER=\"${YOSYS_VERSION}\""
"-DYOSYS_MAJOR=${YOSYS_VERSION_MAJOR}"
"-DYOSYS_MINOR=${YOSYS_VERSION_MINOR}"
"-DYOSYS_COMMIT=${YOSYS_VERSION_COMMIT}"
-I${DATDIR}/include
)
string(JOIN " " LINKFLAGS
${CMAKE_SHARED_LIBRARY_CXX_FLAGS}
-L${LIBDIR}
${platform_link_flags}
)
string(JOIN " " LIBS
${platform_libs}
)
configure_file(${CMAKE_SOURCE_DIR}/misc/yosys-config.in
${YOSYS_PROGRAM_PREFIX}yosys-config${suffix}
USE_SOURCE_PERMISSIONS
@ONLY
)
if (scope STREQUAL INSTALL)
install(PROGRAMS ${CMAKE_BINARY_DIR}/${YOSYS_PROGRAM_PREFIX}yosys-config
DESTINATION ${YOSYS_INSTALL_BINDIR})
endif()
endfunction()

View file

@ -0,0 +1,9 @@
include(GNUInstallDirs)
# Nothing should be installed outside of the following locations.
set(YOSYS_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
set(YOSYS_INSTALL_FULL_BINDIR ${CMAKE_INSTALL_FULL_BINDIR})
set(YOSYS_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}/${YOSYS_PROGRAM_PREFIX}yosys)
set(YOSYS_INSTALL_FULL_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${YOSYS_PROGRAM_PREFIX}yosys)
set(YOSYS_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/${YOSYS_PROGRAM_PREFIX}yosys)
set(YOSYS_INSTALL_FULL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${YOSYS_PROGRAM_PREFIX}yosys)

104
cmake/YosysLinkTarget.cmake Normal file
View file

@ -0,0 +1,104 @@
# Syntax:
#
# yosys_cxx_library(<target> {SHARED|STATIC}
# OUTPUT_NAME <name>
# [INCLUDE_IN_ALL | INCLUDE_IN_ALL_IF <condition>]
# )
#
# Creates a libary target `<target>` with `SHARED` or `STATIC` scope called `<name>` (or `<target>` if
# not specified), placed in the root of the build directory and prefixed with `${YOSYS_PROGRAM_PREFIX}`.
# Target is built by default and installed only if `<condition>` (an `if()` expression) is true.
#
function(yosys_cxx_library arg_TARGET arg_SCOPE)
cmake_parse_arguments(PARSE_ARGV 2 arg "INCLUDE_IN_ALL" "OUTPUT_NAME;INCLUDE_IN_ALL_IF" "")
if (NOT arg_OUTPUT_NAME)
message(FATAL_ERROR "OUTPUT_NAME argument is mandatory")
endif()
set(include_in_all FALSE)
if (arg_INCLUDE_IN_ALL)
set(include_in_all TRUE)
elseif (${arg_INCLUDE_IN_ALL_IF})
set(include_in_all TRUE)
endif()
add_library(${arg_TARGET} ${arg_SCOPE})
set_target_properties(${arg_TARGET} PROPERTIES
PREFIX "${YOSYS_PROGRAM_PREFIX}"
OUTPUT_NAME "${arg_OUTPUT_NAME}"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
if (include_in_all)
install(TARGETS ${arg_TARGET} DESTINATION ${YOSYS_INSTALL_LIBDIR})
else()
set_target_properties(${arg_TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
endfunction()
# Syntax:
#
# yosys_cxx_executable(<target>
# [OUTPUT_NAME <name>]
# [INCLUDE_IN_ALL | INCLUDE_IN_ALL_IF <condition>]
# )
#
# Creates an executable target `<target>` scope called `<name>` (or `<target>` if not specified), placed
# in the root of the build directory and prefixed with `${YOSYS_PROGRAM_PREFIX}`. Target is built by
# default and installed only if `INCLUDE_IN_ALL` is provided or `<condition>` (an `if()` expression) is true.
#
function(yosys_cxx_executable arg_TARGET)
cmake_parse_arguments(PARSE_ARGV 1 arg "INCLUDE_IN_ALL" "OUTPUT_NAME;INCLUDE_IN_ALL_IF" "")
if (NOT arg_OUTPUT_NAME)
message(FATAL_ERROR "OUTPUT_NAME argument is mandatory")
endif()
set(include_in_all FALSE)
if (arg_INCLUDE_IN_ALL)
set(include_in_all TRUE)
elseif (${arg_INCLUDE_IN_ALL_IF})
set(include_in_all TRUE)
endif()
add_executable(${arg_TARGET})
set_target_properties(${arg_TARGET} PROPERTIES
PREFIX "${YOSYS_PROGRAM_PREFIX}"
OUTPUT_NAME "${arg_OUTPUT_NAME}"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
if (include_in_all)
install(TARGETS ${arg_TARGET} DESTINATION ${YOSYS_INSTALL_BINDIR})
else()
set_target_properties(${arg_TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
endfunction()
# Syntax:
#
# yosys_python_executable(<target> <source>)
#
# Installs Python script `<source>` as an executable in the standard binary directory, adding a launcher wrapper
# if the platform requires it. Inside `<source>`, several substitutions are available:
# - `@PYTHON_SHEBANG@` will be replaced with an appropriate shebang line (without the initial `#!`)
# - `@YOSYS_PROGRAM_PREFIX@` will be replaced with the program prefix
# - any other `@\w+@` tokens have unspecified behavior and must not be used
#
function(yosys_python_executable basename source)
if (CMAKE_SYSTEM_NAME STREQUAL MSYS)
execute_process(
COMMAND cygpath -w -m ${CMAKE_INSTALL_BINDIR}/python3
OUTPUT_VARIABLE PYTHON_SHEBANG
COMMAND_ERROR_IS_FATAL ANY
)
add_executable(${basename} ${CMAKE_SOURCE_DIR}/misc/launcher.c)
target_compile_definitions(${basename} GUI=0)
install(TARGETS ${basename} DESTINATION ${YOSYS_INSTALL_BINDIR})
set(scriptname ${CMAKE_BINARY_DIR}/${YOSYS_PROGRAM_PREFIX}${basename}-script.py)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${source} ${scriptname} @ONLY)
install(FILES ${scriptname} DESTINATION ${YOSYS_INSTALL_BINDIR})
else()
set(PYTHON_SHEBANG "/usr/bin/env python3")
set(scriptname ${CMAKE_BINARY_DIR}/${YOSYS_PROGRAM_PREFIX}${basename}${CMAKE_EXECUTABLE_SUFFIX})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${source} ${scriptname} USE_SOURCE_PERMISSIONS @ONLY)
install(PROGRAMS ${scriptname} DESTINATION ${YOSYS_INSTALL_BINDIR})
endif()
endfunction()

48
cmake/YosysVerific.cmake Normal file
View file

@ -0,0 +1,48 @@
if (APPLE)
set(VERIFIC_LIB_SUFFIX -mac.a)
elseif (LINUX)
set(VERIFIC_LIB_SUFFIX -linux.a)
elseif (WIN32)
set(VERIFIC_LIB_SUFFIX -windows.a)
else()
set(VERIFIC_LIB_SUFFIX -NOTFOUND)
endif()
# Syntax:
#
# get_verific_components(<result>)
#
# Assigns variable `<result>` to a list of Verific components detected in `${YOSYS_VERIFIC_DIR}`.
#
function(get_verific_components result)
file(GLOB libraries
RELATIVE ${YOSYS_VERIFIC_DIR}
${YOSYS_VERIFIC_DIR}/*/*${VERIFIC_LIB_SUFFIX}
)
set(components)
foreach (library ${libraries})
cmake_path(GET library PARENT_PATH component)
list(APPEND components ${component})
endforeach()
set(${result} ${components})
return(PROPAGATE ${result})
endfunction()
# Syntax:
#
# get_verific_options(<include_dirs> <libraries> <components>...)
#
# Assigns variables `<include_dirs>` and `<libraries>` to lists required to use Verific
# `<components>`.
#
function(get_verific_options include_dirs libraries)
set(${include_dirs})
set(${libraries})
foreach (component ${ARGN})
list(APPEND ${include_dirs} ${YOSYS_VERIFIC_DIR}/${component})
list(APPEND ${libraries} ${YOSYS_VERIFIC_DIR}/${component}/${component}${VERIFIC_LIB_SUFFIX})
endforeach()
return(PROPAGATE ${include_dirs} ${libraries})
endfunction()

162
cmake/YosysVersion.cmake Normal file
View file

@ -0,0 +1,162 @@
# Syntax:
#
# yosys_call_git(<args>...)
#
# Calls `git <args>...` in the project source directory. Never causes errors.
#
# Defines the following variables:
# - `git_result`: exit code
# - `git_output`: standard output (standard error is discarded)
#
function(yosys_call_git)
execute_process(
COMMAND ${GIT_EXECUTABLE} ${ARGV}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_output
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
return(PROPAGATE git_result git_output)
endfunction()
# Syntax:
#
# yosys_extract_version()
#
# Defines the following variables:
# - `YOSYS_VERSION_MAJOR`: major version number
# - `YOSYS_VERSION_MINOR`: minor version number
# - `YOSYS_VERSION_COMMIT`: distance since release
# - `YOSYS_VERSION`: either `<major>.<minor>+<distance>` or `<major>.<minor>+post`
# - `YOSYS_CHECKOUT_INFO`: either `<abbrev>`, `<abbrev>-dirty`, or `UNKNOWN`
# - `YOSYS_ORIGIN_INFO`: either `forge.tld/repo/user at branch` or ``
#
# For builds without git, it is possible to define `-DYOSYS_CHECKOUT_INFO=` and
# `-DYOSYS_ORIGIN_INFO=` explicitly when configuring, which will be included in log output.
#
function(yosys_extract_version)
# Version numbers are placed in an external file that can be easily rewritten.
include(YosysVersionData)
# Extract git metadata if possible.
set(git_distance "")
set(git_abbrev "")
set(git_dirty NO)
set(git_origin "")
set(git_branch "")
find_package(Git QUIET)
if (Git_FOUND)
yosys_call_git(rev-parse --git-dir)
if (git_result EQUAL 0)
set(git_dir ${git_output})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${git_dir}/HEAD)
file(READ ${git_dir}/HEAD git_head)
if (git_head MATCHES "^ref: (.+)\n$")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${git_dir}/${CMAKE_MATCH_1})
endif()
yosys_call_git(rev-list --count v${YOSYS_VERSION_MAJOR}.${YOSYS_VERSION_MINOR}..HEAD)
set(git_distance ${git_output})
yosys_call_git(rev-parse --short=9 HEAD)
set(git_abbrev ${git_output})
yosys_call_git(diff --exit-code --quiet)
set(git_dirty ${git_result})
yosys_call_git(config --get remote.origin.url)
set(git_origin ${git_output})
yosys_call_git(rev-parse --abbrev-ref HEAD)
set(git_branch ${git_output})
endif()
endif()
# Build YOSYS_VERSION (just the version info).
set(YOSYS_VERSION "${YOSYS_VERSION_MAJOR}.${YOSYS_VERSION_MINOR}")
if (git_distance STREQUAL "")
string(APPEND YOSYS_VERSION "+post")
else()
set(YOSYS_VERSION_COMMIT ${git_distance})
if (NOT git_distance EQUAL 0)
string(APPEND YOSYS_VERSION "+${git_distance}")
endif()
endif()
message(STATUS "Configuring Yosys ${YOSYS_VERSION}")
if (NOT YOSYS_CHECKOUT_INFO)
# Build YOSYS_CHECKOUT_INFO (git sha1 and dirty status).
if (git_abbrev STREQUAL "")
# No git checkout, see if the tarball was created with `git archive`.
file(READ ${CMAKE_SOURCE_DIR}/.gitcommit git_abbrev)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/.gitcommit)
string(STRIP "${git_abbrev}" git_abbrev)
if (git_abbrev MATCHES "Format:")
# No substitutions, we're out of options.
set(YOSYS_CHECKOUT_INFO UNKNOWN)
else()
# Substitutions were made, good.
set(YOSYS_CHECKOUT_INFO ${git_abbrev})
endif()
else()
# Valid git checkout, use accurate information.
set(YOSYS_CHECKOUT_INFO ${git_abbrev})
if (git_dirty)
string(APPEND YOSYS_CHECKOUT_INFO "-dirty")
endif()
endif()
endif()
if (NOT YOSYS_ORIGIN_INFO)
# Build YOSYS_ORIGIN_INFO (git repository origin and branch)
if (git_origin AND git_branch)
string(REGEX REPLACE "^https://|.git$" "" git_origin ${git_origin})
if (git_origin STREQUAL "github.com/YosysHQ/yosys" AND git_branch MATCHES "^HEAD|main|release/v.+$")
# Nothing to highlight.
set(YOSYS_ORIGIN_INFO "")
else()
# Highlight clone URL and branch.
set(YOSYS_ORIGIN_INFO "${git_origin} at ${git_branch}")
endif()
endif()
endif()
if (YOSYS_ORIGIN_INFO)
message(STATUS "Git commit ${YOSYS_CHECKOUT_INFO} from ${YOSYS_ORIGIN_INFO}")
else()
message(STATUS "Git commit ${YOSYS_CHECKOUT_INFO}")
endif()
return(PROPAGATE
YOSYS_VERSION_MAJOR
YOSYS_VERSION_MINOR
YOSYS_VERSION_COMMIT
YOSYS_VERSION
YOSYS_CHECKOUT_INFO
YOSYS_ORIGIN_INFO
)
endfunction()
# Syntax:
#
# yosys_version_file(<input> <output>)
#
# Templates `<output>` file based on `<input>` with the following substitutions:
# - `@YOSYS_VERSION@`: version in `<major>.<minor>+<post>` format
# - `@YOSYS_BUILD_INFO@`: free-form build information
# (not actually entirely free-form as external software tries to parse it sometimes)
#
# Must have executed `yosys_extract_version()` first.
#
function(yosys_version_file arg_INPUT arg_OUTPUT)
set(YOSYS_BUILD_INFO "Yosys")
string(APPEND YOSYS_BUILD_INFO " ${YOSYS_VERSION}")
string(APPEND YOSYS_BUILD_INFO " (git sha1 ${YOSYS_CHECKOUT_INFO},")
if (CMAKE_BUILD_TYPE)
string(APPEND YOSYS_BUILD_INFO " ${CMAKE_BUILD_TYPE},")
endif()
string(APPEND YOSYS_BUILD_INFO " ${CMAKE_CXX_COMPILER_ID}")
string(APPEND YOSYS_BUILD_INFO " ${CMAKE_CXX_COMPILER}")
string(APPEND YOSYS_BUILD_INFO " ${CMAKE_CXX_COMPILER_VERSION})")
if (YOSYS_ORIGIN_INFO)
string(APPEND YOSYS_BUILD_INFO " [${YOSYS_ORIGIN_INFO}]")
endif()
configure_file(${arg_INPUT} ${arg_OUTPUT} @ONLY)
endfunction()

View file

@ -0,0 +1,2 @@
set(YOSYS_VERSION_MAJOR 0)
set(YOSYS_VERSION_MINOR 64)

View file

@ -0,0 +1,8 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View file

@ -0,0 +1,8 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

48
cmake_Makefile_left Normal file
View file

@ -0,0 +1,48 @@
ifneq ($(SEED),)
SEEDOPT="-S $(SEED)"
endif
ifneq ($(ABCEXTERNAL),)
ABCOPT="-A $(ABCEXTERNAL)"
endif
test: vanilla-test unit-test
vanilla-test: $(TARGETS) $(EXTRA_TARGETS)
@$(MAKE) -C tests vanilla-test \
$(if $(ENABLE_VERIFIC),ENABLE_VERIFIC=$(ENABLE_VERIFIC)) \
$(if $(YOSYS_NOVERIFIC),YOSYS_NOVERIFIC=$(YOSYS_NOVERIFIC)) \
SEEDOPT=$(SEEDOPT) ABCOPT=$(ABCOPT)
unit-test: libyosys.so
@$(MAKE) -f $(UNITESTPATH)/Makefile CXX="$(CXX)" CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" \
CXXFLAGS="$(CXXFLAGS)" LINKFLAGS="$(LINKFLAGS)" LIBS="$(LIBS)" ROOTPATH="$(CURDIR)"
VALGRIND ?= valgrind --error-exitcode=1 --leak-check=full --show-reachable=yes --errors-for-leak-kinds=all
vgtest: $(TARGETS) $(EXTRA_TARGETS)
$(VALGRIND) ./yosys -p 'setattr -mod -unset top; synth' $$( ls tests/simple/*.v | grep -v repwhile.v )
@echo ""
@echo " Passed \"make vgtest\"."
@echo ""
vloghtb: $(TARGETS) $(EXTRA_TARGETS)
+cd tests/vloghtb && bash run-test.sh
@echo ""
@echo " Passed \"make vloghtb\"."
@echo ""
ystests: $(TARGETS) $(EXTRA_TARGETS)
rm -rf tests/ystests
git clone https://github.com/YosysHQ/yosys-tests.git tests/ystests
+$(MAKE) PATH="$$PWD:$$PATH" -C tests/ystests
@echo ""
@echo " Finished \"make ystests\"."
@echo ""
FUNC_KERNEL := functional.cc functional.h sexpr.cc sexpr.h compute_graph.h
FUNC_INCLUDES := $(addprefix --include *,functional/* $(FUNC_KERNEL))
coverage_functional:
rm -rf coverage.info coverage_html
lcov --capture -d backends/functional -d kernel $(FUNC_INCLUDES) --no-external -o coverage.info
genhtml coverage.info --output-directory coverage_html

View file

@ -1,3 +1,5 @@
include common.mk
# Makefile for Sphinx documentation
#
@ -46,10 +48,10 @@ help:
.PHONY: clean
clean: clean-examples
rm -rf $(BUILDDIR)/*
rm -rf util/__pycache__
rm -rf source/generated
$(MAKE) -C source/_images clean
@rm -rf $(BUILDDIR)/*
@rm -rf util/__pycache__
@rm -rf source/generated
@$(MAKE) -C source/_images clean
.PHONY: html
html:
@ -235,7 +237,7 @@ test: test-examples test-macros
FORCE:
Makefile-%: FORCE
$(MAKE) -C $(@D) $(*F)
@$(MAKE) -C $(@D) $(*F)
CODE_EXAMPLES := $(wildcard source/code_examples/*/Makefile)
TEST_EXAMPLES := $(addsuffix -examples,$(CODE_EXAMPLES))
@ -245,18 +247,42 @@ clean-examples: $(CLEAN_EXAMPLES)
examples: $(TEST_EXAMPLES)
test-macros:
$(PYTHON) tests/macro_commands.py
@$(PYTHON) tests/macro_commands.py
.PHONY: images
images:
$(MAKE) -C source/_images
$(MAKE) -C source/_images convert
@$(MAKE) -C source/_images
@$(MAKE) -C source/_images convert
.PHONY: extract
extract:
@mkdir -p source/generated
@$(BUILD_CMD)yosys -q -p 'help -dump-cmds-json source/generated/cmds.json'
@$(BUILD_CMD)yosys -q -p 'help -dump-cells-json source/generated/cells.json'
@cp ../passes/cmds/chformal.cc source/generated/
@$(BUILD_CMD)yosys -qQT -h 'chformal' -l source/generated/chformal.log
@mkdir -p source/generated/functional
@cp ../backends/functional/smtlib.cc source/generated/functional/
-@cd .. && diff -U 20 backends/functional/smtlib.cc backends/functional/smtlib_rosette.cc \
> docs/source/generated/functional/rosette.diff || true
@$(BUILD_CMD)yosys --help >source/generated/yosys
@$(BUILD_CMD)yosys-smtbmc --help >source/generated/yosys-smtbmc
@$(BUILD_CMD)yosys-witness --help >source/generated/yosys-witness
@$(BUILD_CMD)yosys-config --help >source/generated/yosys-config
-@$(BUILD_CMD)yosys-filterlib --help 2>source/generated/yosys-filterlib || true
ifeq ($(ABCEXTERNAL),)
-@$(BUILD_CMD)yosys-abc --help 2>source/generated/yosys-abc > /dev/null || true
endif
.PHONY: gen
gen:
$(MAKE) examples
$(MAKE) images
@$(MAKE) examples
@$(MAKE) images
@$(MAKE) extract
.PHONY: reqs
reqs:
$(PYTHON) -m pip install -r source/requirements.txt
@$(PYTHON) -m pip install -r source/requirements.txt

9
docs/common.mk Normal file
View file

@ -0,0 +1,9 @@
ROOT_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
BUILD_DIR ?= $(ROOT_DIR)/../build
BUILD_CMD := $(BUILD_DIR)/$(PROGRAM_PREFIX)
YOSYS ?= $(BUILD_CMD)yosys
YOSYS_CONFIG ?= $(BUILD_CMD)yosys-config
export YOSYS
export YOSYS_CONFIG

View file

@ -34,18 +34,18 @@ all_tex: $(TEX_FILES:.tex=.pdf) $(TEX_FILES:.tex=.svg)
# limit output size to US letter (same as latexpdf output) to avoid oversize error
%.pdf: %.dot
$(FAKETIME) dot -Tpdf -Gsize="8.5,11" -o $@ $<
@$(FAKETIME) dot -Tpdf -Gsize="8.5,11" -o $@ $< >/dev/null 2>&1
%.pdf: %.tex
cd $(@D) && $(FAKETIME) pdflatex $(<F) --interaction=nonstopmode
@cd $(@D) && $(FAKETIME) pdflatex $(<F) --interaction=nonstopmode >/dev/null 2>&1
%.svg: %.pdf
pdf2svg $< $@
@pdf2svg $< $@ >/dev/null 2>&1
.PHONY: clean tidy
tidy:
rm -f **/*.log **/*.aux
@rm -f **/*.log **/*.aux
clean: tidy
rm -rf code_examples
rm -f **/*.pdf **/*.svg
@rm -rf code_examples
@rm -f **/*.pdf **/*.svg

View file

@ -1,33 +1,28 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
.PHONY: all dots examples
all: dots examples
dots: test1.dot my_cmd.so
examples: test0.log test1.log test2.log my_cmd.so
CXXFLAGS=$(shell $(YOSYS)-config --cxxflags)
DATDIR=$(shell $(YOSYS)-config --datdir)
my_cmd.so: my_cmd.cc
$(YOSYS)-config --exec --cxx $(subst $(DATDIR),../../../../share,$(CXXFLAGS)) --ldflags -o my_cmd.so -shared my_cmd.cc --ldlibs
@$(YOSYS_CONFIG) --exec --cxx --cxxflags --ldflags -o my_cmd.so -shared my_cmd.cc --ldlibs
test0.log: my_cmd.so
$(YOSYS) -QTl test0.log_new -m ./my_cmd.so -p 'my_cmd foo bar' -f verilog absval_ref.v
mv test0.log_new test0.log
@$(YOSYS) -QTl test0.log_new -m ./my_cmd.so -p 'my_cmd foo bar' -f verilog absval_ref.v >/dev/null 2>&1
@mv test0.log_new test0.log
test1.log: my_cmd.so
$(YOSYS) -QTl test1.log_new -m ./my_cmd.so -p 'clean; test1; dump' -f verilog absval_ref.v
mv test1.log_new test1.log
@$(YOSYS) -QTl test1.log_new -m ./my_cmd.so -p 'clean; test1; dump' -f verilog absval_ref.v >/dev/null 2>&1
@mv test1.log_new test1.log
test1.dot: my_cmd.so
$(YOSYS) -m ./my_cmd.so -p 'test1; show -format dot -prefix test1'
@$(YOSYS) -m ./my_cmd.so -p 'test1; show -format dot -prefix test1' >/dev/null 2>&1
test2.log: my_cmd.so
$(YOSYS) -QTl test2.log_new -m ./my_cmd.so -p 'hierarchy -top test; test2' -f verilog sigmap_test.v
mv test2.log_new test2.log
@$(YOSYS) -QTl test2.log_new -m ./my_cmd.so -p 'hierarchy -top test; test2' -f verilog sigmap_test.v >/dev/null 2>&1
@mv test2.log_new test2.log
.PHONY: clean
clean:
rm -f *.d *.so *.dot
@rm -f *.d *.so *.dot

View file

@ -1,6 +1,4 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
DOT_NAMES = addr_gen_hier addr_gen_proc addr_gen_clean
DOT_NAMES += rdata_proc rdata_flat rdata_adffe rdata_memrdv2 rdata_alumacc rdata_coarse
@ -16,12 +14,12 @@ dots: $(DOTS) $(MAPDOTS)
examples: fifo.out fifo.stat
$(DOTS) fifo.out: fifo.v fifo.ys
$(YOSYS) fifo.ys -l fifo.out -Q -T
@$(YOSYS) fifo.ys -l fifo.out -Q -T >/dev/null 2>&1
$(MAPDOTS) fifo.stat: fifo.v fifo_map.ys
$(YOSYS) fifo_map.ys
@$(YOSYS) fifo_map.ys >/dev/null 2>&1
.PHONY: clean
clean:
rm -f *.dot
rm -f fifo.out fifo.stat
@rm -f *.dot
@rm -f fifo.out fifo.stat

View file

@ -1,6 +1,4 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
DOTS = counter_00.dot counter_01.dot counter_02.dot counter_03.dot
@ -10,8 +8,8 @@ dots: $(DOTS)
examples:
$(DOTS): counter.v counter.ys mycells.lib
$(YOSYS) counter.ys
@$(YOSYS) counter.ys >/dev/null 2>&1
.PHONY: clean
clean:
rm -f *.dot
@rm -f *.dot

View file

@ -1,6 +1,4 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
DOTS = macc_simple_xmap.dot macc_xilinx_xmap.dot
@ -10,12 +8,12 @@ dots: $(DOTS)
examples:
macc_simple_xmap.dot: macc_simple_*.v macc_simple_test.ys
$(YOSYS) macc_simple_test.ys
@$(YOSYS) macc_simple_test.ys >/dev/null 2>&1
macc_xilinx_xmap.dot: macc_xilinx_*.v macc_xilinx_test.ys
$(YOSYS) macc_xilinx_test.ys
@$(YOSYS) macc_xilinx_test.ys >/dev/null 2>&1
.PHONY: clean
clean:
rm -f *.dot
@rm -f *.dot

View file

@ -1,6 +1,4 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
DOT_NAMES = opt_share opt_muxtree opt_merge opt_expr
@ -12,9 +10,9 @@ dots: $(DOTS)
examples:
%.dot: %.ys
$(YOSYS) $<
gvpack -u -o $@ $*_full.dot
@$(YOSYS) $< >/dev/null 2>&1
@gvpack -u -o $@ $*_full.dot >/dev/null 2>&1
.PHONY: clean
clean:
rm -f *.dot
@rm -f *.dot

View file

@ -1,6 +1,4 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
.PHONY: all dots examples
all: dots examples
@ -8,8 +6,8 @@ dots: scrambler_p01.dot scrambler_p02.dot
examples:
scrambler_p01.dot scrambler_p02.dot: scrambler.ys scrambler.v
$(YOSYS) scrambler.ys
@$(YOSYS) scrambler.ys >/dev/null 2>&1
.PHONY: clean
clean:
rm -f *.dot
@rm -f *.dot

View file

@ -1,6 +1,4 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
SUMPROD = sumprod_00 sumprod_01 sumprod_02 sumprod_03 sumprod_04 sumprod_05
SUMPROD_DOTS := $(addsuffix .dot,$(SUMPROD))
@ -17,18 +15,18 @@ dots: select.dot $(SUMPROD_DOTS) $(MEMDEMO_DOTS) $(SUBMOD_DOTS)
examples: sumprod.out
select.dot: select.v select.ys
$(YOSYS) select.ys
@$(YOSYS) select.ys >/dev/null 2>&1
$(SUMPROD_DOTS) sumprod.out: sumprod.v sumprod.ys
$(YOSYS) sumprod.ys
@$(YOSYS) sumprod.ys >/dev/null 2>&1
$(MEMDEMO_DOTS): memdemo.v memdemo.ys
$(YOSYS) memdemo.ys
@$(YOSYS) memdemo.ys >/dev/null 2>&1
$(SUBMOD_DOTS): memdemo.v submod.ys
$(YOSYS) submod.ys
@$(YOSYS) submod.ys >/dev/null 2>&1
.PHONY: clean
clean:
rm -rf *.dot
rm -f sumprod.out
@rm -rf *.dot
@rm -f sumprod.out

View file

@ -1,6 +1,4 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
EXAMPLE = example_first example_second example_third
EXAMPLE_DOTS := $(addsuffix .dot,$(EXAMPLE))
@ -14,18 +12,18 @@ dots: splice.dot $(EXAMPLE_DOTS) $(CMOS_DOTS)
examples: example.out
splice.dot: splice.v
$(YOSYS) -p 'prep -top splice_demo; show -format dot -prefix splice' splice.v
@$(YOSYS) -p 'prep -top splice_demo; show -format dot -prefix splice' splice.v >/dev/null 2>&1
$(EXAMPLE_DOTS): example.v example.ys
$(YOSYS) example.ys
@$(YOSYS) example.ys >/dev/null 2>&1
example.out: example_lscd.ys example.v
$(YOSYS) $< -l $@ -Q -T
@$(YOSYS) $< -l $@ -Q -T >/dev/null 2>&1
$(CMOS_DOTS): cmos.v cmos.ys
$(YOSYS) cmos.ys
@$(YOSYS) cmos.ys >/dev/null 2>&1
.PHONY: clean
clean:
rm -rf *.dot
rm -f example.out
@rm -rf *.dot
@rm -f example.out

View file

@ -1,3 +1,5 @@
include ../../../common.mk
.PHONY: all dots examples
all: dots examples
dots:
@ -5,15 +7,15 @@ examples:
.PHONY: test
test: stubnets.so
yosys -ql test1.log -m ./stubnets.so test.v -p "stubnets"
yosys -ql test2.log -m ./stubnets.so test.v -p "opt; stubnets"
yosys -ql test3.log -m ./stubnets.so test.v -p "techmap; opt; stubnets -report_bits"
tail test1.log test2.log test3.log
@$(YOSYS) -ql test1.log -m ./stubnets.so test.v -p "stubnets" >/dev/null 2>&1
@$(YOSYS) -ql test2.log -m ./stubnets.so test.v -p "opt; stubnets" >/dev/null 2>&1
@$(YOSYS) -ql test3.log -m ./stubnets.so test.v -p "techmap; opt; stubnets -report_bits" >/dev/null 2>&1
@tail test1.log test2.log test3.log
stubnets.so: stubnets.cc
yosys-config --exec --cxx --cxxflags --ldflags -o $@ -shared $^ --ldlibs
@$(YOSYS)-config --exec --cxx --cxxflags --ldflags -o $@ -shared $^ --ldlibs >/dev/null 2>&1
.PHONY: clean
clean:
rm -f test1.log test2.log test3.log
rm -f stubnets.so stubnets.d
@rm -f test1.log test2.log test3.log
@rm -f stubnets.so stubnets.d

View file

@ -1,12 +1,9 @@
include ../../../common.mk
DOT_TARGETS += proc_01 proc_02 proc_03
DOT_TARGETS += memory_01 memory_02
DOT_TARGETS += techmap_01
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
DOTS = $(addsuffix .dot,$(DOT_TARGETS))
.PHONY: all dots examples
@ -15,9 +12,9 @@ dots: $(DOTS)
examples:
%.dot: %.v %.ys
$(YOSYS) -p 'script $*.ys; show -notitle -prefix $* -format dot'
@$(YOSYS) -p 'script $*.ys; show -notitle -prefix $* -format dot' >/dev/null 2>&1
.PHONY: clean
clean:
rm -f *.dot
@rm -f *.dot

View file

@ -1,6 +1,4 @@
PROGRAM_PREFIX :=
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
include ../../../common.mk
.PHONY: all dots examples
all: dots examples
@ -8,20 +6,20 @@ dots: red_or3x1.dot sym_mul.dot mymul.dot mulshift.dot addshift.dot
examples:
red_or3x1.dot: red_or3x1_*
$(YOSYS) red_or3x1_test.ys
@$(YOSYS) red_or3x1_test.ys >/dev/null 2>&1
sym_mul.dot: sym_mul_*
$(YOSYS) sym_mul_test.ys
@$(YOSYS) sym_mul_test.ys >/dev/null 2>&1
mymul.dot: mymul_*
$(YOSYS) mymul_test.ys
@$(YOSYS) mymul_test.ys >/dev/null 2>&1
mulshift.dot: mulshift_*
$(YOSYS) mulshift_test.ys
@$(YOSYS) mulshift_test.ys >/dev/null 2>&1
addshift.dot: addshift_*
$(YOSYS) addshift_test.ys
@$(YOSYS) addshift_test.ys >/dev/null 2>&1
.PHONY: clean
clean:
rm -f *.dot
@rm -f *.dot

View file

@ -5,6 +5,7 @@ from pathlib import Path
import re
import subprocess
import sys
import os
# basic logging setup
logging.basicConfig(level=logging.INFO)
@ -17,7 +18,7 @@ THIS_FILE = (TESTS_DIR / "macro_commands.py").relative_to(ROOT_DIR)
MACRO_SOURCE = TESTS_DIR.parent / "source" / "code_examples" / "macro_commands"
assert MACRO_SOURCE.exists(), f"can't find macro_commands in {MACRO_SOURCE}"
YOSYS = ROOT_DIR / "yosys"
YOSYS = Path(os.environ.get("YOSYS", ROOT_DIR / "yosys"))
assert YOSYS.exists(), f"can't find yosys executable in {YOSYS}"
raise_error = False

View file

@ -1,5 +1,5 @@
// Note: Set ENABLE_LIBYOSYS=1 in Makefile or Makefile.conf to build libyosys.so
// yosys-config --exec --cxx -o demomain --cxxflags --ldflags demomain.cc -lyosys -lstdc++
// Note: Use `cmake -DYOSYS_INSTALL_LIBRARY=1` or build the `libyosys` target first
// yosys-config --exec --cxx -o demomain --cxxflags --ldflags demomain.cc -lyosys
#include <kernel/yosys.h>

14
flake.lock generated
View file

@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
@ -20,16 +20,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1708807242,
"narHash": "sha256-sRTRkhMD4delO/hPxxi+XwLqPn8BuUq6nnj4JqLwOu0=",
"lastModified": 1778869304,
"narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "73de017ef2d18a04ac4bfd0c02650007ccb31c2a",
"rev": "d233902339c02a9c334e7e593de68855ad26c4cb",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}

View file

@ -1,47 +1,77 @@
{
description = "A nix flake for the Yosys synthesis suite";
description = "A Nix flake for the Yosys synthesis suite.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# This requires Nix >= 2.27.0.
self.submodules = true;
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(final: prev: {
yosys = final.callPackage ./nix/pkgs/yosys.nix {
src = self;
rev = (self.shortRev or self.dirtyShortRev or "unknown");
};
})
];
};
# TODO: don't override src when ./abc is empty
# which happens when the command used is `nix build` and not `nix build ?submodules=1`
abc-verifier = pkgs.abc-verifier;
yosys = pkgs.clangStdenv.mkDerivation {
name = "yosys";
src = ./. ;
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 zlib git pkg-configUpstream llvmPackages.bintools ];
checkInputs = with pkgs; [ gtest ];
propagatedBuildInputs = [ abc-verifier ];
preConfigure = "make config-clang";
checkTarget = "unit-test";
installPhase = ''
make install PREFIX=$out ABCEXTERNAL=yosys-abc
ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc
'';
buildPhase = ''
make -j$(nproc) ABCEXTERNAL=yosys-abc
'';
meta = with pkgs.lib; {
description = "Yosys Open SYnthesis Suite";
homepage = "https://yosyshq.net/yosys/";
license = licenses.isc;
maintainers = with maintainers; [ ];
yosys-clang = pkgs.yosys.override { stdenv = pkgs.clangStdenv; };
win32Pkgs = pkgs.callPackage ./nix/cross/win32.nix { };
win64Pkgs = pkgs.callPackage ./nix/cross/win64.nix { };
mkShell =
t:
pkgs.mkShell.override { stdenv = t.stdenv; } {
inputsFrom = [
t
];
packages = with pkgs; [
llvmPackages.clang-tools
];
shellHook = ''
DRIVER_ROOT="${t.stdenv.cc}/bin"
export CLANGD_FLAGS="--query-driver $DRIVER_ROOT/$CC,$DRIVER_ROOT/$CXX"
'';
};
in
{
formatter = pkgs.nixfmt-tree;
devShells = rec {
shell = mkShell yosys-clang;
shell-gcc = mkShell pkgs.yosys;
shell-win32 = mkShell win32Pkgs.yosys;
shell-win64 = mkShell win64Pkgs.yosys;
default = shell;
};
in {
packages.default = yosys;
defaultPackage = yosys;
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ clang llvmPackages.bintools gcc bison flex libffi tcl readline python3 zlib git gtest abc-verifier verilog ];
packages = rec {
yosys = yosys-clang;
yosys-gcc = pkgs.yosys;
yosys-win32 = win32Pkgs.yosys;
yosys-win64 = win64Pkgs.yosys;
default = yosys;
};
}
);

10
frontends/CMakeLists.txt Normal file
View file

@ -0,0 +1,10 @@
add_subdirectory(aiger)
add_subdirectory(aiger2)
add_subdirectory(ast)
add_subdirectory(blif)
add_subdirectory(json)
add_subdirectory(liberty)
add_subdirectory(rpc)
add_subdirectory(rtlil)
add_subdirectory(verific)
add_subdirectory(verilog)

View file

@ -0,0 +1,6 @@
yosys_frontend(aigerparse
aigerparse.cc
aigerparse.h
REQUIRES
opt_clean
)

View file

@ -1,3 +0,0 @@
OBJS += frontends/aiger/aigerparse.o

View file

@ -0,0 +1,3 @@
yosys_frontend(xaiger2
xaiger.cc
)

View file

@ -1,2 +0,0 @@
OBJS += frontends/aiger2/xaiger.o

View file

@ -0,0 +1,13 @@
yosys_core(ast
ast_binding.cc
ast_binding.h
ast.cc
ast.h
dpicall.cc
genrtlil.cc
simplify.cc
LIBRARIES
$<${YOSYS_ENABLE_LIBFFI}:${Dlfcn_LIBRARIES};PkgConfig::libffi>
REQUIRES
sha1
)

View file

@ -1,7 +0,0 @@
OBJS += frontends/ast/ast.o
OBJS += frontends/ast/simplify.o
OBJS += frontends/ast/genrtlil.o
OBJS += frontends/ast/dpicall.o
OBJS += frontends/ast/ast_binding.o

View file

@ -19,7 +19,7 @@
#include "ast.h"
#ifdef YOSYS_ENABLE_PLUGINS
#ifdef YOSYS_ENABLE_LIBFFI
#include <dlfcn.h>
#include <ffi.h>
@ -149,7 +149,7 @@ std::unique_ptr<AST::AstNode> AST::dpi_call(AstSrcLocType loc, const std::string
YOSYS_NAMESPACE_END
#else /* YOSYS_ENABLE_PLUGINS */
#else /* YOSYS_ENABLE_LIBFFI */
YOSYS_NAMESPACE_BEGIN
@ -160,5 +160,5 @@ std::unique_ptr<AST::AstNode> AST::dpi_call(AstSrcLocType, const std::string&, c
YOSYS_NAMESPACE_END
#endif /* YOSYS_ENABLE_PLUGINS */
#endif /* YOSYS_ENABLE_LIBFFI */

View file

@ -0,0 +1,8 @@
yosys_frontend(blif
blifparse.cc
blifparse.h
DATA_DIR
include/frontends/blif
DATA_FILES
blifparse.h
)

View file

@ -1,3 +0,0 @@
OBJS += frontends/blif/blifparse.o

View file

@ -0,0 +1,3 @@
yosys_frontend(json
jsonparse.cc
)

View file

@ -1,3 +0,0 @@
OBJS += frontends/json/jsonparse.o

View file

@ -0,0 +1,5 @@
yosys_frontend(liberty
liberty.cc
REQUIRES
libparse
)

Some files were not shown because too many files have changed in this diff Show more