From 5f1d2297aa8cc734aa1801f3d89458ae28da02b6 Mon Sep 17 00:00:00 2001 From: Catherine Date: Tue, 12 May 2026 05:33:04 +0000 Subject: [PATCH] Migrate build system to CMake See #5895 for details. This commit does not include CI or documentation changes. --- .gitignore | 4 + CMakeLists.txt | 499 +++++++ Makefile | 1219 ----------------- backends/CMakeLists.txt | 18 + backends/aiger/CMakeLists.txt | 8 + backends/aiger/Makefile.inc | 4 - backends/aiger2/CMakeLists.txt | 5 + backends/aiger2/Makefile.inc | 1 - backends/blif/CMakeLists.txt | 3 + backends/blif/Makefile.inc | 3 - backends/btor/CMakeLists.txt | 7 + backends/btor/Makefile.inc | 3 - backends/cxxrtl/CMakeLists.txt | 19 + backends/cxxrtl/Makefile.inc | 11 - backends/edif/CMakeLists.txt | 3 + backends/edif/Makefile.inc | 3 - backends/firrtl/CMakeLists.txt | 8 + backends/firrtl/Makefile.inc | 3 - backends/functional/CMakeLists.txt | 12 + backends/functional/Makefile.inc | 4 - backends/intersynth/CMakeLists.txt | 3 + backends/intersynth/Makefile.inc | 3 - backends/jny/CMakeLists.txt | 5 + backends/jny/Makefile.inc | 2 - backends/json/CMakeLists.txt | 5 + backends/json/Makefile.inc | 3 - backends/rtlil/CMakeLists.txt | 11 + backends/rtlil/Makefile.inc | 3 - backends/simplec/CMakeLists.txt | 3 + backends/simplec/Makefile.inc | 3 - backends/smt2/CMakeLists.txt | 16 + backends/smt2/Makefile.inc | 46 - backends/smt2/smtbmc.py | 4 +- backends/smt2/witness.py | 4 +- backends/smv/CMakeLists.txt | 7 + backends/smv/Makefile.inc | 3 - backends/spice/CMakeLists.txt | 3 + backends/spice/Makefile.inc | 3 - backends/table/CMakeLists.txt | 3 + backends/table/Makefile.inc | 3 - backends/verilog/CMakeLists.txt | 8 + backends/verilog/Makefile.inc | 3 - cmake/CheckLibcFeatures.cmake | 35 + cmake/Condition.cmake | 35 + cmake/FindDlfcn.cmake | 24 + cmake/FindPyosysEnv.cmake | 42 + cmake/FindPython3Embed.cmake | 16 + cmake/PkgConfig.cmake | 43 + cmake/PmgenCommand.cmake | 60 + cmake/YosysAbc.cmake | 96 ++ cmake/YosysAbcSubmodule.cmake | 64 + cmake/YosysComponent.cmake | 321 +++++ cmake/YosysConfigScript.cmake | 59 + cmake/YosysInstallDirs.cmake | 9 + cmake/YosysLinkTarget.cmake | 92 ++ cmake/YosysVerific.cmake | 48 + cmake/YosysVersion.cmake | 162 +++ cmake/YosysVersionData.cmake | 2 + cmake/toolchain/toolchain-mingw-i686.cmake | 8 + cmake/toolchain/toolchain-mingw-x86_64.cmake | 8 + cmake_Makefile_left | 57 + cmake_notes | 87 ++ docs/Makefile | 27 + docs/source/code_examples/extensions/Makefile | 5 +- docs/source/code_examples/stubnets/Makefile | 12 +- examples/cxx-api/demomain.cc | 4 +- flake.lock | 14 +- flake.nix | 90 +- frontends/CMakeLists.txt | 10 + frontends/aiger/CMakeLists.txt | 6 + frontends/aiger/Makefile.inc | 3 - frontends/aiger2/CMakeLists.txt | 3 + frontends/aiger2/Makefile.inc | 2 - frontends/ast/CMakeLists.txt | 13 + frontends/ast/Makefile.inc | 7 - frontends/ast/dpicall.cc | 6 +- frontends/blif/CMakeLists.txt | 8 + frontends/blif/Makefile.inc | 3 - frontends/json/CMakeLists.txt | 3 + frontends/json/Makefile.inc | 3 - frontends/liberty/CMakeLists.txt | 5 + frontends/liberty/Makefile.inc | 3 - frontends/rpc/CMakeLists.txt | 8 + frontends/rpc/Makefile.inc | 3 - frontends/rtlil/CMakeLists.txt | 3 + frontends/rtlil/Makefile.inc | 1 - frontends/verific/CMakeLists.txt | 70 + frontends/verific/Makefile.inc | 23 - frontends/verilog/CMakeLists.txt | 43 + frontends/verilog/Makefile.inc | 29 - kernel/CMakeLists.txt | 186 +++ {techlibs/common => kernel}/cellhelp.py | 0 kernel/fstdata.cc | 14 +- kernel/log.cc | 4 +- kernel/register.cc | 8 +- kernel/threading.h | 8 +- kernel/version.cc.in | 4 + kernel/yosys.cc | 12 +- kernel/yosys_common.h | 4 + kernel/yosys_config.h.in | 22 + libs/CMakeLists.txt | 9 + libs/bigint/CMakeLists.txt | 14 + libs/dlfcn-win32/CMakeLists.txt | 9 + libs/ezsat/CMakeLists.txt | 16 + libs/ezsat/ezcmdline.cc | 2 +- libs/flex/FlexLexer.h | 220 +++ libs/flex/README.txt | 2 + libs/fst/CMakeLists.txt | 18 + libs/json11/CMakeLists.txt | 8 + libs/minisat/CMakeLists.txt | 24 + libs/sha1/CMakeLists.txt | 8 + libs/subcircuit/CMakeLists.txt | 4 + misc/cmake/check_missing_depends.sh | 9 + misc/cmake/script_pass_depends.py | 29 + nix/cross/tcl.nix | 66 + nix/cross/win-overlay.nix | 51 + nix/cross/win32.nix | 15 + nix/cross/win64.nix | 15 + nix/pkgs/yosys.nix | 52 + passes/CMakeLists.txt | 11 + passes/cmds/CMakeLists.txt | 213 +++ passes/cmds/Makefile.inc | 64 - passes/cmds/sdc/CMakeLists.txt | 9 + passes/cmds/sdc/Makefile.inc | 3 - passes/cmds/show.cc | 8 +- passes/cmds/viz.cc | 6 +- passes/equiv/CMakeLists.txt | 54 + passes/equiv/Makefile.inc | 12 - passes/fsm/CMakeLists.txt | 52 + passes/fsm/Makefile.inc | 11 - passes/hierarchy/CMakeLists.txt | 22 + passes/hierarchy/Makefile.inc | 7 - passes/memory/CMakeLists.txt | 59 + passes/memory/Makefile.inc | 15 - passes/opt/.gitignore | 1 - passes/opt/CMakeLists.txt | 96 ++ passes/opt/Makefile.inc | 43 - passes/opt/opt_clean/CMakeLists.txt | 11 + passes/opt/opt_clean/Makefile.inc | 10 - passes/pmgen/.gitignore | 1 - passes/pmgen/CMakeLists.txt | 15 + passes/pmgen/Makefile.inc | 10 - passes/proc/CMakeLists.txt | 47 + passes/proc/Makefile.inc | 12 - passes/sat/CMakeLists.txt | 74 + passes/sat/Makefile.inc | 23 - passes/techmap/CMakeLists.txt | 224 +++ passes/techmap/Makefile.inc | 68 - passes/techmap/abc.cc | 2 +- passes/tests/CMakeLists.txt | 13 + passes/tests/Makefile.inc | 6 - pyosys/.gitignore | 2 - pyosys/CMakeLists.txt | 29 + pyosys/generator.py | 41 +- pyosys/{__init__.py => modinit.py} | 0 pyosys/wrappers_tpl.cc | 4 - techlibs/.gitignore | 2 - techlibs/CMakeLists.txt | 20 + techlibs/achronix/CMakeLists.txt | 28 + techlibs/achronix/Makefile.inc | 6 - techlibs/analogdevices/CMakeLists.txt | 65 + techlibs/analogdevices/Makefile.inc | 21 - techlibs/anlogic/CMakeLists.txt | 45 + techlibs/anlogic/Makefile.inc | 13 - techlibs/common/.gitignore | 2 - techlibs/common/CMakeLists.txt | 87 ++ techlibs/common/Makefile.inc | 41 - techlibs/common/opensta.cc | 2 +- techlibs/coolrunner2/CMakeLists.txt | 42 + techlibs/coolrunner2/Makefile.inc | 10 - techlibs/easic/CMakeLists.txt | 19 + techlibs/easic/Makefile.inc | 3 - techlibs/efinix/CMakeLists.txt | 40 + techlibs/efinix/Makefile.inc | 10 - techlibs/fabulous/CMakeLists.txt | 41 + techlibs/fabulous/Makefile.inc | 11 - techlibs/gatemate/.gitignore | 2 - techlibs/gatemate/CMakeLists.txt | 65 + techlibs/gatemate/Makefile.inc | 34 - techlibs/gatemate/make_lut_tree_lib.py | 4 +- techlibs/gowin/CMakeLists.txt | 55 + techlibs/gowin/Makefile.inc | 16 - techlibs/greenpak4/CMakeLists.txt | 42 + techlibs/greenpak4/Makefile.inc | 12 - techlibs/ice40/CMakeLists.txt | 84 ++ techlibs/ice40/Makefile.inc | 26 - techlibs/intel/CMakeLists.txt | 52 + techlibs/intel/Makefile.inc | 14 - techlibs/intel_alm/CMakeLists.txt | 57 + techlibs/intel_alm/Makefile.inc | 26 - techlibs/lattice/CMakeLists.txt | 92 ++ techlibs/lattice/Makefile.inc | 52 - techlibs/microchip/CMakeLists.txt | 76 + techlibs/microchip/Makefile.inc | 40 - techlibs/nanoxplore/CMakeLists.txt | 68 + techlibs/nanoxplore/Makefile.inc | 31 - techlibs/quicklogic/.gitignore | 1 - techlibs/quicklogic/CMakeLists.txt | 104 ++ techlibs/quicklogic/Makefile.inc | 44 - techlibs/sf2/CMakeLists.txt | 34 + techlibs/sf2/Makefile.inc | 7 - techlibs/xilinx/CMakeLists.txt | 125 ++ techlibs/xilinx/Makefile.inc | 64 - tests/unit/CMakeLists.txt | 25 + tests/unit/kernel/CMakeLists.txt | 14 + tests/unit/opt/CMakeLists.txt | 5 + tests/unit/techmap/CMakeLists.txt | 5 + 207 files changed, 5257 insertions(+), 2294 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile create mode 100644 backends/CMakeLists.txt create mode 100644 backends/aiger/CMakeLists.txt delete mode 100644 backends/aiger/Makefile.inc create mode 100644 backends/aiger2/CMakeLists.txt delete mode 100644 backends/aiger2/Makefile.inc create mode 100644 backends/blif/CMakeLists.txt delete mode 100644 backends/blif/Makefile.inc create mode 100644 backends/btor/CMakeLists.txt delete mode 100644 backends/btor/Makefile.inc create mode 100644 backends/cxxrtl/CMakeLists.txt delete mode 100644 backends/cxxrtl/Makefile.inc create mode 100644 backends/edif/CMakeLists.txt delete mode 100644 backends/edif/Makefile.inc create mode 100644 backends/firrtl/CMakeLists.txt delete mode 100644 backends/firrtl/Makefile.inc create mode 100644 backends/functional/CMakeLists.txt delete mode 100644 backends/functional/Makefile.inc create mode 100644 backends/intersynth/CMakeLists.txt delete mode 100644 backends/intersynth/Makefile.inc create mode 100644 backends/jny/CMakeLists.txt delete mode 100644 backends/jny/Makefile.inc create mode 100644 backends/json/CMakeLists.txt delete mode 100644 backends/json/Makefile.inc create mode 100644 backends/rtlil/CMakeLists.txt delete mode 100644 backends/rtlil/Makefile.inc create mode 100644 backends/simplec/CMakeLists.txt delete mode 100644 backends/simplec/Makefile.inc create mode 100644 backends/smt2/CMakeLists.txt delete mode 100644 backends/smt2/Makefile.inc mode change 100644 => 100755 backends/smt2/smtbmc.py mode change 100644 => 100755 backends/smt2/witness.py create mode 100644 backends/smv/CMakeLists.txt delete mode 100644 backends/smv/Makefile.inc create mode 100644 backends/spice/CMakeLists.txt delete mode 100644 backends/spice/Makefile.inc create mode 100644 backends/table/CMakeLists.txt delete mode 100644 backends/table/Makefile.inc create mode 100644 backends/verilog/CMakeLists.txt delete mode 100644 backends/verilog/Makefile.inc create mode 100644 cmake/CheckLibcFeatures.cmake create mode 100644 cmake/Condition.cmake create mode 100644 cmake/FindDlfcn.cmake create mode 100644 cmake/FindPyosysEnv.cmake create mode 100644 cmake/FindPython3Embed.cmake create mode 100644 cmake/PkgConfig.cmake create mode 100644 cmake/PmgenCommand.cmake create mode 100644 cmake/YosysAbc.cmake create mode 100644 cmake/YosysAbcSubmodule.cmake create mode 100644 cmake/YosysComponent.cmake create mode 100644 cmake/YosysConfigScript.cmake create mode 100644 cmake/YosysInstallDirs.cmake create mode 100644 cmake/YosysLinkTarget.cmake create mode 100644 cmake/YosysVerific.cmake create mode 100644 cmake/YosysVersion.cmake create mode 100644 cmake/YosysVersionData.cmake create mode 100644 cmake/toolchain/toolchain-mingw-i686.cmake create mode 100644 cmake/toolchain/toolchain-mingw-x86_64.cmake create mode 100644 cmake_Makefile_left create mode 100644 cmake_notes create mode 100644 frontends/CMakeLists.txt create mode 100644 frontends/aiger/CMakeLists.txt delete mode 100644 frontends/aiger/Makefile.inc create mode 100644 frontends/aiger2/CMakeLists.txt delete mode 100644 frontends/aiger2/Makefile.inc create mode 100644 frontends/ast/CMakeLists.txt delete mode 100644 frontends/ast/Makefile.inc create mode 100644 frontends/blif/CMakeLists.txt delete mode 100644 frontends/blif/Makefile.inc create mode 100644 frontends/json/CMakeLists.txt delete mode 100644 frontends/json/Makefile.inc create mode 100644 frontends/liberty/CMakeLists.txt delete mode 100644 frontends/liberty/Makefile.inc create mode 100644 frontends/rpc/CMakeLists.txt delete mode 100644 frontends/rpc/Makefile.inc create mode 100644 frontends/rtlil/CMakeLists.txt delete mode 100644 frontends/rtlil/Makefile.inc create mode 100644 frontends/verific/CMakeLists.txt delete mode 100644 frontends/verific/Makefile.inc create mode 100644 frontends/verilog/CMakeLists.txt delete mode 100644 frontends/verilog/Makefile.inc create mode 100644 kernel/CMakeLists.txt rename {techlibs/common => kernel}/cellhelp.py (100%) create mode 100644 kernel/version.cc.in create mode 100644 kernel/yosys_config.h.in create mode 100644 libs/CMakeLists.txt create mode 100644 libs/bigint/CMakeLists.txt create mode 100644 libs/dlfcn-win32/CMakeLists.txt create mode 100644 libs/ezsat/CMakeLists.txt create mode 100644 libs/flex/FlexLexer.h create mode 100644 libs/flex/README.txt create mode 100644 libs/fst/CMakeLists.txt create mode 100644 libs/json11/CMakeLists.txt create mode 100644 libs/minisat/CMakeLists.txt create mode 100644 libs/sha1/CMakeLists.txt create mode 100644 libs/subcircuit/CMakeLists.txt create mode 100644 misc/cmake/check_missing_depends.sh create mode 100644 misc/cmake/script_pass_depends.py create mode 100644 nix/cross/tcl.nix create mode 100644 nix/cross/win-overlay.nix create mode 100644 nix/cross/win32.nix create mode 100644 nix/cross/win64.nix create mode 100644 nix/pkgs/yosys.nix create mode 100644 passes/CMakeLists.txt create mode 100644 passes/cmds/CMakeLists.txt delete mode 100644 passes/cmds/Makefile.inc create mode 100644 passes/cmds/sdc/CMakeLists.txt delete mode 100644 passes/cmds/sdc/Makefile.inc create mode 100644 passes/equiv/CMakeLists.txt delete mode 100644 passes/equiv/Makefile.inc create mode 100644 passes/fsm/CMakeLists.txt delete mode 100644 passes/fsm/Makefile.inc create mode 100644 passes/hierarchy/CMakeLists.txt delete mode 100644 passes/hierarchy/Makefile.inc create mode 100644 passes/memory/CMakeLists.txt delete mode 100644 passes/memory/Makefile.inc delete mode 100644 passes/opt/.gitignore create mode 100644 passes/opt/CMakeLists.txt delete mode 100644 passes/opt/Makefile.inc create mode 100644 passes/opt/opt_clean/CMakeLists.txt delete mode 100644 passes/opt/opt_clean/Makefile.inc delete mode 100644 passes/pmgen/.gitignore create mode 100644 passes/pmgen/CMakeLists.txt delete mode 100644 passes/pmgen/Makefile.inc create mode 100644 passes/proc/CMakeLists.txt delete mode 100644 passes/proc/Makefile.inc create mode 100644 passes/sat/CMakeLists.txt delete mode 100644 passes/sat/Makefile.inc create mode 100644 passes/techmap/CMakeLists.txt delete mode 100644 passes/techmap/Makefile.inc create mode 100644 passes/tests/CMakeLists.txt delete mode 100644 passes/tests/Makefile.inc delete mode 100644 pyosys/.gitignore create mode 100644 pyosys/CMakeLists.txt rename pyosys/{__init__.py => modinit.py} (100%) delete mode 100644 techlibs/.gitignore create mode 100644 techlibs/CMakeLists.txt create mode 100644 techlibs/achronix/CMakeLists.txt delete mode 100644 techlibs/achronix/Makefile.inc create mode 100644 techlibs/analogdevices/CMakeLists.txt delete mode 100644 techlibs/analogdevices/Makefile.inc create mode 100644 techlibs/anlogic/CMakeLists.txt delete mode 100644 techlibs/anlogic/Makefile.inc delete mode 100644 techlibs/common/.gitignore create mode 100644 techlibs/common/CMakeLists.txt delete mode 100644 techlibs/common/Makefile.inc create mode 100644 techlibs/coolrunner2/CMakeLists.txt delete mode 100644 techlibs/coolrunner2/Makefile.inc create mode 100644 techlibs/easic/CMakeLists.txt delete mode 100644 techlibs/easic/Makefile.inc create mode 100644 techlibs/efinix/CMakeLists.txt delete mode 100644 techlibs/efinix/Makefile.inc create mode 100644 techlibs/fabulous/CMakeLists.txt delete mode 100644 techlibs/fabulous/Makefile.inc create mode 100644 techlibs/gatemate/CMakeLists.txt delete mode 100644 techlibs/gatemate/Makefile.inc create mode 100644 techlibs/gowin/CMakeLists.txt delete mode 100644 techlibs/gowin/Makefile.inc create mode 100644 techlibs/greenpak4/CMakeLists.txt delete mode 100644 techlibs/greenpak4/Makefile.inc create mode 100644 techlibs/ice40/CMakeLists.txt delete mode 100644 techlibs/ice40/Makefile.inc create mode 100644 techlibs/intel/CMakeLists.txt delete mode 100644 techlibs/intel/Makefile.inc create mode 100644 techlibs/intel_alm/CMakeLists.txt delete mode 100644 techlibs/intel_alm/Makefile.inc create mode 100644 techlibs/lattice/CMakeLists.txt delete mode 100644 techlibs/lattice/Makefile.inc create mode 100644 techlibs/microchip/CMakeLists.txt delete mode 100644 techlibs/microchip/Makefile.inc create mode 100644 techlibs/nanoxplore/CMakeLists.txt delete mode 100644 techlibs/nanoxplore/Makefile.inc delete mode 100644 techlibs/quicklogic/.gitignore create mode 100644 techlibs/quicklogic/CMakeLists.txt delete mode 100644 techlibs/quicklogic/Makefile.inc create mode 100644 techlibs/sf2/CMakeLists.txt delete mode 100644 techlibs/sf2/Makefile.inc create mode 100644 techlibs/xilinx/CMakeLists.txt delete mode 100644 techlibs/xilinx/Makefile.inc create mode 100644 tests/unit/CMakeLists.txt create mode 100644 tests/unit/kernel/CMakeLists.txt create mode 100644 tests/unit/opt/CMakeLists.txt create mode 100644 tests/unit/techmap/CMakeLists.txt diff --git a/.gitignore b/.gitignore index b39088088..84d11a7cb 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..550e2ec32 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,499 @@ +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 " + ) +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) + +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) + +set(CMAKE_C_COMPILER_LAUNCHER "${YOSYS_COMPILER_LAUNCHER}") +set(CMAKE_CXX_COMPILER_LAUNCHER "${YOSYS_COMPILER_LAUNCHER}") + +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_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,-z,stack-size=1048576 + ) +endif() + +if (YOSYS_ENABLE_COVERAGE) + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + 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 (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(sanitize_options + "$<$,$>>>:-fsanitize=${SANITIZE}>" + ) + add_compile_options(${sanitize_options}) + add_link_options(${sanitize_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_definitions(_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 (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_RELWITHDEBINFO}") + +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) + yosys_check_abc_submodule() + 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_ + $<$: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}") + set(PYOSYS_INSTALL_DIR ${Python3_SITEARCH}/${PYOSYS_MODULE_PREFIX}pyosys) + install(FILES pyosys/modinit.py + RENAME __init__.py + DESTINATION ${PYOSYS_INSTALL_DIR} + ) + install(TARGETS 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=$ +) +foreach (format html) + 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 +) diff --git a/Makefile b/Makefile deleted file mode 100644 index 6ee34070d..000000000 --- a/Makefile +++ /dev/null @@ -1,1219 +0,0 @@ - -CONFIG := none -# CONFIG := clang -# CONFIG := gcc -# CONFIG := wasi -# CONFIG := msys2-32 -# CONFIG := msys2-64 - -# features (the more the better) -ENABLE_TCL := 1 -ENABLE_ABC := 1 -ENABLE_GLOB := 1 -ENABLE_PLUGINS := 1 -ENABLE_READLINE := 1 -ENABLE_EDITLINE := 0 -ENABLE_GHDL := 0 -ENABLE_VERIFIC := 0 -ENABLE_VERIFIC_SYSTEMVERILOG := 1 -ENABLE_VERIFIC_VHDL := 1 -ENABLE_VERIFIC_HIER_TREE := 1 -ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS := 0 -ENABLE_VERIFIC_EDIF := 0 -ENABLE_VERIFIC_LIBERTY := 0 -ENABLE_LIBYOSYS := 0 -ENABLE_LIBYOSYS_STATIC := 0 -ENABLE_ZLIB := 1 -ENABLE_HELP_SOURCE := 0 - -# python wrappers -ENABLE_PYOSYS := 0 -PYOSYS_USE_UV := 1 - -# other configuration flags -ENABLE_GCOV := 0 -ENABLE_GPROF := 0 -ENABLE_DEBUG := 0 -ENABLE_LTO := 0 -ENABLE_CCACHE := 0 -# sccache is not always a drop-in replacement for ccache in practice -ENABLE_SCCACHE := 0 -ENABLE_FUNCTIONAL_TESTS := 0 -LINK_CURSES := 0 -LINK_TERMCAP := 0 -LINK_ABC := 0 -# Needed for environments that can't run executables (i.e. emscripten, wasm) -DISABLE_SPAWN := 0 -# Needed for environments that don't have proper thread support (i.e. emscripten, wasm--for now) -ENABLE_THREADS := 1 -ifeq ($(ENABLE_THREADS),1) -DISABLE_ABC_THREADS := 0 -else -DISABLE_ABC_THREADS := 1 -endif - -# clang sanitizers -SANITIZER = -# SANITIZER = address -# SANITIZER = memory -# SANITIZER = undefined -# SANITIZER = cfi - -# Prefer using ENABLE_DEBUG over setting these -OPT_LEVEL := -O3 -GCC_LTO := -CLANG_LTO := -flto=thin - -PROGRAM_PREFIX := - -OS := $(shell uname -s) -PREFIX ?= /usr/local -INSTALL_SUDO := -ifneq ($(filter MINGW%,$(OS)),) -OS := MINGW -endif - -ifneq ($(wildcard Makefile.conf),) -include Makefile.conf -endif - -ifeq ($(ENABLE_PYOSYS),1) -ENABLE_LIBYOSYS := 1 -endif - -BINDIR := $(PREFIX)/bin -LIBDIR := $(PREFIX)/lib/$(PROGRAM_PREFIX)yosys -DATDIR := $(PREFIX)/share/$(PROGRAM_PREFIX)yosys - -EXE = -OBJS = -GENFILES = -EXTRA_OBJS = -EXTRA_TARGETS = -TARGETS = $(PROGRAM_PREFIX)yosys$(EXE) $(PROGRAM_PREFIX)yosys-config - -PRETTY = 1 -SMALL = 0 - -all: top-all - -YOSYS_SRC := $(dir $(firstword $(MAKEFILE_LIST))) -VPATH := $(YOSYS_SRC) - -# Unit test -UNITESTPATH := $(YOSYS_SRC)/tests/unit - -export CXXSTD ?= c++20 -CXXFLAGS := $(CXXFLAGS) -Wall -Wextra -Werror=unused -ggdb -I. -I"$(YOSYS_SRC)" -MD -MP -D_YOSYS_ -fPIC -I$(PREFIX)/include -LIBS := $(LIBS) -lstdc++ -lm -PLUGIN_LINKFLAGS := -PLUGIN_LIBS := -EXE_LINKFLAGS := -EXE_LIBS := -ifeq ($(OS), MINGW) -EXE_LINKFLAGS := -Wl,--export-all-symbols -Wl,--out-implib,libyosys_exe.a -PLUGIN_LINKFLAGS += -L"$(LIBDIR)" -PLUGIN_LIBS := -lyosys_exe -endif - -ifeq ($(ENABLE_HELP_SOURCE),1) -CXXFLAGS += -DYOSYS_ENABLE_HELP_SOURCE -endif - -PKG_CONFIG ?= pkg-config -SED ?= sed -BISON ?= bison -STRIP ?= strip -AWK ?= awk - -ifeq ($(OS), Darwin) -PLUGIN_LINKFLAGS += -undefined dynamic_lookup -LINKFLAGS += -rdynamic - -# homebrew search paths -ifneq ($(shell :; command -v brew),) -BREW_PREFIX := $(shell brew --prefix)/opt -$(info $$BREW_PREFIX is [${BREW_PREFIX}]) -CXXFLAGS += -I$(BREW_PREFIX)/readline/include -I$(BREW_PREFIX)/flex/include -LINKFLAGS += -L$(BREW_PREFIX)/readline/lib -L$(BREW_PREFIX)/flex/lib -PKG_CONFIG_PATH := $(BREW_PREFIX)/libffi/lib/pkgconfig:$(PKG_CONFIG_PATH) -PKG_CONFIG_PATH := $(BREW_PREFIX)/tcl-tk/lib/pkgconfig:$(PKG_CONFIG_PATH) -export PATH := $(BREW_PREFIX)/bison/bin:$(BREW_PREFIX)/gettext/bin:$(BREW_PREFIX)/flex/bin:$(PATH) - -# macports search paths -else ifneq ($(shell :; command -v port),) -PORT_PREFIX := $(patsubst %/bin/port,%,$(shell :; command -v port)) -CXXFLAGS += -I$(PORT_PREFIX)/include -LINKFLAGS += -L$(PORT_PREFIX)/lib -PKG_CONFIG_PATH := $(PORT_PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH) -export PATH := $(PORT_PREFIX)/bin:$(PATH) -endif - -else -LINKFLAGS += -rdynamic -ifneq ($(OS), OpenBSD) -LIBS += -lrt -endif -endif - -ifeq ($(OS), Haiku) -# Allow usage of non-posix vasprintf, mkstemps functions -CXXFLAGS += -D_DEFAULT_SOURCE -endif - -YOSYS_VER := 0.65 - -ifneq (, $(shell command -v git 2>/dev/null)) -ifneq (, $(shell git rev-parse --git-dir 2>/dev/null)) - GIT_COMMIT_COUNT := $(or $(shell git rev-list --count v$(YOSYS_VER)..HEAD 2>/dev/null),0) - ifneq ($(GIT_COMMIT_COUNT),0) - YOSYS_VER := $(YOSYS_VER)+$(GIT_COMMIT_COUNT) - endif -else - YOSYS_VER := $(YOSYS_VER)+post -endif -endif - -YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1) -YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2 | cut -d'+' -f1) -YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'+' -f2) -CXXFLAGS += -DYOSYS_VER=\\"$(YOSYS_VER)\\" \ - -DYOSYS_MAJOR=$(YOSYS_MAJOR) \ - -DYOSYS_MINOR=$(YOSYS_MINOR) \ - -DYOSYS_COMMIT=$(YOSYS_COMMIT) - -# Note: We arrange for .gitcommit to contain the (short) commit hash in -# tarballs generated with git-archive(1) using .gitattributes. The git repo -# will have this file in its unexpanded form tough, in which case we fall -# back to calling git directly. -TARBALL_GIT_REV := $(shell cat $(YOSYS_SRC)/.gitcommit) -ifneq ($(findstring Format:,$(TARBALL_GIT_REV)),) -GIT_REV := $(shell GIT_DIR=$(YOSYS_SRC)/.git git rev-parse --short=9 HEAD || echo UNKNOWN) -GIT_DIRTY := $(shell GIT_DIR=$(YOSYS_SRC)/.git git diff --exit-code --quiet 2>/dev/null; if [ $$? -ne 0 ]; then echo "-dirty"; fi) -else -GIT_REV := $(TARBALL_GIT_REV) -GIT_DIRTY := "" -endif - -OBJS = kernel/version_$(GIT_REV).o - -ABCMKARGS = CC="$(CXX)" CXX="$(CXX)" ABC_USE_LIBSTDCXX=1 ABC_USE_NAMESPACE=abc VERBOSE=$(Q) - -# set ABCEXTERNAL = to use an external ABC instance -# Note: The in-tree ABC (yosys-abc) will not be installed when ABCEXTERNAL is set. -ABCEXTERNAL ?= - -define newline - - -endef - -ifneq ($(wildcard Makefile.conf),) -# don't echo Makefile.conf contents when invoked to print source versions -ifeq ($(findstring echo-,$(MAKECMDGOALS)),) -$(info $(subst $$--$$,$(newline),$(shell sed 's,^,[Makefile.conf] ,; s,$$,$$--$$,;' < Makefile.conf | tr -d '\n' | sed 's,\$$--\$$$$,,'))) -endif -include Makefile.conf -endif - -PYTHON_EXECUTABLE ?= $(shell if python3 -c ""; then echo "python3"; else echo "python"; fi) -ifeq ($(ENABLE_PYOSYS),1) -PYTHON_VERSION_TESTCODE := "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));print(t)" -PYTHON_VERSION := $(shell $(PYTHON_EXECUTABLE) -c ""$(PYTHON_VERSION_TESTCODE)"") -PYTHON_MAJOR_VERSION := $(shell echo $(PYTHON_VERSION) | cut -f1 -d.) - -PYTHON_CONFIG := $(PYTHON_EXECUTABLE)-config -PYTHON_CONFIG_FOR_EXE := $(PYTHON_CONFIG) -PYTHON_CONFIG_EMBED_AVAILABLE ?= $(shell $(PYTHON_EXECUTABLE)-config --embed --libs > /dev/null && echo 1) -ifeq ($(PYTHON_CONFIG_EMBED_AVAILABLE),1) -PYTHON_CONFIG_FOR_EXE := $(PYTHON_CONFIG) --embed -endif - -PYTHON_DESTDIR := $(shell $(PYTHON_EXECUTABLE) -c "import site; print(site.getsitepackages()[-1]);") - -# Reload Makefile.conf to override python specific variables if defined -ifneq ($(wildcard Makefile.conf),) -include Makefile.conf -endif - -endif - -ABC_ARCHFLAGS = "" -ifeq ($(OS), OpenBSD) -ABC_ARCHFLAGS += "-DABC_NO_RLIMIT" -endif - -# This gets overridden later. -LTOFLAGS := $(GCC_LTO) - -ifeq ($(CONFIG),clang) -CXX = clang++ -CXXFLAGS += -std=$(CXXSTD) $(OPT_LEVEL) -ifeq ($(ENABLE_LTO),1) -LINKFLAGS += -fuse-ld=lld -endif -ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H $(ABC_ARCHFLAGS)" -LTOFLAGS := $(CLANG_LTO) - -ifneq ($(SANITIZER),) -$(info [Clang Sanitizer] $(SANITIZER)) -CXXFLAGS += -g -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=$(SANITIZER) -LINKFLAGS += -g -fsanitize=$(SANITIZER) -ifneq ($(findstring memory,$(SANITIZER)),) -CXXFLAGS += -fPIE -fsanitize-memory-track-origins -LINKFLAGS += -fPIE -fsanitize-memory-track-origins -endif -ifneq ($(findstring cfi,$(SANITIZER)),) -CXXFLAGS += -flto -LINKFLAGS += -flto -LTOFLAGS = -endif -endif - -else ifeq ($(CONFIG),gcc) -CXX = g++ -CXXFLAGS += -std=$(CXXSTD) $(OPT_LEVEL) -ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H $(ABC_ARCHFLAGS)" - -else ifeq ($(CONFIG),gcc-static) -LINKFLAGS := $(filter-out -rdynamic,$(LINKFLAGS)) -static -LIBS := $(filter-out -lrt,$(LIBS)) -CXXFLAGS := $(filter-out -fPIC,$(CXXFLAGS)) -CXXFLAGS += -std=$(CXXSTD) $(OPT_LEVEL) -ABCMKARGS = CC="$(CC)" CXX="$(CXX)" LD="$(CXX)" ABC_USE_LIBSTDCXX=1 LIBS="-lm -lpthread -static" OPTFLAGS="-O" \ - ARCHFLAGS="-DABC_USE_STDINT_H -DABC_NO_DYNAMIC_LINKING=1 -Wno-unused-but-set-variable $(ARCHFLAGS)" ABC_USE_NO_READLINE=1 -ifeq ($(DISABLE_ABC_THREADS),1) -ABCMKARGS += "ABC_USE_NO_PTHREADS=1" -endif - -else ifeq ($(CONFIG),wasi) -ifeq ($(WASI_SDK),) -CXX = clang++ -AR = llvm-ar -RANLIB = llvm-ranlib -WASIFLAGS := -target wasm32-wasip1 $(WASIFLAGS) -else -CXX = $(WASI_SDK)/bin/clang++ -AR = $(WASI_SDK)/bin/ar -RANLIB = $(WASI_SDK)/bin/ranlib -endif -CXXFLAGS := $(WASIFLAGS) -std=$(CXXSTD) $(OPT_LEVEL) -D_WASI_EMULATED_PROCESS_CLOCKS -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false $(filter-out -fPIC,$(CXXFLAGS)) -LINKFLAGS := $(WASIFLAGS) -Wl,-z,stack-size=1048576 $(filter-out -rdynamic,$(LINKFLAGS)) -fwasm-exceptions -lunwind -LIBS := -lwasi-emulated-process-clocks $(filter-out -lrt,$(LIBS)) -ABCMKARGS += AR="$(AR)" RANLIB="$(RANLIB)" -ABCMKARGS += ARCHFLAGS="$(WASIFLAGS) -D_WASI_EMULATED_PROCESS_CLOCKS -DABC_USE_STDINT_H -DABC_NO_DYNAMIC_LINKING -DABC_NO_RLIMIT" -ABCMKARGS += OPTFLAGS="-Os" -LTOFLAGS = -EXE = .wasm - -DISABLE_SPAWN := 1 - -ifeq ($(ENABLE_ABC),1) -LINK_ABC := 1 -ENABLE_THREADS := 0 -DISABLE_ABC_THREADS := 1 -endif - -else ifeq ($(CONFIG),msys2-32) -CXX = i686-w64-mingw32-g++ -CXXFLAGS += -std=$(CXXSTD) $(OPT_LEVEL) -D_POSIX_SOURCE -DYOSYS_WIN32_UNIX_DIR -CXXFLAGS := $(filter-out -fPIC,$(CXXFLAGS)) -LINKFLAGS := $(filter-out -rdynamic,$(LINKFLAGS)) -s -LIBS := $(filter-out -lrt,$(LIBS)) -ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H -DWIN32_NO_DLL -DWIN32 -DHAVE_STRUCT_TIMESPEC -fpermissive -w" -ABCMKARGS += LIBS="-lpthread -lshlwapi -s" ABC_USE_NO_READLINE=0 CC="i686-w64-mingw32-gcc" CXX="$(CXX)" -EXE = .exe - -else ifeq ($(CONFIG),msys2-64) -CXX = x86_64-w64-mingw32-g++ -CXXFLAGS += -std=$(CXXSTD) $(OPT_LEVEL) -D_POSIX_SOURCE -DYOSYS_WIN32_UNIX_DIR -CXXFLAGS := $(filter-out -fPIC,$(CXXFLAGS)) -LINKFLAGS := $(filter-out -rdynamic,$(LINKFLAGS)) -s -LIBS := $(filter-out -lrt,$(LIBS)) -ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H -DWIN32_NO_DLL -DWIN32 -DHAVE_STRUCT_TIMESPEC -fpermissive -w" -ABCMKARGS += LIBS="-lpthread -lshlwapi -s" ABC_USE_NO_READLINE=0 CC="x86_64-w64-mingw32-gcc" CXX="$(CXX)" -EXE = .exe - -else ifeq ($(CONFIG),none) -CXXFLAGS += -std=$(CXXSTD) $(OPT_LEVEL) -ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H $(ABC_ARCHFLAGS)" -LTOFLAGS = - -else -$(error Invalid CONFIG setting '$(CONFIG)'. Valid values: clang, gcc, msys2-32, msys2-64, none) -endif - - -ifeq ($(ENABLE_LTO),1) -CXXFLAGS += $(LTOFLAGS) -LINKFLAGS += $(LTOFLAGS) -endif - -ifeq ($(ENABLE_LIBYOSYS),1) -TARGETS += libyosys.so -ifeq ($(ENABLE_LIBYOSYS_STATIC),1) -TARGETS += libyosys.a -endif -endif - -PY_WRAPPER_FILE = pyosys/wrappers - -# running make clean on just those and then recompiling saves a lot of -# time when running cibuildwheel -PYTHON_OBJECTS = pyosys/wrappers.o kernel/drivers.o kernel/yosys.o passes/cmds/plugin.o - -ifeq ($(ENABLE_PYOSYS),1) -# python-config --ldflags includes -l and -L, but LINKFLAGS is only -L - -UV_ENV := -ifeq ($(PYOSYS_USE_UV),1) -UV_ENV := uv run --no-project --with 'pybind11>3,<4' --with 'cxxheaderparser' -endif - -LINKFLAGS += $(filter-out -l%,$(shell $(PYTHON_CONFIG) --ldflags)) -LIBS += $(shell $(PYTHON_CONFIG) --libs) -EXE_LIBS += $(filter-out $(LIBS),$(shell $(PYTHON_CONFIG_FOR_EXE) --libs)) -PYBIND11_INCLUDE ?= $(shell $(UV_ENV) $(PYTHON_EXECUTABLE) -m pybind11 --includes) -CXXFLAGS += -I$(PYBIND11_INCLUDE) -DYOSYS_ENABLE_PYTHON -CXXFLAGS += $(shell $(PYTHON_CONFIG) --includes) -DYOSYS_ENABLE_PYTHON - -OBJS += $(PY_WRAPPER_FILE).o -PY_GEN_SCRIPT = $(YOSYS_SRC)/pyosys/generator.py -PY_WRAP_INCLUDES := $(shell $(UV_ENV) $(PYTHON_EXECUTABLE) $(PY_GEN_SCRIPT) --print-includes) -endif # ENABLE_PYOSYS - -ifeq ($(ENABLE_READLINE),1) -CXXFLAGS += -DYOSYS_ENABLE_READLINE -ifeq ($(OS), $(filter $(OS),FreeBSD OpenBSD NetBSD)) -CXXFLAGS += -I/usr/local/include -endif -LIBS += -lreadline -ifeq ($(LINK_CURSES),1) -LIBS += -lcurses -ABCMKARGS += "ABC_READLINE_LIBRARIES=-lcurses -lreadline" -endif -ifeq ($(LINK_TERMCAP),1) -LIBS += -ltermcap -ABCMKARGS += "ABC_READLINE_LIBRARIES=-lreadline -ltermcap" -endif -else -ifeq ($(ENABLE_EDITLINE),1) -CXXFLAGS += -DYOSYS_ENABLE_EDITLINE -LIBS += -ledit -endif -ABCMKARGS += "ABC_USE_NO_READLINE=1" -endif - -ifeq ($(DISABLE_ABC_THREADS),1) -ABCMKARGS += "ABC_USE_NO_PTHREADS=1" -endif - -ifeq ($(LINK_ABC),1) -ABCMKARGS += "ABC_USE_PIC=1" -endif - -ifeq ($(DISABLE_SPAWN),1) -CXXFLAGS += -DYOSYS_DISABLE_SPAWN -endif - -ifeq ($(ENABLE_PLUGINS),1) -CXXFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --cflags libffi) -DYOSYS_ENABLE_PLUGINS -ifeq ($(OS), MINGW) -CXXFLAGS += -Ilibs/dlfcn-win32 -endif -LIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --libs libffi || echo -lffi) -ifneq ($(OS), $(filter $(OS),FreeBSD OpenBSD NetBSD MINGW)) -LIBS += -ldl -endif -endif - -ifeq ($(ENABLE_GLOB),1) -CXXFLAGS += -DYOSYS_ENABLE_GLOB -endif - -ifeq ($(ENABLE_ZLIB),1) -CXXFLAGS += -DYOSYS_ENABLE_ZLIB -LIBS += -lz -endif - - -ifeq ($(ENABLE_TCL),1) -TCL_VERSION ?= tcl$(shell bash -c "tclsh <(echo 'puts [info tclversion]')") -ifeq ($(OS), $(filter $(OS),FreeBSD OpenBSD NetBSD)) -# BSDs usually use tcl8.6, but the lib is named "libtcl86" -TCL_INCLUDE ?= /usr/local/include/$(TCL_VERSION) -TCL_LIBS ?= -l$(subst .,,$(TCL_VERSION)) -else -TCL_INCLUDE ?= /usr/include/$(TCL_VERSION) -TCL_LIBS ?= -l$(TCL_VERSION) -endif - -CXXFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --cflags tcl || echo -I$(TCL_INCLUDE)) -DYOSYS_ENABLE_TCL -LIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --libs tcl || echo $(TCL_LIBS)) -ifneq (,$(findstring TCL_WITH_EXTERNAL_TOMMATH,$(CXXFLAGS))) -LIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --libs libtommath || echo) -endif -endif - -ifeq ($(ENABLE_GCOV),1) -LLVM_PROFILE_FILE ?= $(realpath $(YOSYS_SRC))/coverage/coverage_%p.profraw -export LLVM_PROFILE_FILE -export LLVM_PROFILE_FILE_BUFFER_SIZE=0 -CXXFLAGS += -fprofile-instr-generate -fcoverage-mapping -LINKFLAGS+= -fprofile-instr-generate -endif - -ifeq ($(ENABLE_GPROF),1) -CXXFLAGS += -pg -LINKFLAGS += -pg -endif - -ifeq ($(ENABLE_DEBUG),1) -CXXFLAGS := -Og -DDEBUG $(filter-out $(OPT_LEVEL),$(CXXFLAGS)) -STRIP := -endif - -ifeq ($(ENABLE_THREADS),1) -CXXFLAGS += -DYOSYS_ENABLE_THREADS -LIBS += -lpthread -endif - -ifeq ($(ENABLE_ABC),1) -CXXFLAGS += -DYOSYS_ENABLE_ABC -ifeq ($(LINK_ABC),1) -CXXFLAGS += -DYOSYS_LINK_ABC -ifeq ($(DISABLE_ABC_THREADS),0) -LIBS += -lpthread -endif -else -ifeq ($(ABCEXTERNAL),) -TARGETS := $(PROGRAM_PREFIX)yosys-abc$(EXE) $(TARGETS) -endif -ifeq ($(DISABLE_SPAWN),1) -$(error ENABLE_ABC=1 requires either LINK_ABC=1 or DISABLE_SPAWN=0) -endif -endif -endif - -ifeq ($(ENABLE_GHDL),1) -GHDL_PREFIX ?= $(PREFIX) -GHDL_INCLUDE_DIR ?= $(GHDL_PREFIX)/include -GHDL_LIB_DIR ?= $(GHDL_PREFIX)/lib -CXXFLAGS += -I$(GHDL_INCLUDE_DIR) -DYOSYS_ENABLE_GHDL -LIBS += $(GHDL_LIB_DIR)/libghdl.a $(file <$(GHDL_LIB_DIR)/libghdl.link) -endif - -LIBS_VERIFIC = -ifeq ($(ENABLE_VERIFIC),1) -VERIFIC_DIR ?= /usr/local/src/verific_lib -VERIFIC_COMPONENTS ?= database util containers -ifeq ($(ENABLE_VERIFIC_HIER_TREE),1) -VERIFIC_COMPONENTS += hier_tree -CXXFLAGS += -DVERIFIC_HIER_TREE_SUPPORT -else -ifneq ($(wildcard $(VERIFIC_DIR)/hier_tree),) -VERIFIC_COMPONENTS += hier_tree -endif -endif -ifeq ($(ENABLE_VERIFIC_SYSTEMVERILOG),1) -VERIFIC_COMPONENTS += verilog -CXXFLAGS += -DVERIFIC_SYSTEMVERILOG_SUPPORT -else -ifneq ($(wildcard $(VERIFIC_DIR)/verilog),) -VERIFIC_COMPONENTS += verilog -endif -endif -ifeq ($(ENABLE_VERIFIC_VHDL),1) -VERIFIC_COMPONENTS += vhdl -CXXFLAGS += -DVERIFIC_VHDL_SUPPORT -else -ifneq ($(wildcard $(VERIFIC_DIR)/vhdl),) -VERIFIC_COMPONENTS += vhdl -endif -endif -ifeq ($(ENABLE_VERIFIC_EDIF),1) -VERIFIC_COMPONENTS += edif -CXXFLAGS += -DVERIFIC_EDIF_SUPPORT -endif -ifeq ($(ENABLE_VERIFIC_LIBERTY),1) -VERIFIC_COMPONENTS += synlib -CXXFLAGS += -DVERIFIC_LIBERTY_SUPPORT -endif -ifeq ($(ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS),1) -VERIFIC_COMPONENTS += extensions -CXXFLAGS += -DYOSYSHQ_VERIFIC_EXTENSIONS -else -# YosysHQ flavor of Verific always needs extensions linked -# if disabled it will just not be invoked but parts -# are required for it to initialize properly -ifneq ($(wildcard $(VERIFIC_DIR)/extensions),) -VERIFIC_COMPONENTS += extensions -OBJS += kernel/log_compat.o -endif -endif -CXXFLAGS += $(patsubst %,-I$(VERIFIC_DIR)/%,$(VERIFIC_COMPONENTS)) -DYOSYS_ENABLE_VERIFIC -ifeq ($(OS), Darwin) -LIBS_VERIFIC += $(foreach comp,$(patsubst %,$(VERIFIC_DIR)/%/*-mac.a,$(VERIFIC_COMPONENTS)),-Wl,-force_load $(comp)) -lz -else -LIBS_VERIFIC += -Wl,--whole-archive $(patsubst %,$(VERIFIC_DIR)/%/*-linux.a,$(VERIFIC_COMPONENTS)) -Wl,--no-whole-archive -lz -endif -endif - -ifeq ($(ENABLE_CCACHE),1) -CXX := ccache $(CXX) -else -ifeq ($(ENABLE_SCCACHE),1) -CXX := sccache $(CXX) -endif -endif - -define add_share_file -EXTRA_TARGETS += $(subst //,/,$(1)/$(notdir $(2))) -$(subst //,/,$(1)/$(notdir $(2))): $(2) - $$(P) mkdir -p $(1) - $$(Q) cp "$(YOSYS_SRC)"/$(2) $(subst //,/,$(1)/$(notdir $(2))) -endef - -define add_share_file_and_rename -EXTRA_TARGETS += $(subst //,/,$(1)/$(3)) -$(subst //,/,$(1)/$(3)): $(2) - $$(P) mkdir -p $(1) - $$(Q) cp "$(YOSYS_SRC)"/$(2) $(subst //,/,$(1)/$(3)) -endef - -define add_gen_share_file -EXTRA_TARGETS += $(subst //,/,$(1)/$(notdir $(2))) -$(subst //,/,$(1)/$(notdir $(2))): $(2) - $$(P) mkdir -p $(1) - $$(Q) cp $(2) $(subst //,/,$(1)/$(notdir $(2))) -endef - -define add_include_file -$(eval $(call add_share_file,$(dir share/include/$(1)),$(1))) -endef - -define add_extra_objs -EXTRA_OBJS += $(1) -.SECONDARY: $(1) -endef - -ifeq ($(PRETTY), 1) -P_STATUS = 0 -P_OFFSET = 0 -P_UPDATE = $(eval P_STATUS=$(shell echo $(OBJS) $(PROGRAM_PREFIX)yosys$(EXE) | $(AWK) 'BEGIN { RS = " "; I = $(P_STATUS)+0; } $$1 == "$@" && NR > I { I = NR; } END { print I; }')) -P_SHOW = [$(shell $(AWK) "BEGIN { N=$(words $(OBJS) $(PROGRAM_PREFIX)yosys$(EXE)); printf \"%3d\", $(P_OFFSET)+90*$(P_STATUS)/N; exit; }")%] -P = @echo "$(if $(findstring $@,$(TARGETS) $(EXTRA_TARGETS)),$(eval P_OFFSET = 10))$(call P_UPDATE)$(call P_SHOW) Building $@"; -Q = @ -S = -s -else -P_SHOW = -> -P = -Q = -S = -endif - -$(eval $(call add_include_file,kernel/binding.h)) -$(eval $(call add_include_file,kernel/bitpattern.h)) -$(eval $(call add_include_file,kernel/cellaigs.h)) -$(eval $(call add_include_file,kernel/celledges.h)) -$(eval $(call add_include_file,kernel/celltypes.h)) -$(eval $(call add_include_file,kernel/newcelltypes.h)) -$(eval $(call add_include_file,kernel/consteval.h)) -$(eval $(call add_include_file,kernel/constids.inc)) -$(eval $(call add_include_file,kernel/cost.h)) -$(eval $(call add_include_file,kernel/drivertools.h)) -$(eval $(call add_include_file,kernel/ff.h)) -$(eval $(call add_include_file,kernel/ffinit.h)) -$(eval $(call add_include_file,kernel/ffmerge.h)) -$(eval $(call add_include_file,kernel/fmt.h)) -ifeq ($(ENABLE_ZLIB),1) -$(eval $(call add_include_file,kernel/fstdata.h)) -endif -$(eval $(call add_include_file,kernel/gzip.h)) -$(eval $(call add_include_file,kernel/hashlib.h)) -$(eval $(call add_include_file,kernel/io.h)) -$(eval $(call add_include_file,kernel/json.h)) -$(eval $(call add_include_file,kernel/log.h)) -$(eval $(call add_include_file,kernel/macc.h)) -$(eval $(call add_include_file,kernel/modtools.h)) -$(eval $(call add_include_file,kernel/mem.h)) -$(eval $(call add_include_file,kernel/qcsat.h)) -$(eval $(call add_include_file,kernel/register.h)) -$(eval $(call add_include_file,kernel/rtlil.h)) -$(eval $(call add_include_file,kernel/satgen.h)) -$(eval $(call add_include_file,kernel/scopeinfo.h)) -$(eval $(call add_include_file,kernel/sexpr.h)) -$(eval $(call add_include_file,kernel/sigtools.h)) -$(eval $(call add_include_file,kernel/threading.h)) -$(eval $(call add_include_file,kernel/timinginfo.h)) -$(eval $(call add_include_file,kernel/utils.h)) -$(eval $(call add_include_file,kernel/yosys.h)) -$(eval $(call add_include_file,kernel/yosys_common.h)) -$(eval $(call add_include_file,kernel/yw.h)) -$(eval $(call add_include_file,libs/ezsat/ezsat.h)) -$(eval $(call add_include_file,libs/ezsat/ezminisat.h)) -$(eval $(call add_include_file,libs/ezsat/ezcmdline.h)) -ifeq ($(ENABLE_ZLIB),1) -$(eval $(call add_include_file,libs/fst/fstapi.h)) -endif -$(eval $(call add_include_file,libs/sha1/sha1.h)) -$(eval $(call add_include_file,libs/json11/json11.hpp)) -$(eval $(call add_include_file,passes/fsm/fsmdata.h)) -$(eval $(call add_include_file,passes/techmap/libparse.h)) -$(eval $(call add_include_file,frontends/blif/blifparse.h)) -$(eval $(call add_include_file,backends/rtlil/rtlil_backend.h)) - -OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o kernel/yosys.o kernel/io.o kernel/gzip.o -OBJS += kernel/rtlil_bufnorm.o -OBJS += kernel/log_help.o -ifeq ($(ENABLE_VERIFIC_YOSYSHQ_EXTENSIONS),1) -OBJS += kernel/log_compat.o -endif -OBJS += kernel/binding.o kernel/tclapi.o -OBJS += kernel/cellaigs.o kernel/celledges.o kernel/cost.o kernel/satgen.o kernel/scopeinfo.o kernel/qcsat.o kernel/mem.o kernel/ffmerge.o kernel/ff.o kernel/yw.o kernel/json.o kernel/fmt.o kernel/sexpr.o -OBJS += kernel/drivertools.o kernel/functional.o kernel/threading.o -ifeq ($(ENABLE_ZLIB),1) -OBJS += kernel/fstdata.o -endif -ifeq ($(ENABLE_PLUGINS),1) -ifeq ($(OS), MINGW) -OBJS += libs/dlfcn-win32/dlfcn.o -endif -endif - -kernel/log.o: CXXFLAGS += -DYOSYS_SRC='"$(YOSYS_SRC)"' -kernel/yosys.o: CXXFLAGS += -DYOSYS_DATDIR='"$(DATDIR)"' -DYOSYS_PROGRAM_PREFIX='"$(PROGRAM_PREFIX)"' -ifeq ($(ENABLE_ABC),1) -ifneq ($(ABCEXTERNAL),) -kernel/yosys.o: CXXFLAGS += -DABCEXTERNAL='"$(ABCEXTERNAL)"' -endif -endif - -OBJS += libs/bigint/BigIntegerAlgorithms.o libs/bigint/BigInteger.o libs/bigint/BigIntegerUtils.o -OBJS += libs/bigint/BigUnsigned.o libs/bigint/BigUnsignedInABase.o - -OBJS += libs/sha1/sha1.o - -OBJS += libs/json11/json11.o - -OBJS += libs/ezsat/ezsat.o -OBJS += libs/ezsat/ezminisat.o -OBJS += libs/ezsat/ezcmdline.o - -OBJS += libs/minisat/Options.o -OBJS += libs/minisat/SimpSolver.o -OBJS += libs/minisat/Solver.o -OBJS += libs/minisat/System.o - -ifeq ($(ENABLE_ZLIB),1) -OBJS += libs/fst/fstapi.o -OBJS += libs/fst/fastlz.o -OBJS += libs/fst/lz4.o -endif - -techlibs/%_pm.h: passes/pmgen/pmgen.py techlibs/%.pmg - $(P) mkdir -p $(dir $@) && $(PYTHON_EXECUTABLE) $< -o $@ -p $(notdir $*) $(filter-out $<,$^) - -ifneq ($(SMALL),1) - -OBJS += libs/subcircuit/subcircuit.o - -include $(YOSYS_SRC)/frontends/*/Makefile.inc -include $(YOSYS_SRC)/passes/*/Makefile.inc -include $(YOSYS_SRC)/backends/*/Makefile.inc -include $(YOSYS_SRC)/techlibs/*/Makefile.inc - -else - -include $(YOSYS_SRC)/frontends/verilog/Makefile.inc -ifeq ($(ENABLE_VERIFIC),1) -include $(YOSYS_SRC)/frontends/verific/Makefile.inc -endif -include $(YOSYS_SRC)/frontends/rtlil/Makefile.inc -include $(YOSYS_SRC)/frontends/ast/Makefile.inc -include $(YOSYS_SRC)/frontends/blif/Makefile.inc - -OBJS += passes/hierarchy/hierarchy.o -OBJS += passes/cmds/select.o -OBJS += passes/cmds/show.o -OBJS += passes/cmds/stat.o -OBJS += passes/cmds/design.o -OBJS += passes/cmds/plugin.o - -include $(YOSYS_SRC)/passes/proc/Makefile.inc -include $(YOSYS_SRC)/passes/opt/Makefile.inc -include $(YOSYS_SRC)/passes/techmap/Makefile.inc - -include $(YOSYS_SRC)/backends/verilog/Makefile.inc -include $(YOSYS_SRC)/backends/rtlil/Makefile.inc - -include $(YOSYS_SRC)/techlibs/common/Makefile.inc - -endif - -ifeq ($(LINK_ABC),1) -OBJS += $(PROGRAM_PREFIX)yosys-libabc.a -endif - -# prevent the CXXFLAGS set by this Makefile from reaching abc/Makefile, -# especially the -MD flag which will break the build when CXX is clang -unexport CXXFLAGS - -top-all: $(TARGETS) $(EXTRA_TARGETS) - @echo "" - @echo " Build successful." - @echo "" - -.PHONY: compile-only -compile-only: $(OBJS) $(GENFILES) $(EXTRA_TARGETS) - @echo "" - @echo " Compile successful." - @echo "" - -.PHONY: share -share: $(EXTRA_TARGETS) - @echo "" - @echo " Share directory created." - @echo "" - -$(PROGRAM_PREFIX)yosys$(EXE): $(OBJS) - $(P) $(CXX) -o $(PROGRAM_PREFIX)yosys$(EXE) $(EXE_LINKFLAGS) $(LINKFLAGS) $(OBJS) $(EXE_LIBS) $(LIBS) $(LIBS_VERIFIC) - -libyosys.so: $(filter-out kernel/driver.o,$(OBJS)) -ifeq ($(OS), Darwin) - $(P) $(CXX) -o libyosys.so -shared -undefined dynamic_lookup -Wl,-install_name,libyosys.so $(LINKFLAGS) $^ $(LIBS) $(LIBS_VERIFIC) -else - $(P) $(CXX) -o libyosys.so -shared -Wl,-soname,libyosys.so $(LINKFLAGS) $^ $(LIBS) $(LIBS_VERIFIC) -endif - -libyosys.a: $(filter-out kernel/driver.o,$(OBJS)) - $(P) $(AR) rcs $@ $^ - -%.o: %.cc - $(Q) mkdir -p $(dir $@) - $(P) $(CXX) -o $@ -c $(CPPFLAGS) $(CXXFLAGS) $< - -%.pyh: %.h - $(Q) mkdir -p $(dir $@) - $(P) cat $< | grep -E -v "#[ ]*(include|error)" | $(CXX) $(CXXFLAGS) -x c++ -o $@ -E -P - - -ifeq ($(ENABLE_PYOSYS),1) -$(PY_WRAPPER_FILE).cc: $(PY_GEN_SCRIPT) pyosys/wrappers_tpl.cc $(PY_WRAP_INCLUDES) pyosys/hashlib.h - $(Q) mkdir -p $(dir $@) - $(P) $(UV_ENV) $(PYTHON_EXECUTABLE) $(PY_GEN_SCRIPT) $(PY_WRAPPER_FILE).cc -endif - -%.o: %.cpp - $(Q) mkdir -p $(dir $@) - $(P) $(CXX) -o $@ -c $(CPPFLAGS) $(CXXFLAGS) $< - -YOSYS_REPO := -ifneq (, $(shell command -v git 2>/dev/null)) -ifneq (, $(shell git rev-parse --git-dir 2>/dev/null)) - GIT_REMOTE := $(strip $(shell git config --get remote.origin.url 2>/dev/null | $(AWK) '{print tolower($$0)}')) - ifneq ($(strip $(GIT_REMOTE)),) - YOSYS_REPO := $(strip $(shell echo $(GIT_REMOTE) | $(AWK) -F '[:/]' '{gsub(/\.git$$/, "", $$NF); printf "%s/%s", $$(NF-1), $$NF}')) - endif - ifeq ($(strip $(YOSYS_REPO)),yosyshq/yosys) - YOSYS_REPO := - endif - GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) - ifeq ($(filter main HEAD release/v%,$(GIT_BRANCH)),) - YOSYS_REPO := $(YOSYS_REPO) at $(GIT_BRANCH) - endif - YOSYS_REPO := $(strip $(YOSYS_REPO)) -endif -endif - -YOSYS_GIT_STR := $(GIT_REV)$(GIT_DIRTY) -YOSYS_COMPILER := $(notdir $(CXX)) $(shell $(CXX) --version | tr ' ()' '\n' | grep '^[0-9]' | head -n1) $(filter -f% -m% -O% -DNDEBUG,$(CXXFLAGS)) -YOSYS_VER_STR := Yosys $(YOSYS_VER) (git sha1 $(YOSYS_GIT_STR), $(YOSYS_COMPILER)) -ifneq ($(strip $(YOSYS_REPO)),) - YOSYS_VER_STR := $(YOSYS_VER_STR) [$(YOSYS_REPO)] -endif - -kernel/version_$(GIT_REV).cc: $(YOSYS_SRC)/Makefile - $(P) rm -f kernel/version_*.o kernel/version_*.d kernel/version_*.cc - $(Q) mkdir -p kernel && echo "namespace Yosys { extern const char *yosys_version_str; const char *yosys_version_str=\"$(YOSYS_VER_STR)\"; const char *yosys_git_hash_str=\"$(YOSYS_GIT_STR)\"; }" > kernel/version_$(GIT_REV).cc - -ifeq ($(ENABLE_VERIFIC),1) -CXXFLAGS_NOVERIFIC = $(foreach v,$(CXXFLAGS),$(if $(findstring $(VERIFIC_DIR),$(v)),,$(v))) -LIBS_NOVERIFIC = $(foreach v,$(LIBS),$(if $(findstring $(VERIFIC_DIR),$(v)),,$(v))) -else -CXXFLAGS_NOVERIFIC = $(CXXFLAGS) -LIBS_NOVERIFIC = $(LIBS) -endif - -$(PROGRAM_PREFIX)yosys-config: misc/yosys-config.in $(YOSYS_SRC)/Makefile - $(P) $(SED) -e 's#@CXXFLAGS@#$(subst -Ilibs/dlfcn-win32,,$(subst -I. -I"$(YOSYS_SRC)",-I"$(DATDIR)/include",$(strip $(CXXFLAGS_NOVERIFIC))))#;' \ - -e 's#@CXX@#$(strip $(CXX))#;' -e 's#@LINKFLAGS@#$(strip $(LINKFLAGS) $(PLUGIN_LINKFLAGS))#;' -e 's#@LIBS@#$(strip $(LIBS_NOVERIFIC) $(PLUGIN_LIBS))#;' \ - -e 's#@BINDIR@#$(strip $(BINDIR))#;' -e 's#@DATDIR@#$(strip $(DATDIR))#;' < $< > $(PROGRAM_PREFIX)yosys-config - $(Q) chmod +x $(PROGRAM_PREFIX)yosys-config - -.PHONY: check-git-abc - -check-git-abc: - @if [ ! -d "$(YOSYS_SRC)/abc" ] && git -C "$(YOSYS_SRC)" status >/dev/null 2>&1; then \ - echo "Error: The 'abc' directory does not exist."; \ - echo "Initialize the submodule: Run 'git submodule update --init' to set up 'abc' as a submodule."; \ - exit 1; \ - elif git -C "$(YOSYS_SRC)" submodule status abc 2>/dev/null | grep -q '^ '; then \ - exit 0; \ - elif [ -f "$(YOSYS_SRC)/abc/.gitcommit" ] && ! grep -q '\$$Format:%[hH]\$$' "$(YOSYS_SRC)/abc/.gitcommit"; then \ - echo "'abc' comes from a tarball. Continuing."; \ - exit 0; \ - elif git -C "$(YOSYS_SRC)" submodule status abc 2>/dev/null | grep -q '^+'; then \ - echo "'abc' submodule does not match expected commit."; \ - echo "Run 'git submodule update' to check out the correct version."; \ - echo "Note: If testing a different version of abc, call 'git commit abc' in the Yosys source directory to update the expected commit."; \ - exit 1; \ - elif git -C "$(YOSYS_SRC)" submodule status abc 2>/dev/null | grep -q '^U'; then \ - echo "'abc' submodule has merge conflicts."; \ - echo "Please resolve merge conflicts before continuing."; \ - exit 1; \ - elif [ -f "$(YOSYS_SRC)/abc/.gitcommit" ] && grep -q '\$$Format:%[hH]\$$' "$(YOSYS_SRC)/abc/.gitcommit"; then \ - echo "Error: 'abc' is not configured as a git submodule."; \ - echo "To resolve this:"; \ - echo "1. Back up your changes: Save any modifications from the 'abc' directory to another location."; \ - echo "2. Remove the existing 'abc' directory: Delete the 'abc' directory and all its contents."; \ - echo "3. Initialize the submodule: Run 'git submodule update --init' to set up 'abc' as a submodule."; \ - echo "4. Reapply your changes: Move your saved changes back to the 'abc' directory, if necessary."; \ - exit 1; \ - elif ! git -C "$(YOSYS_SRC)" status >/dev/null 2>&1; then \ - echo "$(realpath $(YOSYS_SRC)) is not configured as a git repository, and 'abc' folder is missing."; \ - echo "If you already have ABC, set 'ABCEXTERNAL' make variable to point to ABC executable."; \ - echo "Otherwise, download release archive 'yosys.tar.gz' from https://github.com/YosysHQ/yosys/releases."; \ - echo " ('Source code' archive does not contain submodules.)"; \ - exit 1; \ - else \ - echo "Initialize the submodule: Run 'git submodule update --init' to set up 'abc' as a submodule."; \ - exit 1; \ - fi - -.git-abc-submodule-hash: FORCE - @new=$$(cd abc 2>/dev/null && git rev-parse HEAD 2>/dev/null || echo none); \ - old=$$(cat .git-abc-submodule-hash 2>/dev/null || echo none); \ - if [ "$$new" != "$$old" ]; then \ - echo "$$new" > .git-abc-submodule-hash; \ - fi - -abc/abc$(EXE) abc/libabc.a: .git-abc-submodule-hash | check-git-abc - @if [ "$$(cd abc 2>/dev/null && git rev-parse HEAD 2>/dev/null)" != "$$(cat ../.git-abc-submodule-hash 2>/dev/null || echo none)" ]; then \ - rm -f abc/abc$(EXE); \ - fi - $(P) - $(Q) mkdir -p abc && $(MAKE) -C $(PROGRAM_PREFIX)abc -f "$(realpath $(YOSYS_SRC)/abc/Makefile)" ABCSRC="$(realpath $(YOSYS_SRC)/abc/)" $(S) $(ABCMKARGS) $(if $(filter %.a,$@),PROG="abc",PROG="abc$(EXE)") MSG_PREFIX="$(eval P_OFFSET = 5)$(call P_SHOW)$(eval P_OFFSET = 10) ABC: " $(if $(filter %.a,$@),libabc.a) - -$(PROGRAM_PREFIX)yosys-abc$(EXE): abc/abc$(EXE) - $(P) cp $< $(PROGRAM_PREFIX)yosys-abc$(EXE) - -$(PROGRAM_PREFIX)yosys-libabc.a: abc/libabc.a - $(P) cp $< $(PROGRAM_PREFIX)yosys-libabc.a - -ifneq ($(SEED),) -SEEDOPT="-S $(SEED)" -else -SEEDOPT="" -endif - -ifneq ($(ABCEXTERNAL),) -ABCOPT="-A $(ABCEXTERNAL)" -else -ABCOPT="" -endif - -test: vanilla-test unit-test - -.PHONY: vanilla-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) - -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 "" - -# Unit test -unit-test: libyosys.so - @$(MAKE) -f $(UNITESTPATH)/Makefile CXX="$(CXX)" CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" \ - CXXFLAGS="$(CXXFLAGS)" LINKFLAGS="$(LINKFLAGS)" LIBS="$(LIBS)" ROOTPATH="$(CURDIR)" - -clean-unit-test: - @$(MAKE) -f $(UNITESTPATH)/Makefile clean - -install-dev: $(PROGRAM_PREFIX)yosys-config share - $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(BINDIR) - $(INSTALL_SUDO) cp $(PROGRAM_PREFIX)yosys-config $(DESTDIR)$(BINDIR) - $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(DATDIR) - $(INSTALL_SUDO) cp -r share/. $(DESTDIR)$(DATDIR)/. - -install: $(TARGETS) $(EXTRA_TARGETS) - $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(BINDIR) - $(INSTALL_SUDO) cp $(filter-out libyosys.so libyosys.a,$(TARGETS)) $(DESTDIR)$(BINDIR) -ifneq ($(filter $(PROGRAM_PREFIX)yosys$(EXE),$(TARGETS)),) - if [ -n "$(STRIP)" ]; then $(INSTALL_SUDO) $(STRIP) -S $(DESTDIR)$(BINDIR)/$(PROGRAM_PREFIX)yosys$(EXE); fi -endif -ifneq ($(filter $(PROGRAM_PREFIX)yosys-abc$(EXE),$(TARGETS)),) - if [ -n "$(STRIP)" ]; then $(INSTALL_SUDO) $(STRIP) $(DESTDIR)$(BINDIR)/$(PROGRAM_PREFIX)yosys-abc$(EXE); fi -endif -ifneq ($(filter $(PROGRAM_PREFIX)yosys-filterlib$(EXE),$(TARGETS)),) - if [ -n "$(STRIP)" ]; then $(INSTALL_SUDO) $(STRIP) $(DESTDIR)$(BINDIR)/$(PROGRAM_PREFIX)yosys-filterlib$(EXE); fi -endif - $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(DATDIR) - $(INSTALL_SUDO) cp -r share/. $(DESTDIR)$(DATDIR)/. -ifeq ($(ENABLE_LIBYOSYS),1) - $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(LIBDIR) - $(INSTALL_SUDO) cp libyosys.so $(DESTDIR)$(LIBDIR)/ - if [ -n "$(STRIP)" ]; then $(INSTALL_SUDO) $(STRIP) -S $(DESTDIR)$(LIBDIR)/libyosys.so; fi -ifeq ($(ENABLE_LIBYOSYS_STATIC),1) - $(INSTALL_SUDO) cp libyosys.a $(DESTDIR)$(LIBDIR)/ -endif -ifeq ($(ENABLE_PYOSYS),1) - $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys - $(INSTALL_SUDO) cp $(YOSYS_SRC)/pyosys/__init__.py $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys/__init__.py - $(INSTALL_SUDO) cp libyosys.so $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys/libyosys.so - $(INSTALL_SUDO) cp -r share $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys -ifeq ($(ENABLE_ABC),1) -ifeq ($(ABCEXTERNAL),) - $(INSTALL_SUDO) cp $(PROGRAM_PREFIX)yosys-abc$(EXE) $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys/yosys-abc$(EXE) -endif -endif -endif -endif -ifeq ($(ENABLE_PLUGINS),1) -ifeq ($(OS), MINGW) - $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(LIBDIR) - $(INSTALL_SUDO) cp libyosys_exe.a $(DESTDIR)$(LIBDIR)/ -endif -endif - -uninstall: - $(INSTALL_SUDO) rm -vf $(addprefix $(DESTDIR)$(BINDIR)/,$(notdir $(TARGETS))) - $(INSTALL_SUDO) rm -rvf $(DESTDIR)$(DATDIR) -ifeq ($(ENABLE_LIBYOSYS),1) - $(INSTALL_SUDO) rm -vf $(DESTDIR)$(LIBDIR)/libyosys.so -ifeq ($(ENABLE_LIBYOSYS_STATIC),1) - $(INSTALL_SUDO) rm -vf $(DESTDIR)$(LIBDIR)/libyosys.a -endif -ifeq ($(ENABLE_PYOSYS),1) - $(INSTALL_SUDO) rm -vf $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys/libyosys.so - $(INSTALL_SUDO) rm -vf $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys/__init__.py - $(INSTALL_SUDO) rmdir $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys -endif -endif - -docs/source/generated/cmds.json: docs/source/generated $(TARGETS) $(EXTRA_TARGETS) - $(Q) ./$(PROGRAM_PREFIX)yosys -p 'help -dump-cmds-json $@' - -docs/source/generated/cells.json: docs/source/generated $(TARGETS) $(EXTRA_TARGETS) - $(Q) ./$(PROGRAM_PREFIX)yosys -p 'help -dump-cells-json $@' - -docs/source/generated/%.cc: backends/%.cc - $(Q) mkdir -p $(@D) - $(Q) cp $< $@ - -# diff returns exit code 1 if the files are different, but it's not an error -docs/source/generated/functional/rosette.diff: backends/functional/smtlib.cc backends/functional/smtlib_rosette.cc - $(Q) mkdir -p $(@D) - $(Q) diff -U 20 $^ > $@ || exit 0 - -PHONY: docs/gen/functional_ir -docs/gen/functional_ir: docs/source/generated/functional/smtlib.cc docs/source/generated/functional/rosette.diff - -docs/source/generated/%.log: docs/source/generated $(TARGETS) $(EXTRA_TARGETS) - $(Q) ./$(PROGRAM_PREFIX)yosys -qQT -h '$*' -l $@ - -docs/source/generated/chformal.cc: passes/cmds/chformal.cc docs/source/generated - $(Q) cp $< $@ - -PHONY: docs/gen/chformal -docs/gen/chformal: docs/source/generated/chformal.log docs/source/generated/chformal.cc - -PHONY: docs/gen docs/usage docs/reqs -docs/gen: $(TARGETS) - $(Q) $(MAKE) -C docs gen - -docs/source/generated: - $(Q) mkdir -p docs/source/generated - -# some commands return an error and print the usage text to stderr -define DOC_USAGE_STDERR -docs/source/generated/$(1): $(TARGETS) docs/source/generated FORCE - -$(Q) ./$(PROGRAM_PREFIX)$(1) --help 2> $$@ -endef -DOCS_USAGE_STDERR := yosys-filterlib - -# The in-tree ABC (yosys-abc) is only built when ABCEXTERNAL is not set. -ifeq ($(ABCEXTERNAL),) -DOCS_USAGE_STDERR += yosys-abc -endif - -$(foreach usage,$(DOCS_USAGE_STDERR),$(eval $(call DOC_USAGE_STDERR,$(usage)))) - -# others print to stdout -define DOC_USAGE_STDOUT -docs/source/generated/$(1): $(TARGETS) docs/source/generated - $(Q) ./$(PROGRAM_PREFIX)$(1) --help > $$@ || rm $$@ -endef -DOCS_USAGE_STDOUT := yosys yosys-smtbmc yosys-witness yosys-config -$(foreach usage,$(DOCS_USAGE_STDOUT),$(eval $(call DOC_USAGE_STDOUT,$(usage)))) - -docs/usage: $(addprefix docs/source/generated/,$(DOCS_USAGE_STDOUT) $(DOCS_USAGE_STDERR)) - -docs/reqs: - $(Q) $(MAKE) -C docs reqs - -.PHONY: docs/prep -docs/prep: docs/source/generated/cells.json docs/source/generated/cmds.json docs/gen docs/usage docs/gen/functional_ir docs/gen/chformal - -DOC_TARGET ?= html -docs: docs/prep - $(Q) $(MAKE) -C docs $(DOC_TARGET) - -clean: clean-py clean-unit-test - rm -rf share - rm -f $(OBJS) $(GENFILES) $(TARGETS) $(EXTRA_TARGETS) $(EXTRA_OBJS) - rm -f kernel/version_*.o kernel/version_*.cc - rm -f libs/*/*.d frontends/*/*.d passes/*/*.d backends/*/*.d kernel/*.d techlibs/*/*.d - rm -rf vloghtb/Makefile vloghtb/refdat vloghtb/rtl vloghtb/scripts vloghtb/spec vloghtb/check_yosys vloghtb/vloghammer_tb.tar.bz2 vloghtb/temp vloghtb/log_test_* - -$(MAKE) -C $(YOSYS_SRC)/tests clean - -$(MAKE) -C $(YOSYS_SRC)/docs clean - rm -rf docs/util/__pycache__ - rm -f libyosys.so - -clean-py: - rm -f $(PY_WRAPPER_FILE).inc.cc $(PY_WRAPPER_FILE).cc - rm -f $(PYTHON_OBJECTS) - rm -f *.whl - rm -f libyosys.so libyosys.a - rm -rf kernel/*.pyh - -clean-abc: - $(MAKE) -C $(YOSYS_SRC)/abc DEP= clean - rm -f $(PROGRAM_PREFIX)yosys-abc$(EXE) $(PROGRAM_PREFIX)yosys-libabc.a abc/abc-[0-9a-f]* abc/libabc-[0-9a-f]*.a .git-abc-submodule-hash - -mrproper: clean - git clean -xdf - -coverage: - ./$(PROGRAM_PREFIX)yosys -qp 'help; help -all' - rm -rf coverage_html - llvm-profdata merge -sparse coverage/coverage_*.profraw -o yosys.profdata - llvm-cov show ./$(PROGRAM_PREFIX)yosys -instr-profile=yosys.profdata -format=html -output-dir=coverage_html --compilation-dir=. -ignore-filename-regex='(^|.*/)libs/.*|/usr/include/.*|$(subst /,\/,$(VERIFIC_DIR))/.*' - -clean_coverage: - rm -rf coverage - rm -f yosys.profdata - -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 - -qtcreator: - echo "$(CXXFLAGS)" | grep -o '\-D[^ ]*' | tr ' ' '\n' | sed 's/-D/#define /' | sed 's/=/ /'> qtcreator.config - { for file in $(basename $(OBJS)); do \ - for prefix in cc y l; do if [ -f $${file}.$${prefix} ]; then echo $$file.$${prefix}; fi; done \ - done; find backends frontends kernel libs passes -type f \( -name '*.h' -o -name '*.hh' \); } > qtcreator.files - { echo .; find backends frontends kernel libs passes -type f \( -name '*.h' -o -name '*.hh' \) -printf '%h\n' | sort -u; } > qtcreator.includes - touch qtcreator.creator - -VCX_DIR_NAME := yosys-win32-vcxsrc-$(YOSYS_VER) -vcxsrc: $(GENFILES) $(EXTRA_TARGETS) kernel/version_$(GIT_REV).cc - rm -rf $(VCX_DIR_NAME){,.zip} - cp -f kernel/version_$(GIT_REV).cc kernel/version.cc - set -e; for f in `ls $(filter %.cc %.cpp,$(GENFILES)) $(addsuffix .cc,$(basename $(OBJS))) $(addsuffix .cpp,$(basename $(OBJS))) 2> /dev/null`; do \ - echo "Analyse: $$f" >&2; cpp -std=c++20 -MM -I. -D_YOSYS_ $$f; done | sed 's,.*:,,; s,//*,/,g; s,/[^/]*/\.\./,/,g; y, \\,\n\n,;' | grep '^[^/]' | sort -u | grep -v kernel/version_ > srcfiles.txt - echo "libs/fst/fst_win_unistd.h" >> srcfiles.txt - echo "kernel/version.cc" >> srcfiles.txt - bash misc/create_vcxsrc.sh $(VCX_DIR_NAME) $(YOSYS_VER) - zip $(VCX_DIR_NAME)/genfiles.zip $(GENFILES) kernel/version.cc - zip -r $(VCX_DIR_NAME).zip $(VCX_DIR_NAME)/ - rm -f srcfiles.txt kernel/version.cc - -config-clean: clean - rm -f Makefile.conf - -config-clang: clean - echo 'CONFIG := clang' > Makefile.conf - -config-gcc: clean - echo 'CONFIG := gcc' > Makefile.conf - -config-gcc-static: clean - echo 'CONFIG := gcc-static' > Makefile.conf - echo 'ENABLE_PLUGINS := 0' >> Makefile.conf - echo 'ENABLE_READLINE := 0' >> Makefile.conf - echo 'ENABLE_TCL := 0' >> Makefile.conf - -config-wasi: clean - echo 'CONFIG := wasi' > Makefile.conf - echo 'ENABLE_TCL := 0' >> Makefile.conf - echo 'ENABLE_ABC := 0' >> Makefile.conf - echo 'ENABLE_PLUGINS := 0' >> Makefile.conf - echo 'ENABLE_READLINE := 0' >> Makefile.conf - echo 'ENABLE_ZLIB := 0' >> Makefile.conf - -config-msys2-32: clean - echo 'CONFIG := msys2-32' > Makefile.conf - echo "PREFIX := $(MINGW_PREFIX)" >> Makefile.conf - -config-msys2-64: clean - echo 'CONFIG := msys2-64' > Makefile.conf - echo "PREFIX := $(MINGW_PREFIX)" >> Makefile.conf - -config-gcov: clean - echo 'CONFIG := clang' > Makefile.conf - echo 'ENABLE_GCOV := 1' >> Makefile.conf - echo 'ENABLE_DEBUG := 1' >> Makefile.conf - -config-gprof: clean - echo 'CONFIG := gcc' > Makefile.conf - echo 'ENABLE_GPROF := 1' >> Makefile.conf - -config-sudo: - echo "INSTALL_SUDO := sudo" >> Makefile.conf - -echo-yosys-ver: - @echo "$(YOSYS_VER)" - -echo-git-rev: - @echo "$(GIT_REV)" - -echo-cxx: - @echo "$(CXX)" - --include libs/*/*.d --include frontends/*/*.d --include passes/*/*.d --include backends/*/*.d --include kernel/*.d --include techlibs/*/*.d - -FORCE: - -.PHONY: all top-all abc test install-dev install install-abc docs clean mrproper qtcreator coverage vcxsrc -.PHONY: config-clean config-clang config-gcc config-gcc-static config-gprof config-sudo diff --git a/backends/CMakeLists.txt b/backends/CMakeLists.txt new file mode 100644 index 000000000..a38c2ec94 --- /dev/null +++ b/backends/CMakeLists.txt @@ -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) diff --git a/backends/aiger/CMakeLists.txt b/backends/aiger/CMakeLists.txt new file mode 100644 index 000000000..4cf940196 --- /dev/null +++ b/backends/aiger/CMakeLists.txt @@ -0,0 +1,8 @@ +yosys_backend(aiger + aiger.cc + REQUIRES + json11 +) +yosys_backend(xaiger + xaiger.cc +) diff --git a/backends/aiger/Makefile.inc b/backends/aiger/Makefile.inc deleted file mode 100644 index 4a4cf30bd..000000000 --- a/backends/aiger/Makefile.inc +++ /dev/null @@ -1,4 +0,0 @@ - -OBJS += backends/aiger/aiger.o -OBJS += backends/aiger/xaiger.o - diff --git a/backends/aiger2/CMakeLists.txt b/backends/aiger2/CMakeLists.txt new file mode 100644 index 000000000..f77b8d9ee --- /dev/null +++ b/backends/aiger2/CMakeLists.txt @@ -0,0 +1,5 @@ +yosys_backend(aiger2 + aiger.cc + PROVIDES + write_xaiger2 +) diff --git a/backends/aiger2/Makefile.inc b/backends/aiger2/Makefile.inc deleted file mode 100644 index 494b8d6c6..000000000 --- a/backends/aiger2/Makefile.inc +++ /dev/null @@ -1 +0,0 @@ -OBJS += backends/aiger2/aiger.o diff --git a/backends/blif/CMakeLists.txt b/backends/blif/CMakeLists.txt new file mode 100644 index 000000000..06b177513 --- /dev/null +++ b/backends/blif/CMakeLists.txt @@ -0,0 +1,3 @@ +yosys_backend(blif + blif.cc +) diff --git a/backends/blif/Makefile.inc b/backends/blif/Makefile.inc deleted file mode 100644 index 517dabaf2..000000000 --- a/backends/blif/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/blif/blif.o - diff --git a/backends/btor/CMakeLists.txt b/backends/btor/CMakeLists.txt new file mode 100644 index 000000000..ca40d538e --- /dev/null +++ b/backends/btor/CMakeLists.txt @@ -0,0 +1,7 @@ +yosys_backend(btor + btor.cc + REQUIRES + bmuxmap + demuxmap + bwmuxmap +) diff --git a/backends/btor/Makefile.inc b/backends/btor/Makefile.inc deleted file mode 100644 index af7ab14dc..000000000 --- a/backends/btor/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/btor/btor.o - diff --git a/backends/cxxrtl/CMakeLists.txt b/backends/cxxrtl/CMakeLists.txt new file mode 100644 index 000000000..f5d10539a --- /dev/null +++ b/backends/cxxrtl/CMakeLists.txt @@ -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 +) diff --git a/backends/cxxrtl/Makefile.inc b/backends/cxxrtl/Makefile.inc deleted file mode 100644 index dd77d2ad3..000000000 --- a/backends/cxxrtl/Makefile.inc +++ /dev/null @@ -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)) diff --git a/backends/edif/CMakeLists.txt b/backends/edif/CMakeLists.txt new file mode 100644 index 000000000..126d09f07 --- /dev/null +++ b/backends/edif/CMakeLists.txt @@ -0,0 +1,3 @@ +yosys_backend(edif + edif.cc +) diff --git a/backends/edif/Makefile.inc b/backends/edif/Makefile.inc deleted file mode 100644 index 93de0e24f..000000000 --- a/backends/edif/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/edif/edif.o - diff --git a/backends/firrtl/CMakeLists.txt b/backends/firrtl/CMakeLists.txt new file mode 100644 index 000000000..2f38cd208 --- /dev/null +++ b/backends/firrtl/CMakeLists.txt @@ -0,0 +1,8 @@ +yosys_backend(firrtl + firrtl.cc + REQUIRES + pmuxtree + bmuxmap + demuxmap + bwmuxmap +) diff --git a/backends/firrtl/Makefile.inc b/backends/firrtl/Makefile.inc deleted file mode 100644 index fdf100d34..000000000 --- a/backends/firrtl/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/firrtl/firrtl.o - diff --git a/backends/functional/CMakeLists.txt b/backends/functional/CMakeLists.txt new file mode 100644 index 000000000..5e7a6e92f --- /dev/null +++ b/backends/functional/CMakeLists.txt @@ -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 +) diff --git a/backends/functional/Makefile.inc b/backends/functional/Makefile.inc deleted file mode 100644 index 16d1c0542..000000000 --- a/backends/functional/Makefile.inc +++ /dev/null @@ -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 diff --git a/backends/intersynth/CMakeLists.txt b/backends/intersynth/CMakeLists.txt new file mode 100644 index 000000000..e34bab4e1 --- /dev/null +++ b/backends/intersynth/CMakeLists.txt @@ -0,0 +1,3 @@ +yosys_backend(intersynth + intersynth.cc +) diff --git a/backends/intersynth/Makefile.inc b/backends/intersynth/Makefile.inc deleted file mode 100644 index 85df1b393..000000000 --- a/backends/intersynth/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/intersynth/intersynth.o - diff --git a/backends/jny/CMakeLists.txt b/backends/jny/CMakeLists.txt new file mode 100644 index 000000000..e76a74e97 --- /dev/null +++ b/backends/jny/CMakeLists.txt @@ -0,0 +1,5 @@ +yosys_backend(jny + jny.cc + PROVIDES + jny +) diff --git a/backends/jny/Makefile.inc b/backends/jny/Makefile.inc deleted file mode 100644 index 5e417128e..000000000 --- a/backends/jny/Makefile.inc +++ /dev/null @@ -1,2 +0,0 @@ - -OBJS += backends/jny/jny.o diff --git a/backends/json/CMakeLists.txt b/backends/json/CMakeLists.txt new file mode 100644 index 000000000..99c404d92 --- /dev/null +++ b/backends/json/CMakeLists.txt @@ -0,0 +1,5 @@ +yosys_backend(json + json.cc + PROVIDES + json +) diff --git a/backends/json/Makefile.inc b/backends/json/Makefile.inc deleted file mode 100644 index a463daf91..000000000 --- a/backends/json/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/json/json.o - diff --git a/backends/rtlil/CMakeLists.txt b/backends/rtlil/CMakeLists.txt new file mode 100644 index 000000000..40b3cffe0 --- /dev/null +++ b/backends/rtlil/CMakeLists.txt @@ -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 +) diff --git a/backends/rtlil/Makefile.inc b/backends/rtlil/Makefile.inc deleted file mode 100644 index f691282ca..000000000 --- a/backends/rtlil/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/rtlil/rtlil_backend.o - diff --git a/backends/simplec/CMakeLists.txt b/backends/simplec/CMakeLists.txt new file mode 100644 index 000000000..1a9feed9f --- /dev/null +++ b/backends/simplec/CMakeLists.txt @@ -0,0 +1,3 @@ +yosys_backend(simplec + simplec.cc +) diff --git a/backends/simplec/Makefile.inc b/backends/simplec/Makefile.inc deleted file mode 100644 index fee1376c5..000000000 --- a/backends/simplec/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/simplec/simplec.o - diff --git a/backends/smt2/CMakeLists.txt b/backends/smt2/CMakeLists.txt new file mode 100644 index 000000000..b703f1837 --- /dev/null +++ b/backends/smt2/CMakeLists.txt @@ -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) diff --git a/backends/smt2/Makefile.inc b/backends/smt2/Makefile.inc deleted file mode 100644 index 3afe990e7..000000000 --- a/backends/smt2/Makefile.inc +++ /dev/null @@ -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 diff --git a/backends/smt2/smtbmc.py b/backends/smt2/smtbmc.py old mode 100644 new mode 100755 index 9dfbd2a25..60fa97e36 --- a/backends/smt2/smtbmc.py +++ b/backends/smt2/smtbmc.py @@ -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 diff --git a/backends/smt2/witness.py b/backends/smt2/witness.py old mode 100644 new mode 100755 index b7e25851c..83416c695 --- a/backends/smt2/witness.py +++ b/backends/smt2/witness.py @@ -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 diff --git a/backends/smv/CMakeLists.txt b/backends/smv/CMakeLists.txt new file mode 100644 index 000000000..ea9e85f28 --- /dev/null +++ b/backends/smv/CMakeLists.txt @@ -0,0 +1,7 @@ +yosys_backend(smv + smv.cc + REQUIRES + bmuxmap + demuxmap + bwmuxmap +) diff --git a/backends/smv/Makefile.inc b/backends/smv/Makefile.inc deleted file mode 100644 index 66c192d80..000000000 --- a/backends/smv/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/smv/smv.o - diff --git a/backends/spice/CMakeLists.txt b/backends/spice/CMakeLists.txt new file mode 100644 index 000000000..efbfc84d0 --- /dev/null +++ b/backends/spice/CMakeLists.txt @@ -0,0 +1,3 @@ +yosys_backend(spice + spice.cc +) diff --git a/backends/spice/Makefile.inc b/backends/spice/Makefile.inc deleted file mode 100644 index 9c8530cb2..000000000 --- a/backends/spice/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/spice/spice.o - diff --git a/backends/table/CMakeLists.txt b/backends/table/CMakeLists.txt new file mode 100644 index 000000000..371d1e8f0 --- /dev/null +++ b/backends/table/CMakeLists.txt @@ -0,0 +1,3 @@ +yosys_backend(table + table.cc +) diff --git a/backends/table/Makefile.inc b/backends/table/Makefile.inc deleted file mode 100644 index 8cd1dc619..000000000 --- a/backends/table/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/table/table.o - diff --git a/backends/verilog/CMakeLists.txt b/backends/verilog/CMakeLists.txt new file mode 100644 index 000000000..6de8dd1f6 --- /dev/null +++ b/backends/verilog/CMakeLists.txt @@ -0,0 +1,8 @@ +yosys_backend(verilog + verilog_backend.cc + verilog_backend.h + REQUIRES + bmuxmap + demuxmap + clean_zerowidth +) diff --git a/backends/verilog/Makefile.inc b/backends/verilog/Makefile.inc deleted file mode 100644 index c2dffef7a..000000000 --- a/backends/verilog/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ - -OBJS += backends/verilog/verilog_backend.o - diff --git a/cmake/CheckLibcFeatures.cmake b/cmake/CheckLibcFeatures.cmake new file mode 100644 index 000000000..99dff944e --- /dev/null +++ b/cmake/CheckLibcFeatures.cmake @@ -0,0 +1,35 @@ +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 + 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) +endfunction() diff --git a/cmake/Condition.cmake b/cmake/Condition.cmake new file mode 100644 index 000000000..6ef400a32 --- /dev/null +++ b/cmake/Condition.cmake @@ -0,0 +1,35 @@ +# Syntax: +# +# condition( ...) +# +# If `...` is truthful (evaluated as in `if()`) then assigns 1 to ``, else assigns 0. +# The assigned value is `0`/`1` rather than `TRUE`/`FALSE` for ease of use in generator expressions. +# Note that `...` *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() diff --git a/cmake/FindDlfcn.cmake b/cmake/FindDlfcn.cmake new file mode 100644 index 000000000..201745a3f --- /dev/null +++ b/cmake/FindDlfcn.cmake @@ -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 +) diff --git a/cmake/FindPyosysEnv.cmake b/cmake/FindPyosysEnv.cmake new file mode 100644 index 000000000..4cbf69a61 --- /dev/null +++ b/cmake/FindPyosysEnv.cmake @@ -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 +) diff --git a/cmake/FindPython3Embed.cmake b/cmake/FindPython3Embed.cmake new file mode 100644 index 000000000..f3fda9070 --- /dev/null +++ b/cmake/FindPython3Embed.cmake @@ -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}") diff --git a/cmake/PkgConfig.cmake b/cmake/PkgConfig.cmake new file mode 100644 index 000000000..b37d74622 --- /dev/null +++ b/cmake/PkgConfig.cmake @@ -0,0 +1,43 @@ +# Syntax: +# +# pkg_config_import() +# +# 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 `` as a CMake `IMPORTED` target `PkgConfig::`. +# Updates the global `PACKAGES_FOUND` and `PACKAGES_NOT_FOUND` properties and defines +# the `_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() diff --git a/cmake/PmgenCommand.cmake b/cmake/PmgenCommand.cmake new file mode 100644 index 000000000..889d7653e --- /dev/null +++ b/cmake/PmgenCommand.cmake @@ -0,0 +1,60 @@ +# Syntax: +# +# pmgen_command( +# [...] +# [PREFIX ] +# [DEBUG] +# ) +# +# Builds `_pm.h` in the current binary directory from pmgen source files ``, which must have +# the `*.pmg` extension. If `...` contains more than one file, `` must be provided. +# +# Defines the following variables: +# - `PMGEN__DEFINED`: Boolean indicating whether this command was successfully invoked. +# - `PMGEN__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} + "$<$:-g>" + "$<$:-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() diff --git a/cmake/YosysAbc.cmake b/cmake/YosysAbc.cmake new file mode 100644 index 000000000..adf70d601 --- /dev/null +++ b/cmake/YosysAbc.cmake @@ -0,0 +1,96 @@ +include(CheckCompilerFlag) + +define_property(TARGET PROPERTY YOSYS_NO_SANITIZE) + +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} $<$:${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 ${contents}) + 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 + $<$: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 + $<$:Threads::Threads> + $<${YOSYS_ENABLE_READLINE}:PkgConfig::readline> + $<$:-lshlwapi> + ) + set_target_properties(${arg_LIBNAME} PROPERTIES + YOSYS_NO_SANITIZE 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_NO_SANITIZE ON + ) +endfunction() diff --git a/cmake/YosysAbcSubmodule.cmake b/cmake/YosysAbcSubmodule.cmake new file mode 100644 index 000000000..43a8c2135 --- /dev/null +++ b/cmake/YosysAbcSubmodule.cmake @@ -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 (IS_READABLE "${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() diff --git a/cmake/YosysComponent.cmake b/cmake/YosysComponent.cmake new file mode 100644 index 000000000..9786ba156 --- /dev/null +++ b/cmake/YosysComponent.cmake @@ -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( [INTERFACE] +# [...] +# [DEFINITIONS ...] +# [INCLUDE_DIRS ...] +# [LIBRARIES ...] +# [PROVIDES ...] +# [REQUIRES ...] +# [DATA_DIR ] +# [DATA_FILES ...] +# [DATA_EXPLICIT [ ]...] +# [ESSENTIAL] +# [ENABLE_IF ""] +# ) +# +# Creates a target `yosys_` (if `` is empty) or `yosys__` (if `` 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. +# - `...` is a shortcut for `target_sources(PRIVATE)`. +# - `DEFINITIONS ...` is a shortcut for `target_compile_definitions(PRIVATE)`. +# - `INCLUDE_DIRS ...` is a shortcut for `target_include_directories(PRIVATE)`. +# - `LIBRARIES ...` is a shortcut for `target_link_libraries(PRIVATE)`. +# - `PROVIDES ...` creates aliases to each `` component name. +# - `REQUIRES ...` ensures that if this target is linked into the Yosys binary, then every +# `` component is also linked in. +# - `DATA_DIR ` configures a base directory for installing data files; this directory +# is (relative to the root build directory or the installation prefix) `share/` if +# `DATA_DIR` is provided, and `share` if not. +# - `DATA_FILES ...` installs each of `` as `share///`, +# where `` is the directory name of `` and `` is the filename of ``. +# - `DATA_EXPLICIT [ ]...` installs each `` as `share//`. +# Where possible, `DATA_FILES` should be used instead. +# - `ESSENTIAL` ensures that this target is always linked into the Yosys binary. +# - `ENABLE_IF ""` marks the component as available only when `if()` would run. +# +# Avoid using this function directly. Instead, use one of the wrappers below as follows: +# - to define a normal pass, use `yosys_pass()` to add a component called ``. +# - to define a test pass, use `yosys_test_pass()` to add a component called `test_`. +# - to define a frontend, use `yosys_frontend()` to add a component called `read_`. +# - to define a backend, use `yosys_backend()` to add a component called `write_`. +# - 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 ` +# 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( [