STAR-future commited on
Commit
2d66860
·
verified ·
1 Parent(s): 9ded85f

add chips/yosys

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. chips/yosys/.clang-format +13 -0
  3. chips/yosys/.editorconfig +20 -0
  4. chips/yosys/.gitattributes +2 -0
  5. chips/yosys/.gitcommit +1 -0
  6. chips/yosys/.github/ISSUE_TEMPLATE/bug_report.yml +77 -0
  7. chips/yosys/.github/ISSUE_TEMPLATE/config.yml +7 -0
  8. chips/yosys/.github/ISSUE_TEMPLATE/docs_report.yml +54 -0
  9. chips/yosys/.github/ISSUE_TEMPLATE/feature_request.yml +24 -0
  10. chips/yosys/.github/PULL_REQUEST_TEMPLATE.md +9 -0
  11. chips/yosys/.github/actions/setup-build-env/action.yml +120 -0
  12. chips/yosys/.github/actions/setup-iverilog/action.yml +70 -0
  13. chips/yosys/.github/workflows/codeql.yml +41 -0
  14. chips/yosys/.github/workflows/extra-builds.yml +191 -0
  15. chips/yosys/.github/workflows/nix.yml +24 -0
  16. chips/yosys/.github/workflows/prepare-docs.yml +99 -0
  17. chips/yosys/.github/workflows/source-vendor.yml +39 -0
  18. chips/yosys/.github/workflows/test-build.yml +312 -0
  19. chips/yosys/.github/workflows/test-compile.yml +130 -0
  20. chips/yosys/.github/workflows/test-sanitizers.yml +94 -0
  21. chips/yosys/.github/workflows/test-verific-cfg.yml +95 -0
  22. chips/yosys/.github/workflows/test-verific.yml +177 -0
  23. chips/yosys/.github/workflows/wheels.yml +132 -0
  24. chips/yosys/.github/workflows/wheels/_test_cibw_local.py +45 -0
  25. chips/yosys/.github/workflows/wheels/cibw_before_all.sh +110 -0
  26. chips/yosys/.github/workflows/wheels/cibw_before_build.sh +13 -0
  27. chips/yosys/.gitignore +97 -0
  28. chips/yosys/.gitmodules +26 -0
  29. chips/yosys/.mailmap +7 -0
  30. chips/yosys/.pre-commit-config.yaml +30 -0
  31. chips/yosys/.readthedocs.yaml +20 -0
  32. chips/yosys/Brewfile +15 -0
  33. chips/yosys/CHANGELOG +1898 -0
  34. chips/yosys/CMakeLists.txt +639 -0
  35. chips/yosys/CMakePresets.json +93 -0
  36. chips/yosys/CODEOWNERS +50 -0
  37. chips/yosys/CODE_OF_CONDUCT.md +128 -0
  38. chips/yosys/CONTRIBUTING.md +17 -0
  39. chips/yosys/COPYING +15 -0
  40. chips/yosys/README.md +249 -0
  41. chips/yosys/SOURCE.json +9 -0
  42. chips/yosys/backends/CMakeLists.txt +18 -0
  43. chips/yosys/backends/aiger/CMakeLists.txt +8 -0
  44. chips/yosys/backends/aiger/aiger.cc +1062 -0
  45. chips/yosys/backends/aiger/xaiger.cc +815 -0
  46. chips/yosys/backends/aiger2/CMakeLists.txt +5 -0
  47. chips/yosys/backends/aiger2/aiger.cc +1978 -0
  48. chips/yosys/backends/blif/CMakeLists.txt +3 -0
  49. chips/yosys/backends/blif/blif.cc +742 -0
  50. chips/yosys/backends/btor/.gitignore +1 -0
.gitattributes CHANGED
@@ -3076,3 +3076,5 @@ chips/openroad_flow_scripts/flow/platforms/sky130ram/sky130_sram_1rw1r_80x64_8/s
3076
  chips/openroad_flow_scripts/flow/platforms/sky130ram/sky130_sram_1rw1r_80x64_8/sky130_sram_1rw1r_80x64_8.lef filter=lfs diff=lfs merge=lfs -text
3077
  chips/openroad_flow_scripts/flow/tutorials/scripts/metal_fill/5_route.odb filter=lfs diff=lfs merge=lfs -text
3078
  energy/nrel_pvdaq_parquet/MANIFEST.jsonl filter=lfs diff=lfs merge=lfs -text
 
 
 
3076
  chips/openroad_flow_scripts/flow/platforms/sky130ram/sky130_sram_1rw1r_80x64_8/sky130_sram_1rw1r_80x64_8.lef filter=lfs diff=lfs merge=lfs -text
3077
  chips/openroad_flow_scripts/flow/tutorials/scripts/metal_fill/5_route.odb filter=lfs diff=lfs merge=lfs -text
3078
  energy/nrel_pvdaq_parquet/MANIFEST.jsonl filter=lfs diff=lfs merge=lfs -text
3079
+ chips/yosys/docs/source/_downloads/APPNOTE_010_Verilog_to_BLIF.pdf filter=lfs diff=lfs merge=lfs -text
3080
+ chips/yosys/docs/source/_downloads/APPNOTE_012_Verilog_to_BTOR.pdf filter=lfs diff=lfs merge=lfs -text
chips/yosys/.clang-format ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Default Linux style
2
+ BasedOnStyle: LLVM
3
+ IndentWidth: 8
4
+ UseTab: Always
5
+ BreakBeforeBraces: Linux
6
+ AllowShortIfStatementsOnASingleLine: false
7
+ IndentCaseLabels: false
8
+
9
+ # From guidelines/CodingStyle
10
+ TabWidth: 8
11
+ ContinuationIndentWidth: 2
12
+ ColumnLimit: 150
13
+ # BreakBeforeBraces: Linux
chips/yosys/.editorconfig ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = tab
5
+ indent_size = tab
6
+ trim_trailing_whitespace = true
7
+ insert_final_newline = true
8
+
9
+ [abc/**]
10
+ indent_style = space
11
+ indent_size = 2
12
+ trim_trailing_whitespace = false
13
+
14
+ [*.rst]
15
+ indent_style = space
16
+ indent_size = 3
17
+
18
+ [*.yml]
19
+ indent_style = space
20
+ indent_size = 2
chips/yosys/.gitattributes ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *.v linguist-language=Verilog
2
+ /.gitcommit export-subst
chips/yosys/.gitcommit ADDED
@@ -0,0 +1 @@
 
 
1
+ $Format:%H$
chips/yosys/.github/ISSUE_TEMPLATE/bug_report.yml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Bug Report
2
+ description: Report an issue or regression with Yosys
3
+ labels: ["pending-verification"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: >
8
+
9
+ Learn more in our [Reporting bugs](https://yosyshq.readthedocs.io/projects/yosys/en/latest/yosys_internals/extending_yosys/contributing.html#reporting-bugs) docs section. We fix well-reported bugs the fastest.
10
+
11
+ If you have a general question, please ask it on the [Discourse forum](https://yosyshq.discourse.group/).
12
+
13
+
14
+ If you have a feature request, please fill out the appropriate issue form, this form is for bugs and/or regressions.
15
+
16
+
17
+ Please contact [YosysHQ GmbH](https://www.yosyshq.com/) if you need
18
+ commercial support or work done for Yosys.
19
+
20
+ - type: input
21
+ id: yosys_version
22
+ attributes:
23
+ label: Version
24
+ description: "The version of yosys this bug was encountered on."
25
+ placeholder: "The output of `yosys --version`"
26
+ validations:
27
+ required: true
28
+
29
+ - type: dropdown
30
+ id: os
31
+ attributes:
32
+ label: On which OS did this happen?
33
+ options:
34
+ - Linux
35
+ - macOS
36
+ - Windows
37
+ - BSD
38
+ - WebAssembly
39
+ multiple: true
40
+ validations:
41
+ required: true
42
+
43
+ - type: markdown
44
+ attributes:
45
+ value: >
46
+ When providing steps to reproduce the issue, please ensure that the issue
47
+ is reproducible in the current git main of Yosys. Also ensure to
48
+ provide all necessary source files needed.
49
+
50
+
51
+ Please see [https://stackoverflow.com/help/mcve](https://stackoverflow.com/help/mcve)
52
+ for information on how to create a Minimal, Complete, and Verifiable Example
53
+ (MCVE).
54
+
55
+ - type: textarea
56
+ id: reproduction_steps
57
+ attributes:
58
+ label: Reproduction Steps
59
+ description: "Please provide clear and concise steps to reproduce the issue."
60
+ validations:
61
+ required: true
62
+
63
+ - type: textarea
64
+ id: expected_behavior
65
+ attributes:
66
+ label: Expected Behavior
67
+ description: "Please describe the behavior you would have expected from the tool."
68
+ validations:
69
+ required: true
70
+
71
+ - type: textarea
72
+ id: actual_behavior
73
+ attributes:
74
+ label: Actual Behavior
75
+ description: "Please describe how the behavior you see differs from the expected behavior."
76
+ validations:
77
+ required: true
chips/yosys/.github/ISSUE_TEMPLATE/config.yml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ contact_links:
2
+ - name: Discourse
3
+ url: https://yosyshq.discourse.group
4
+ about: "Have a question? Ask it on our Discourse group!"
5
+ - name: IRC Channel
6
+ url: https://web.libera.chat/#yosys
7
+ about: "#yosys on irc.libera.chat"
chips/yosys/.github/ISSUE_TEMPLATE/docs_report.yml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Documentation Report
2
+ description: Report a problem with the Yosys documentation
3
+ labels: ["pending-verification"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: >
8
+
9
+ If you have a general question, please ask it on the [Discourse forum](https://yosyshq.discourse.group/).
10
+
11
+
12
+ If you have found a bug in Yosys, or in building the documentation,
13
+ please fill out the Bug Report issue form, this form is for problems
14
+ with the live documentation on [Read the
15
+ Docs](https://yosyshq.readthedocs.io/projects/yosys/). Please only
16
+ report problems that appear on the latest version of the documentation.
17
+
18
+
19
+ Please contact [YosysHQ GmbH](https://www.yosyshq.com/) if you need
20
+ commercial support for Yosys.
21
+
22
+ - type: input
23
+ id: docs_url
24
+ attributes:
25
+ label: Link to page
26
+ description: "Please provide a link to the page where the problem was found."
27
+ placeholder: "e.g. https://yosyshq.readthedocs.io/projects/yosys/"
28
+ validations:
29
+ required: true
30
+
31
+ - type: input
32
+ id: build_number
33
+ attributes:
34
+ label: Build number
35
+ description: "If possible, please provide the latest build number from https://readthedocs.org/projects/yosys/builds/."
36
+ placeholder: "e.g. Build #24078236"
37
+ validations:
38
+ required: false
39
+
40
+ - type: textarea
41
+ id: problem
42
+ attributes:
43
+ label: Issue
44
+ description: "Please describe what is incorrect, invalid, or missing."
45
+ validations:
46
+ required: true
47
+
48
+ - type: textarea
49
+ id: expected
50
+ attributes:
51
+ label: Expected
52
+ description: "If applicable, please describe what should appear instead."
53
+ validations:
54
+ required: false
chips/yosys/.github/ISSUE_TEMPLATE/feature_request.yml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Feature Request
2
+ description: "Submit a feature request for Yosys"
3
+ labels: ["feature-request"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: >
8
+
9
+ If you have a general question, please ask it on the [Discourse forum](https://yosyshq.discourse.group/).
10
+
11
+
12
+ If you have a bug report, please fill out the appropriate issue form, this form is for feature requests.
13
+
14
+
15
+ Please contact [YosysHQ GmbH](https://www.yosyshq.com/) if you need
16
+ commercial support or work done for Yosys.
17
+
18
+ - type: textarea
19
+ id: feature_description
20
+ attributes:
21
+ label: Feature Description
22
+ description: "A clear and detailed description of the feature."
23
+ validations:
24
+ required: true
chips/yosys/.github/PULL_REQUEST_TEMPLATE.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ _If your work is part of a larger effort, please discuss your general plans on [Discourse](https://yosyshq.discourse.group/) first to align your vision with maintainers._
2
+
3
+ _What are the reasons/motivation for this change?_
4
+
5
+ _Explain how this is achieved._
6
+
7
+ _Make sure your change comes with tests. If not possible, share how a reviewer might evaluate it._
8
+
9
+ _These template prompts can be deleted when you're done responding to them._
chips/yosys/.github/actions/setup-build-env/action.yml ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build environment setup
2
+ description: Configure build env for Yosys builds
3
+
4
+ inputs:
5
+ runs-on:
6
+ required: true
7
+ type: string
8
+ get-build-deps:
9
+ description: 'Install Yosys build dependencies'
10
+ default: false
11
+ required: false
12
+ type: boolean
13
+ get-docs-deps:
14
+ description: 'Install Yosys docs dependencies'
15
+ default: false
16
+ required: false
17
+ type: boolean
18
+ get-test-deps:
19
+ description: 'Install Yosys test dependencies'
20
+ default: false
21
+ required: false
22
+ type: boolean
23
+ get-iverilog:
24
+ description: 'Install iverilog'
25
+ default: false
26
+ required: false
27
+ type: boolean
28
+
29
+ runs:
30
+ using: composite
31
+ steps:
32
+ # if updating common/build/docs dependencies, make sure to update README.md
33
+ # and docs/source/getting_started/installation.rst to match.
34
+ - name: Linux common dependencies
35
+ if: runner.os == 'Linux'
36
+ uses: awalsh128/cache-apt-pkgs-action@v1.6.1
37
+ with:
38
+ packages: gawk git make python3
39
+ version: ${{ inputs.runs-on }}-commonys
40
+
41
+ - name: Linux build dependencies
42
+ if: runner.os == 'Linux' && inputs.get-build-deps == 'true'
43
+ uses: awalsh128/cache-apt-pkgs-action@v1.6.1
44
+ with:
45
+ packages: bison clang flex libffi-dev libfl-dev libreadline-dev pkg-config tcl-dev zlib1g-dev libgtest-dev libgmock-dev
46
+ version: ${{ inputs.runs-on }}-buildys
47
+
48
+ - name: Linux docs dependencies
49
+ if: runner.os == 'Linux' && inputs.get-docs-deps == 'true'
50
+ uses: awalsh128/cache-apt-pkgs-action@v1.6.1
51
+ with:
52
+ packages: graphviz xdot
53
+ version: ${{ inputs.runs-on }}-docsys
54
+
55
+ - name: Install macOS Dependencies
56
+ if: runner.os == 'macOS'
57
+ shell: bash
58
+ run: |
59
+ brew install bison gawk libffi git pkg-config python3 bash googletest tcl-tk llvm
60
+
61
+ - name: Install Homebrew flex 2.6.4_2
62
+ if: runner.os == 'macOS'
63
+ env:
64
+ HOMEBREW_DEVELOPER: 1
65
+ shell: bash
66
+ run: |
67
+ set -euo pipefail
68
+
69
+ case "$(uname -m):$(sw_vers -productVersion | cut -d. -f1)" in
70
+ arm64:26)
71
+ tag=arm64_tahoe
72
+ sha=62ca8b8763bc2c97fe3ec02a4f55e410a6bf80ab26c291b0914313a82d004afe
73
+ ;;
74
+ arm64:27)
75
+ tag=arm64_golden_gate
76
+ sha=c13235c5d79d815518424d61ded84ede60fcd46e8644493fa3cea9d546665220
77
+ ;;
78
+ *)
79
+ echo '::error::No flex 2.6.4_2 bottle configured for this runner'
80
+ exit 1
81
+ ;;
82
+ esac
83
+
84
+ bottle="$RUNNER_TEMP/flex--2.6.4_2.$tag.bottle.tar.gz"
85
+ token=$(curl -fsSL --retry 3 \
86
+ 'https://ghcr.io/token?service=ghcr.io&scope=repository:homebrew/core/flex:pull' \
87
+ | jq -er '.token')
88
+
89
+ curl -fsSL --retry 3 -H "Authorization: Bearer $token" \
90
+ "https://ghcr.io/v2/homebrew/core/flex/blobs/sha256:$sha" -o "$bottle"
91
+ printf '%s %s\n' "$sha" "$bottle" | shasum -a 256 -c -
92
+
93
+ brew reinstall -f "$bottle"
94
+
95
+ flex_bin="$(brew --prefix flex)/bin"
96
+ "$flex_bin/flex" --version
97
+ printf '%s\n' "$flex_bin" >> "$GITHUB_PATH"
98
+
99
+ - name: Linux runtime environment
100
+ if: runner.os == 'Linux'
101
+ shell: bash
102
+ run: |
103
+ echo "${{ github.workspace }}/.local/bin" >> $GITHUB_PATH
104
+ echo "procs=$(nproc)" >> $GITHUB_ENV
105
+
106
+ - name: macOS runtime environment
107
+ if: runner.os == 'macOS'
108
+ shell: bash
109
+ run: |
110
+ echo "${{ github.workspace }}/.local/bin" >> $GITHUB_PATH
111
+ echo "$(brew --prefix llvm)/bin" >> $GITHUB_PATH
112
+ echo "$(brew --prefix bison)/bin" >> $GITHUB_PATH
113
+ # echo "$(brew --prefix flex)/bin" >> $GITHUB_PATH
114
+ echo "procs=$(sysctl -n hw.ncpu)" >> $GITHUB_ENV
115
+
116
+ - name: Setup iverilog
117
+ if: inputs.get-iverilog == 'true'
118
+ uses: ./.github/actions/setup-iverilog
119
+ with:
120
+ runs-on: ${{ inputs.runs-on }}
chips/yosys/.github/actions/setup-iverilog/action.yml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: iverilog setup
2
+ description: Cached build and install of iverilog
3
+
4
+ inputs:
5
+ runs-on:
6
+ required: true
7
+ type: string
8
+
9
+ runs:
10
+ using: composite
11
+ steps:
12
+ - name: iverilog Linux deps
13
+ if: steps.restore-iverilog.outputs.cache-hit != 'true' && runner.os == 'Linux'
14
+ uses: awalsh128/cache-apt-pkgs-action@v1.6.1
15
+ with:
16
+ packages: autoconf gperf make gcc g++ bison flex libbz2-dev
17
+ version: ${{ inputs.runs-on }}-iverilog
18
+
19
+ - name: iverilog macOS deps
20
+ if: steps.restore-iverilog.outputs.cache-hit != 'true' && runner.os == 'macOS'
21
+ shell: bash
22
+ run: |
23
+ brew install autoconf
24
+
25
+ - name: Get iverilog
26
+ id: get-iverilog
27
+ shell: bash
28
+ run: |
29
+ git clone https://github.com/steveicarus/iverilog.git
30
+ cd iverilog
31
+ echo "IVERILOG_GIT=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
32
+
33
+ - name: Get vcd2fst
34
+ shell: bash
35
+ run: |
36
+ git clone https://github.com/mmicko/libwave.git
37
+ mkdir -p ${{ github.workspace }}/.local/
38
+ cd libwave
39
+ cmake . -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/.local
40
+ make -j$procs
41
+ make install
42
+
43
+ - uses: actions/cache/restore@v6
44
+ id: restore-iverilog
45
+ with:
46
+ path: .local/
47
+ key: ${{ inputs.runs-on }}-${{ steps.get-iverilog.outputs.IVERILOG_GIT }}
48
+
49
+ - name: Build iverilog
50
+ if: steps.restore-iverilog.outputs.cache-hit != 'true'
51
+ shell: bash
52
+ run: |
53
+ mkdir -p ${{ github.workspace }}/.local/
54
+ cd iverilog
55
+ autoconf
56
+ CC=gcc CXX=g++ ./configure --prefix=${{ github.workspace }}/.local
57
+ make -j$procs
58
+ make install
59
+
60
+ - name: Check iverilog
61
+ shell: bash
62
+ run: |
63
+ iverilog -V
64
+
65
+ - uses: actions/cache/save@v6
66
+ id: save-iverilog
67
+ if: steps.restore-iverilog.outputs.cache-hit != 'true'
68
+ with:
69
+ path: .local/
70
+ key: ${{ steps.restore-iverilog.outputs.cache-primary-key }}
chips/yosys/.github/workflows/codeql.yml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "CodeQL"
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ schedule:
6
+ - cron: '0 3 * * 6'
7
+
8
+ jobs:
9
+ analyze:
10
+ name: Analyze
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout repository
14
+ uses: actions/checkout@v7
15
+ with:
16
+ submodules: true
17
+ persist-credentials: false
18
+
19
+ - name: Setup environment
20
+ uses: ./.github/actions/setup-build-env
21
+ with:
22
+ runs-on: ubuntu-latest
23
+ get-build-deps: true
24
+
25
+ - name: Initialize CodeQL
26
+ uses: github/codeql-action/init@v4
27
+ with:
28
+ languages: cpp
29
+ queries: security-extended,security-and-quality
30
+
31
+ - name: Build
32
+ run: |
33
+ rm -rf build Configuration.cmake
34
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
35
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
36
+
37
+ cmake -C Configuration.cmake -B build . -DYOSYS_WITHOUT_ABC=ON -DYOSYS_WITHOUT_SLANG=ON
38
+ cmake --build build -j6
39
+
40
+ - name: Perform CodeQL Analysis
41
+ uses: github/codeql-action/analyze@v4
chips/yosys/.github/workflows/extra-builds.yml ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Test extra build flows
2
+
3
+ on:
4
+ pull_request:
5
+ merge_group:
6
+ push:
7
+ branches: [ main ]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ pre_job:
12
+ runs-on: ubuntu-latest
13
+ outputs:
14
+ should_skip: ${{ steps.set_output.outputs.should_skip }}
15
+ steps:
16
+ - id: skip_check
17
+ if: ${{ github.event_name != 'merge_group' }}
18
+ uses: fkirc/skip-duplicate-actions@v5.3.2
19
+ with:
20
+ # don't run on documentation changes
21
+ paths_ignore: '["**/README.md", "docs/**", "guidelines/**"]'
22
+ # cancel previous builds if a new commit is pushed
23
+ # but never cancel main
24
+ cancel_others: ${{ github.ref != 'refs/heads/main' }}
25
+
26
+ - id: set_output
27
+ run: |
28
+ if [ "${{ github.event_name }}" = "merge_group" ]; then
29
+ echo "should_skip=false" >> $GITHUB_OUTPUT
30
+ elif [ "${{ github.event_name }}" = "push" ]; then
31
+ should_skip=false
32
+ else
33
+ echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT
34
+ fi
35
+
36
+ vs-build:
37
+ name: Visual Studio build
38
+ runs-on: windows-latest
39
+ needs: [pre_job]
40
+ if: (github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
41
+ steps:
42
+ - uses: actions/checkout@v7
43
+ with:
44
+ submodules: true
45
+ persist-credentials: false
46
+
47
+ - name: Setup MSVC
48
+ uses: TheMrMilchmann/setup-msvc-dev@v4
49
+ with:
50
+ arch: x64
51
+
52
+ - name: ccache
53
+ uses: hendrikmuhs/ccache-action@v1.2.23
54
+ with:
55
+ key: vs-build
56
+ save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
57
+ restore-keys: |
58
+ vs-build-
59
+
60
+ - name: Install flex/bison
61
+ shell: pwsh
62
+ run: |
63
+ choco install winflexbison3 --no-progress
64
+
65
+ # Make tools visible to CMake
66
+ echo "C:\Program Files (x86)\GnuWin32\bin" | Out-File -Append -FilePath $env:GITHUB_PATH
67
+ echo "C:\ProgramData\chocolatey\lib\winflexbison3\tools" | Out-File -Append -FilePath $env:GITHUB_PATH
68
+
69
+ - name: Configure CMake
70
+ run: >
71
+ cmake -S . -B build
72
+ -G Ninja
73
+ -DCMAKE_BUILD_TYPE=Release
74
+ -DYOSYS_COMPILER_LAUNCHER=ccache
75
+
76
+ - name: Build
77
+ run: >
78
+ cmake --build build
79
+ --config Release
80
+ --parallel
81
+
82
+ mingw-build:
83
+ name: MINGW64 build
84
+ runs-on: windows-latest
85
+ needs: [pre_job]
86
+ if: (github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
87
+ steps:
88
+ - uses: actions/checkout@v7
89
+ with:
90
+ submodules: true
91
+ persist-credentials: false
92
+
93
+ - name: Setup MSYS2 (UCRT64)
94
+ uses: msys2/setup-msys2@v2
95
+ with:
96
+ msystem: UCRT64
97
+ update: true
98
+
99
+ install: >-
100
+ base-devel
101
+ bison
102
+ flex
103
+ gawk
104
+ diffutils
105
+ make
106
+ mingw-w64-ucrt-x86_64-toolchain
107
+ mingw-w64-ucrt-x86_64-cmake
108
+ mingw-w64-ucrt-x86_64-gtest
109
+ mingw-w64-ucrt-x86_64-pkgconf
110
+ mingw-w64-ucrt-x86_64-python
111
+ mingw-w64-ucrt-x86_64-tcl
112
+ mingw-w64-ucrt-x86_64-libffi
113
+ mingw-w64-ucrt-x86_64-git
114
+ mingw-w64-ucrt-x86_64-ccache
115
+
116
+ - name: ccache
117
+ uses: hendrikmuhs/ccache-action@v1.2.23
118
+ with:
119
+ key: mingw-build
120
+ save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
121
+ restore-keys: |
122
+ mingw-build-
123
+
124
+ - name: Build Yosys
125
+ shell: msys2 {0}
126
+ run: |
127
+ set -e
128
+ procs=$(nproc)
129
+ rm -rf build
130
+ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DYOSYS_COMPILER_LAUNCHER=ccache
131
+ cmake --build build -j${procs}
132
+ ctest --test-dir build/tests/unit --output-on-failure
133
+
134
+ wasi-build:
135
+ name: WASI build
136
+ needs: pre_job
137
+ if: (github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
138
+ runs-on: ubuntu-latest
139
+ steps:
140
+ - uses: actions/checkout@v7
141
+ with:
142
+ submodules: true
143
+ persist-credentials: false
144
+
145
+ - name: ccache
146
+ uses: hendrikmuhs/ccache-action@v1.2.23
147
+ with:
148
+ key: wasi-build
149
+ save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
150
+ restore-keys: |
151
+ wasi-build-
152
+
153
+ - name: Build
154
+ run: |
155
+ WASI_VER=33
156
+ WASI_SDK=wasi-sdk-${WASI_VER}.0-x86_64-linux
157
+ WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VER}/${WASI_SDK}.tar.gz
158
+ if ! [ -d ${WASI_SDK} ]; then curl -L ${WASI_SDK_URL} | tar xzf -; fi
159
+ WASI_SDK_PATH=$(pwd)/${WASI_SDK}
160
+ FLEX_VER=2.6.4
161
+ FLEX=flex-${FLEX_VER}
162
+ FLEX_URL=https://github.com/westes/flex/releases/download/v${FLEX_VER}/${FLEX}.tar.gz
163
+ if ! [ -d ${FLEX} ]; then curl -L ${FLEX_URL} | tar xzf -; fi
164
+
165
+ mkdir -p flex-build
166
+ (cd flex-build &&
167
+ ../${FLEX}/configure --prefix=$(pwd)/../flex-prefix &&
168
+ make &&
169
+ make install)
170
+
171
+ export PATH=${WASI_SDK_PATH}/bin:$(pwd)/flex-prefix/bin:${PATH}
172
+ cmake -B build -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-p1.cmake -DCMAKE_BUILD_TYPE=Release -DYOSYS_COMPILER_LAUNCHER=ccache .
173
+ cmake --build build -j$(nproc)
174
+
175
+ extra-builds-result:
176
+ runs-on: ubuntu-latest
177
+ needs:
178
+ - vs-build
179
+ - mingw-build
180
+ - wasi-build
181
+ if: always()
182
+ steps:
183
+ - name: Check results
184
+ run: |
185
+ echo "Needs results: ${{ join(needs.*.result, ',') }}"
186
+ if [[ "${{ join(needs.*.result, ',') }}" == *failure* ]] || \
187
+ [[ "${{ join(needs.*.result, ',') }}" == *cancelled* ]]; then
188
+ echo "Some jobs failed or were cancelled"
189
+ exit 1
190
+ fi
191
+ - run: echo "All good"
chips/yosys/.github/workflows/nix.yml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Test nix build
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ schedule:
6
+ - cron: '0 5 * * 6'
7
+
8
+ jobs:
9
+ nix-build:
10
+ name: "Build nix flake"
11
+ runs-on: ${{ matrix.os }}
12
+ strategy:
13
+ matrix:
14
+ os: [ubuntu-latest, macos-latest]
15
+ fail-fast: false
16
+ steps:
17
+ - uses: actions/checkout@v7
18
+ with:
19
+ submodules: true
20
+ persist-credentials: false
21
+ - uses: cachix/install-nix-action@v31
22
+ with:
23
+ install_url: https://releases.nixos.org/nix/nix-2.30.0/install
24
+ - run: nix build -L
chips/yosys/.github/workflows/prepare-docs.yml ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build docs artifact with Verific
2
+
3
+ on:
4
+ pull_request:
5
+ merge_group:
6
+ push:
7
+ branches: [ main, "docs-preview/**", "docs-preview*" ]
8
+ tags: [ "*" ]
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ check_docs_rebuild:
13
+ runs-on: ubuntu-latest
14
+ outputs:
15
+ should_skip: ${{ steps.set_output.outputs.should_skip }}
16
+ docs_export: ${{ steps.docs_var.outputs.docs_export }}
17
+ env:
18
+ docs_export: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/docs-preview') || startsWith(github.ref, 'refs/tags/') }}
19
+ steps:
20
+ - id: skip_check
21
+ uses: fkirc/skip-duplicate-actions@v5.3.2
22
+ with:
23
+ paths_ignore: '["**/README.md"]'
24
+ # don't cancel in case we're updating docs
25
+ cancel_others: 'false'
26
+ # push filtering means we only want to skip duplicates for PRs
27
+ do_not_skip: '["workflow_dispatch", "merge_group", "push"]'
28
+ concurrent_skipping: 'same_content_newer'
29
+
30
+ - id: docs_var
31
+ run: echo "docs_export=${docs_export}" >> $GITHUB_OUTPUT
32
+
33
+ - id: set_output
34
+ run: |
35
+ if [ "${{ github.event_name }}" = "merge_group" ]; then
36
+ echo "should_skip=false" >> $GITHUB_OUTPUT
37
+ else
38
+ echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT
39
+ fi
40
+
41
+ prepare-docs:
42
+ # docs builds are needed for anything on main, any tagged versions, and any tag
43
+ # or branch starting with docs-preview
44
+ needs: check_docs_rebuild
45
+ if: ${{ needs.check_docs_rebuild.outputs.should_skip != 'true' && github.repository_owner == 'YosysHQ' }}
46
+ runs-on: [self-hosted, linux, x64, fast]
47
+ steps:
48
+ - name: Checkout Yosys
49
+ uses: actions/checkout@v7
50
+ with:
51
+ persist-credentials: false
52
+ submodules: true
53
+
54
+ - name: Runtime environment
55
+ run: |
56
+ echo "procs=$(nproc)" >> $GITHUB_ENV
57
+
58
+ - name: Build Yosys
59
+ run: |
60
+ rm -rf build Configuration.cmake
61
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
62
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
63
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
64
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
65
+
66
+ cmake -C Configuration.cmake -B build .
67
+ cmake --build build -j$procs
68
+
69
+ - name: Prepare docs
70
+ shell: bash
71
+ run:
72
+ cmake --build build --target docs-prepare -j$procs
73
+
74
+ - name: Upload artifact
75
+ uses: actions/upload-artifact@v7
76
+ with:
77
+ name: cmd-ref-${{ github.sha }}
78
+ path: |
79
+ docs/source/generated
80
+ docs/source/_images
81
+ docs/source/code_examples
82
+
83
+ - name: Install doc prereqs
84
+ shell: bash
85
+ run: |
86
+ make -C docs reqs
87
+
88
+ - name: Test build docs
89
+ shell: bash
90
+ run: |
91
+ cmake --build build --target docs-html -j$procs
92
+
93
+ - name: Trigger RTDs build
94
+ if: ${{ needs.check_docs_rebuild.outputs.docs_export == 'true' && github.repository == 'YosysHQ/yosys' }}
95
+ uses: dfm/rtds-action@v1.1.0
96
+ with:
97
+ webhook_url: ${{ secrets.RTDS_WEBHOOK_URL }}
98
+ webhook_token: ${{ secrets.RTDS_WEBHOOK_TOKEN }}
99
+ commit_ref: ${{ github.ref }}
chips/yosys/.github/workflows/source-vendor.yml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Create source archive with vendored dependencies
2
+
3
+ on:
4
+ pull_request:
5
+ merge_group:
6
+ push:
7
+ branches: [ main ]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ vendor-sources:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Checkout repository with submodules
15
+ uses: actions/checkout@v7
16
+ with:
17
+ submodules: 'recursive'
18
+ persist-credentials: false
19
+
20
+ - name: Create clean tarball
21
+ run: |
22
+ git archive --format=tar HEAD -o yosys-src-vendored.tar
23
+ git submodule foreach '
24
+ git archive --format=tar --prefix="${sm_path}/" HEAD --output=${toplevel}/vendor-${name}.tar
25
+ '
26
+
27
+ # 2008 bug https://lists.gnu.org/archive/html/bug-tar/2008-08/msg00002.html
28
+ for file in vendor-*.tar; do
29
+ tar --concatenate --file=yosys-src-vendored.tar "$file"
30
+ done
31
+
32
+ gzip yosys-src-vendored.tar
33
+
34
+ - name: Store tarball artifact
35
+ uses: actions/upload-artifact@v7
36
+ with:
37
+ name: vendored-sources
38
+ path: yosys-src-vendored.tar.gz
39
+ retention-days: 1
chips/yosys/.github/workflows/test-build.yml ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build and run tests
2
+
3
+ on:
4
+ pull_request:
5
+ merge_group:
6
+ push:
7
+ branches: [ main ]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ pre_job:
12
+ runs-on: ubuntu-latest
13
+ outputs:
14
+ should_skip: ${{ steps.set_output.outputs.should_skip }}
15
+ steps:
16
+ - id: skip_check
17
+ if: ${{ github.event_name != 'merge_group' }}
18
+ uses: fkirc/skip-duplicate-actions@v5.3.2
19
+ with:
20
+ # don't run on documentation changes
21
+ paths_ignore: '["**/README.md", "docs/**", "guidelines/**"]'
22
+ # cancel previous builds if a new commit is pushed
23
+ # but never cancel main
24
+ cancel_others: ${{ github.ref != 'refs/heads/main' }}
25
+
26
+ - id: set_output
27
+ run: |
28
+ if [ "${{ github.event_name }}" = "merge_group" ]; then
29
+ echo "should_skip=true" >> $GITHUB_OUTPUT
30
+ else
31
+ echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT
32
+ fi
33
+
34
+ pre_docs_job:
35
+ runs-on: ubuntu-latest
36
+ outputs:
37
+ should_skip: ${{ steps.set_output.outputs.should_skip }}
38
+ steps:
39
+ - id: skip_check
40
+ if: ${{ github.event_name != 'merge_group' }}
41
+ uses: fkirc/skip-duplicate-actions@v5.3.2
42
+ with:
43
+ # don't run on readme changes
44
+ paths_ignore: '["**/README.md"]'
45
+ # cancel previous builds if a new commit is pushed
46
+ # but never cancel main
47
+ cancel_others: ${{ github.ref != 'refs/heads/main' }}
48
+
49
+ - id: set_output
50
+ run: |
51
+ if [ "${{ github.event_name }}" = "merge_group" ]; then
52
+ echo "should_skip=true" >> $GITHUB_OUTPUT
53
+ elif [ "${{ github.event_name }}" = "push" ]; then
54
+ should_skip=false
55
+ else
56
+ echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT
57
+ fi
58
+
59
+ build-yosys:
60
+ name: Reusable build
61
+ runs-on: ${{ matrix.os }}
62
+ # pre_job is a subset of pre_docs_job, so we can always build for pre_docs_job
63
+ needs: pre_docs_job
64
+ if: needs.pre_docs_job.outputs.should_skip != 'true'
65
+ env:
66
+ CC: clang
67
+ strategy:
68
+ matrix:
69
+ os: [ubuntu-latest, macos-latest]
70
+ fail-fast: false
71
+ steps:
72
+ - name: Checkout Yosys
73
+ uses: actions/checkout@v7
74
+ with:
75
+ submodules: true
76
+ persist-credentials: false
77
+
78
+ - name: Setup environment
79
+ uses: ./.github/actions/setup-build-env
80
+ with:
81
+ runs-on: ${{ matrix.os }}
82
+ get-build-deps: true
83
+
84
+ - name: ccache
85
+ uses: hendrikmuhs/ccache-action@v1.2.23
86
+ with:
87
+ key: test-build-${{ matrix.os }}
88
+ save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
89
+ restore-keys: |
90
+ test-build-${{ matrix.os }}-
91
+
92
+ - name: Build
93
+ shell: bash
94
+ run: |
95
+ rm -rf build
96
+ cmake -B build . -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DYOSYS_COMPILER_LAUNCHER=ccache -DYOSYS_USE_BUNDLED_LIBS=ON -DYOSYS_ENABLE_HOMEBREW=OFF
97
+ cmake --build build -j$procs
98
+ ctest --test-dir build/tests/unit
99
+
100
+ - name: Log yosys-config output
101
+ run: |
102
+ ./build/yosys-config || true
103
+
104
+ - name: Compress build
105
+ shell: bash
106
+ run: |
107
+ cd build
108
+ tar -cvf ../build.tar share/ yosys yosys-*
109
+
110
+ - name: Store build artifact
111
+ uses: actions/upload-artifact@v7
112
+ with:
113
+ name: build-${{ matrix.os }}
114
+ path: build.tar
115
+ retention-days: 1
116
+
117
+ test-yosys:
118
+ name: Run tests
119
+ runs-on: ${{ matrix.os }}
120
+ needs: [build-yosys, pre_job]
121
+ if: github.event_name != 'push' && needs.pre_job.outputs.should_skip != 'true'
122
+ env:
123
+ CC: clang
124
+ strategy:
125
+ matrix:
126
+ os: [ubuntu-latest, macos-latest]
127
+ fail-fast: false
128
+ steps:
129
+ - name: Checkout Yosys
130
+ uses: actions/checkout@v7
131
+ with:
132
+ persist-credentials: false
133
+
134
+ - name: Setup environment
135
+ uses: ./.github/actions/setup-build-env
136
+ with:
137
+ runs-on: ${{ matrix.os }}
138
+ get-test-deps: true
139
+ get-iverilog: true
140
+
141
+ - name: Download build artifact
142
+ uses: actions/download-artifact@v8
143
+ with:
144
+ name: build-${{ matrix.os }}
145
+
146
+ - name: Uncompress build
147
+ shell: bash
148
+ run: |
149
+ mkdir -p build
150
+ tar -xvf build.tar -C build
151
+
152
+ - name: Log yosys-config output
153
+ run: |
154
+ ./build/yosys-config || true
155
+
156
+ - name: Run tests
157
+ shell: bash
158
+ run: |
159
+ make -C tests -j$procs vanilla-test
160
+
161
+ - name: Report errors
162
+ if: ${{ failure() }}
163
+ shell: bash
164
+ run: |
165
+ find tests/**/*.err -print -exec cat {} \;
166
+
167
+ test-cells:
168
+ name: Run test_cell
169
+ runs-on: ${{ matrix.os }}
170
+ needs: [build-yosys, pre_job]
171
+ if: github.event_name != 'push' && needs.pre_job.outputs.should_skip != 'true'
172
+ env:
173
+ CC: clang
174
+ strategy:
175
+ matrix:
176
+ os: [ubuntu-latest]
177
+ steps:
178
+ - name: Checkout Yosys
179
+ uses: actions/checkout@v7
180
+ with:
181
+ persist-credentials: false
182
+
183
+ - name: Setup environment
184
+ uses: ./.github/actions/setup-build-env
185
+ with:
186
+ runs-on: ${{ matrix.os }}
187
+
188
+ - name: Download build artifact
189
+ uses: actions/download-artifact@v8
190
+ with:
191
+ name: build-${{ matrix.os }}
192
+
193
+ - name: Uncompress build
194
+ shell: bash
195
+ run:
196
+ tar -xvf build.tar
197
+
198
+ - name: test_cell
199
+ shell: bash
200
+ run: |
201
+ ./yosys -p 'test_cell -n 20 -s 1 all'
202
+ ./yosys -p 'test_cell -n 20 -s 1 -nosat -aigmap $pow $pmux'
203
+ ./yosys -p 'test_cell -n 20 -s 1 -nosat -aigmap $eqx $nex $bweqx'
204
+ ./yosys -p 'test_cell -n 20 -s 1 -aigmap $buf'
205
+
206
+ test-docs:
207
+ name: Run docs tests
208
+ runs-on: ${{ matrix.os }}
209
+ needs: [build-yosys, pre_docs_job]
210
+ if: github.event_name != 'push' && needs.pre_job.outputs.should_skip != 'true'
211
+ strategy:
212
+ matrix:
213
+ os: [ubuntu-latest]
214
+ fail-fast: false
215
+ steps:
216
+ - name: Checkout Yosys
217
+ uses: actions/checkout@v7
218
+ with:
219
+ persist-credentials: false
220
+
221
+ - name: Setup environment
222
+ uses: ./.github/actions/setup-build-env
223
+ with:
224
+ runs-on: ${{ matrix.os }}
225
+ get-build-deps: true
226
+ get-docs-deps: true
227
+
228
+ - name: Download build artifact
229
+ uses: actions/download-artifact@v8
230
+ with:
231
+ name: build-${{ matrix.os }}
232
+
233
+ - name: Uncompress build
234
+ shell: bash
235
+ run: |
236
+ mkdir -p build
237
+ tar -xvf build.tar -C build
238
+
239
+ - name: Log yosys-config output
240
+ run: |
241
+ ./build/yosys-config || true
242
+
243
+ - name: Run tests
244
+ shell: bash
245
+ run: |
246
+ make -C docs test -j$procs
247
+
248
+ test-docs-build:
249
+ name: Try build docs
250
+ runs-on: [self-hosted, linux, x64, fast]
251
+ needs: [pre_docs_job]
252
+ if: ${{ github.event_name != 'push' && needs.pre_docs_job.outputs.should_skip != 'true' && github.repository_owner == 'YosysHQ' }}
253
+ strategy:
254
+ matrix:
255
+ docs-target: [html, latexpdf]
256
+ fail-fast: false
257
+ steps:
258
+ - name: Checkout Yosys
259
+ uses: actions/checkout@v7
260
+ with:
261
+ submodules: true
262
+ persist-credentials: false
263
+
264
+ - name: Runtime environment
265
+ run: |
266
+ echo "procs=$(nproc)" >> $GITHUB_ENV
267
+
268
+ - name: Build Yosys
269
+ run: |
270
+ rm -rf build Configuration.cmake
271
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
272
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
273
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
274
+
275
+ cmake -C Configuration.cmake -B build .
276
+ cmake --build build -j$procs
277
+
278
+ - name: Install doc prereqs
279
+ shell: bash
280
+ run: |
281
+ make -C docs reqs
282
+
283
+ - name: Build docs
284
+ shell: bash
285
+ run: |
286
+ cmake --build build --target docs-${{ matrix.docs-target }} -j$procs
287
+
288
+ - name: Store docs build artifact
289
+ uses: actions/upload-artifact@v7
290
+ with:
291
+ name: docs-build-${{ matrix.docs-target }}
292
+ path: docs/build/
293
+ retention-days: 7
294
+
295
+ test-build-result:
296
+ runs-on: ubuntu-latest
297
+ needs:
298
+ - test-yosys
299
+ - test-cells
300
+ - test-docs
301
+ - test-docs-build
302
+ if: always()
303
+ steps:
304
+ - name: Check results
305
+ run: |
306
+ echo "Needs results: ${{ join(needs.*.result, ',') }}"
307
+ if [[ "${{ join(needs.*.result, ',') }}" == *failure* ]] || \
308
+ [[ "${{ join(needs.*.result, ',') }}" == *cancelled* ]]; then
309
+ echo "Some jobs failed or were cancelled"
310
+ exit 1
311
+ fi
312
+ - run: echo "All good"
chips/yosys/.github/workflows/test-compile.yml ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Compiler testing
2
+
3
+ on:
4
+ pull_request:
5
+ merge_group:
6
+ push:
7
+ branches: [ main ]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ pre_job:
12
+ runs-on: ubuntu-latest
13
+ outputs:
14
+ should_skip: ${{ steps.set_output.outputs.should_skip }}
15
+ steps:
16
+ - id: skip_check
17
+ if: ${{ github.event_name != 'merge_group' }}
18
+ uses: fkirc/skip-duplicate-actions@v5.3.2
19
+ with:
20
+ # don't run on documentation changes
21
+ paths_ignore: '["**/README.md", "docs/**", "guidelines/**"]'
22
+ # cancel previous builds if a new commit is pushed
23
+ # but never cancel main
24
+ cancel_others: ${{ github.ref != 'refs/heads/main' }}
25
+
26
+ - id: set_output
27
+ run: |
28
+ if [ "${{ github.event_name }}" = "merge_group" ]; then
29
+ echo "should_skip=false" >> $GITHUB_OUTPUT
30
+ elif [ "${{ github.event_name }}" = "push" ]; then
31
+ should_skip=false
32
+ else
33
+ echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT
34
+ fi
35
+
36
+ test-compile:
37
+ runs-on: ${{ matrix.os }}
38
+ needs: pre_job
39
+ if: (github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
40
+ env:
41
+ CXXFLAGS: ${{ startsWith(matrix.compiler, 'gcc') && '-Wp,-D_GLIBCXX_ASSERTIONS' || ''}}
42
+ strategy:
43
+ matrix:
44
+ os:
45
+ - ubuntu-latest
46
+ compiler:
47
+ # oldest supported
48
+ - 'clang-16'
49
+ - 'gcc-11'
50
+ # newest, make sure to update maximum standard step to match
51
+ - 'clang-22'
52
+ - 'gcc-16'
53
+ include:
54
+ # macOS arm
55
+ - os: macos-latest
56
+ compiler: 'clang-22'
57
+ fail-fast: false
58
+ steps:
59
+ - name: Checkout Yosys
60
+ uses: actions/checkout@v7
61
+ with:
62
+ submodules: true
63
+ persist-credentials: false
64
+
65
+ - name: Setup environment
66
+ uses: ./.github/actions/setup-build-env
67
+ with:
68
+ runs-on: ${{ matrix.os }}
69
+ get-build-deps: true
70
+
71
+ - name: ccache
72
+ uses: hendrikmuhs/ccache-action@v1.2.23
73
+ with:
74
+ key: test-compile-${{ matrix.os }}-${{ matrix.compiler }}
75
+ save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
76
+ restore-keys: |
77
+ test-compile-${{ matrix.os }}-${{ matrix.compiler }}-
78
+
79
+ - name: Setup Cpp
80
+ uses: aminya/setup-cpp@v1
81
+ with:
82
+ compiler: ${{ matrix.compiler }}
83
+ gcc: ${{ (runner.os == 'Linux' && matrix.compiler == 'clang-16') && '13' || '' }}
84
+
85
+ - name: Select compatible libstdc++ for Clang 16
86
+ if: runner.os == 'Linux' && matrix.compiler == 'clang-16'
87
+ shell: bash
88
+ run: |
89
+ # Clang 16 cannot compile the ranges headers from libstdc++ 15.
90
+ gcc_install_dir="$(dirname "$(gcc-13 -print-libgcc-file-name)")"
91
+ echo "CXXFLAGS=${CXXFLAGS} --gcc-install-dir=${gcc_install_dir}" >> "$GITHUB_ENV"
92
+
93
+ - name: Tool versions
94
+ shell: bash
95
+ run: |
96
+ $CC --version
97
+ $CXX --version
98
+
99
+ # minimum standard
100
+ - name: Build C++20
101
+ shell: bash
102
+ run: |
103
+ rm -rf build
104
+ cmake -B build -DCMAKE_CXX_STANDARD=20 -DYOSYS_COMPILER_LAUNCHER=ccache . --fresh
105
+ cmake --build build --target yosys -j$procs
106
+
107
+ # maximum standard, only on newest compilers
108
+ - name: Build C++26
109
+ if: ${{ matrix.compiler == 'clang-22' || matrix.compiler == 'gcc-16' }}
110
+ shell: bash
111
+ run: |
112
+ rm -rf build
113
+ cmake -B build -DCMAKE_CXX_STANDARD=26 -DYOSYS_COMPILER_LAUNCHER=ccache . --fresh
114
+ cmake --build build --target yosys -j$procs
115
+
116
+ test-compile-result:
117
+ runs-on: ubuntu-latest
118
+ needs:
119
+ - test-compile
120
+ if: always()
121
+ steps:
122
+ - name: Check results
123
+ run: |
124
+ echo "Needs results: ${{ join(needs.*.result, ',') }}"
125
+ if [[ "${{ join(needs.*.result, ',') }}" == *failure* ]] || \
126
+ [[ "${{ join(needs.*.result, ',') }}" == *cancelled* ]]; then
127
+ echo "Some jobs failed or were cancelled"
128
+ exit 1
129
+ fi
130
+ - run: echo "All good"
chips/yosys/.github/workflows/test-sanitizers.yml ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Check clang sanitizers
2
+
3
+ on:
4
+ pull_request:
5
+ merge_group:
6
+ #push:
7
+ # branches: [ main ]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ pre_job:
12
+ runs-on: ubuntu-latest
13
+ outputs:
14
+ should_skip: ${{ steps.set_output.outputs.should_skip }}
15
+ steps:
16
+ - id: skip_check
17
+ if: ${{ github.event_name != 'merge_group' }}
18
+ uses: fkirc/skip-duplicate-actions@v5.3.2
19
+ with:
20
+ # don't run on documentation changes
21
+ paths_ignore: '["**/README.md", "docs/**", "guidelines/**"]'
22
+ # cancel previous builds if a new commit is pushed
23
+ # but never cancel main
24
+ cancel_others: ${{ github.ref != 'refs/heads/main' }}
25
+
26
+ - id: set_output
27
+ run: |
28
+ if [ "${{ github.event_name }}" = "merge_group" ]; then
29
+ echo "should_skip=false" >> $GITHUB_OUTPUT
30
+ elif [ "${{ github.event_name }}" = "push" ]; then
31
+ should_skip=false
32
+ else
33
+ echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT
34
+ fi
35
+
36
+ test-sanitizers:
37
+ runs-on: [self-hosted, linux, x64, fast]
38
+ needs: pre_job
39
+ if: (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true'
40
+ env:
41
+ CC: clang
42
+ ASAN_OPTIONS: halt_on_error=1 detect_container_overflow=0
43
+ UBSAN_OPTIONS: halt_on_error=1
44
+ steps:
45
+ - name: Checkout Yosys
46
+ uses: actions/checkout@v7
47
+ with:
48
+ submodules: true
49
+ persist-credentials: false
50
+
51
+ - name: Runtime environment
52
+ run: |
53
+ echo "procs=$(nproc)" >> $GITHUB_ENV
54
+
55
+ - name: Build
56
+ shell: bash
57
+ run: |
58
+ rm -rf build
59
+ cmake -B build . \
60
+ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
61
+ -DCMAKE_BUILD_TYPE=Sanitize -DSANITIZE='undefined,address' \
62
+ -DYOSYS_COMPILER_LAUNCHER=ccache
63
+ cmake --build build -j$procs
64
+
65
+ - name: Log yosys-config output
66
+ run: |
67
+ ./build/yosys-config || true
68
+
69
+ - name: Run tests
70
+ shell: bash
71
+ run: |
72
+ make -C tests -j$procs vanilla-test
73
+
74
+ - name: Report errors
75
+ if: ${{ failure() }}
76
+ shell: bash
77
+ run: |
78
+ find tests/**/*.err -print -exec cat {} \;
79
+
80
+ test-sanitizers-result:
81
+ runs-on: ubuntu-latest
82
+ needs:
83
+ - test-sanitizers
84
+ if: always()
85
+ steps:
86
+ - name: Check results
87
+ run: |
88
+ echo "Needs results: ${{ join(needs.*.result, ',') }}"
89
+ if [[ "${{ join(needs.*.result, ',') }}" == *failure* ]] || \
90
+ [[ "${{ join(needs.*.result, ',') }}" == *cancelled* ]]; then
91
+ echo "Some jobs failed or were cancelled"
92
+ exit 1
93
+ fi
94
+ - run: echo "All good"
chips/yosys/.github/workflows/test-verific-cfg.yml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build various Verific configurations
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ test-verific-cfg:
8
+ if: github.repository_owner == 'YosysHQ'
9
+ runs-on: [self-hosted, linux, x64, fast]
10
+ steps:
11
+ - name: Checkout Yosys
12
+ uses: actions/checkout@v7
13
+ with:
14
+ persist-credentials: false
15
+ submodules: true
16
+ - name: Runtime environment
17
+ run: |
18
+ echo "procs=$(nproc)" >> $GITHUB_ENV
19
+
20
+ - name: verific [SV]
21
+ run: |
22
+ rm -rf build Configuration.cmake
23
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
24
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
25
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
26
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
27
+ echo 'set(YOSYS_VERIFIC_FEATURES "systemverilog" CACHE STRING "")' >> Configuration.cmake
28
+ cmake -C Configuration.cmake -B build .
29
+ cmake --build build -j$procs
30
+
31
+ - name: verific [VHDL]
32
+ run: |
33
+ rm -rf build Configuration.cmake
34
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
35
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
36
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
37
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
38
+ echo 'set(YOSYS_VERIFIC_FEATURES "vhdl" CACHE STRING "")' >> Configuration.cmake
39
+ cmake -C Configuration.cmake -B build .
40
+ cmake --build build -j$procs
41
+
42
+ - name: verific [SV + VHDL]
43
+ run: |
44
+ rm -rf build Configuration.cmake
45
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
46
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
47
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
48
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
49
+ echo 'set(YOSYS_VERIFIC_FEATURES "vhdl;systemverilog" CACHE STRING "")' >> Configuration.cmake
50
+ cmake -C Configuration.cmake -B build .
51
+ cmake --build build -j$procs
52
+
53
+ - name: verific [SV + HIER]
54
+ run: |
55
+ rm -rf build Configuration.cmake
56
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
57
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
58
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
59
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
60
+ echo 'set(YOSYS_VERIFIC_FEATURES "systemverilog;hier_tree" CACHE STRING "")' >> Configuration.cmake
61
+ cmake -C Configuration.cmake -B build .
62
+ cmake --build build -j$procs
63
+
64
+ - name: verific [VHDL + HIER]
65
+ run: |
66
+ rm -rf build Configuration.cmake
67
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
68
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
69
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
70
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
71
+ echo 'set(YOSYS_VERIFIC_FEATURES "vhdl;hier_tree" CACHE STRING "")' >> Configuration.cmake
72
+ cmake -C Configuration.cmake -B build .
73
+ cmake --build build -j$procs
74
+
75
+ - name: verific [SV + VHDL + HIER]
76
+ run: |
77
+ rm -rf build Configuration.cmake
78
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
79
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
80
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
81
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
82
+ echo 'set(YOSYS_VERIFIC_FEATURES "systemverilog;vhdl;hier_tree" CACHE STRING "")' >> Configuration.cmake
83
+ cmake -C Configuration.cmake -B build .
84
+ cmake --build build -j$procs
85
+
86
+ - name: verific [SV + VHDL + HIER + EDIF + LIBERTY]
87
+ run: |
88
+ rm -rf build Configuration.cmake
89
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
90
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
91
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
92
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
93
+ echo 'set(YOSYS_VERIFIC_FEATURES "systemverilog;vhdl;hier_tree;edif;liberty" CACHE STRING "")' >> Configuration.cmake
94
+ cmake -C Configuration.cmake -B build .
95
+ cmake --build build -j$procs
chips/yosys/.github/workflows/test-verific.yml ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build and run tests with Verific (Linux)
2
+
3
+ on:
4
+ pull_request:
5
+ merge_group:
6
+ push:
7
+ branches: [ main ]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ pre_job:
12
+ runs-on: ubuntu-latest
13
+ outputs:
14
+ should_skip: ${{ steps.set_output.outputs.should_skip }}
15
+ steps:
16
+ - id: skip_check
17
+ if: ${{ github.event_name != 'merge_group' && github.event_name != 'push' }}
18
+ uses: fkirc/skip-duplicate-actions@v5.3.2
19
+ with:
20
+ # don't run on documentation changes
21
+ paths_ignore: '["**/README.md", "docs/**", "guidelines/**"]'
22
+ # cancel previous builds if a new commit is pushed
23
+ # but never cancel main
24
+ cancel_others: ${{ github.ref != 'refs/heads/main' }}
25
+
26
+ - id: set_output
27
+ run: |
28
+ if [ "${{ github.event_name }}" = "merge_group" ] || [ "${{ github.event_name }}" = "push" ]; then
29
+ echo "should_skip=false" >> $GITHUB_OUTPUT
30
+ else
31
+ echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT
32
+ fi
33
+
34
+ test-verific:
35
+ needs: pre_job
36
+ if: ${{ needs.pre_job.outputs.should_skip != 'true' && github.repository_owner == 'YosysHQ' }}
37
+ runs-on: [self-hosted, linux, x64, fast]
38
+ steps:
39
+ - name: Checkout Yosys
40
+ uses: actions/checkout@v7
41
+ with:
42
+ persist-credentials: false
43
+ submodules: true
44
+ - name: Runtime environment
45
+ run: |
46
+ echo "procs=$(nproc)" >> $GITHUB_ENV
47
+ mkdir -p "${GITHUB_WORKSPACE}/coverage"
48
+ echo "LLVM_PROFILE_FILE=${GITHUB_WORKSPACE}/coverage/coverage_%p.profraw" >> $GITHUB_ENV
49
+ echo "LLVM_PROFILE_FILE_BUFFER_SIZE=0" >> $GITHUB_ENV
50
+ echo "SEED=0" >> $GITHUB_ENV
51
+
52
+ - name: Build Yosys
53
+ run: |
54
+ rm -rf build Configuration.cmake coverage
55
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
56
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
57
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
58
+ echo 'set(YOSYS_ENABLE_COVERAGE ON CACHE BOOL "")' >> Configuration.cmake
59
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
60
+
61
+ cmake -C Configuration.cmake -B build . -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/.local -DCMAKE_BUILD_TYPE=Debug
62
+ cmake --build build -j$procs
63
+
64
+ - name: Install Yosys
65
+ run: |
66
+ cmake --build build --target install
67
+
68
+ - name: Checkout SBY
69
+ uses: actions/checkout@v7
70
+ with:
71
+ repository: 'YosysHQ/sby'
72
+ path: 'sby'
73
+ persist-credentials: false
74
+
75
+ - name: Build SBY
76
+ run: |
77
+ make -C sby install DESTDIR=${GITHUB_WORKSPACE}/.local PREFIX=
78
+
79
+ - name: Run unit tests
80
+ run: |
81
+ ctest --test-dir build/tests/unit --output-on-failure
82
+
83
+ - name: Run Yosys tests
84
+ run: |
85
+ YOSYS_NOVERIFIC=1 make -C tests -j$procs vanilla-test
86
+
87
+ - name: Run Verific specific Yosys tests
88
+ run: |
89
+ make -C tests prep
90
+ make -C tests/sva
91
+ make -C tests/svtypes
92
+ make -C tests/check_mem
93
+
94
+ - name: Run coverage
95
+ if: ${{ github.event_name != 'merge_group'}}
96
+ run: |
97
+ make -C tests coverage
98
+
99
+ - name: Clean coverage
100
+ run: |
101
+ make -C tests clean_coverage
102
+
103
+ - name: Upload coverage reports to Codecov
104
+ if: ${{ github.event_name != 'merge_group'}}
105
+ uses: codecov/codecov-action@v7
106
+ with:
107
+ token: ${{ secrets.CODECOV_TOKEN }}
108
+ slug: YosysHQ/yosys
109
+ files: build/coverage.info
110
+ disable_search: true
111
+
112
+ - name: Skip generating files
113
+ if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }}
114
+ run: |
115
+ echo "LLVM_PROFILE_FILE=/dev/null" >> $GITHUB_ENV
116
+
117
+ - name: Run SBY tests
118
+ if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }}
119
+ run: |
120
+ make -C sby run_ci
121
+
122
+ test-pyosys:
123
+ needs: pre_job
124
+ if: ${{ needs.pre_job.outputs.should_skip != 'true' && github.repository_owner == 'YosysHQ' && github.event_name != 'push' }}
125
+ runs-on: [self-hosted, linux, x64, fast]
126
+ steps:
127
+ - name: Checkout Yosys
128
+ uses: actions/checkout@v7
129
+ with:
130
+ persist-credentials: false
131
+ submodules: true
132
+ - name: Install UV
133
+ run: |
134
+ curl -LsSf https://astral.sh/uv/install.sh | sh
135
+ - name: Runtime environment
136
+ run: |
137
+ echo "procs=$(nproc)" >> $GITHUB_ENV
138
+ echo "${{ github.workspace }}/.local/bin" >> $GITHUB_PATH
139
+
140
+ - name: Build pyosys
141
+ run: |
142
+ echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
143
+ echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
144
+ echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
145
+ echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
146
+ echo 'set(YOSYS_WITH_PYTHON ON CACHE BOOL "")' >> Configuration.cmake
147
+ echo 'set(YOSYS_INSTALL_PYTHON ON CACHE BOOL "")' >> Configuration.cmake
148
+ cmake -C Configuration.cmake -B build . \
149
+ -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/.local \
150
+ -DYOSYS_INSTALL_PYTHON_SITEDIR=$GITHUB_WORKSPACE/.local/usr/lib/python3/site-packages
151
+ cmake --build build -j$procs
152
+
153
+ - name: Install pyosys
154
+ run: |
155
+ cmake --build build --target install
156
+
157
+ - name: Run pyosys tests
158
+ run: |
159
+ export PYTHONPATH=${GITHUB_WORKSPACE}/.local/usr/lib/python3/site-packages:$PYTHONPATH
160
+ python3 tests/pyosys/run_tests.py
161
+
162
+ test-verific-result:
163
+ runs-on: ubuntu-latest
164
+ needs:
165
+ - test-verific
166
+ - test-pyosys
167
+ if: always()
168
+ steps:
169
+ - name: Check results
170
+ run: |
171
+ echo "Needs results: ${{ join(needs.*.result, ',') }}"
172
+ if [[ "${{ join(needs.*.result, ',') }}" == *failure* ]] || \
173
+ [[ "${{ join(needs.*.result, ',') }}" == *cancelled* ]]; then
174
+ echo "Some jobs failed or were cancelled"
175
+ exit 1
176
+ fi
177
+ - run: echo "All good"
chips/yosys/.github/workflows/wheels.yml ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build Wheels for PyPI
2
+
3
+ # run every Sunday at 10 AM
4
+ on:
5
+ workflow_dispatch:
6
+ schedule:
7
+ - cron: "0 10 * * 0"
8
+
9
+ jobs:
10
+ build_wheels:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [
15
+ {
16
+ name: "Ubuntu 26.04",
17
+ family: "linux",
18
+ runner: "ubuntu-26.04",
19
+ archs: "x86_64",
20
+ },
21
+ {
22
+ name: "Ubuntu 26.04",
23
+ family: "linux",
24
+ runner: "ubuntu-26.04-arm",
25
+ archs: "aarch64",
26
+ },
27
+ {
28
+ name: "macOS 26",
29
+ family: "macos",
30
+ runner: "macos-26",
31
+ archs: "arm64",
32
+ },
33
+ ## Windows still has a couple issues.
34
+ # {
35
+ # name: "Windows Server 2025",
36
+ # family: "windows",
37
+ # runner: "windows-2025",
38
+ # archs: "AMD64",
39
+ # },
40
+ ]
41
+ name: Build Wheels | ${{ matrix.os.name }} | ${{ matrix.os.archs }}
42
+ runs-on: ${{ matrix.os.runner }}
43
+ steps:
44
+ - uses: actions/checkout@v7
45
+ with:
46
+ fetch-depth: 0
47
+ submodules: true
48
+ persist-credentials: false
49
+ - uses: actions/setup-python@v6
50
+ with:
51
+ python-version: "3.x"
52
+ ## Software installed by default in GitHub Action Runner VMs:
53
+ ## https://github.com/actions/runner-images
54
+ - id: get-ccache-dir
55
+ name: Set Ccache Directory
56
+ if: ${{ matrix.os.family != 'windows' }}
57
+ run: |
58
+ if test "$(uname)" = "Darwin"; then
59
+ echo "ccache_dir=$HOME/Library/Caches/ccache/" | tee -a $GITHUB_OUTPUT
60
+ else
61
+ echo "ccache_dir=$HOME/.cache/ccache/" | tee -a $GITHUB_OUTPUT
62
+ fi
63
+ - name: Cache Ccache Directory
64
+ uses: actions/cache@v6
65
+ with:
66
+ path: ${{ steps.get-ccache-dir.outputs.ccache_dir }}
67
+ key: pyosys-ccache-${{ matrix.os.family }}-${{ matrix.os.archs }}
68
+ - if: ${{ matrix.os.family == 'windows' }}
69
+ name: "[Windows] Flex/Bison"
70
+ run: |
71
+ choco install winflexbison3
72
+ - name: Build wheels
73
+ uses: pypa/cibuildwheel@v4.1.0
74
+ env:
75
+ CIBW_PROJECT_REQUIRES_PYTHON: ">=3.10"
76
+ # * APIs not supported by PyPy
77
+ # * Musllinux disabled because it increases build time from 48m to ~3h
78
+ CIBW_SKIP: >
79
+ *musllinux*
80
+ CIBW_ARCHS: ${{ matrix.os.archs }}
81
+ CIBW_BUILD_VERBOSITY: "1"
82
+ # manylinux2014 (default) does not have a modern enough C++ compiler for Yosys
83
+ # update: it technically does, devtoolset-11, but it's a matter of
84
+ # time before it doesn't
85
+ CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
86
+ CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_28
87
+ CIBW_BEFORE_ALL: bash ./.github/workflows/wheels/cibw_before_all.sh
88
+ CIBW_CONFIG_SETTINGS: >
89
+ cmake="
90
+ -DYOSYS_COMPILER_LAUNCHER=ccache
91
+ -DCMAKE_BUILD_TYPE=Release
92
+ -DYOSYS_ENABLE_HOMEBREW:BOOL=OFF
93
+ -DSLANG_USE_SYSTEM_FMT:BOOL=OFF
94
+ "
95
+ CIBW_ENVIRONMENT_MACOS: >
96
+ OPTFLAGS=-O3
97
+ PKG_CONFIG_PATH="$PWD/ffi/pfx/lib/pkgconfig:$PKG_CONFIG_PATH"
98
+ PATH="$PWD/ccache/bin:$PWD/bison/pfx/bin:$PWD/flex/pfx/bin:$PATH"
99
+ MACOSX_DEPLOYMENT_TARGET=11
100
+ CIBW_ENVIRONMENT_LINUX: >
101
+ OPTFLAGS=-O3
102
+ PKG_CONFIG_PATH="$PWD/ffi/pfx/lib/pkgconfig:$PKG_CONFIG_PATH"
103
+ PATH="$PWD/ccache/bin:$PWD/bison/pfx/bin:$PWD/flex/pfx/bin:$PATH"
104
+ CCACHE_CONFIGPATH=/host/home/runner/.config/ccache/ccache.conf
105
+ CIBW_BEFORE_BUILD: bash ./.github/workflows/wheels/cibw_before_build.sh
106
+ CIBW_TEST_COMMAND: python3 {project}/tests/pyosys/run_tests.py
107
+ - uses: actions/upload-artifact@v7
108
+ with:
109
+ name: python-wheels-${{ matrix.os.runner }}
110
+ path: ./wheelhouse/*.whl
111
+ upload_wheels:
112
+ name: Upload Wheels
113
+ if: (github.repository == 'YosysHQ/yosys') && (github.event_name == 'workflow_dispatch')
114
+ runs-on: ubuntu-latest
115
+ # Specifying a GitHub environment is optional, but strongly encouraged
116
+ environment: pypi
117
+ permissions:
118
+ # IMPORTANT: this permission is mandatory for Trusted Publishing
119
+ id-token: write
120
+ needs: build_wheels
121
+ steps:
122
+ - uses: actions/download-artifact@v8
123
+ with:
124
+ path: "."
125
+ pattern: python-wheels-*
126
+ merge-multiple: true
127
+ - run: |
128
+ ls
129
+ mkdir -p ./dist
130
+ mv *.whl ./dist
131
+ - name: Publish
132
+ uses: pypa/gh-action-pypi-publish@release/v1
chips/yosys/.github/workflows/wheels/_test_cibw_local.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # Copyright (C) 2024 UmbraLogic Technologies LLC
3
+ # SPDX-License-Identifier: MIT
4
+ """
5
+ This runs the cibuildwheel step from the wheels workflow locally.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ import platform
11
+ import subprocess
12
+ from pathlib import Path
13
+
14
+ import yaml
15
+ from packaging.tags import sys_tags
16
+
17
+ __yosys_root__ = Path(__file__).absolute().parents[3]
18
+
19
+ with open(__yosys_root__ / ".github" / "workflows" / "wheels.yml") as f:
20
+ workflow = yaml.safe_load(f)
21
+
22
+ env = os.environ.copy()
23
+
24
+ steps = workflow["jobs"]["build_wheels"]["steps"]
25
+ cibw_step = None
26
+ for step in steps:
27
+ if (step.get("uses") or "").startswith("pypa/cibuildwheel"):
28
+ cibw_step = step
29
+ break
30
+
31
+ env_filter = {
32
+ "linux": ("_WINDOWS", "_MAC"),
33
+ "darwin": ("_LINUX", "_WINDOWS"),
34
+ "win32": ("_LINUX", "_MAC"),
35
+ }[sys.platform]
36
+ for key, value in cibw_step["env"].items():
37
+ if key.endswith(env_filter):
38
+ continue
39
+ if key not in env: # prioritize user-set keys
40
+ env[key] = value
41
+
42
+ python_tag = next(sys_tags()).interpreter
43
+ env["CIBW_BUILD"] = os.getenv("CIBW_BUILD", f"{python_tag}-*")
44
+ env["CIBW_ARCHS"] = os.getenv("CIBW_ARCHS", platform.machine())
45
+ subprocess.check_call(["cibuildwheel"], env=env)
chips/yosys/.github/workflows/wheels/cibw_before_all.sh ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -e -x
3
+ set -o pipefail
4
+
5
+ # Build-time dependencies
6
+ ## Linux Docker Images
7
+ if command -v apk &> /dev/null; then
8
+ apk add flex bison
9
+ fi
10
+
11
+ ## Platform-independent
12
+ ### Installing ccache on RHEL is a pain and pulls in libfmt on macOS which
13
+ ### slang jumps on immediately and refuses to compile its own libfmt, causing
14
+ ### wheel delocation to fail (Homebrew libraries are built per-OS).
15
+ ###
16
+ ### might as well just install them all the same way, each tarball is like 2MiB
17
+ CCACHE_VER=4.14.3
18
+ if ! command -v ccache &> /dev/null; then
19
+ CCACHE_BIN=$(mktemp -d)
20
+ id=$(uname)-$(uname -m)
21
+ case $id in
22
+ Linux-x86_64)
23
+ id=linux-x86_64-musl-static
24
+ CCACHE_SHA256SUM="e4583fd653b794a480b9915358679a75cdd7a7010dd865eaf4cbdc61e665a3f0"
25
+ ;;
26
+ Linux-aarch64)
27
+ id=linux-aarch64-musl-static
28
+ CCACHE_SHA256SUM="4b0ecece7929cbaf548ff1ab9a24074b240132ab8176bc3865a27d88c457a0d8"
29
+ ;;
30
+ Darwin*)
31
+ # universal
32
+ id=darwin
33
+ CCACHE_SHA256SUM="764dd2a8100ff83e6bbd7b9a1e2016cc401be34bee8a70ea99698186622c34d5"
34
+ ;;
35
+ esac
36
+ mkdir -p $PWD/ccache/bin
37
+ curl --connect-timeout 5 --retry 3 -L https://github.com/ccache/ccache/releases/download/v$CCACHE_VER/ccache-$CCACHE_VER-$id.tar.gz > ccache/ccache.tgz
38
+ echo "$CCACHE_SHA256SUM ccache/ccache.tgz" | sha256sum -c -
39
+ tar -xzC $PWD/ccache/bin --strip-components 1 -f ccache/ccache.tgz
40
+ fi
41
+
42
+ ### just build bison if it's missing or out of date
43
+ BISON_VER="3.8.2"
44
+ BISON_SHA256SUM="9bba0214ccf7f1079c5d59210045227bcf619519840ebfa80cd3849cff5a5bf2"
45
+ which -a bison || true
46
+ if ! printf '%s\n' '%require "3.8"' '%%' 'start: ;' | bison -o /dev/null /dev/stdin ; then
47
+ PREFIX=$PWD/bison/pfx
48
+ rm -rf $PREFIX
49
+ BISON_SRC=$(mktemp -d)
50
+ (
51
+ set -e -x
52
+ cd $BISON_SRC
53
+ curl --connect-timeout 5 --retry 3 -L https://ftp.gnu.org/gnu/bison/bison-${BISON_VER}.tar.xz > bison.tar.xz
54
+ echo "$BISON_SHA256SUM bison.tar.xz" | sha256sum -c -
55
+ tar --strip-components=1 -xJC . -f bison.tar.xz
56
+ ./configure --prefix=$PREFIX CC="ccache ${CC:-cc}" CXX="ccache ${CXX:-c++}"
57
+ make install -j$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu)
58
+ )
59
+ rm -rf $BISON_SRC
60
+ fi
61
+
62
+
63
+ ### The Xcode Command Line Tools ersion of flex has an Apple-specific
64
+ ### extension where int is substituted for size_t in some parts of the codebase.
65
+ ### This is not compatible with Yosys.
66
+ ###
67
+ ### Also, the AlmaLinux repos are slow.
68
+ ###
69
+ ### It's best to just build flex if we don't like its output.
70
+ TMP_LEXER=$(mktemp)
71
+ FLEX_VER="2.6.4"
72
+ FLEX_SHA256SUM="e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995"
73
+ which -a flex || true
74
+ if ! ( printf "\n%%%%\n. { }\n%%%%\n" | flex -+ -o $TMP_LEXER && grep "yyFlexLexer::LexerOutput" $TMP_LEXER | grep -v 'size_t' ) ; then
75
+ PREFIX=$PWD/flex/pfx
76
+ rm -rf $PREFIX
77
+ FLEX_SRC=$(mktemp -d)
78
+ (
79
+ set -e -x
80
+ cd $FLEX_SRC
81
+ curl --connect-timeout 5 --retry 3 -L https://github.com/westes/flex/releases/download/v${FLEX_VER}/flex-${FLEX_VER}.tar.gz > flex.tar.gz
82
+ echo "$FLEX_SHA256SUM flex.tar.gz" | sha256sum -c -
83
+ tar --strip-components=1 -xzC . -f flex.tar.gz
84
+ ./configure --prefix=$PREFIX --disable-shared --disable-silent-rules CFLAGS=-D_GNU_SOURCE CC="ccache ${CC:-cc}" CXX="ccache ${CXX:-c++}"
85
+ make install -j$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu)
86
+ )
87
+ rm -rf $FLEX_SRC
88
+ fi
89
+
90
+ # Runtime Dependencies
91
+ ## Build Static FFI (platform-dependent but not Python version dependent) if
92
+ ## missing
93
+ LIBFFI_VER="3.4.8"
94
+ LIBFFI_SHA256SUM="bc9842a18898bfacb0ed1252c4febcc7e78fa139fd27fdc7a3e30d9d9356119b"
95
+ if ! echo "int main() {}" | cc -x c -l:libffi.a - ; then
96
+ PREFIX=$PWD/ffi/pfx
97
+ rm -rf $PREFIX
98
+ LIBFFI_SRC=$(mktemp -d)
99
+ (
100
+ set -e -x
101
+ cd $LIBFFI_SRC
102
+ curl --connect-timeout 5 --retry 3 -L "https://github.com/libffi/libffi/releases/download/v${LIBFFI_VER}/libffi-${LIBFFI_VER}.tar.gz" > libffi.tar.gz
103
+ echo "$LIBFFI_SHA256SUM libffi.tar.gz" | sha256sum -c -
104
+ tar --strip-components=1 -xzC . -f libffi.tar.gz
105
+ ## Ultimate libyosys.so will be shared, so we need fPIC for the static libraries
106
+ CC="ccache ${CC:-cc}" CXX="ccache ${CXX:-c++}" LDFLAGS=-fPIC CFLAGS=-fPIC CXXFLAGS=-fPIC ./configure --prefix=$PREFIX --enable-static --disable-shared
107
+ make install -j$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu)
108
+ )
109
+ rm -rf $LIBFFI_SRC
110
+ fi
chips/yosys/.github/workflows/wheels/cibw_before_build.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ set -e
2
+ set -x
3
+
4
+ # DEBUG: show python3 and python3-config outputs
5
+ if [ "$(uname)" != "Linux" ]; then
6
+ # https://github.com/pypa/cibuildwheel/issues/2021
7
+ ln -s $(dirname $(readlink -f $(which python3)))/python3-config $(dirname $(which python3))/python3-config
8
+ fi
9
+ python3 --version
10
+ python3-config --includes
11
+
12
+ ccache -s
13
+ ccache -z
chips/yosys/.gitignore ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## user config
2
+ /Makefile.conf
3
+ /Configuration.cmake
4
+ /CMakeUserPresets.json
5
+
6
+ ## homebrew
7
+ /Brewfile.lock.json
8
+
9
+ ## build artifacts
10
+ /.git-abc-submodule-hash
11
+ # compiler intermediate files
12
+ *.o
13
+ *.d
14
+ *.dwo
15
+ *.gch
16
+ *.gcda
17
+ *.gcno
18
+ *.so.dSYM/
19
+
20
+ ## test artifacts
21
+ **/run-test.mk
22
+ *.err
23
+ *.log
24
+ *.tmp
25
+
26
+ # compiler output files
27
+ /kernel/version_*.cc
28
+ /share
29
+ /yosys
30
+ /yosys.exe
31
+ /yosys.js
32
+ /yosys.wasm
33
+ /yosys-abc
34
+ /yosys-abc.exe
35
+ /yosys-config
36
+ /yosys-smtbmc
37
+ /yosys-smtbmc.exe
38
+ /yosys-smtbmc-script.py
39
+ /yosys-witness
40
+ /yosys-witness.exe
41
+ /yosys-witness-script.py
42
+ /yosys-filterlib
43
+ /yosys-filterlib.exe
44
+ /yosys-win32-mxebin-*
45
+ /yosys-win32-vcxsrc-*
46
+ /yosysjs-*
47
+ /libyosys.so
48
+
49
+ # build directories
50
+ /tests/unit/bintest/
51
+ /tests/unit/objtest/
52
+ /tests/ystests
53
+ /build
54
+ /build-*
55
+ /result
56
+ /result-*
57
+ /dist
58
+
59
+ # pyosys
60
+ /kernel/*.pyh
61
+ /kernel/python_wrappers.cc
62
+ /ffi
63
+ /bison
64
+ /flex
65
+ /ccache
66
+ /venv
67
+ /*.whl
68
+ /*.egg-info
69
+ /wheelhouse
70
+
71
+ # yosysjs dependency
72
+ /viz.js
73
+
74
+ # other
75
+ /yosys.profdata
76
+ /coverage
77
+ /coverage_html
78
+
79
+ # these really belong in global gitignore since they're not specific to this project but rather to user tool choice
80
+ # but too many people don't have a global gitignore configured:
81
+ # https://docs.github.com/en/get-started/git-basics/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer
82
+ __pycache__
83
+ *~
84
+ .*.swp
85
+ /.cache
86
+ /.vscode
87
+ /.cproject
88
+ /.project
89
+ /.settings
90
+ /qtcreator.files
91
+ /qtcreator.includes
92
+ /qtcreator.config
93
+ /qtcreator.creator
94
+ /qtcreator.creator.user
95
+ /compile_commands.json
96
+ /.direnv
97
+ /.envrc
chips/yosys/.gitmodules ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [submodule "abc"]
2
+ path = abc
3
+ url = https://github.com/YosysHQ/abc
4
+ # Don't use paths as names to avoid git archive problems
5
+ [submodule "cxxopts"]
6
+ path = libs/cxxopts
7
+ url = https://github.com/jarro2783/cxxopts
8
+ [submodule "fmt"]
9
+ path = libs/fmt
10
+ url = https://github.com/fmtlib/fmt
11
+ [submodule "tomlplusplus"]
12
+ path = libs/tomlplusplus
13
+ url = https://github.com/marzer/tomlplusplus
14
+ [submodule "boost_regex"]
15
+ path = libs/boost_regex
16
+ url = https://github.com/MikePopoloski/regex
17
+ [submodule "slang"]
18
+ path = libs/slang
19
+ url = https://github.com/MikePopoloski/slang
20
+ [submodule "sv-elab"]
21
+ path = frontends/slang/lib
22
+ url = https://github.com/povik/sv-elab
23
+ [submodule "symfpu"]
24
+ path = libs/symfpu
25
+ url = https://github.com/YosysHQ/symfpu
26
+ branch = floatWithStatusFlags
chips/yosys/.mailmap ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ Wanda Phinode <wanda@phinode.net> <mwk@0x04.net>
2
+ Wanda Phinode <wanda@phinode.net> <koriakin@0x04.net>
3
+ Wanda Phinode <wanda@phinode.net> <marcin@symbioticeda.com>
4
+ Claire Xenia Wolf <claire@yosyshq.com> <claire@clairexen.net>
5
+ Claire Xenia Wolf <claire@yosyshq.com> <claire@symbioticeda.com>
6
+ Claire Xenia Wolf <claire@yosyshq.com> <clifford@symbioticeda.com>
7
+ Claire Xenia Wolf <claire@yosyshq.com> <clifford@clifford.at>
chips/yosys/.pre-commit-config.yaml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # To use:
2
+ #
3
+ # pre-commit run -a
4
+ #
5
+ # Or:
6
+ #
7
+ # pre-commit install # (runs every time you commit in git)
8
+ #
9
+ # To update this file:
10
+ #
11
+ # pre-commit autoupdate
12
+ #
13
+ # See https://github.com/pre-commit/pre-commit
14
+
15
+ exclude: ^libs/
16
+
17
+ repos:
18
+ - repo: https://github.com/pre-commit/pre-commit-hooks
19
+ rev: v6.0.0
20
+ hooks:
21
+ - id: check-case-conflict
22
+ - id: check-executables-have-shebangs
23
+ - id: check-illegal-windows-names
24
+ - id: check-yaml
25
+ args: [--allow-multiple-documents]
26
+ - id: end-of-file-fixer
27
+ - id: fix-byte-order-marker
28
+ - id: mixed-line-ending
29
+ args: [--fix,lf]
30
+ - id: trailing-whitespace
chips/yosys/.readthedocs.yaml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # .readthedocs.yaml
2
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
+
4
+ version: 2
5
+
6
+ build:
7
+ os: ubuntu-22.04
8
+ tools:
9
+ python: '3.12'
10
+
11
+ formats:
12
+ - pdf
13
+
14
+ sphinx:
15
+ configuration: docs/source/conf.py
16
+ fail_on_warning: true
17
+
18
+ python:
19
+ install:
20
+ - requirements: docs/source/requirements.txt
chips/yosys/Brewfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ brew "bison"
2
+ brew "flex"
3
+ brew "gawk"
4
+ brew "libffi"
5
+ brew "git"
6
+ brew "graphviz"
7
+ brew "pkg-config"
8
+ brew "python3"
9
+ brew "uv"
10
+ brew "xdot"
11
+ brew "bash"
12
+ brew "llvm"
13
+ brew "lld"
14
+ brew "googletest"
15
+ brew "tcl-tk"
chips/yosys/CHANGELOG ADDED
@@ -0,0 +1,1898 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ List of major changes and improvements between releases
3
+ =======================================================
4
+
5
+ Yosys 0.71 .. Yosys 0.72-dev
6
+ --------------------------
7
+
8
+ Yosys 0.70 .. Yosys 0.71
9
+ --------------------------
10
+ * Commands and options
11
+ - Added "-readable" and "-small" to "dump" and "write_rtlil" passes
12
+ for convenience with the new string implementation.
13
+ - Added "shuffle" pass to deterministically reorder design objects.
14
+ - Added "-target" and "-family" to "verific" and "read_slang" passes
15
+ as experimental feature to specify FPGA synthesis target.
16
+ - Added "-nodec_attr" and "-dec_param" to "write_verilog" pass for
17
+ compatibility with other tools.
18
+
19
+ * Various
20
+ - Strings have been reimplemented with prefix deduplication to improve
21
+ performance. Plugins may need to be adapted. Please refer to
22
+ docs/source/yosys_internals/idstring.rst
23
+ - MCM pass now uses HCUB algorithm, improving runtime performance on
24
+ big multipliers and removing the 32-bit maximum size.
25
+ - Fixed out-of-memory crashes on large casez/priority case statements.
26
+ - verific: Improved detection of unsupported SVA constructs.
27
+
28
+ Yosys 0.69 .. Yosys 0.70
29
+ --------------------------
30
+ * Commands and options
31
+ - Added "-macc-only" to "alumacc" pass.
32
+ - Added "optbarriers" experimental pass for optimization barriers insertion
33
+ - Added "-barriers" to "flatten" and "prep" pass.
34
+ - Added "mcm" pass to replace constant multipliers with shared adder graphs.
35
+ - Added "-purge" to "rmports" pass.
36
+ - Added "-select" to "ltp" pass.
37
+ - Removed "read_xaiger2" pass.
38
+
39
+ * Various
40
+ - Added colored log messages output in terminal mode.
41
+
42
+ Yosys 0.68 .. Yosys 0.69
43
+ --------------------------
44
+ * Commands and options
45
+ - Removed sum of products related parameters from
46
+ "abc" pass.
47
+ - Removed coolrunner2 and greenpak4 synthesis and related
48
+ passes.
49
+ - Removed "nlutmap" pass.
50
+ - Removed "-retime", "-noabc9", "-abc2" and "-abc" options
51
+ from synthesis passes.
52
+ - Removed "-[no]stderr" from "logger" pass.
53
+
54
+ * Various
55
+ - verific: Added "-sv2023" flag option to support System
56
+ Verilog 2023.
57
+
58
+ Yosys 0.67 .. Yosys 0.68
59
+ --------------------------
60
+ * New commands and options
61
+ - Added "symfpu" and "symfpu_convert" passes.
62
+ - Removed "-fast" option from "abc" pass.
63
+ - Removed "flowmap" pass and "-flowmap" from "synth"
64
+ and "synth_ice40" passes.
65
+ - Removed "-wideports" option from "read_aiger" pass.
66
+
67
+ * Various
68
+ - nexus: fix Radiant netlist compatibility.
69
+
70
+ Yosys 0.66 .. Yosys 0.67
71
+ --------------------------
72
+ * Various
73
+ - Project is now requiring CMake 3.28 or later as
74
+ build system.
75
+ - At least Clang-16 or GCC-13 are required, but we
76
+ recommend using later versions.
77
+ - Microsoft Visual Studio builds are now fully working
78
+ (including building ABC), but mingw-64 builds are
79
+ still recommended for Windows platform.
80
+ - For SystemVerilog support now using sv-elab,
81
+ built on top of slang library.
82
+ - FABulous techlib to removes all hardcoded mappings
83
+ and primitives, allowing them to be specified via
84
+ the options of "synth_fabulous".
85
+ - smtbmc: Latest bitwuzla is now supported.
86
+
87
+ * New commands and options
88
+ - Added "abc_ops_reintegrate" pass as replacement
89
+ for "abc9_ops -reintegrate".
90
+ - Added "check_mem" pass to check for memory problems
91
+ in the design.
92
+ - Added "-strategy", "-final" and "-no-fma" options to
93
+ "arith_tree" pass.
94
+ - Added "-ignore-unknown-cells" option to "equiv_opt".
95
+ - Added "-no-undriven-check" and "-undriven-warn" options
96
+ to "sim" pass.
97
+ - Added "-latches" option to synth passes able to
98
+ produce latches for control of latch inference.
99
+ - Added "-nolatches" to "check" pass.
100
+ - Added "-latches" to "proc" and "proc_dlatch" passes.
101
+
102
+ Yosys 0.65 .. Yosys 0.66
103
+ --------------------------
104
+ * Various
105
+ - C++ compiler with C++20 support is required.
106
+ - Please be aware that next release will also
107
+ migrate to CMake build system.
108
+
109
+ * New commands and options
110
+ - Added "lattice_dsp_nexus" pass for Lattice Nexus
111
+ DSP inference.
112
+ - Added "-scopename" option to "synth_gatemate" pass
113
+ that is propagated to "flatten".
114
+
115
+ Yosys 0.64 .. Yosys 0.65
116
+ --------------------------
117
+ * New commands and options
118
+ - Added "arith_tree" pass to convert add/sub/macc chains
119
+ to carry-save adder trees.
120
+ - Removed "-force" option from "share" pass.
121
+
122
+ * Various
123
+ - read_verilog: support positional assignment patterns
124
+ for unpacked arrays.
125
+
126
+ Yosys 0.63 .. Yosys 0.64
127
+ --------------------------
128
+ * New commands and options
129
+ - Added "synth_analogdevices" pass to support synthesis
130
+ for Analog Devices FPGAs.
131
+
132
+ * Various
133
+ - Removed rarely-used options from ABC/ABC9.
134
+ - Removed "-S" option from "abc" pass.
135
+ - Removed "-fast" option from "abc9" and "abc9_exe".
136
+ - Calls to "abc -g AND -fast" to map logic to
137
+ AND-Inverter Graph form should be replaced with
138
+ "aigmap".
139
+ - The above change was made to SBY, so we recommend
140
+ updating it.
141
+ - Added hardware latch support for Gowin FPGAs.
142
+
143
+ Yosys 0.62 .. Yosys 0.63
144
+ --------------------------
145
+ * Various
146
+ - Added DSP inference for Gowin GW1N and GW2A.
147
+ - Added support for subtract in preadder for Xilinx arch.
148
+ - Added infrastructure to run a sat solver as a command.
149
+
150
+ * New commands and options
151
+ - Added "-ignore-unknown-cells" option to "equiv_induct"
152
+ and "equiv_simple" pass.
153
+ - Added "-force-params" option to "memory_libmap" pass.
154
+ - Added "-select-solver" option to "sat" pass.
155
+ - Added "-default_params" option to "write_verilog" pass.
156
+ - Added "-nodsp" option to "synth_gowin" pass.
157
+
158
+ Yosys 0.61 .. Yosys 0.62
159
+ --------------------------
160
+ * Various
161
+ - verific: Added "-sv2017" flag option to support System
162
+ Verilog 2017.
163
+ - verific: Added VHDL related flags to "-f" and "-F" and
164
+ support reading VHDL file from file lists.
165
+ - Updated cell libs with proper module declaration where
166
+ non standard (...) style was used.
167
+
168
+ * New commands and options
169
+ - Added "-word" option to "lut2mux" pass to enable emitting
170
+ word level cells.
171
+ - Added experimental "opt_balance_tree" pass to convert
172
+ cascaded cells into tree of cells to improve timing.
173
+ - Added "-gatesi" option to "write_blif" pass to init gates
174
+ under gates_mode in BLIF format.
175
+ - Added "-on" and "-off" options to "debug" pass for
176
+ persistent debug logging.
177
+ - Added "linux_perf" pass to control performance recording.
178
+
179
+ Yosys 0.60 .. Yosys 0.61
180
+ --------------------------
181
+ * Various
182
+ - Removed "cover" pass for coverage tracking.
183
+ - Avoid merging formal properties with "opt_merge" pass.
184
+ - Parallelize "opt_merge" pass.
185
+
186
+ * New commands and options
187
+ - Added "design_equal" pass to support fuzz-test comparison.
188
+ - Added "lut2bmux" pass to convert $lut to $bmux.
189
+ - Added "-legalize" option to "read_rtlil" pass to prevent
190
+ semantic errors.
191
+
192
+ Yosys 0.59 .. Yosys 0.60
193
+ --------------------------
194
+ * Various
195
+ - read_verilog: suport unsized parameters.
196
+ - Added static library compile option.
197
+
198
+ * New commands and options
199
+ - Added "sdc" pass for reading SDC files.
200
+ - Added experimental "sdc_expand" and "opensta" for OpenSTA integration.
201
+ - Added "icell_liberty" pass for used internal cells.
202
+
203
+ Yosys 0.58 .. Yosys 0.59
204
+ --------------------------
205
+ * Various
206
+ - Pyosys is rewritten using pybind11.
207
+ - alumacc: merge independent of sign.
208
+ - write_btor: Include $assert and $assume cells in -ywmap output.
209
+ - RTLIL parser rewritten for efficiency.
210
+ - Wildcards enabled for Liberty file consuming.
211
+ - timeest: Add top ports launching/sampling.
212
+
213
+ * New commands and options
214
+ - Added "-apply_derived_type" option to "box_derive" pass.
215
+ - Added "-publish_icells" option to "chtype" pass.
216
+ - Added "-width" option to "sim" pass.
217
+ - Added "sort" pass for sorting the design objects.
218
+ - Merged "synth_ecp5" and "synth_nexus" into "synth_lattice" pass.
219
+ - Added "-strict-gw5a-dffs" and "-setundef" options to "synth_gowin" pass.
220
+
221
+ Yosys 0.57 .. Yosys 0.58
222
+ --------------------------
223
+ * Various
224
+ - Run ABC passes in parallel.
225
+ - Extending support for buffer normalization.
226
+ - Overhaul of logging APIs.
227
+ - read_blif: Represent sequential elements with gate cells.
228
+ - Support multiple lib files in abc9_exe.
229
+
230
+ * New commands and options
231
+ - Added "-wireshape" option to "show" command to allow
232
+ control the shape of wire nodes.
233
+ - Added "-relativeshare" option to "read_verilog", "synth"
234
+ and "techmap" pass for synthesis reproducibility testing.
235
+ - "write_rtlil" pass no longer sorts design, added "-sort"
236
+ option to match old behavior
237
+ - Added "-sva-continue-on-err" to "verific" pass to allow
238
+ processing designs that includes unsupported SVA.
239
+
240
+ Yosys 0.56 .. Yosys 0.57
241
+ --------------------------
242
+ * New commands and options
243
+ - Added "-initstates" option to "abstract" pass.
244
+ - Added "-set-assumes" option to "equiv_induct"
245
+ and "equiv_simple" passes.
246
+ - Added "-always" option to "raise_error" pass.
247
+ - Added "-hierarchy" option to "stat" pass.
248
+ - Added "-noflatten" option to "synth_quicklogic" pass.
249
+
250
+ * Various
251
+ - smtbmc: Support skipping steps in cover mode.
252
+ - write_btor: support $buf.
253
+ - read_verilog: support package import.
254
+
255
+ Yosys 0.55 .. Yosys 0.56
256
+ --------------------------
257
+ * New commands and options
258
+ - Added "-unescape" option to "rename" pass.
259
+ - Added "-assert2cover" option to "chformal" pass.
260
+ - Added "linecoverage" pass to generate lcov report from selection.
261
+ - Added "opt_hier" pass to enable hierarchical optimization.
262
+ - Added "-hieropt" option to "synth" pass.
263
+ - Added "-expect-return", "-err-grep" and "-suffix" options
264
+ to "bugpoint" pass.
265
+ - Added "raise_error" dev pass.
266
+
267
+ * Various
268
+ - Added groups to command reference documentation.
269
+ - Added bugpoint guide to documentation.
270
+ - verific: correctly reset Verific flags after import.
271
+
272
+ Yosys 0.54 .. Yosys 0.55
273
+ --------------------------
274
+ * Various
275
+ - read_verilog: Implemented SystemVerilog unique/priority if.
276
+ - "attrmap" pass is able to alter memory attributes.
277
+ - verific: Support SVA followed-by operator in cover mode.
278
+
279
+ Yosys 0.53 .. Yosys 0.54
280
+ --------------------------
281
+ * New commands and options
282
+ - Added "-genlib" option to "abc_new" and "abc9_exe" passes.
283
+ - Added "-verbose" and "-quiet" options to "libcache" pass.
284
+ - Added "-no-sort" option to "write_aiger" pass.
285
+
286
+ * Various
287
+ - Added "muldiv_c" peepopt.
288
+ - Accept (and ignore) SystemVerilog unique/priority if.
289
+ - "read_verilog" copy inout ports in and out of functions/tasks.
290
+ - Enable single-bit vector wires in RTLIL.
291
+
292
+ * Xilinx support
293
+ - Single-port URAM mapping to support memories 2048 x 144b
294
+
295
+ Yosys 0.52 .. Yosys 0.53
296
+ --------------------------
297
+ * New commands and options
298
+ - Added "constmap" pass for technology mapping of coarse constant value.
299
+ - Added "timeest" pass to estimate the critical path in clock domain.
300
+ - Added "-blackbox" option to "cutpoint" pass to cut all instances of
301
+ blackboxes.
302
+ - Added "-noscopeinfo" option to "cutpoint" pass.
303
+ - Added "-nocleanup" option to "flatten" pass to prevent removal of
304
+ unused submodules.
305
+ - Added "-declockgate" option to "formalff" pass that turns clock
306
+ gating into clock enables.
307
+
308
+ * Various
309
+ - Added "$scopeinfo" cells to preserve information during "cutpoint" pass.
310
+ - Added dataflow tracking documentation.
311
+ - share: Restrict activation patterns to potentially relevant signal.
312
+ - liberty: More robust parsing.
313
+ - verific: bit blast RAM if using mem2reg attribute.
314
+
315
+ Yosys 0.51 .. Yosys 0.52
316
+ --------------------------
317
+ * New commands and options
318
+ - Added "-pattern-limit" option to "share" pass to limit analysis effort.
319
+ - Added "libcache" pass to control caching of technology library
320
+ data parsed from liberty files.
321
+ - Added "read_verilog_file_list" to parse verilog file list.
322
+
323
+ * Various
324
+ - Added $macc_v2 cell.
325
+ - Improve lexer performance and zlib support for "read_liberty".
326
+ - opt_expr: optimize pow of 2 cells.
327
+
328
+
329
+ Yosys 0.50 .. Yosys 0.51
330
+ --------------------------
331
+ * New commands and options
332
+ - Added "abstract" pass to allow reducing and never increasing
333
+ the constraints on a circuit's behavior in a formal verification setting.
334
+
335
+ * Various
336
+ - "splitcells" pass now splits "aldff" cells.
337
+ - FunctionalIR documentation
338
+
339
+ * QuickLogic support
340
+ - Added IOFF inference for qlf_k6n10f
341
+
342
+ * Intel support
343
+ - Fixed RAM and DSP support.
344
+ - Overall performance improvement for "synth_intel".
345
+
346
+ Yosys 0.49 .. Yosys 0.50
347
+ --------------------------
348
+ * Various
349
+ - "write_verilog" emits "$check" cell names as labels.
350
+
351
+ Yosys 0.48 .. Yosys 0.49
352
+ --------------------------
353
+ * Various
354
+ - "$scopeinfo" cells are now part of JSON export by default.
355
+ - Added option to specify hierarchical separator for "flatten".
356
+ - Improved "wreduce" to handle more cases of operator size reduction.
357
+ - Updated hashing interface, see docs/source/yosys_internals/hashing.rst
358
+ for breaking API changes.
359
+
360
+ * New commands and options
361
+ - Added "-noscopeinfo" option to "json" and "write_json" pass.
362
+
363
+ Yosys 0.47 .. Yosys 0.48
364
+ --------------------------
365
+ * Various
366
+ - Removed "read_ilang" deprecated pass.
367
+ - Enhanced boxing features in the experimental "abc_new" command.
368
+ - Added new Tcl methods for design inspection.
369
+ - Added clock enable inference to "dfflibmap".
370
+ - Added a Han-Carlson and Sklansky option for $lcu mapping.
371
+
372
+ * New commands and options
373
+ - Added "-nopeepopt" option to "clk2fflogic" pass.
374
+ - Added "-liberty" and "-dont_use" options to "clockgate" pass.
375
+ - Added "-ignore_buses" option to "read_liberty" pass.
376
+ - Added "-dont_map" option to "techmap" pass.
377
+ - Added "-selected" option to "write_json" pass.
378
+ - Added "wrapcell" command for creating wrapper modules
379
+ around selected cells.
380
+ - Added "portarcs" command for deriving propagation timing arcs.
381
+ - Added "setenv" command for setting environment variables.
382
+
383
+ * Gowin support
384
+ - Added "-family" option to "synth_gowin" pass.
385
+ - Cell definitions split by family.
386
+
387
+ * Verific support
388
+ - Improved blackbox support.
389
+
390
+ Yosys 0.46 .. Yosys 0.47
391
+ --------------------------
392
+ * Various
393
+ - Added cxxopts library for handling command line arguments.
394
+ - Added docs generation from cells help output.
395
+
396
+ * New commands and options
397
+ - Added "-json" option to "synth_xilinx" pass.
398
+ - Added "-derive_luts" option to "cellmatch" pass.
399
+ - Added "t:@<name>" syntax to "select" pass.
400
+ - Added "-list-mod" option to "select" pass.
401
+ - Removed deprecated "qwp" pass.
402
+
403
+ * Verific support
404
+ - Initial state handling for VHDL assertions.
405
+
406
+ Yosys 0.45 .. Yosys 0.46
407
+ --------------------------
408
+ * Various
409
+ - Added new "functional backend" infrastructure with three example
410
+ backends (C++, SMTLIB and Rosette).
411
+ - Added new coarse-grain buffer cell type "$buf" to RTLIL.
412
+ - Added "-y" command line option to execute a Python script with
413
+ libyosys available as a built-in module.
414
+ - Added support for casting to type in Verilog frontend.
415
+
416
+ * New commands and options
417
+ - Added "clockgate" pass for automatic clock gating cell insertion.
418
+ - Added "bufnorm" experimental pass to convert design into
419
+ buffered-normalized form.
420
+ - Added experimental "aiger2" and "xaiger2" backends, and an
421
+ experimental "abc_new" command
422
+ - Added "-force-detailed-loop-check" option to "check" pass.
423
+ - Added "-unit_delay" option to "read_liberty" pass.
424
+
425
+ * Verific support
426
+ - Added left and right bound properties to wires when using
427
+ specific VHDL types.
428
+
429
+ Yosys 0.44 .. Yosys 0.45
430
+ --------------------------
431
+ * Various
432
+ - Added cell types help messages.
433
+
434
+ * New back-ends
435
+ - Added initial NG-Ultra support. ( synth_nanoxplore )
436
+
437
+ Yosys 0.43 .. Yosys 0.44
438
+ --------------------------
439
+ * Various
440
+ - Added ENABLE_LTO compile option to enable link time
441
+ optimizations.
442
+ - Build support for Haiku OS.
443
+
444
+ * New commands and options
445
+ - Added "keep_hierarchy" pass to add attribute with
446
+ same name to modules based on cost.
447
+ - Added options "-noopt","-bloat" and "-check_cost" to
448
+ "test_cell" pass.
449
+
450
+ * New back-ends
451
+ - Added initial PolarFire support. ( synth_microchip )
452
+
453
+ Yosys 0.42 .. Yosys 0.43
454
+ --------------------------
455
+ * Various
456
+ - C++ compiler with C++17 support is required.
457
+ - Support for IO liberty files for verification.
458
+ - Limit padding from shiftadd for "peepopt" pass.
459
+
460
+ * Verific support
461
+ - Support building Yosys with various Verific library
462
+ configurations. Can be built now without YosysHQ
463
+ specific patch and extension library.
464
+
465
+ Yosys 0.41 .. Yosys 0.42
466
+ --------------------------
467
+ * New commands and options
468
+ - Added "box_derive" pass to derive box modules.
469
+ - Added option "assert-mod-count" to "select" pass.
470
+ - Added option "-header","-push" and "-pop" to "log" pass.
471
+ * Intel support
472
+ - Dropped Quartus support in "synth_intel_alm" pass.
473
+
474
+ Yosys 0.40 .. Yosys 0.41
475
+ --------------------------
476
+ * New commands and options
477
+ - Added "cellmatch" pass for picking out standard cells automatically.
478
+
479
+ * Various
480
+ - Extended the experimental incremental JSON API to allow arbitrary
481
+ smtlib subexpressions.
482
+ - Added support for using ABCs library merging when providing multiple
483
+ liberty files.
484
+
485
+ * Verific support
486
+ - Expose library name as module attribute.
487
+
488
+ Yosys 0.39 .. Yosys 0.40
489
+ --------------------------
490
+ * New commands and options
491
+ - Added option "-vhdl2019" to "read" and "verific" pass.
492
+
493
+ * Various
494
+ - Major documentation overhaul.
495
+ - Added port statistics to "stat" command.
496
+ - Added new formatting features to cxxrtl backend.
497
+
498
+ * Verific support
499
+ - Added better support for VHDL constants import.
500
+ - Added support for VHDL 2009.
501
+
502
+ Yosys 0.38 .. Yosys 0.39
503
+ --------------------------
504
+ * New commands and options
505
+ - Added option "-extra-map" to "synth" pass.
506
+ - Added option "-dont_use" to "dfflibmap" pass.
507
+ - Added option "-href" to "show" command.
508
+ - Added option "-noscopeinfo" to "flatten" pass.
509
+ - Added option "-scopename" to "flatten" pass.
510
+
511
+ * SystemVerilog
512
+ - Added support for packed multidimensional arrays.
513
+
514
+ * Various
515
+ - Added "$scopeinfo" cells to preserve information about
516
+ the hierarchy during flattening.
517
+ - Added sequential area output to "stat -liberty".
518
+ - Added ability to record/replay diagnostics in cxxrtl backend.
519
+
520
+ * Verific support
521
+ - Added attributes to module instantiation.
522
+
523
+ Yosys 0.37 .. Yosys 0.38
524
+ --------------------------
525
+ * New commands and options
526
+ - Added option "-tech" to "opt_lut" pass.
527
+ - Added option "-nokeep_prints" to "hierarchy" pass.
528
+ - Added option "-nolower" to "async2sync" and "clk2fflogic" pass.
529
+ - Added option "-lower" to "chformal" pass.
530
+
531
+ * Various
532
+ - Added $check cell to represent assertions with messages.
533
+ - Allow capturing $print cell output in CXXRTL.
534
+ - Added API to overwrite existing pass from plugin.
535
+ - Follow the XDG Base Directory Specification for storing history files.
536
+ - Without a known top module, derive all deferred modules (hierarchy pass).
537
+ - Detect and error out on combinational loops in write_aiger.
538
+
539
+ * Verific support
540
+ - Added option "-no-split-complex-ports" to "verific -import".
541
+
542
+ Yosys 0.36 .. Yosys 0.37
543
+ --------------------------
544
+ * New commands and options
545
+ - Added option "-nodisplay" to read_verilog.
546
+
547
+ * SystemVerilog
548
+ - Correct hierarchical path names for structs and unions.
549
+
550
+ * Various
551
+ - Print hierarchy for failed assertions in "sim" pass.
552
+ - Add "--present-only" option to "yosys-witness" to omit unused signals.
553
+ - Implement a generic record/replay interface for CXXRTL.
554
+ - Improved readability of emitted code with "write_verilog".
555
+
556
+ Yosys 0.35 .. Yosys 0.36
557
+ --------------------------
558
+ * New commands and options
559
+ - Added option "--" to pass arguments down to tcl when using -c option.
560
+ - Added ability on MacOS and Windows to pass options after arguments on cli.
561
+ - Added option "-cmp2softlogic" to synth_lattice.
562
+ - Added option "-lowpower" to "booth" pass.
563
+
564
+ * QuickLogic support
565
+ - Added "K6N10f" support.
566
+ - Added "-nodsp", "-nocarry", "-nobram" and "-bramtypes" options to
567
+ "synth_quicklogic" pass.
568
+ - Added "ql_bram_merge" pass to merge 18K BRAM cells into TDP36K.
569
+ - Added "ql_bram_types" pass to change TDP36K depending on configuration.
570
+ - Added "ql_dsp_io_regs" pass to update QL_DSP2 depending on configuration.
571
+ - Added "ql_dsp_macc" pass to infer multiplier-accumulator DSP cells.
572
+ - Added "ql_dsp_simd" pass to merge DSP pairs to operate in SIMD mode.
573
+
574
+ * ECP5,iCE40 and Gowin support
575
+ - Enabled abc9 by default, added "-noabc9" option to disable.
576
+
577
+ * MachXO3 support
578
+ - Quality of results improvements.
579
+ - Enabled "booth" pass by default for it in "synth_lattice".
580
+
581
+ * Various
582
+ - Improved "peepopt" by adding shiftadd pattern support.
583
+ - Added "--incremental" mode to smtbmc.
584
+
585
+ Yosys 0.34 .. Yosys 0.35
586
+ --------------------------
587
+ * Various
588
+ - Improvements on "peepopt" shiftmul matcher.
589
+ - Improvements on "ram_style" attributes handling.
590
+
591
+ * Verific support
592
+ - Improved static elaboration for VHDL and mixed HDL designs.
593
+ - Expose "hdlname" attribute with original module name.
594
+ - Expose "architecture" attribute with VHDL architecture name.
595
+
596
+ Yosys 0.33 .. Yosys 0.34
597
+ --------------------------
598
+ * New commands and options
599
+ - Added option "-assert" to "sim" pass.
600
+ - Added option "-noinitstate" to "sim" pass.
601
+ - Added option "-dont_use" to "abc" pass.
602
+ - Added "dft_tag" pass to create tagging logic for data flow tracking.
603
+ - Added "future" pass to resolve future sampled value functions.
604
+ - Added "booth" pass to map $mul cells to Booth multipliers.
605
+ - Added option "-booth" to "synth" pass.
606
+
607
+ * SystemVerilog
608
+ - Added support for assignments within expressions, e.g., `x[y++] = z;` or
609
+ `x = (y *= 2) - 1;`.
610
+
611
+ * Verific support
612
+ - "src" attribute contain full location info.
613
+ - module parameters are kept after import.
614
+ - accurate access order semantics in memory inference.
615
+ - better "bind" support for mixed language projects.
616
+
617
+ * Various
618
+ - "show" command displays dot instead of box for wire aliases.
619
+
620
+ Yosys 0.32 .. Yosys 0.33
621
+ --------------------------
622
+ * Various
623
+ - Added "$print" cell, produced by "$display" and "$write"
624
+ Verilog tasks.
625
+ - Added "$print" cell handling in CXXRTL.
626
+
627
+ * Lattice FPGA support
628
+ - Added generic "synth_lattice" pass (for now MachXO2/XO3/XO3D)
629
+ - Removed "synth_machxo2" pass
630
+ - Pass "ecp5_gsr" renamed to "lattice_gsr"
631
+ - "synth_machxo2" equivalent is "synth_lattice -family xo2"
632
+
633
+ Yosys 0.31 .. Yosys 0.32
634
+ --------------------------
635
+ * Verific support
636
+ - Added sub option "-lib" to reading commands for VHDL and
637
+ SystemVerilog, that will later import all units/modules from
638
+ marked files as blackboxes.
639
+
640
+ * Various
641
+ - Added support for $lt, $le, $gt, $ge to the code generating AIGs.
642
+
643
+ Yosys 0.30 .. Yosys 0.31
644
+ --------------------------
645
+ * New commands and options
646
+ - Added option "-lsbidx" to "write_edif" pass.
647
+
648
+ * Various
649
+ - Added support for $divfloor operator to cxxrtl backend.
650
+ - dfflegalize: allow setting mince and minsrst args from scratchpad.
651
+
652
+ Yosys 0.29 .. Yosys 0.30
653
+ --------------------------
654
+ * New commands and options
655
+ - Added "recover_names" pass to recover names post-mapping.
656
+
657
+ * Gowin support
658
+ - Added remaining primitives blackboxes.
659
+
660
+ * Various
661
+ - "show -colorattr" will now color the cells, wires, and
662
+ connection arrows.
663
+ - "show -viewer none" will not execute viewer.
664
+
665
+ Yosys 0.28 .. Yosys 0.29
666
+ --------------------------
667
+ * New commands and options
668
+ - Added "synthprop" pass for synthesizable properties.
669
+
670
+ * Verific support
671
+ - Handle conditions on clocked concurrent assertions in unclocked
672
+ procedural contexts.
673
+
674
+ * Verilog
675
+ - Fix const eval of unbased unsized constants.
676
+ - Handling of attributes for struct / union variables.
677
+
678
+ Yosys 0.27 .. Yosys 0.28
679
+ --------------------------
680
+ * Verilog
681
+ - Out of bounds checking for struct/union members.
682
+
683
+ * Verific support
684
+ - Fix enum_values support and signed attribute values.
685
+
686
+ * ECP5 support
687
+ - Added "synth_ecp5 -iopad"
688
+
689
+ * MachXO2 support
690
+ - Added "synth_machxo2 -ccu2"
691
+
692
+ Yosys 0.26 .. Yosys 0.27
693
+ --------------------------
694
+ * New commands and options
695
+ - Added option "-make_assert" to "equiv_make" pass.
696
+ - Added option "-coverenable" to "chformal" pass.
697
+
698
+ * Verilog
699
+ - Resolve package types in interfaces.
700
+ - Handle range offsets in packed arrays within packed structs.
701
+ - Support for data and array queries on struct/union item expressions.
702
+
703
+ * GateMate support
704
+ - Enable register initialization.
705
+
706
+ Yosys 0.25 .. Yosys 0.26
707
+ --------------------------
708
+ * New commands and options
709
+ - Added "bwmuxmap" pass to replace $bwmux cells with equivalent logic.
710
+ - Added "xprop" experimental pass for formal x propagation.
711
+ - Added "splitcells" pass to split up multi-bit cells.
712
+ - Added "viz" pass to visualize data flow graph.
713
+ - Added option "-make_cover" to "miter" pass.
714
+ - Added option "-noparallelcase" to "write_verilog" pass.
715
+ - Added option "-chain" to "insbuf" pass.
716
+ - Added options "-hierarchy" and "-assume" to "formalff" pass.
717
+ - Added options "-append" and "-summary" to "sim" pass.
718
+ - Added option "-ywmap" to "write_btor" pass.
719
+ - Added option "-ignore-self-reset" to "fsm_detect" pass.
720
+
721
+ * Verilog
722
+ - Support for struct members of union type.
723
+ - Support for struct member package types.
724
+
725
+ * Various
726
+ - Added Yosys witness (.yw) cosimulation.
727
+ - GCC 4.8 is deprecated, compiler with full C++11 support is required.
728
+
729
+ Yosys 0.24 .. Yosys 0.25
730
+ --------------------------
731
+ * Verific support
732
+ - Respect "noblackbox" attribute for modules.
733
+
734
+ * Various
735
+ - Documentation is hosted at https://yosyshq.readthedocs.io/projects/yosys/en/latest/
736
+
737
+ Yosys 0.23 .. Yosys 0.24
738
+ --------------------------
739
+ * New commands and options
740
+ - Added option "-set-def-formal" to "sat" pass.
741
+ - Added option "-s" to "tee" command.
742
+
743
+ * Verilog
744
+ - Support for module-scoped identifiers referring to tasks and functions.
745
+ - Support for arrays with swapped ranges within structs.
746
+
747
+ * Verific support
748
+ - Support for importing verilog configurations per name.
749
+ - "verific -set-XXXXX" commands are now able to set severity to all messages
750
+ of certain type (errors, warnings, infos and comments)
751
+
752
+ * Various
753
+ - TCL shell support (use "yosys -C")
754
+ - Added FABulous eFPGA frontend
755
+
756
+ Yosys 0.22 .. Yosys 0.23
757
+ --------------------------
758
+ * New commands and options
759
+ - Added option "-cross" to "miter" pass.
760
+ - Added option "-nocheck" to "equiv_opt" pass.
761
+
762
+ * Formal Verification
763
+ - yosys-smtbmc: Added "--detect-loops" option for checking if states are
764
+ unique in temporal induction counter examples.
765
+
766
+ * Verific support
767
+ - Added support for reading Liberty files using Verific library.
768
+ (Optinally enabled with ENABLE_VERIFIC_LIBERTY)
769
+ - Added option "-cells" to "verific -import" enabling import of
770
+ all cells from verific design.
771
+
772
+ * Various
773
+ - MinGW build (Windows) plugin support.
774
+ - Added YOSYS_ABORT_ON_LOG_ERROR environment variable for debugging.
775
+ Setting it to 1 causes abort() to be called when Yosys terminates with an
776
+ error message.
777
+
778
+ Yosys 0.21 .. Yosys 0.22
779
+ --------------------------
780
+ * Verific support
781
+ - Added support for here-document for "verific" command (for reading
782
+ source files).
783
+ - Added support for reading EDIF files using Verific library.
784
+ (Optinally enabled with ENABLE_VERIFIC_EDIF)
785
+
786
+ * Various
787
+ - Added tech specific utilization to "stat" json.
788
+
789
+ Yosys 0.20 .. Yosys 0.21
790
+ --------------------------
791
+ * New commands and options
792
+ - Added "formalff" pass - transforms FFs for formal verification
793
+ - Added option "-formal" to "memory_map" pass
794
+ - Added option "-witness" to "rename" - give public names to all signals
795
+ present in yosys witness traces
796
+ - Added option "-hdlname" to "sim" pass - preserves hiearachy when writing
797
+ simulation output for a flattened design
798
+ - Addded option "-scramble-name" to "rename" pass
799
+
800
+ * Formal Verification
801
+ - Added $anyinit cell to directly represent FFs with an unconstrained
802
+ initialization value. These can be generated by the new formalff pass.
803
+ - New JSON based yosys witness format for formal verification traces.
804
+ - yosys-smtbmc: Reading and writing of yosys witness traces.
805
+ - write_smt2: Emit inline metadata to support yosys witness trace.
806
+ - yosys-witness is a new tool to inspect and convert yosys witness traces.
807
+ - write_aiger: Option to write a map file for yosys witness trace
808
+ conversion.
809
+ - yosys-witness: Conversion from and to AIGER witness traces.
810
+
811
+ * Verific support
812
+ - Filename re-writing support for "verific" pass.
813
+
814
+ * Various
815
+ - ABC performance improvements
816
+ - Filename re-writing added for "show -lib".
817
+
818
+ * SmartFusion2 support
819
+ - Added $alu support
820
+ - Added SYSRESET and XTLOSC cells
821
+ - Compatible now with LiberoSoc flow
822
+
823
+ Yosys 0.19 .. Yosys 0.20
824
+ --------------------------
825
+ * New commands and options
826
+ - Added option "-wb" to "read_liberty" pass
827
+
828
+ * Various
829
+ - Added support for $modfloor operator to cxxrtl backend
830
+ - Support build on OpenBSD
831
+ - Fixed smt2 backend use of $shift/$shiftx with negative shift amounts,
832
+ which affects bit/part-select assignments with a dynamic index. Shift
833
+ operators were not affected.
834
+
835
+ * Verific support
836
+ - Proper import of port ranges into Yosys, may result in reversed
837
+ bit-order of top-level ports for some synthesis flows.
838
+
839
+ Yosys 0.18 .. Yosys 0.19
840
+ --------------------------
841
+ * New commands and options
842
+ - Added option "-rom-only" to "memory_libmap" pass
843
+ - Added option "-smtcheck" to "hierarchy" pass
844
+ - Added option "-keepdc" to "memory_libmap" pass
845
+ - Added option "-suffix" to "rename" pass
846
+ - Added "gatemate_foldinv" pass
847
+
848
+ * Formal Verification
849
+ - Added support for $pos cell in btor backend
850
+ - Added the "smtlib2_module" and "smtlib2_comb_expr" attributes
851
+
852
+ * GateMate support
853
+ - Added LUT tree mapping
854
+
855
+ * Verific support
856
+ - Added option "-pp" to "verific -import"
857
+
858
+ Yosys 0.17 .. Yosys 0.18
859
+ --------------------------
860
+ * Various
861
+ - Migrated most flows to use memory_libmap based memory inference
862
+
863
+ * New commands and options
864
+ - Added "memory_libmap" pass
865
+ - Added "memory_bmux2rom" pass - converts muxes to ROMs
866
+ - Added "memory_dff -no-rw-check"
867
+ - Added "opt_ffinv" pass - push inverters through FFs
868
+ - Added "proc_rom" pass - convert switches to ROMs
869
+ - Added "proc -norom" option - will omit the proc_rom pass
870
+ - Added option "-no-rw-check" to synth passes
871
+ - Added "synth_ice40 -spram" option for automatic inference of SB_SPRAM256KA
872
+ - Added options "-nobram" and "-nolutram" to synth_machxo2 pass
873
+
874
+ * Formal Verification
875
+ - Fixed the signedness of $past's return value to be the same as the
876
+ argument's instead of always unsigned.
877
+
878
+ * Verilog
879
+ - Fixed an issue where simplifying case statements by removing unreachable
880
+ cases could result in the wrong signedness being used for comparison with
881
+ the remaining cases
882
+ - Fixed size and signedness computation for expressions containing array
883
+ querying functions
884
+ - Fixed size and signedness computation of functions used in ternary
885
+ expressions or case item expressions
886
+
887
+ * Verific support
888
+ - Proper file location for readmem commands
889
+ - Added "-vlog-libext" option to specify search extension for libraries
890
+
891
+ Yosys 0.16 .. Yosys 0.17
892
+ --------------------------
893
+ * New commands and options
894
+ - Added "write_jny" ( JSON netlist metadata format )
895
+ - Added "tribuf -formal"
896
+
897
+ * SystemVerilog
898
+ - Fixed automatic `nosync` inference for local variables in `always_comb`
899
+ procedures not applying to nested blocks and blocks in functions
900
+
901
+ Yosys 0.15 .. Yosys 0.16
902
+ --------------------------
903
+ * Various
904
+ - Added BTOR2 witness file co-simulation.
905
+ - Simulation calls external vcd2fst for VCD conversion.
906
+ - Added fst2tb pass - generates testbench for the circuit using
907
+ the given top-level module and simulus signal from FST file.
908
+ - yosys-smtbmc: Option to keep going after failed assertions in BMC mode
909
+
910
+ * Verific support
911
+ - Import modules in alphabetic (reproducable) order.
912
+
913
+ Yosys 0.14 .. Yosys 0.15
914
+ --------------------------
915
+
916
+ * Various
917
+ - clk2fflogic: nice names for autogenerated signals
918
+ - simulation include support for all flip-flop types.
919
+ - Added AIGER witness file co-simulation.
920
+
921
+ * Verilog
922
+ - Fixed evaluation of constant functions with variables or arguments with
923
+ reversed dimensions
924
+ - Fixed elaboration of dynamic range assignments where the vector is
925
+ reversed or is not zero-indexed
926
+ - Added frontend support for time scale delay values (e.g., `#1ns`)
927
+
928
+ * SystemVerilog
929
+ - Added support for accessing whole sub-structures in expressions
930
+
931
+ * New commands and options
932
+ - Added glift command, used to create gate-level information flow tracking
933
+ (GLIFT) models by the "constructive mapping" approach
934
+
935
+ * Verific support
936
+ - Ability to override default parser mode for verific -f command.
937
+
938
+ Yosys 0.13 .. Yosys 0.14
939
+ --------------------------
940
+
941
+ * Various
942
+ - Added $bmux and $demux cells and related optimization patterns.
943
+
944
+ * New commands and options
945
+ - Added "bmuxmap" and "dmuxmap" passes
946
+ - Added "-fst" option to "sim" pass for writing FST files
947
+ - Added "-r", "-scope", "-start", "-stop", "-at", "-sim", "-sim-gate",
948
+ "-sim-gold" options to "sim" pass for co-simulation
949
+
950
+ * Anlogic support
951
+ - Added support for BRAMs
952
+
953
+ Yosys 0.12 .. Yosys 0.13
954
+ --------------------------
955
+
956
+ * Various
957
+ - Use "read" command to parse HDL files from Yosys command-line
958
+ - Added "yosys -r <topmodule>" command line option
959
+ - write_verilog: dump zero width sigspecs correctly
960
+
961
+ * SystemVerilog
962
+ - Fixed regression preventing the use array querying functions in case
963
+ expressions and case item expressions
964
+ - Fixed static size casts inadvertently limiting the result width of binary
965
+ operations
966
+ - Fixed static size casts ignoring expression signedness
967
+ - Fixed static size casts not extending unbased unsized literals
968
+ - Added automatic `nosync` inference for local variables in `always_comb`
969
+ procedures which are always assigned before they are used to avoid errant
970
+ latch inference
971
+
972
+ * New commands and options
973
+ - Added "clean_zerowidth" pass
974
+
975
+ * Verific support
976
+ - Add YOSYS to the implicitly defined verilog macros in verific
977
+
978
+ Yosys 0.11 .. Yosys 0.12
979
+ --------------------------
980
+
981
+ * Various
982
+ - Added iopadmap native support for negative-polarity output enable
983
+ - ABC update
984
+
985
+ * SystemVerilog
986
+ - Support parameters using struct as a wiretype
987
+
988
+ * New commands and options
989
+ - Added "-genlib" option to "abc" pass
990
+ - Added "sta" very crude static timing analysis pass
991
+
992
+ * Verific support
993
+ - Fixed memory block size in import
994
+
995
+ * New back-ends
996
+ - Added support for GateMate FPGA from Cologne Chip AG
997
+
998
+ * Intel ALM support
999
+ - Added preliminary Arria V support
1000
+
1001
+
1002
+ Yosys 0.10 .. Yosys 0.11
1003
+ --------------------------
1004
+
1005
+ * Various
1006
+ - Added $aldff and $aldffe (flip-flops with async load) cells
1007
+
1008
+ * SystemVerilog
1009
+ - Fixed an issue which prevented writing directly to a memory word via a
1010
+ connection to an output port
1011
+ - Fixed an issue which prevented unbased unsized literals (e.g., `'1`) from
1012
+ filling the width of a cell input
1013
+ - Fixed an issue where connecting a slice covering the entirety of a signed
1014
+ signal to a cell input would cause a failed assertion
1015
+
1016
+ * Verific support
1017
+ - Importer support for {PRIM,WIDE_OPER}_DFF
1018
+ - Importer support for PRIM_BUFIF1
1019
+ - Option to use Verific without VHDL support
1020
+ - Importer support for {PRIM,WIDE_OPER}_DLATCH{,RS}
1021
+ - Added -cfg option for getting/setting Verific runtime flags
1022
+
1023
+ Yosys 0.9 .. Yosys 0.10
1024
+ --------------------------
1025
+
1026
+ * Various
1027
+ - Added automatic gzip decompression for frontends
1028
+ - Added $_NMUX_ cell type
1029
+ - Added automatic gzip compression (based on filename extension) for backends
1030
+ - Improve attribute and parameter encoding in JSON to avoid ambiguities between
1031
+ bit vectors and strings containing [01xz]*
1032
+ - Improvements in pmgen: subpattern and recursive matches
1033
+ - Support explicit FIRRTL properties
1034
+ - Improvements in pmgen: slices, choices, define, generate
1035
+ - Added "_TECHMAP_WIREINIT_*_" parameter and "_TECHMAP_REMOVEINIT_*_" wire for "techmap" pass
1036
+ - Added +/mul2dsp.v for decomposing wide multipliers to custom-sized ones
1037
+ - Added new frontend: rpc
1038
+ - Added --version and -version as aliases for -V
1039
+ - Improve yosys-smtbmc "solver not found" handling
1040
+ - Improved support of $readmem[hb] Memory Content File inclusion
1041
+ - Added CXXRTL backend
1042
+ - Use YosysHQ/abc instead of upstream berkeley-abc/abc
1043
+ - Added WASI platform support.
1044
+ - Added extmodule support to firrtl backend
1045
+ - Added $divfloor and $modfloor cells
1046
+ - Added $adffe, $dffsre, $sdff, $sdffe, $sdffce, $adlatch cells
1047
+ - Added "_TECHMAP_CELLNAME_" parameter for "techmap" pass
1048
+ - Added firrtl backend support for generic parameters in blackbox components
1049
+ - Added $meminit_v2 cells (with support for write mask)
1050
+ - Added $mem_v2, $memrd_v2, $memwr_v2, with the following features:
1051
+ - write priority masks, per write/write port pair
1052
+ - transparency and undefined collision behavior masks, per read/write port pair
1053
+ - read port reset and initialization
1054
+ - wide ports (accessing a naturally aligned power-of-two number of memory cells)
1055
+
1056
+ * New commands and options
1057
+ - Added "write_xaiger" backend
1058
+ - Added "read_xaiger"
1059
+ - Added "abc9" pass for timing-aware techmapping (experimental, FPGA only)
1060
+ - Added "synth -abc9" (experimental)
1061
+ - Added "script -scriptwire"
1062
+ - Added "clkbufmap" pass
1063
+ - Added "extractinv" pass and "invertible_pin" attribute
1064
+ - Added "proc_clean -quiet"
1065
+ - Added "proc_prune" pass
1066
+ - Added "stat -tech cmos"
1067
+ - Added "opt_share" pass, run as part of "opt -full"
1068
+ - Added "-match-init" option to "dff2dffs" pass
1069
+ - Added "equiv_opt -multiclock"
1070
+ - Added "techmap_autopurge" support to techmap
1071
+ - Added "add -mod <modname[s]>"
1072
+ - Added "paramap" pass
1073
+ - Added "portlist" command
1074
+ - Added "check -mapped"
1075
+ - Added "check -allow-tbuf"
1076
+ - Added "autoname" pass
1077
+ - Added "write_verilog -extmem"
1078
+ - Added "opt_mem" pass
1079
+ - Added "scratchpad" pass
1080
+ - Added "fminit" pass
1081
+ - Added "opt_lut_ins" pass
1082
+ - Added "logger" pass
1083
+ - Added "show -nobg"
1084
+ - Added "exec" command
1085
+ - Added "design -delete"
1086
+ - Added "design -push-copy"
1087
+ - Added "qbfsat" command
1088
+ - Added "select -unset"
1089
+ - Added "dfflegalize" pass
1090
+ - Removed "opt_expr -clkinv" option, made it the default
1091
+ - Added "proc -nomux
1092
+ - Merged "dffsr2dff", "opt_rmdff", "dff2dffe", "dff2dffs", "peepopt.dffmux" passes into a new "opt_dff" pass
1093
+
1094
+ * SystemVerilog
1095
+ - Added checking of always block types (always_comb, always_latch and always_ff)
1096
+ - Added support for wildcard port connections (.*)
1097
+ - Added support for enum typedefs
1098
+ - Added support for structs and packed unions.
1099
+ - Allow constant function calls in for loops and generate if and case
1100
+ - Added support for static cast
1101
+ - Added support for logic typed parameters
1102
+ - Fixed generate scoping issues
1103
+ - Added support for real-valued parameters
1104
+ - Allow localparams in constant functions
1105
+ - Module name scope support
1106
+ - Support recursive functions using ternary expressions
1107
+ - Extended support for integer types
1108
+ - Support for parameters without default values
1109
+ - Allow globals in one file to depend on globals in another
1110
+ - Added support for: *=, /=, %=, <<=, >>=, <<<=, >>>=
1111
+ - Added support for parsing the 'bind' construct
1112
+ - support declaration in procedural for initialization
1113
+ - support declaration in generate for initialization
1114
+ - Support wand and wor of data types
1115
+
1116
+ * Verific support
1117
+ - Added "verific -L"
1118
+ - Add Verific SVA support for "always" properties
1119
+ - Add Verific support for SVA nexttime properties
1120
+ - Improve handling of verific primitives in "verific -import -V" mode
1121
+ - Import attributes for wires
1122
+ - Support VHDL enums
1123
+ - Added support for command files
1124
+
1125
+ * New back-ends
1126
+ - Added initial EFINIX support
1127
+ - Added Intel ALM: alternative synthesis for Intel FPGAs
1128
+ - Added initial Nexus support
1129
+ - Added initial MachXO2 support
1130
+ - Added initial QuickLogic PolarPro 3 support
1131
+
1132
+ * ECP5 support
1133
+ - Renamed labels/options in synth_ecp5 (e.g. dram -> map_lutram; -nodram -> -nolutram)
1134
+ - Added "synth_ecp5 -abc9" (experimental)
1135
+ - Added "synth_ecp5 -nowidelut"
1136
+ - "synth_ecp5" to now infer DSP blocks (-nodsp to disable, experimental)
1137
+
1138
+ * iCE40 support
1139
+ - Added "synth_ice40 -abc9" (experimental)
1140
+ - Added "synth_ice40 -device"
1141
+ - Renamed labels/options in synth_ice40 (e.g. dram -> map_lutram; -nodram -> -nolutram)
1142
+ - Added "ice40_wrapcarry" to encapsulate SB_LUT+SB_CARRY pairs for techmapping
1143
+ - Removed "ice40_unlut"
1144
+ - Added "ice40_dsp" for Lattice iCE40 DSP packing
1145
+ - "synth_ice40 -dsp" to infer DSP blocks
1146
+
1147
+ * Xilinx support
1148
+ - Added "synth_xilinx -abc9" (experimental)
1149
+ - Added "synth_xilinx -nocarry"
1150
+ - Added "synth_xilinx -nowidelut"
1151
+ - "synth_xilinx" to now infer wide multiplexers (-widemux <min> to enable)
1152
+ - Renamed labels/options in synth_xilinx (e.g. dram -> map_lutram; -nodram -> -nolutram)
1153
+ - Added "synth_xilinx -family xc6s" for Spartan 6 support (experimental)
1154
+ - Added "synth_xilinx -ise" (experimental)
1155
+ - Added "synth_xilinx -iopad"
1156
+ - "synth_xilinx" now automatically inserts clock buffers (add -noclkbuf to disable)
1157
+ - Added "xilinx_srl" for Xilinx shift register extraction
1158
+ - Removed "shregmap -tech xilinx" (superseded by "xilinx_srl")
1159
+ - Added "xilinx_dsp" for Xilinx DSP packing
1160
+ - "synth_xilinx" to now infer DSP blocks (-nodsp to disable)
1161
+ - Added latch support to synth_xilinx
1162
+ - Added support for flip-flops with synchronous reset to synth_xilinx
1163
+ - Added support for flip-flops with reset and enable to synth_xilinx
1164
+ - Added "xilinx_dffopt" pass
1165
+ - Added "synth_xilinx -dff"
1166
+
1167
+ * Intel support
1168
+ - Renamed labels in synth_intel (e.g. bram -> map_bram)
1169
+ - synth_intel: cyclone10 -> cyclone10lp, a10gx -> arria10gx
1170
+ - Added "intel_alm -abc9" (experimental)
1171
+
1172
+ * CoolRunner2 support
1173
+ - Separate and improve buffer cell insertion pass
1174
+ - Use extract_counter to optimize counters
1175
+
1176
+ Yosys 0.8 .. Yosys 0.9
1177
+ ----------------------
1178
+
1179
+ * Various
1180
+ - Many bugfixes and small improvements
1181
+ - Added support for SystemVerilog interfaces and modports
1182
+ - Added "write_edif -attrprop"
1183
+ - Added "opt_lut" pass
1184
+ - Added "gate2lut.v" techmap rule
1185
+ - Added "rename -src"
1186
+ - Added "equiv_opt" pass
1187
+ - Added "flowmap" LUT mapping pass
1188
+ - Added "rename -wire" to rename cells based on the wires they drive
1189
+ - Added "bugpoint" for creating minimised testcases
1190
+ - Added "write_edif -gndvccy"
1191
+ - "write_verilog" to escape Verilog keywords
1192
+ - Fixed sign handling of real constants
1193
+ - "write_verilog" to write initial statement for initial flop state
1194
+ - Added pmgen pattern matcher generator
1195
+ - Fixed opt_rmdff handling of $_DFFSR_???_ and $_DLATCHSR_???_
1196
+ - Added "setundef -params" to replace undefined cell parameters
1197
+ - Renamed "yosys -D" to "yosys -U", added "yosys -D" to set Verilog defines
1198
+ - Fixed handling of defparam when default_nettype is none
1199
+ - Fixed "wreduce" flipflop handling
1200
+ - Fixed FIRRTL to Verilog process instance subfield assignment
1201
+ - Added "write_verilog -siminit"
1202
+ - Several fixes and improvements for mem2reg memories
1203
+ - Fixed handling of task output ports in clocked always blocks
1204
+ - Improved handling of and-with-1 and or-with-0 in "opt_expr"
1205
+ - Added "read_aiger" frontend
1206
+ - Added "mutate" pass
1207
+ - Added "hdlname" attribute
1208
+ - Added "rename -output"
1209
+ - Added "read_ilang -lib"
1210
+ - Improved "proc" full_case detection and handling
1211
+ - Added "whitebox" and "lib_whitebox" attributes
1212
+ - Added "read_verilog -nowb", "flatten -wb" and "wbflip"
1213
+ - Added Python bindings and support for Python plug-ins
1214
+ - Added "pmux2shiftx"
1215
+ - Added log_debug framework for reduced default verbosity
1216
+ - Improved "opt_expr" and "opt_clean" handling of (partially) undriven and/or unused wires
1217
+ - Added "peepopt" peephole optimisation pass using pmgen
1218
+ - Added approximate support for SystemVerilog "var" keyword
1219
+ - Added parsing of "specify" blocks into $specrule and $specify[23]
1220
+ - Added support for attributes on parameters and localparams
1221
+ - Added support for parsing attributes on port connections
1222
+ - Added "wreduce -keepdc"
1223
+ - Added support for optimising $dffe and $_DFFE_* cells in "opt_rmdff"
1224
+ - Added Verilog wand/wor wire type support
1225
+ - Added support for elaboration system tasks
1226
+ - Added "muxcover -mux{4,8,16}=<cost>"
1227
+ - Added "muxcover -dmux=<cost>"
1228
+ - Added "muxcover -nopartial"
1229
+ - Added "muxpack" pass
1230
+ - Added "pmux2shiftx -norange"
1231
+ - Added support for "~" in filename parsing
1232
+ - Added "read_verilog -pwires" feature to turn parameters into wires
1233
+ - Fixed sign extension of unsized constants with 'bx and 'bz MSB
1234
+ - Fixed genvar to be a signed type
1235
+ - Added support for attributes on case rules
1236
+ - Added "upto" and "offset" to JSON frontend and backend
1237
+ - Several liberty file parser improvements
1238
+ - Fixed handling of more complex BRAM patterns
1239
+ - Add "write_aiger -I -O -B"
1240
+
1241
+ * Formal Verification
1242
+ - Added $changed support to read_verilog
1243
+ - Added "read_verilog -noassert -noassume -assert-assumes"
1244
+ - Added btor ops for $mul, $div, $mod and $concat
1245
+ - Added yosys-smtbmc support for btor witnesses
1246
+ - Added "supercover" pass
1247
+ - Fixed $global_clock handling vs autowire
1248
+ - Added $dffsr support to "async2sync"
1249
+ - Added "fmcombine" pass
1250
+ - Added memory init support in "write_btor"
1251
+ - Added "cutpoint" pass
1252
+ - Changed "ne" to "neq" in btor2 output
1253
+ - Added support for SVA "final" keyword
1254
+ - Added "fmcombine -initeq -anyeq"
1255
+ - Added timescale and generated-by header to yosys-smtbmc vcd output
1256
+ - Improved BTOR2 handling of undriven wires
1257
+
1258
+ * Verific support
1259
+ - Enabled Verific flags vhdl_support_variable_slice and veri_elaborate_top_level_modules_having_interface_ports
1260
+ - Improved support for asymmetric memories
1261
+ - Added "verific -chparam"
1262
+ - Fixed "verific -extnets" for more complex situations
1263
+ - Added "read -verific" and "read -noverific"
1264
+ - Added "hierarchy -chparam"
1265
+
1266
+ * New back-ends
1267
+ - Added initial Anlogic support
1268
+ - Added initial SmartFusion2 and IGLOO2 support
1269
+
1270
+ * ECP5 support
1271
+ - Added "synth_ecp5 -nowidelut"
1272
+ - Added BRAM inference support to "synth_ecp5"
1273
+ - Added support for transforming Diamond IO and flipflop primitives
1274
+
1275
+ * iCE40 support
1276
+ - Added "ice40_unlut" pass
1277
+ - Added "synth_ice40 -relut"
1278
+ - Added "synth_ice40 -noabc"
1279
+ - Added "synth_ice40 -dffe_min_ce_use"
1280
+ - Added DSP inference support using pmgen
1281
+ - Added support for initialising BRAM primitives from a file
1282
+ - Added iCE40 Ultra RGB LED driver cells
1283
+
1284
+ * Xilinx support
1285
+ - Use "write_edif -pvector bra" for Xilinx EDIF files
1286
+ - Fixes for VPR place and route support with "synth_xilinx"
1287
+ - Added more cell simulation models
1288
+ - Added "synth_xilinx -family"
1289
+ - Added "stat -tech xilinx" to estimate logic cell usage
1290
+ - Added "synth_xilinx -nocarry"
1291
+ - Added "synth_xilinx -nowidelut"
1292
+ - "synth_xilinx" to now infer hard shift registers (-nosrl to disable)
1293
+ - Added support for mapping RAM32X1D
1294
+
1295
+ Yosys 0.7 .. Yosys 0.8
1296
+ ----------------------
1297
+
1298
+ * Various
1299
+ - Many bugfixes and small improvements
1300
+ - Strip debug symbols from installed binary
1301
+ - Replace -ignore_redef with -[no]overwrite in front-ends
1302
+ - Added write_verilog hex dump support, add -nohex option
1303
+ - Added "write_verilog -decimal"
1304
+ - Added "scc -set_attr"
1305
+ - Added "verilog_defines" command
1306
+ - Remember defines from one read_verilog to next
1307
+ - Added support for hierarchical defparam
1308
+ - Added FIRRTL back-end
1309
+ - Improved ABC default scripts
1310
+ - Added "design -reset-vlog"
1311
+ - Added "yosys -W regex", "yosys -w regex", and "yosys -e regex"
1312
+ - Added Verilog $rtoi and $itor support
1313
+ - Added "check -initdrv"
1314
+ - Added "read_blif -wideports"
1315
+ - Added support for SystemVerilog "++" and "--" operators
1316
+ - Added support for SystemVerilog unique, unique0, and priority case
1317
+ - Added "write_edif" options for edif "flavors"
1318
+ - Added support for resetall compiler directive
1319
+ - Added simple C beck-end (bitwise combinatorical only atm)
1320
+ - Added $_ANDNOT_ and $_ORNOT_ cell types
1321
+ - Added cell library aliases to "abc -g"
1322
+ - Added "setundef -anyseq"
1323
+ - Added "chtype" command
1324
+ - Added "design -import"
1325
+ - Added "write_table" command
1326
+ - Added "read_json" command
1327
+ - Added "sim" command
1328
+ - Added "extract_fa" and "extract_reduce" commands
1329
+ - Added "extract_counter" command
1330
+ - Added "opt_demorgan" command
1331
+ - Added support for $size and $bits SystemVerilog functions
1332
+ - Added "blackbox" command
1333
+ - Added "ltp" command
1334
+ - Added support for editline as replacement for readline
1335
+ - Added warnings for driver-driver conflicts between FFs (and other cells) and constants
1336
+ - Added "yosys -E" for creating Makefile dependencies files
1337
+ - Added "synth -noshare"
1338
+ - Added "memory_nordff"
1339
+ - Added "setundef -undef -expose -anyconst"
1340
+ - Added "expose -input"
1341
+ - Added specify/specparam parser support (simply ignore them)
1342
+ - Added "write_blif -inames -iattr"
1343
+ - Added "hierarchy -simcheck"
1344
+ - Added an option to statically link abc into yosys
1345
+ - Added protobuf back-end
1346
+ - Added BLIF parsing support for .conn and .cname
1347
+ - Added read_verilog error checking for reg/wire/logic misuse
1348
+ - Added "make coverage" and ENABLE_GCOV build option
1349
+
1350
+ * Changes in Yosys APIs
1351
+ - Added ConstEval defaultval feature
1352
+ - Added {get,set}_src_attribute() methods on RTLIL::AttrObject
1353
+ - Added SigSpec::is_fully_ones() and Const::is_fully_ones()
1354
+ - Added log_file_warning() and log_file_error() functions
1355
+
1356
+ * Formal Verification
1357
+ - Added "write_aiger"
1358
+ - Added "yosys-smtbmc --aig"
1359
+ - Added "always <positive_int>" to .smtc format
1360
+ - Added $cover cell type and support for cover properties
1361
+ - Added $fair/$live cell type and support for liveness properties
1362
+ - Added smtbmc support for memory vcd dumping
1363
+ - Added "chformal" command
1364
+ - Added "write_smt2 -stbv" and "write_smt2 -stdt"
1365
+ - Fix equiv_simple, old behavior now available with "equiv_simple -short"
1366
+ - Change to Yices2 as default SMT solver (it is GPL now)
1367
+ - Added "yosys-smtbmc --presat" (now default in SBY)
1368
+ - Added "yosys-smtbmc --smtc-init --smtc-top --noinit"
1369
+ - Added a brand new "write_btor" command for BTOR2
1370
+ - Added clk2fflogic memory support and other improvements
1371
+ - Added "async memory write" support to write_smt2
1372
+ - Simulate clock toggling in yosys-smtbmc VCD output
1373
+ - Added $allseq/$allconst cells for EA-solving
1374
+ - Make -nordff the default in "prep"
1375
+ - Added (* gclk *) attribute
1376
+ - Added "async2sync" pass for single-clock designs with async resets
1377
+
1378
+ * Verific support
1379
+ - Many improvements in Verific front-end
1380
+ - Added proper handling of concurent SVA properties
1381
+ - Map "const" and "rand const" to $anyseq/$anyconst
1382
+ - Added "verific -import -flatten" and "verific -import -extnets"
1383
+ - Added "verific -vlog-incdir -vlog-define -vlog-libdir"
1384
+ - Remove PSL support (because PSL has been removed in upstream Verific)
1385
+ - Improve integration with "hierarchy" command design elaboration
1386
+ - Added YOSYS_NOVERIFIC for running non-verific test cases with verific bin
1387
+ - Added simpilied "read" command that automatically uses verific if available
1388
+ - Added "verific -set-<severity> <msg_id>.."
1389
+ - Added "verific -work <libname>"
1390
+
1391
+ * New back-ends
1392
+ - Added initial Coolrunner-II support
1393
+ - Added initial eASIC support
1394
+ - Added initial ECP5 support
1395
+
1396
+ * GreenPAK Support
1397
+ - Added support for GP_DLATCH, GP_SPI, GP_DCMx, GP_COUNTx, etc.
1398
+
1399
+ * iCE40 Support
1400
+ - Add "synth_ice40 -vpr"
1401
+ - Add "synth_ice40 -nodffe"
1402
+ - Add "synth_ice40 -json"
1403
+ - Add Support for UltraPlus cells
1404
+
1405
+ * MAX10 and Cyclone IV Support
1406
+ - Added initial version of metacommand "synth_intel".
1407
+ - Improved write_verilog command to produce VQM netlist for Quartus Prime.
1408
+ - Added support for MAX10 FPGA family synthesis.
1409
+ - Added support for Cyclone IV family synthesis.
1410
+ - Added example of implementation for DE2i-150 board.
1411
+ - Added example of implementation for MAX10 development kit.
1412
+ - Added LFSR example from Asic World.
1413
+ - Added "dffinit -highlow" for mapping to Intel primitives
1414
+
1415
+
1416
+ Yosys 0.6 .. Yosys 0.7
1417
+ ----------------------
1418
+
1419
+ * Various
1420
+ - Added "yosys -D" feature
1421
+ - Added support for installed plugins in $(DATDIR)/plugins/
1422
+ - Renamed opt_const to opt_expr
1423
+ - Renamed opt_share to opt_merge
1424
+ - Added "prep -flatten" and "synth -flatten"
1425
+ - Added "prep -auto-top" and "synth -auto-top"
1426
+ - Using "mfs" and "lutpack" in ABC lut mapping
1427
+ - Support for abstract modules in chparam
1428
+ - Cleanup abstract modules at end of "hierarchy -top"
1429
+ - Added tristate buffer support to iopadmap
1430
+ - Added opt_expr support for div/mod by power-of-two
1431
+ - Added "select -assert-min <N> -assert-max <N>"
1432
+ - Added "attrmvcp" pass
1433
+ - Added "attrmap" command
1434
+ - Added "tee +INT -INT"
1435
+ - Added "zinit" pass
1436
+ - Added "setparam -type"
1437
+ - Added "shregmap" pass
1438
+ - Added "setundef -init"
1439
+ - Added "nlutmap -assert"
1440
+ - Added $sop cell type and "abc -sop -I <num> -P <num>"
1441
+ - Added "dc2" to default ABC scripts
1442
+ - Added "deminout"
1443
+ - Added "insbuf" command
1444
+ - Added "prep -nomem"
1445
+ - Added "opt_rmdff -keepdc"
1446
+ - Added "prep -nokeepdc"
1447
+ - Added initial version of "synth_gowin"
1448
+ - Added "fsm_expand -full"
1449
+ - Added support for fsm_encoding="user"
1450
+ - Many improvements in GreenPAK4 support
1451
+ - Added black box modules for all Xilinx 7-series lib cells
1452
+ - Added synth_ice40 support for latches via logic loops
1453
+ - Fixed ice40_opt lut unmapping, added "ice40_opt -unlut"
1454
+
1455
+ * Build System
1456
+ - Added ABCEXTERNAL and ABCURL make variables
1457
+ - Added BINDIR, LIBDIR, and DATDIR make variables
1458
+ - Added PKG_CONFIG make variable
1459
+ - Added SEED make variable (for "make test")
1460
+ - Added YOSYS_VER_STR make variable
1461
+ - Updated min GCC requirement to GCC 4.8
1462
+ - Updated required Bison version to Bison 3.x
1463
+
1464
+ * Internal APIs
1465
+ - Added ast.h to exported headers
1466
+ - Added ScriptPass helper class for script-like passes
1467
+ - Added CellEdgesDatabase API
1468
+
1469
+ * Front-ends and Back-ends
1470
+ - Added filename glob support to all front-ends
1471
+ - Added avail (black-box) module params to ilang format
1472
+ - Added $display %m support
1473
+ - Added support for $stop Verilog system task
1474
+ - Added support for SystemVerilog packages
1475
+ - Fixed procedural assignments to non-unique lvalues, e.g. {y,y} = {a,b}
1476
+ - Added support for "active high" and "active low" latches in read_blif and write_blif
1477
+ - Use init value "2" for all uninitialized FFs in BLIF back-end
1478
+ - Added "read_blif -sop"
1479
+ - Added "write_blif -noalias"
1480
+ - Added various write_blif options for VTR support
1481
+ - write_json: also write module attributes.
1482
+ - Added "write_verilog -nodec -nostr -defparam"
1483
+ - Added "read_verilog -norestrict -assume-asserts"
1484
+ - Added support for bus interfaces to "read_liberty -lib"
1485
+ - Added liberty parser support for types within cell decls
1486
+ - Added "write_verilog -renameprefix -v"
1487
+ - Added "write_edif -nogndvcc"
1488
+
1489
+ * Formal Verification
1490
+ - Support for hierarchical designs in smt2 back-end
1491
+ - Yosys-smtbmc: Support for hierarchical VCD dumping
1492
+ - Added $initstate cell type and vlog function
1493
+ - Added $anyconst and $anyseq cell types and vlog functions
1494
+ - Added printing of code loc of failed asserts to yosys-smtbmc
1495
+ - Added memory_memx pass, "memory -memx", and "prep -memx"
1496
+ - Added "proc_mux -ifx"
1497
+ - Added "yosys-smtbmc -g"
1498
+ - Deprecated "write_smt2 -regs" (by default on now)
1499
+ - Made "write_smt2 -bv -mem" default, added "write_smt2 -nobv -nomem"
1500
+ - Added support for memories to smtio.py
1501
+ - Added "yosys-smtbmc --dump-vlogtb"
1502
+ - Added "yosys-smtbmc --smtc --dump-smtc"
1503
+ - Added "yosys-smtbmc --dump-all"
1504
+ - Added assertpmux command
1505
+ - Added "yosys-smtbmc --unroll"
1506
+ - Added $past, $stable, $rose, $fell SVA functions
1507
+ - Added "yosys-smtbmc --noinfo and --dummy"
1508
+ - Added "yosys-smtbmc --noincr"
1509
+ - Added "yosys-smtbmc --cex <filename>"
1510
+ - Added $ff and $_FF_ cell types
1511
+ - Added $global_clock verilog syntax support for creating $ff cells
1512
+ - Added clk2fflogic
1513
+
1514
+
1515
+ Yosys 0.5 .. Yosys 0.6
1516
+ ----------------------
1517
+
1518
+ * Various
1519
+ - Added Contributor Covenant Code of Conduct
1520
+ - Various improvements in dict<> and pool<>
1521
+ - Added hashlib::mfp and refactored SigMap
1522
+ - Improved support for reals as module parameters
1523
+ - Various improvements in SMT2 back-end
1524
+ - Added "keep_hierarchy" attribute
1525
+ - Verilog front-end: define `BLACKBOX in -lib mode
1526
+ - Added API for converting internal cells to AIGs
1527
+ - Added ENABLE_LIBYOSYS Makefile option
1528
+ - Removed "techmap -share_map" (use "-map +/filename" instead)
1529
+ - Switched all Python scripts to Python 3
1530
+ - Added support for $display()/$write() and $finish() to Verilog front-end
1531
+ - Added "yosys-smtbmc" formal verification flow
1532
+ - Added options for clang sanitizers to Makefile
1533
+
1534
+ * New commands and options
1535
+ - Added "scc -expect <N> -nofeedback"
1536
+ - Added "proc_dlatch"
1537
+ - Added "check"
1538
+ - Added "select %xe %cie %coe %M %C %R"
1539
+ - Added "sat -dump_json" (WaveJSON format)
1540
+ - Added "sat -tempinduct-baseonly -tempinduct-inductonly"
1541
+ - Added "sat -stepsize" and "sat -tempinduct-step"
1542
+ - Added "sat -show-regs -show-public -show-all"
1543
+ - Added "write_json" (Native Yosys JSON format)
1544
+ - Added "write_blif -attr"
1545
+ - Added "dffinit"
1546
+ - Added "chparam"
1547
+ - Added "muxcover"
1548
+ - Added "pmuxtree"
1549
+ - Added memory_bram "make_outreg" feature
1550
+ - Added "splice -wires"
1551
+ - Added "dff2dffe -direct-match"
1552
+ - Added simplemap $lut support
1553
+ - Added "read_blif"
1554
+ - Added "opt_share -share_all"
1555
+ - Added "aigmap"
1556
+ - Added "write_smt2 -mem -regs -wires"
1557
+ - Added "memory -nordff"
1558
+ - Added "write_smv"
1559
+ - Added "synth -nordff -noalumacc"
1560
+ - Added "rename -top new_name"
1561
+ - Added "opt_const -clkinv"
1562
+ - Added "synth -nofsm"
1563
+ - Added "miter -assert"
1564
+ - Added "read_verilog -noautowire"
1565
+ - Added "read_verilog -nodpi"
1566
+ - Added "tribuf"
1567
+ - Added "lut2mux"
1568
+ - Added "nlutmap"
1569
+ - Added "qwp"
1570
+ - Added "test_cell -noeval"
1571
+ - Added "edgetypes"
1572
+ - Added "equiv_struct"
1573
+ - Added "equiv_purge"
1574
+ - Added "equiv_mark"
1575
+ - Added "equiv_add -try -cell"
1576
+ - Added "singleton"
1577
+ - Added "abc -g -luts"
1578
+ - Added "torder"
1579
+ - Added "write_blif -cname"
1580
+ - Added "submod -copy"
1581
+ - Added "dffsr2dff"
1582
+ - Added "stat -liberty"
1583
+
1584
+ * Synthesis metacommands
1585
+ - Various improvements in synth_xilinx
1586
+ - Added synth_ice40 and synth_greenpak4
1587
+ - Added "prep" metacommand for "synthesis lite"
1588
+
1589
+ * Cell library changes
1590
+ - Added cell types to "help" system
1591
+ - Added $meminit cell type
1592
+ - Added $assume cell type
1593
+ - Added $_MUX4_, $_MUX8_, and $_MUX16_ cells
1594
+ - Added $tribuf and $_TBUF_ cell types
1595
+ - Added read-enable to memory model
1596
+
1597
+ * YosysJS
1598
+ - Various improvements in emscripten build
1599
+ - Added alternative webworker-based JS API
1600
+ - Added a few example applications
1601
+
1602
+
1603
+ Yosys 0.4 .. Yosys 0.5
1604
+ ----------------------
1605
+
1606
+ * API changes
1607
+ - Added log_warning()
1608
+ - Added eval_select_args() and eval_select_op()
1609
+ - Added cell->known(), cell->input(portname), cell->output(portname)
1610
+ - Skip blackbox modules in design->selected_modules()
1611
+ - Replaced std::map<> and std::set<> with dict<> and pool<>
1612
+ - New SigSpec::extend() is what used to be SigSpec::extend_u0()
1613
+ - Added YS_OVERRIDE, YS_FINAL, YS_ATTRIBUTE, YS_NORETURN
1614
+
1615
+ * Cell library changes
1616
+ - Added flip-flops with enable ($dffe etc.)
1617
+ - Added $equiv cells for equivalence checking framework
1618
+
1619
+ * Various
1620
+ - Updated ABC to hg rev 61ad5f908c03
1621
+ - Added clock domain partitioning to ABC pass
1622
+ - Improved plugin building (see "yosys-config --build")
1623
+ - Added ENABLE_NDEBUG Makefile flag for high-performance builds
1624
+ - Added "yosys -d", "yosys -L" and other driver improvements
1625
+ - Added support for multi-bit (array) cell ports to "write_edif"
1626
+ - Now printing most output to stdout, not stderr
1627
+ - Added "onehot" attribute (set by "fsm_map")
1628
+ - Various performance improvements
1629
+ - Vastly improved Xilinx flow
1630
+ - Added "make unsintall"
1631
+
1632
+ * Equivalence checking
1633
+ - Added equivalence checking commands:
1634
+ equiv_make equiv_simple equiv_status
1635
+ equiv_induct equiv_miter
1636
+ equiv_add equiv_remove
1637
+
1638
+ * Block RAM support:
1639
+ - Added "memory_bram" command
1640
+ - Added BRAM support to Xilinx flow
1641
+
1642
+ * Other New Commands and Options
1643
+ - Added "dff2dffe"
1644
+ - Added "fsm -encfile"
1645
+ - Added "dfflibmap -prepare"
1646
+ - Added "write_blid -unbuf -undef -blackbox"
1647
+ - Added "write_smt2" for writing SMT-LIBv2 files
1648
+ - Added "test_cell -w -muxdiv"
1649
+ - Added "select -read"
1650
+
1651
+
1652
+ Yosys 0.3.0 .. Yosys 0.4
1653
+ ------------------------
1654
+
1655
+ * Platform Support
1656
+ - Added support for mxe-based cross-builds for win32
1657
+ - Added sourcecode-export as VisualStudio project
1658
+ - Added experimental EMCC (JavaScript) support
1659
+
1660
+ * Verilog Frontend
1661
+ - Added -sv option for SystemVerilog (and automatic *.sv file support)
1662
+ - Added support for real-valued constants and constant expressions
1663
+ - Added support for non-standard "via_celltype" attribute on task/func
1664
+ - Added support for non-standard "module mod_name(...);" syntax
1665
+ - Added support for non-standard """ macro bodies
1666
+ - Added support for array with more than one dimension
1667
+ - Added support for $readmemh and $readmemb
1668
+ - Added support for DPI functions
1669
+
1670
+ * Changes in internal cell library
1671
+ - Added $shift and $shiftx cell types
1672
+ - Added $alu, $lcu, $fa and $macc cell types
1673
+ - Removed $bu0 and $safe_pmux cell types
1674
+ - $mem/$memwr WR_EN input is now a per-data-bit enable signal
1675
+ - Added $_NAND_ $_NOR_ $_XNOR_ $_AOI3_ $_OAI3_ $_AOI4_ $_OAI4_
1676
+ - Renamed ports of $lut cells (from I->O to A->Y)
1677
+ - Renamed $_INV_ to $_NOT_
1678
+
1679
+ * Changes for simple synthesis flows
1680
+ - There is now a "synth" command with a recommended default script
1681
+ - Many improvements in synthesis of arithmetic functions to gates
1682
+ - Multipliers and adders with many operands are using carry-save adder trees
1683
+ - Remaining adders are now implemented using Brent-Kung carry look-ahead adders
1684
+ - Various new high-level optimizations on RTL netlist
1685
+ - Various improvements in FSM optimization
1686
+ - Updated ABC to hg 5b5af75f1dda (from 2014-11-07)
1687
+
1688
+ * Changes in internal APIs and RTLIL
1689
+ - Added log_id() and log_cell() helper functions
1690
+ - Added function-like cell creation helpers
1691
+ - Added GetSize() function (like .size() but with int)
1692
+ - Major refactoring of RTLIL::Module and related classes
1693
+ - Major refactoring of RTLIL::SigSpec and related classes
1694
+ - Now RTLIL::IdString is essentially an int
1695
+ - Added macros for code coverage counters
1696
+ - Added some Makefile magic for pretty make logs
1697
+ - Added "kernel/yosys.h" with all the core definitions
1698
+ - Changed a lot of code from FILE* to c++ streams
1699
+ - Added RTLIL::Monitor API and "trace" command
1700
+ - Added "Yosys" C++ namespace
1701
+
1702
+ * Changes relevant to SAT solving
1703
+ - Added ezSAT::keep_cnf() and ezSAT::non_incremental()
1704
+ - Added native ezSAT support for vector shift ops
1705
+ - Updated MiniSAT to git 37dc6c67e2 (from 2013-09-25)
1706
+
1707
+ * New commands (or large improvements to commands)
1708
+ - Added "synth" command with default script
1709
+ - Added "share" (finally some real resource sharing)
1710
+ - Added "memory_share" (reduce number of ports on memories)
1711
+ - Added "wreduce" and "alumacc" commands
1712
+ - Added "opt -keepdc -fine -full -fast"
1713
+ - Added some "test_*" commands
1714
+
1715
+ * Various other changes
1716
+ - Added %D and %c select operators
1717
+ - Added support for labels in yosys scripts
1718
+ - Added support for here-documents in yosys scripts
1719
+ - Support "+/" prefix for files from proc_share_dir
1720
+ - Added "autoidx" statement to ilang language
1721
+ - Switched from "yosys-svgviewer" to "xdot"
1722
+ - Renamed "stdcells.v" to "techmap.v"
1723
+ - Various bug fixes and small improvements
1724
+ - Improved welcome and bye messages
1725
+
1726
+
1727
+ Yosys 0.2.0 .. Yosys 0.3.0
1728
+ --------------------------
1729
+
1730
+ * Driver program and overall behavior:
1731
+ - Added "design -push" and "design -pop"
1732
+ - Added "tee" command for redirecting log output
1733
+
1734
+ * Changes in the internal cell library:
1735
+ - Added $dlatchsr and $_DLATCHSR_???_ cell types
1736
+
1737
+ * Improvements in Verilog frontend:
1738
+ - Improved support for const functions (case, always, repeat)
1739
+ - The generate..endgenerate keywords are now optional
1740
+ - Added support for arrays of module instances
1741
+ - Added support for "`default_nettype" directive
1742
+ - Added support for "`line" directive
1743
+
1744
+ * Other front- and back-ends:
1745
+ - Various changes to "write_blif" options
1746
+ - Various improvements in EDIF backend
1747
+ - Added "vhdl2verilog" pseudo-front-end
1748
+ - Added "verific" pseudo-front-end
1749
+
1750
+ * Improvements in technology mapping:
1751
+ - Added support for recursive techmap
1752
+ - Added CONSTMSK and CONSTVAL features to techmap
1753
+ - Added _TECHMAP_CONNMAP_*_ feature to techmap
1754
+ - Added _TECHMAP_REPLACE_ feature to techmap
1755
+ - Added "connwrappers" command for wrap-extract-unwrap method
1756
+ - Added "extract -map %<design_name>" feature
1757
+ - Added "extract -ignore_param ..." and "extract -ignore_parameters"
1758
+ - Added "techmap -max_iter" option
1759
+
1760
+ * Improvements to "eval" and "sat" framework:
1761
+ - Now include a copy of Minisat (with build fixes applied)
1762
+ - Switched to Minisat::SimpSolver as SAT back-end
1763
+ - Added "sat -dump_vcd" feature
1764
+ - Added "sat -dump_cnf" feature
1765
+ - Added "sat -initsteps <N>" feature
1766
+ - Added "freduce -stop <N>" feature
1767
+ - Added "freduce -dump <prefix>" feature
1768
+
1769
+ * Integration with ABC:
1770
+ - Updated ABC rev to 7600ffb9340c
1771
+
1772
+ * Improvements in the internal APIs:
1773
+ - Added RTLIL::Module::add... helper methods
1774
+ - Various build fixes for OSX (Darwin) and OpenBSD
1775
+
1776
+
1777
+ Yosys 0.1.0 .. Yosys 0.2.0
1778
+ --------------------------
1779
+
1780
+ * Changes to the driver program:
1781
+ - Added "yosys -h" and "yosys -H"
1782
+ - Added support for backslash line continuation in scripts
1783
+ - Added support for #-comments in same line as command
1784
+ - Added "echo" and "log" commands
1785
+
1786
+ * Improvements in Verilog frontend:
1787
+ - Added support for local registers in named blocks
1788
+ - Added support for "case" in "generate" blocks
1789
+ - Added support for $clog2 system function
1790
+ - Added support for basic SystemVerilog assert statements
1791
+ - Added preprocessor support for macro arguments
1792
+ - Added preprocessor support for `elsif statement
1793
+ - Added "verilog_defaults" command
1794
+ - Added read_verilog -icells option
1795
+ - Added support for constant sizes from parameters
1796
+ - Added "read_verilog -setattr"
1797
+ - Added support for function returning 'integer'
1798
+ - Added limited support for function calls in parameter values
1799
+ - Added "read_verilog -defer" to suppress evaluation of modules with default parameters
1800
+
1801
+ * Other front- and back-ends:
1802
+ - Added BTOR backend
1803
+ - Added Liberty frontend
1804
+
1805
+ * Improvements in technology mapping:
1806
+ - The "dfflibmap" command now strongly prefers solutions with
1807
+ no inverters in clock paths
1808
+ - The "dfflibmap" command now prefers cells with smaller area
1809
+ - Added support for multiple -map options to techmap
1810
+ - Added "dfflibmap" support for //-comments in liberty files
1811
+ - Added "memory_unpack" command to revert "memory_collect"
1812
+ - Added standard techmap rule "techmap -share_map pmux2mux.v"
1813
+ - Added "iopadmap -bits"
1814
+ - Added "setundef" command
1815
+ - Added "hilomap" command
1816
+
1817
+ * Changes in the internal cell library:
1818
+ - Major rewrite of simlib.v for better compatibility with other tools
1819
+ - Added PRIORITY parameter to $memwr cells
1820
+ - Added TRANSPARENT parameter to $memrd cells
1821
+ - Added RD_TRANSPARENT parameter to $mem cells
1822
+ - Added $bu0 cell (always 0-extend, even undef MSB)
1823
+ - Added $assert cell type
1824
+ - Added $slice and $concat cell types
1825
+
1826
+ * Integration with ABC:
1827
+ - Updated ABC to hg rev 2058c8ccea68
1828
+ - Tighter integration of ABC build with Yosys build. The make
1829
+ targets 'make abc' and 'make install-abc' are now obsolete.
1830
+ - Added support for passing FFs from one clock domain through ABC
1831
+ - Now always use BLIF as exchange format with ABC
1832
+ - Added support for "abc -script +<command_sequence>"
1833
+ - Improved standard ABC recipe
1834
+ - Added support for "keep" attribute to abc command
1835
+ - Added "abc -dff / -clk / -keepff" options
1836
+
1837
+ * Improvements to "eval" and "sat" framework:
1838
+ - Added support for "0" and "~0" in right-hand side -set expressions
1839
+ - Added "eval -set-undef" and "eval -table"
1840
+ - Added "sat -set-init" and "sat -set-init-*" for sequential problems
1841
+ - Added undef support to SAT solver, incl. various new "sat" options
1842
+ - Added correct support for === and !== for "eval" and "sat"
1843
+ - Added "sat -tempinduct" (default -seq is now non-induction sequential)
1844
+ - Added "sat -prove-asserts"
1845
+ - Complete rewrite of the 'freduce' command
1846
+ - Added "miter" command
1847
+ - Added "sat -show-inputs" and "sat -show-outputs"
1848
+ - Added "sat -ignore_unknown_cells" (now produce an error by default)
1849
+ - Added "sat -falsify"
1850
+ - Now "sat -verify" and "sat -falsify" can also be used without "-prove"
1851
+ - Added "expose" command
1852
+ - Added support for @<sel_name> to sat and eval signal expressions
1853
+
1854
+ * Changes in the 'make test' framework and auxiliary test tools:
1855
+ - Added autotest.sh -p and -f options
1856
+ - Replaced autotest.sh ISIM support with XSIM support
1857
+ - Added test cases for SAT framework
1858
+
1859
+ * Added "abbreviated IDs":
1860
+ - Now $<something>$foo can be abbreviated as $foo.
1861
+ - Usually this last part is a unique id (from RTLIL::autoidx)
1862
+ - This abbreviated IDs are now also used in "show" output
1863
+
1864
+ * Other changes to selection framework:
1865
+ - Now */ is optional in */<mode>:<arg> expressions
1866
+ - Added "select -assert-none" and "select -assert-any"
1867
+ - Added support for matching modules by attribute (A:<expr>)
1868
+ - Added "select -none"
1869
+ - Added support for r:<expr> pattern for matching cell parameters
1870
+ - Added support for !=, <, <=, >=, > for attribute and parameter matching
1871
+ - Added support for %s for selecting sub-modules
1872
+ - Added support for %m for expanding selections to whole modules
1873
+ - Added support for i:*, o:* and x:* pattern for selecting module ports
1874
+ - Added support for s:<expr> pattern for matching wire width
1875
+ - Added support for %a operation to select wire aliases
1876
+
1877
+ * Various other changes to commands and options:
1878
+ - The "ls" command now supports wildcards
1879
+ - Added "show -pause" and "show -format dot"
1880
+ - Added "show -color" support for cells
1881
+ - Added "show -label" and "show -notitle"
1882
+ - Added "dump -m" and "dump -n"
1883
+ - Added "history" command
1884
+ - Added "rename -hide"
1885
+ - Added "connect" command
1886
+ - Added "splitnets -driver"
1887
+ - Added "opt_const -mux_undef"
1888
+ - Added "opt_const -mux_bool"
1889
+ - Added "opt_const -undriven"
1890
+ - Added "opt -mux_undef -mux_bool -undriven -purge"
1891
+ - Added "hierarchy -libdir"
1892
+ - Added "hierarchy -purge_lib" (by default now do not remove lib cells)
1893
+ - Added "delete" command
1894
+ - Added "dump -append"
1895
+ - Added "setattr" and "setparam" commands
1896
+ - Added "design -stash/-copy-from/-copy-to"
1897
+ - Added "copy" command
1898
+ - Added "splice" command
chips/yosys/CMakeLists.txt ADDED
@@ -0,0 +1,639 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
2
+ set(rm "rm -rf")
3
+ if (WIN32)
4
+ set(rm "del /s /q")
5
+ endif()
6
+ message(FATAL_ERROR
7
+ "In-tree builds are not supported. Instead, run:\n"
8
+ "${rm} CMakeCache.txt CMakeFiles ; cmake -B build <options>"
9
+ )
10
+ endif()
11
+
12
+ cmake_minimum_required(VERSION 3.28)
13
+ project(yosys LANGUAGES C CXX)
14
+
15
+ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
16
+ include(CMakeDependentOption)
17
+ include(FeatureSummary)
18
+ include(CheckPIESupported)
19
+
20
+ include(Condition)
21
+ include(CheckLibcFeatures)
22
+ include(PkgConfig)
23
+ include(PmgenCommand)
24
+ include(YosysVersion)
25
+ include(YosysInstallDirs)
26
+ include(YosysConfigScript)
27
+ include(YosysComponent)
28
+ include(YosysLinkTarget)
29
+ include(YosysAbc)
30
+ include(YosysAbcSubmodule)
31
+ include(YosysVerific)
32
+ include(UseHomebrew)
33
+
34
+ # Fix for using Clang from nixpkgs
35
+ # see https://github.com/YosysHQ/yosys/pull/5936#issuecomment-4637319568
36
+ set(CMAKE_CXX_SCAN_FOR_MODULES NO)
37
+
38
+ # Cache current yosys cmake root path
39
+ set(YOSYS_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Save source path")
40
+ set(YOSYS_CMAKE_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "Save binary path")
41
+
42
+ # Build options.
43
+ set(YOSYS_COMPILER_LAUNCHER "" CACHE STRING "Compiler launcher (ccache, sccache)")
44
+ option(YOSYS_ENABLE_UNIT_TESTS "Enable unit tests" ON)
45
+ option(YOSYS_ENABLE_COVERAGE "Enable code coverage" OFF)
46
+ option(YOSYS_ENABLE_PROFILING "Enable instruction profiling" OFF)
47
+ option(YOSYS_ENABLE_FUNCTIONAL_TESTS "Enable running functional tests" OFF)
48
+ option(YOSYS_ENABLE_TWINE_PROVENANCE "Twine provenance for debugging. Worsens performance" OFF)
49
+
50
+ set(YOSYS_PROGRAM_PREFIX "" CACHE STRING "Name prefix for programs, libraries, and data")
51
+ set(YOSYS_COMPONENTS "everything" CACHE STRING "List of components to build (use pass names)")
52
+ option(BUILD_SHARED_LIBS "Build libyosys as a shared library" ON)
53
+
54
+ option(YOSYS_DISABLE_THREADS "Disable threading" OFF)
55
+ set(YOSYS_ABC_EXECUTABLE "" CACHE FILEPATH
56
+ "Path to the ABC executable (empty for vendored, 'INTEGRATED-NOTFOUND' for in-process)")
57
+ option(YOSYS_WITHOUT_ABC "Disable ABC support (not recommended)" OFF)
58
+ option(YOSYS_WITHOUT_ZLIB "Disable zlib integration" OFF)
59
+ option(YOSYS_WITHOUT_LIBFFI "Disable libffi integration" OFF)
60
+ option(YOSYS_WITHOUT_READLINE "Disable readline integration" OFF)
61
+ option(YOSYS_WITHOUT_EDITLINE "Disable editline integration" OFF)
62
+ option(YOSYS_WITHOUT_SLANG "Disable Slang integration" OFF)
63
+ option(YOSYS_WITHOUT_TCL "Disable Tcl integration" OFF)
64
+ option(YOSYS_WITH_PYTHON "Enable Python integration" OFF)
65
+
66
+ option(YOSYS_USE_BUNDLED_LIBS "Use bundled third-party libraries" OFF)
67
+
68
+ set(YOSYS_VERIFIC_DIR "" CACHE FILEPATH "Path to the Verific source code (empty to disable)")
69
+ set(YOSYS_VERIFIC_COMPONENTS "" CACHE STRING
70
+ "List of Verific components to link (empty for autodetect)")
71
+ set(YOSYS_VERIFIC_FEATURES "" CACHE STRING
72
+ "List of Yosys Verific frontend features to enable (empty for autodetect)")
73
+
74
+ option(YOSYS_INSTALL_DRIVER "Install Yosys executable" ON)
75
+ option(YOSYS_INSTALL_LIBRARY "Install libyosys library" OFF)
76
+ cmake_dependent_option(YOSYS_INSTALL_PYTHON "Install Python extension module" OFF
77
+ YOSYS_WITH_PYTHON OFF)
78
+ set(YOSYS_INSTALL_PYTHON_SITEDIR "" CACHE STRING "Path to Python package installation directory")
79
+
80
+ # This option is something of a hack to make Python wheels buildable in an environment that has
81
+ # the `Development.Module` component, but not `Development.Embed` (e.g. cibuildwheel). It is only
82
+ # present to be used in the wheel build and is not supported otherwise.
83
+ cmake_dependent_option(YOSYS_BUILD_PYTHON_ONLY "Build only Pyosys components" ON
84
+ "NOT (YOSYS_INSTALL_DRIVER OR YOSYS_INSTALL_LIBRARY) AND YOSYS_INSTALL_PYTHON" OFF)
85
+ mark_as_advanced(YOSYS_BUILD_PYTHON_ONLY)
86
+
87
+ # Configure compiler.
88
+ set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
89
+
90
+ if (YOSYS_COMPILER_LAUNCHER)
91
+ set(CMAKE_C_COMPILER_LAUNCHER "${YOSYS_COMPILER_LAUNCHER}")
92
+ set(CMAKE_CXX_COMPILER_LAUNCHER "${YOSYS_COMPILER_LAUNCHER}")
93
+ endif()
94
+
95
+ set(CMAKE_CXX_STANDARD 20)
96
+ set(CMAKE_CXX_STANDARD_REQUIRED YES)
97
+
98
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
99
+ check_pie_supported() # opportunistically enable PIE
100
+
101
+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
102
+ if (NOT CMAKE_PRESET)
103
+ set(CMAKE_CXX_FLAGS_DEBUG "-Og -ggdb")
104
+ set(CMAKE_CXX_FLAGS_RELEASE "-O3")
105
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -ggdb")
106
+ set(CMAKE_CXX_FLAGS_MINSIZEREL"-Os")
107
+ set(CMAKE_CXX_FLAGS_SANITIZE "-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
108
+ endif()
109
+ if ("${SANITIZE}" MATCHES "memory")
110
+ add_compile_options(
111
+ "$<$<AND:$<NOT:$<BOOL:$<TARGET_PROPERTY:YOSYS_IS_ABC>>>,$<CONFIG:Sanitize>>:-fsanitize-memory-track-origins>"
112
+ )
113
+ endif()
114
+ set(no_abc_options
115
+ "$<$<AND:$<NOT:$<BOOL:$<TARGET_PROPERTY:YOSYS_IS_ABC>>>,$<CONFIG:Sanitize>>:-fsanitize=${SANITIZE}>"
116
+ "$<$<NOT:$<BOOL:$<TARGET_PROPERTY:YOSYS_IS_ABC>>>:-Wall;-Wextra;-Werror=unused-variable;-Werror=unused-parameter;-Werror=unused-function>"
117
+ )
118
+ add_compile_options("${no_abc_options}")
119
+ add_link_options("${no_abc_options}")
120
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
121
+ set(CMAKE_CXX_FLAGS_DEBUG "/Od /DEBUG")
122
+ set(CMAKE_CXX_FLAGS_RELEASE "/O2")
123
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /DEBUG")
124
+ set(CMAKE_CXX_FLAGS_MINSIZEREL "/Os")
125
+ add_compile_options(/Zc:__cplusplus)
126
+ add_compile_definitions(
127
+ _CRT_NONSTDC_NO_DEPRECATE
128
+ _CRT_SECURE_NO_WARNINGS
129
+ )
130
+ else()
131
+ # We have to do this because CMake adds `-DNDEBUG` in release builds by default, and there's
132
+ # no particularly good way to prevent this without also erasing optimization flags.
133
+ # If you see this message, reproduce the block above with the flags supported by your compiler.
134
+ message(FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} compiler is not supported")
135
+ endif()
136
+
137
+ if (YOSYS_ENABLE_COVERAGE)
138
+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
139
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
140
+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
141
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-inline -fno-inline-small-functions -fno-default-inline")
142
+ else()
143
+ message(FATAL_ERROR "Code coverage is not supported on ${CMAKE_CXX_COMPILER_ID} compiler")
144
+ endif()
145
+ endif()
146
+
147
+ if (YOSYS_ENABLE_PROFILING)
148
+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
149
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
150
+ else()
151
+ message(FATAL_ERROR "Instruction profiling is not supported on ${CMAKE_CXX_COMPILER_ID} compiler")
152
+ endif()
153
+ endif()
154
+
155
+ if (NOT CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID)
156
+ message(FATAL_ERROR "C and C++ compilers must be provided by the same vendor")
157
+ endif()
158
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
159
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
160
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
161
+ set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
162
+ set(CMAKE_C_FLAGS_SANITIZE "${CMAKE_CXX_FLAGS_SANITIZE}")
163
+
164
+ if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
165
+ add_compile_options(
166
+ -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false
167
+ -D_WASI_EMULATED_PROCESS_CLOCKS
168
+ )
169
+ add_link_options(
170
+ -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -lunwind
171
+ -lwasi-emulated-process-clocks
172
+ -Wl,--stack-first,-z,stack-size=8388608
173
+ )
174
+ endif()
175
+
176
+ if (MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "16.0.0")
177
+ # GCC 15.2 sometimes refuses to construct an import directory for yosys.exe/libyosys.dll with:
178
+ # .../ld.exe: error: export ordinal too large: 67035
179
+ # The cause is unknown.
180
+ message(WARNING "MinGW GCC is supported starting with version 16.0.0")
181
+ endif()
182
+
183
+ # Required dependencies.
184
+ if (APPLE AND (NOT DEFINED YOSYS_ENABLE_HOMEBREW OR YOSYS_ENABLE_HOMEBREW))
185
+ # In practice, we can't expect paths to Homebrew packages to be configured.
186
+ use_homebrew()
187
+ endif()
188
+
189
+ find_package(FLEX 2.6)
190
+ set_package_properties(FLEX PROPERTIES
191
+ URL "https://github.com/westes/flex"
192
+ DESCRIPTION "The Fast Lexical Analyzer"
193
+ PURPOSE "Compiling the Verilog lexer"
194
+ TYPE REQUIRED
195
+ )
196
+
197
+ find_package(BISON 3.6)
198
+ set_package_properties(BISON PROPERTIES
199
+ URL "https://www.gnu.org/software/bison/"
200
+ DESCRIPTION "The Yacc-compatible Parser Generator"
201
+ PURPOSE "Compiling the Verilog parser"
202
+ TYPE REQUIRED
203
+ )
204
+
205
+ find_package(Python3 3.7 COMPONENTS Interpreter)
206
+ set_package_properties(Python3 PROPERTIES
207
+ URL "https://www.python.org/"
208
+ DESCRIPTION "Dynamic programming language (Interpreter)"
209
+ PURPOSE "Generating data files\n Running external SMT2 solvers"
210
+ TYPE REQUIRED
211
+ )
212
+
213
+ # Optional dependencies.
214
+ check_glob()
215
+ check_system()
216
+ check_popen()
217
+ find_package(Threads QUIET)
218
+ check_pthread_create()
219
+ find_package(Dlfcn QUIET)
220
+
221
+ find_package(PkgConfig)
222
+ set_package_properties(PkgConfig PROPERTIES
223
+ URL "https://www.freedesktop.org/wiki/Software/pkg-config/"
224
+ DESCRIPTION "Library metadata manager"
225
+ PURPOSE "Discovering dependencies"
226
+ TYPE RECOMMENDED
227
+ )
228
+
229
+ pkg_config_import(zlib)
230
+ set_package_properties(zlib PROPERTIES
231
+ URL "https://github.com/madler/zlib"
232
+ DESCRIPTION "A massively spiffy yet delicately unobtrusive compression library"
233
+ PURPOSE "Handling Gzip and FST file formats"
234
+ )
235
+
236
+ pkg_config_import(libffi)
237
+ set_package_properties(libffi PROPERTIES
238
+ URL "https://sourceware.org/libffi/"
239
+ DESCRIPTION "A Portable Foreign Function Interface Library"
240
+ PURPOSE "Implementing Verilog DPI-C"
241
+ )
242
+
243
+ pkg_config_import(editline MODULES libedit)
244
+ set_package_properties(editline PROPERTIES
245
+ URL "https://www.thrysoee.dk/editline/"
246
+ DESCRIPTION "Line editing and history library (BSD)"
247
+ PURPOSE "Enhancing the command prompt"
248
+ TYPE RECOMMENDED
249
+ )
250
+
251
+ pkg_config_import(readline)
252
+ set_package_properties(readline PROPERTIES
253
+ URL "https://tiswww.case.edu/php/chet/readline/rltop.html"
254
+ DESCRIPTION "Line editing and history library (GPL)"
255
+ PURPOSE "Enhancing the command prompt"
256
+ TYPE RECOMMENDED
257
+ )
258
+
259
+ # See https://core.tcl-lang.org/tips/doc/trunk/tip/538.md
260
+ pkg_config_import(tcl MODULES tcl)
261
+ set_package_properties(tcl PROPERTIES
262
+ URL "https://www.tcl-lang.org/"
263
+ DESCRIPTION "Dynamic programming language"
264
+ PURPOSE "Parsing SDC constraint files\n Binding Yosys API"
265
+ )
266
+
267
+ if (tcl_FOUND)
268
+ get_target_property(tcl_options PkgConfig::tcl INTERFACE_COMPILE_OPTIONS)
269
+ if (tcl_options MATCHES "TCL_WITH_EXTERNAL_TOMMATH")
270
+ pkg_config_import(libtommath)
271
+ set_package_properties(libtommath PROPERTIES
272
+ URL "https://www.libtom.net/LibTomMath/"
273
+ DESCRIPTION "Multiple-precision integer library"
274
+ PURPOSE "Required by this build of Tcl"
275
+ TYPE REQUIRED
276
+ )
277
+ # Unfortunately the pkg-config file for Tcl includes libtommath as a private dependency,
278
+ # while it should be public since it is exposed in the public API and necessary for its use.
279
+ target_link_libraries(PkgConfig::tcl INTERFACE PkgConfig::libtommath)
280
+ else()
281
+ # Vendored within Tcl itself.
282
+ set(libtommath_FOUND TRUE)
283
+ endif()
284
+ endif()
285
+
286
+ if (YOSYS_WITH_PYTHON)
287
+ find_package(Python3Devel REQUIRED)
288
+ set_property(GLOBAL PROPERTY _CMAKE_Python3Devel_REQUIRED_VERSION "== ${Python3_VERSION}")
289
+ set_package_properties(Python3Devel PROPERTIES
290
+ URL "https://www.python.org/"
291
+ DESCRIPTION "Dynamic programming language (Embedding)"
292
+ PURPOSE "Binding Yosys API"
293
+ )
294
+
295
+ find_package(PyosysEnv REQUIRED)
296
+ set_package_properties(PyosysEnv PROPERTIES
297
+ DESCRIPTION "Pyosys wrapper generator environment"
298
+ PURPOSE "Either 'uv' or 'pybind11>3,<4 cxxheaderparser'"
299
+ )
300
+ endif()
301
+
302
+ find_package(GTest)
303
+ set_package_properties(GTest PROPERTIES
304
+ URL "https://google.github.io/googletest/"
305
+ DESCRIPTION "C++ testing and mocking framework by Google"
306
+ PURPOSE "Running unit tests"
307
+ TYPE RECOMMENDED
308
+ )
309
+
310
+ # Configure features based on dependency availability.
311
+ message(VERBOSE "Conditional features:")
312
+ condition(YOSYS_ENABLE_GLOB HAVE_GLOB)
313
+ condition(YOSYS_ENABLE_SPAWN HAVE_SYSTEM AND HAVE_POPEN)
314
+ condition(YOSYS_ENABLE_THREADS Threads_FOUND AND HAVE_PTHREAD_CREATE AND NOT YOSYS_DISABLE_THREADS)
315
+ condition(YOSYS_ENABLE_PLUGINS Dlfcn_FOUND)
316
+ condition(YOSYS_ENABLE_ABC NOT YOSYS_WITHOUT_ABC)
317
+ condition(YOSYS_ENABLE_ZLIB zlib_FOUND AND NOT YOSYS_WITHOUT_ZLIB)
318
+ condition(YOSYS_ENABLE_LIBFFI Dlfcn_FOUND AND libffi_FOUND AND NOT YOSYS_WITHOUT_LIBFFI)
319
+ condition(YOSYS_ENABLE_READLINE readline_FOUND AND NOT YOSYS_WITHOUT_READLINE)
320
+ condition(YOSYS_ENABLE_EDITLINE editline_FOUND AND NOT YOSYS_WITHOUT_EDITLINE AND NOT YOSYS_ENABLE_READLINE)
321
+ condition(YOSYS_ENABLE_TCL tcl_FOUND AND libtommath_FOUND AND NOT YOSYS_WITHOUT_TCL)
322
+ condition(YOSYS_ENABLE_PYTHON Python3Devel_FOUND AND PyosysEnv_FOUND AND YOSYS_WITH_PYTHON)
323
+ condition(YOSYS_ENABLE_VERIFIC YOSYS_VERIFIC_DIR AND zlib_FOUND)
324
+ condition(YOSYS_ENABLE_SLANG NOT YOSYS_WITHOUT_SLANG)
325
+
326
+ # Describe dependencies and features
327
+ # CMake 4.0 would let us use proper conditions, but that's too new for now.
328
+ add_feature_info(have_glob YOSYS_ENABLE_GLOB "Glob expansion in filenames")
329
+ add_feature_info(have_spawn YOSYS_ENABLE_SPAWN "Passes that invoke external tools")
330
+ add_feature_info(have_threads YOSYS_ENABLE_THREADS "Multithreaded netlist operations")
331
+ add_feature_info(twine_provenance YOSYS_ENABLE_TWINE_PROVENANCE "Twine provenance for debugging. Worsens performance")
332
+ add_feature_info(have_plugins YOSYS_ENABLE_PLUGINS "Dynamically loadable binary plugins")
333
+ add_feature_info(with_abc YOSYS_ENABLE_ABC "Production-quality logic synthesis flow")
334
+ add_feature_info(with_zlib YOSYS_ENABLE_ZLIB "Transparent Gzip decompression and FST file format support")
335
+ add_feature_info(with_libffi YOSYS_ENABLE_LIBFFI "Verilog DPI-C foreign function interface")
336
+ add_feature_info(with_readline YOSYS_ENABLE_READLINE "Using readline for prompt editing and history")
337
+ add_feature_info(with_editline YOSYS_ENABLE_EDITLINE "Using editline for prompt editing and history")
338
+ add_feature_info(with_tcl YOSYS_ENABLE_TCL "Tcl scripting and SDC parsing")
339
+ add_feature_info(with_python YOSYS_ENABLE_PYTHON "Python scripting and embedding")
340
+ add_feature_info(with_verific YOSYS_ENABLE_VERIFIC "Verific frontend integration")
341
+ message(STATUS "")
342
+ feature_summary(WHAT PACKAGES_FOUND
343
+ DEFAULT_DESCRIPTION)
344
+ feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND
345
+ DEFAULT_DESCRIPTION QUIET_ON_EMPTY FATAL_ON_MISSING_REQUIRED_PACKAGES
346
+ )
347
+ feature_summary(WHAT PACKAGES_NOT_FOUND
348
+ DEFAULT_DESCRIPTION QUIET_ON_EMPTY
349
+ )
350
+ feature_summary(WHAT ENABLED_FEATURES
351
+ DEFAULT_DESCRIPTION QUIET_ON_EMPTY)
352
+ feature_summary(WHAT DISABLED_FEATURES
353
+ DEFAULT_DESCRIPTION QUIET_ON_EMPTY)
354
+
355
+ # Describe project version.
356
+ yosys_extract_version()
357
+
358
+ # Describe ABC integration.
359
+ if (YOSYS_ENABLE_ABC AND NOT YOSYS_ENABLE_SPAWN AND NOT YOSYS_ABC_EXECUTABLE STREQUAL "INTEGRATED-NOTFOUND")
360
+ message(WARNING "ABC support on this platform forces -DYOSYS_ABC_EXECUTABLE=INTEGRATED-NOTFOUND")
361
+ set(YOSYS_ABC_EXECUTABLE "INTEGRATED-NOTFOUND" CACHE FILEPATH "" FORCE)
362
+ endif()
363
+
364
+ set(YOSYS_LINK_ABC 0)
365
+ if (YOSYS_ENABLE_ABC)
366
+ if (NOT YOSYS_ABC_EXECUTABLE AND NOT YOSYS_SKIP_ABC_SUBMODULE_CHECK)
367
+ yosys_check_abc_submodule()
368
+ endif()
369
+ if (YOSYS_ABC_EXECUTABLE STREQUAL "INTEGRATED-NOTFOUND")
370
+ set(YOSYS_LINK_ABC 1)
371
+ message(STATUS "Building ABC: (integrated)")
372
+ elseif (YOSYS_ABC_EXECUTABLE STREQUAL "")
373
+ set(abc_filename ${YOSYS_PROGRAM_PREFIX}yosys-abc${CMAKE_EXECUTABLE_SUFFIX})
374
+ message(STATUS "Building ABC: ${YOSYS_INSTALL_FULL_BINDIR}/${abc_filename}")
375
+ else()
376
+ message(STATUS "External ABC: ${YOSYS_ABC_EXECUTABLE}")
377
+ endif()
378
+ endif()
379
+
380
+ # Ensure invalid dependencies fail at configuration time, not link time.
381
+ set(CMAKE_LINK_LIBRARIES_ONLY_TARGETS ON)
382
+
383
+ # Pseudo-library that injects common compilation options into every Yosys component.
384
+ add_library(yosys_common INTERFACE)
385
+ target_compile_definitions(yosys_common INTERFACE
386
+ _YOSYS_
387
+ $<$<CONFIG:Debug,RelWithDebInfo>:DEBUG>
388
+ )
389
+ target_include_directories(yosys_common INTERFACE
390
+ ${YOSYS_CMAKE_SOURCE_DIR}
391
+ ${YOSYS_CMAKE_BINARY_DIR}
392
+ )
393
+ if (SANITIZE)
394
+ target_compile_options(yosys_common INTERFACE
395
+ ${sanitize_options}
396
+ )
397
+ endif()
398
+
399
+ # Two pseudo-components used for dependency tracking only.
400
+ yosys_core(essentials BOOTSTRAP)
401
+ yosys_core(everything BOOTSTRAP)
402
+
403
+ # All of the source code.
404
+ add_subdirectory(libs)
405
+ add_subdirectory(kernel)
406
+ add_subdirectory(passes)
407
+ add_subdirectory(frontends)
408
+ add_subdirectory(backends)
409
+ add_subdirectory(techlibs)
410
+ if (YOSYS_ENABLE_PYTHON)
411
+ add_subdirectory(pyosys)
412
+ endif()
413
+
414
+ # ABC submodule.
415
+ if (YOSYS_ENABLE_ABC AND NOT YOSYS_ABC_EXECUTABLE)
416
+ set(YOSYS_ABC_INSTALL NO)
417
+ if (YOSYS_ABC_EXECUTABLE STREQUAL "" AND (YOSYS_INSTALL_DRIVER OR YOSYS_INSTALL_LIBRARY))
418
+ set(YOSYS_ABC_INSTALL YES)
419
+ endif()
420
+ yosys_abc_target(libyosys-abc yosys-abc
421
+ INSTALL_IF ${YOSYS_ABC_INSTALL}
422
+ )
423
+ endif()
424
+
425
+ # Compute a transitive closure of enabled components.
426
+ yosys_expand_components(library_components essentials ${YOSYS_COMPONENTS})
427
+ if (NOT YOSYS_BUILD_PYTHON_ONLY)
428
+ yosys_expand_components(driver_components driver ${YOSYS_COMPONENTS})
429
+ endif()
430
+
431
+ # Main Yosys executable (compiler driver).
432
+ if (NOT YOSYS_BUILD_PYTHON_ONLY)
433
+ yosys_cxx_executable(yosys
434
+ OUTPUT_NAME yosys
435
+ INSTALL_IF ${YOSYS_INSTALL_DRIVER}
436
+ )
437
+ yosys_link_components(yosys PRIVATE ${driver_components})
438
+ set_property(TARGET yosys PROPERTY ENABLE_EXPORTS ON)
439
+ if (MINGW)
440
+ target_link_options(yosys PRIVATE -municode LINKER:--export-all-symbols)
441
+ set_target_properties(yosys PROPERTIES
442
+ # Final name: `yosys.exe.a` (linked to explicitly)
443
+ IMPORT_PREFIX ""
444
+ IMPORT_SUFFIX ".exe.a"
445
+ )
446
+ if (YOSYS_INSTALL_DRIVER)
447
+ install(FILES ${YOSYS_CMAKE_BINARY_DIR}/yosys.exe.a DESTINATION ${YOSYS_INSTALL_LIBDIR})
448
+ endif()
449
+ endif()
450
+ endif()
451
+
452
+ # Yosys components as a library.
453
+ if (NOT YOSYS_BUILD_PYTHON_ONLY)
454
+ if (BUILD_SHARED_LIBS)
455
+ set(libyosys_type SHARED)
456
+ else()
457
+ set(libyosys_type STATIC)
458
+ endif()
459
+ yosys_cxx_library(libyosys ${libyosys_type}
460
+ OUTPUT_NAME libyosys
461
+ INSTALL_IF ${YOSYS_INSTALL_LIBRARY}
462
+ )
463
+ yosys_link_components(libyosys PRIVATE ${library_components})
464
+ add_library(Yosys::libyosys ALIAS libyosys)
465
+ if (MINGW)
466
+ set_target_properties(libyosys PROPERTIES
467
+ # Final name: `libyosys.dll.a` (linked to via `-lyosys`)
468
+ IMPORT_PREFIX ""
469
+ )
470
+ endif()
471
+ endif()
472
+
473
+ # Yosys data files (mainly headers and technological libraries).
474
+ if (YOSYS_INSTALL_DRIVER OR YOSYS_INSTALL_LIBRARY)
475
+ yosys_install_component_data(${library_components} DESTINATION ${YOSYS_INSTALL_DATADIR})
476
+ endif()
477
+
478
+ # Build SN binary part of ABC
479
+ if (NOT MSVC AND NOT YOSYS_WITHOUT_SLANG)
480
+ block()
481
+ set(ABC_SOURCE_DIR "${YOSYS_CMAKE_SOURCE_DIR}/abc")
482
+ add_subdirectory(abc/tools/sn EXCLUDE_FROM_ALL)
483
+
484
+ set_target_properties(sn_slang_lib PROPERTIES YOSYS_IS_ABC ON)
485
+ set_target_properties(sn PROPERTIES YOSYS_IS_ABC ON)
486
+ if(SANITIZE)
487
+ target_link_options(sn PRIVATE -fsanitize=${SANITIZE})
488
+ endif()
489
+
490
+ set_target_properties(sn PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${YOSYS_CMAKE_BINARY_DIR}")
491
+ install(TARGETS sn DESTINATION ${CMAKE_INSTALL_BINDIR})
492
+ add_dependencies(yosys-abc sn)
493
+ endblock()
494
+ endif()
495
+
496
+ # Python binary extension (for using Yosys as a Python library).
497
+ if (YOSYS_ENABLE_PYTHON)
498
+ yosys_cxx_library(pyosys MODULE
499
+ OUTPUT_NAME pyosys
500
+ )
501
+ yosys_link_components(pyosys PRIVATE ${library_components})
502
+ set_target_properties(pyosys PROPERTIES EXCLUDE_FROM_ALL FALSE) # build but not install
503
+ if (YOSYS_ENABLE_ABC AND YOSYS_ABC_EXECUTABLE STREQUAL "")
504
+ add_dependencies(pyosys yosys-abc)
505
+ endif()
506
+
507
+ if (YOSYS_INSTALL_PYTHON)
508
+ string(REPLACE "-" "_" PYOSYS_MODULE_PREFIX "${YOSYS_PROGRAM_PREFIX}")
509
+ if (YOSYS_INSTALL_PYTHON_SITEDIR STREQUAL "")
510
+ set(YOSYS_INSTALL_PYTHON_SITEDIR ${Python3_SITEARCH})
511
+ endif()
512
+ set(pyosys_install_dir ${YOSYS_INSTALL_PYTHON_SITEDIR}/${PYOSYS_MODULE_PREFIX}pyosys)
513
+ install(FILES pyosys/modinit.py
514
+ RENAME __init__.py
515
+ DESTINATION ${pyosys_install_dir}
516
+ )
517
+ install(FILES $<TARGET_FILE:pyosys>
518
+ RENAME libyosys${CMAKE_SHARED_MODULE_SUFFIX}
519
+ DESTINATION ${pyosys_install_dir}
520
+ )
521
+ if (YOSYS_ENABLE_ABC AND YOSYS_ABC_EXECUTABLE STREQUAL "")
522
+ # If ABC is vendored it needs to be installed as a part of pyosys.
523
+ install(TARGETS yosys-abc
524
+ DESTINATION ${pyosys_install_dir}
525
+ )
526
+ endif()
527
+ if (NOT MSVC AND NOT YOSYS_WITHOUT_SLANG)
528
+ install(TARGETS sn
529
+ DESTINATION ${pyosys_install_dir}
530
+ )
531
+ endif()
532
+ yosys_install_component_data(${library_components} DESTINATION ${pyosys_install_dir}/share)
533
+ endif()
534
+ endif()
535
+
536
+ # Plugin build tool.
537
+ yosys_config_script(BUILD)
538
+ if (YOSYS_INSTALL_DRIVER OR YOSYS_INSTALL_LIBRARY)
539
+ yosys_config_script(INSTALL)
540
+ endif()
541
+
542
+ # Configuration for Makefile-based steps.
543
+ # (The use of `${makefile_vars}` in `add_custom_{target,command}()` adds dependencies for
544
+ # all of the targets specified via `$<TARGET_FILE:tgt>`.)
545
+ set(makefile_vars
546
+ BUILD_DIR=${YOSYS_CMAKE_BINARY_DIR}
547
+ PROGRAM_PREFIX=${YOSYS_PROGRAM_PREFIX}
548
+ ABC=$<IF:$<TARGET_EXISTS:yosys-abc>,$<TARGET_FILE:yosys-abc>,${YOSYS_ABC_EXECUTABLE}>
549
+ YOSYS=$<TARGET_FILE:yosys>
550
+ YOSYS_CONFIG=${YOSYS_CMAKE_BINARY_DIR}/${YOSYS_PROGRAM_PREFIX}yosys-config
551
+ YOSYS_FILTERLIB=$<$<TARGET_EXISTS:yosys-filterlib>:$<TARGET_FILE:yosys-filterlib>>
552
+ YOSYS_SMTBMC=${YOSYS_CMAKE_BINARY_DIR}/${YOSYS_PROGRAM_PREFIX}yosys-smtbmc
553
+ YOSYS_WITNESS=${YOSYS_CMAKE_BINARY_DIR}/${YOSYS_PROGRAM_PREFIX}yosys-witness
554
+ )
555
+ set(makefile_depends
556
+ # abc is implied via $<TARGET_FILE>
557
+ # yosys is implied via $<TARGET_FILE>
558
+ # yosys-filterlib is implied via $<TARGET_FILE>
559
+ $<$<TARGET_EXISTS:yosys-smtbmc>:yosys-smtbmc>
560
+ $<$<TARGET_EXISTS:yosys-witness>:yosys-witness>
561
+ )
562
+
563
+ if (NOT YOSYS_BUILD_PYTHON_ONLY AND YOSYS_ENABLE_UNIT_TESTS)
564
+ # Tests.
565
+ add_subdirectory(tests/unit)
566
+
567
+ add_custom_target(test-unit
568
+ COMMAND ${CMAKE_CTEST_COMMAND} --test-dir tests/unit --output-on-failure
569
+ WORKING_DIRECTORY ${YOSYS_CMAKE_BINARY_DIR}
570
+ DEPENDS $<$<TARGET_EXISTS:yosys-gtest-all>:yosys-gtest-all>
571
+ )
572
+
573
+ add_custom_target(test-vanilla
574
+ COMMAND make vanilla-test ${makefile_vars}
575
+ ENABLE_FUNCTIONAL_TESTS=$<IF:$<BOOL:${YOSYS_ENABLE_FUNCTIONAL_TESTS}>,1,0>
576
+ WORKING_DIRECTORY ${YOSYS_CMAKE_SOURCE_DIR}/tests
577
+ DEPENDS ${makefile_depends}
578
+ USES_TERMINAL
579
+ JOB_SERVER_AWARE TRUE
580
+ )
581
+
582
+ add_custom_target(test-functional
583
+ COMMAND make functional ${makefile_vars}
584
+ ENABLE_FUNCTIONAL_TESTS=$<IF:$<BOOL:${YOSYS_ENABLE_FUNCTIONAL_TESTS}>,1,0>
585
+ WORKING_DIRECTORY ${YOSYS_CMAKE_SOURCE_DIR}/tests
586
+ DEPENDS ${makefile_depends}
587
+ USES_TERMINAL
588
+ JOB_SERVER_AWARE TRUE
589
+ )
590
+
591
+ add_custom_target(test
592
+ DEPENDS test-unit test-vanilla
593
+ )
594
+
595
+ # Docs.
596
+ add_custom_target(docs-prepare
597
+ COMMAND make gen ${makefile_vars}
598
+ WORKING_DIRECTORY ${YOSYS_CMAKE_SOURCE_DIR}/docs
599
+ DEPENDS ${makefile_depends}
600
+ JOB_SERVER_AWARE TRUE
601
+ )
602
+ foreach (format html latexpdf)
603
+ add_custom_target(docs-${format}
604
+ COMMAND make ${format}
605
+ WORKING_DIRECTORY ${YOSYS_CMAKE_SOURCE_DIR}/docs
606
+ DEPENDS docs-prepare
607
+ )
608
+ endforeach()
609
+ add_custom_target(test-docs
610
+ COMMAND make test ${makefile_vars}
611
+ WORKING_DIRECTORY ${YOSYS_CMAKE_SOURCE_DIR}/docs
612
+ DEPENDS ${makefile_depends}
613
+ JOB_SERVER_AWARE TRUE
614
+ )
615
+ endif()
616
+
617
+ # Utilities.
618
+ add_custom_target(print-version
619
+ COMMAND ${CMAKE_COMMAND} -E echo ${YOSYS_VERSION}
620
+ VERBATIM
621
+ )
622
+
623
+ yosys_expand_components(all_components everything QUIET)
624
+ list(TRANSFORM all_components PREPEND "COMMAND;${CMAKE_COMMAND};-E;echo;" OUTPUT_VARIABLE echo_all_components)
625
+ add_custom_target(print-yosys-components
626
+ ${echo_all_components}
627
+ VERBATIM
628
+ )
629
+
630
+ math(EXPR YOSYS_VERSION_MINOR_next "${YOSYS_VERSION_MINOR} + 1")
631
+ add_custom_target(increment-minor-version
632
+ COMMAND ${CMAKE_COMMAND} -E echo
633
+ "set(YOSYS_VERSION_MAJOR ${YOSYS_VERSION_MAJOR})"
634
+ > ${YOSYS_CMAKE_SOURCE_DIR}/cmake/YosysVersionData.cmake
635
+ COMMAND ${CMAKE_COMMAND} -E echo
636
+ "set(YOSYS_VERSION_MINOR ${YOSYS_VERSION_MINOR_next})"
637
+ >> ${YOSYS_CMAKE_SOURCE_DIR}/cmake/YosysVersionData.cmake
638
+ VERBATIM
639
+ )
chips/yosys/CMakePresets.json ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 6,
3
+ "configurePresets": [
4
+ {
5
+ "name": "base",
6
+ "hidden": true,
7
+ "cacheVariables": {
8
+ "CMAKE_PRESET": "True"
9
+ }
10
+ },
11
+ {
12
+ "name": "default",
13
+ "inherits": "debug",
14
+ "displayName": "Default",
15
+ "binaryDir": "${sourceDir}/build"
16
+ },
17
+ {
18
+ "name": "debug",
19
+ "inherits": "base",
20
+ "displayName": "Debug",
21
+ "binaryDir": "${sourceDir}/build-dbg",
22
+ "cacheVariables": {
23
+ "CMAKE_BUILD_TYPE": "Debug",
24
+ "CMAKE_C_FLAGS_DEBUG": "-Og -ggdb -fno-inline -fno-omit-frame-pointer -fno-optimize-sibling-calls",
25
+ "CMAKE_CXX_FLAGS_DEBUG": "-Og -ggdb -fno-inline -fno-omit-frame-pointer -fno-optimize-sibling-calls"
26
+
27
+ }
28
+ },
29
+ {
30
+ "name": "sanitize",
31
+ "inherits": "debug",
32
+ "displayName": "Debug with Sanitizers",
33
+ "binaryDir": "${sourceDir}/build-san",
34
+ "cacheVariables": {
35
+ "CMAKE_BUILD_TYPE": "Sanitize",
36
+ "SANITIZE": "address,undefined",
37
+ "CMAKE_C_FLAGS_DEBUG": "-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls",
38
+ "CMAKE_CXX_FLAGS_DEBUG": "-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls"
39
+
40
+ }
41
+ },
42
+ {
43
+ "name": "sanitize_mem",
44
+ "inherits": "sanitize",
45
+ "displayName": "Debug with MemorySanitizer",
46
+ "binaryDir": "${sourceDir}/build-memsan",
47
+ "cacheVariables": {
48
+ "SANITIZE": "memory",
49
+ "CMAKE_C_COMPILER": "clang",
50
+ "CMAKE_CXX_COMPILER": "clang++"
51
+ }
52
+ },
53
+ {
54
+ "name": "optdbg",
55
+ "inherits": "base",
56
+ "displayName": "Release with debug info",
57
+ "binaryDir": "${sourceDir}/build-optdbg",
58
+ "cacheVariables": {
59
+ "CMAKE_BUILD_TYPE": "RelWithDebInfo",
60
+ "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-O3 -ggdb -fno-omit-frame-pointer -fno-optimize-sibling-calls",
61
+ "CMAKE_C_FLAGS_RELWITHDEBINFO": "-O3 -ggdb -fno-omit-frame-pointer -fno-optimize-sibling-calls"
62
+ }
63
+ },
64
+ {
65
+ "name": "release",
66
+ "inherits": "base",
67
+ "displayName": "Release",
68
+ "binaryDir": "${sourceDir}/build-rel",
69
+ "cacheVariables": {
70
+ "CMAKE_BUILD_TYPE": "Release",
71
+ "CMAKE_CXX_FLAGS_RELEASE": "-O3",
72
+ "CMAKE_C_FLAGS_RELEASE": "-O3"
73
+ }
74
+ },
75
+ {
76
+ "name": "lto",
77
+ "inherits": "release",
78
+ "binaryDir": "${sourceDir}/build-lto",
79
+ "generator": "Unix Makefiles",
80
+ "cacheVariables": {
81
+ "CMAKE_C_COMPILER": "clang",
82
+ "CMAKE_CXX_COMPILER": "clang++",
83
+ "YOSYS_WITH_PYTHON": "false",
84
+ "YOSYS_INSTALL_PYTHON": "false",
85
+ "CMAKE_BUILD_TYPE": "Release",
86
+ "CMAKE_INTERPROCEDURAL_OPTIMIZATION": "ON",
87
+ "CMAKE_EXE_LINKER_FLAGS": "-fuse-ld=lld",
88
+ "CMAKE_SHARED_LINKER_FLAGS": "-fuse-ld=lld",
89
+ "CMAKE_MODULE_LINKER_FLAGS": "-fuse-ld=lld"
90
+ }
91
+ }
92
+ ]
93
+ }
chips/yosys/CODEOWNERS ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## CODE NOTIFICATIONS
2
+ # Register yourself here to be notified about modifications
3
+ # for any files you have an interest in/know your way around.
4
+
5
+ # Each line is a file pattern followed by one or more users.
6
+ # Both github usernames and email addresses are supported.
7
+ # Order is important; the last matching pattern takes the most
8
+ # precedence. Previous matches will not be applied.
9
+
10
+
11
+ # PATH (can use glob) USERNAME(S)
12
+
13
+ CODEOWNERS @nakengelhardt
14
+ passes/cmds/scratchpad.cc @nakengelhardt
15
+ frontends/rpc/ @whitequark
16
+ backends/cxxrtl/ @whitequark
17
+ passes/cmds/bugpoint.cc @whitequark
18
+ passes/opt/opt_lut.cc @whitequark
19
+ passes/techmap/abc9*.cc @eddiehung @Ravenslofty
20
+ backends/aiger/xaiger.cc @eddiehung
21
+ docs/ @KrystalDelusion
22
+ docs/source/using_yosys/synthesis/abc.rst @KrystalDelusion @Ravenslofty
23
+ .github/workflows/*.yml @mmicko
24
+
25
+ ## External Contributors
26
+ # Only users with write permission to the repository get review
27
+ # requests automatically, but we add information for other
28
+ # contributors here too, so we know who to ask to take a look.
29
+ # These still override previous lines, so be careful not to
30
+ # accidentally disable any of the above rules.
31
+
32
+ frontends/verilog/ @widlarizer
33
+ frontends/ast/ @widlarizer
34
+
35
+ techlibs/intel_alm/ @Ravenslofty
36
+ techlibs/gowin/ @pepijndevos
37
+ techlibs/gatemate/ @pu-cc
38
+ techlibs/fabulous/ fpga.research.group@gmail.com
39
+
40
+ # pyosys
41
+ pyosys/* @donn
42
+ setup.py @donn
43
+
44
+ backends/firrtl @ucbjrl @azidar
45
+
46
+ passes/sat/qbfsat.cc @boqwxp
47
+ passes/sat/qbfsat.h @boqwxp
48
+ passes/cmds/exec.cc @boqwxp
49
+ passes/cmds/glift.cc @boqwxp
50
+ passes/cmds/printattrs.cc @boqwxp
chips/yosys/CODE_OF_CONDUCT.md ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported by contacting the project team at contact@yosyshq.com and/or
63
+ claire@clairexen.net.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
chips/yosys/CONTRIBUTING.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Contributing to Yosys
2
+
3
+ Thanks for considering helping out. If this is your
4
+ first time contributing to an open source project, please take a look at the
5
+ following guide about the basics:
6
+ https://opensource.guide/how-to-contribute/#orienting-yourself-to-a-new-project.
7
+
8
+ Check out our [Contributing guidelines](https://yosys.readthedocs.io/en/latest/yosys_internals/extending_yosys/contributing.html) to learn the best ways to
9
+
10
+ Please make sure to consult our [interim AI policy](https://blog.yosyshq.com/p/interim-yosyshq-llm-policy/) before submitting a PR.
11
+
12
+ + get help
13
+ + report bugs
14
+ + contribute code
15
+ + review code
16
+
17
+ If you're reading this file offline and don't have internet access, you can [read the contributing.rst file locally](docs/source/yosys_internals/extending_yosys/contributing.rst).
chips/yosys/COPYING ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ISC License
2
+
3
+ Copyright (C) 2012 - 2026 Claire Xenia Wolf <claire@yosyshq.com>
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
chips/yosys/README.md ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ yosys – Yosys Open SYnthesis Suite
2
+ ===================================
3
+
4
+ This is a framework for RTL synthesis tools. It currently has
5
+ extensive Verilog-2005 support and provides a basic set of
6
+ synthesis algorithms for various application domains.
7
+
8
+ Yosys is using [sv-elab](https://github.com/povik/sv-elab) and [slang](https://github.com/MikePopoloski/slang) libraries to provide comprehensive SystemVerilog support.
9
+ It supports an (informally defined) synthesizable subset of SystemVerilog in version IEEE 1800-2017 or IEEE 1800-2023.
10
+
11
+ Yosys can be adapted to perform any synthesis job by combining
12
+ the existing passes (algorithms) using synthesis scripts and
13
+ adding additional passes as needed by extending the yosys C++
14
+ code base.
15
+
16
+ Yosys is free software licensed under the ISC license (a GPL
17
+ compatible license that is similar in terms to the MIT license
18
+ or the 2-clause BSD license).
19
+
20
+ Third-party software distributed alongside this software
21
+ is licensed under compatible licenses.
22
+ Please refer to `abc` and `libs` subdirectories for their license terms.
23
+
24
+
25
+ Web Site and Other Resources
26
+ ============================
27
+
28
+ More information and documentation can be found on the Yosys web site:
29
+ - https://yosyshq.net/yosys/
30
+
31
+ If you have any Yosys-related questions, please post them on the Discourse group:
32
+ - https://yosyshq.discourse.group
33
+
34
+ Documentation from this repository is automatically built and available on Read
35
+ the Docs:
36
+ - https://yosyshq.readthedocs.io/projects/yosys
37
+
38
+ Users interested in formal verification might want to use the formal
39
+ verification front-end for Yosys, SBY:
40
+ - https://yosyshq.readthedocs.io/projects/sby/
41
+ - https://github.com/YosysHQ/sby
42
+
43
+ The Yosys blog has news and articles from users:
44
+ - https://blog.yosyshq.com
45
+
46
+
47
+ Installation
48
+ ============
49
+
50
+ Yosys is part of the [Tabby CAD Suite](https://www.yosyshq.com/tabby-cad-datasheet) and the [OSS CAD Suite](https://github.com/YosysHQ/oss-cad-suite-build)! The easiest way to use yosys is to install the binary software suite, which contains all required dependencies and related tools.
51
+
52
+ * [Contact YosysHQ](https://www.yosyshq.com/contact) for a [Tabby CAD Suite](https://www.yosyshq.com/tabby-cad-datasheet) Evaluation License and download link
53
+ * OR go to https://github.com/YosysHQ/oss-cad-suite-build/releases to download the free OSS CAD Suite
54
+ * Follow the [Install Instructions on GitHub](https://github.com/YosysHQ/oss-cad-suite-build#installation)
55
+
56
+ Make sure to get a Tabby CAD Suite Evaluation License if you need features such as industry-grade SystemVerilog and VHDL parsers!
57
+
58
+ For more information about the difference between Tabby CAD Suite and the OSS CAD Suite, please visit https://www.yosyshq.com/tabby-cad-datasheet
59
+
60
+ Many Linux distributions also provide Yosys binaries, some more up to date than others. Check with your package manager!
61
+
62
+
63
+ Building from Source
64
+ ====================
65
+
66
+ ### TL;DR
67
+
68
+ The following libraries are required, this command will install them on Ubuntu Linux 22.04 LTS based systems:
69
+
70
+ $ sudo apt-get install gawk git make python3 lld bison clang flex \
71
+ libffi-dev libfl-dev libreadline-dev pkg-config tcl-dev zlib1g-dev \
72
+ graphviz xdot
73
+
74
+ This sequence of commands will build Yosys from source using the default preset:
75
+
76
+ $ git clone --recurse-submodules https://github.com/YosysHQ/yosys.git
77
+ $ cd yosys
78
+ $ cmake --preset default
79
+ $ cmake --build build --parallel $(nproc)
80
+
81
+ For release builds, substitute the cmake commands with these:
82
+
83
+ $ cmake --preset release
84
+ $ cmake --build build-rel --config Release --parallel $(nproc)
85
+
86
+ To run tests, run the following:
87
+
88
+ $ export BUILD_DIR=$(realpath build-rel) && make -C tests -j"$(nproc)" vanilla-test
89
+
90
+ ### Detailed instructions
91
+
92
+ For more details, and instructions for other platforms, check [building from
93
+ source](https://yosyshq.readthedocs.io/projects/yosys/en/latest/getting_started/installation.html#building-from-source) and [running the tests](https://yosyshq.readthedocs.io/projects/yosys/en/latest/yosys_internals/extending_yosys/test_suites.html)
94
+ on Read the Docs.
95
+
96
+ Getting Started
97
+ ===============
98
+
99
+ Yosys can be used with the interactive command shell, with
100
+ synthesis scripts or with command line arguments. Let's perform
101
+ a simple synthesis job using the interactive command shell:
102
+
103
+ $ ./build/yosys
104
+ yosys>
105
+
106
+ the command ``help`` can be used to print a list of all available
107
+ commands and ``help <command>`` to print details on the specified command:
108
+
109
+ yosys> help help
110
+
111
+ reading and elaborating the design using the Verilog frontend:
112
+
113
+ yosys> read -sv tests/simple/fiedler-cooley.v
114
+ yosys> hierarchy -top up3down5
115
+
116
+ writing the design to the console in the RTLIL format used by Yosys
117
+ internally:
118
+
119
+ yosys> write_rtlil
120
+
121
+ convert processes (``always`` blocks) to netlist elements and perform
122
+ some simple optimizations:
123
+
124
+ yosys> proc; opt
125
+
126
+ display design netlist using ``xdot``:
127
+
128
+ yosys> show
129
+
130
+ the same thing using ``gv`` as postscript viewer:
131
+
132
+ yosys> show -format ps -viewer gv
133
+
134
+ translating netlist to gate logic and perform some simple optimizations:
135
+
136
+ yosys> techmap; opt
137
+
138
+ write design netlist to a new Verilog file:
139
+
140
+ yosys> write_verilog synth.v
141
+
142
+ or using a simple synthesis script:
143
+
144
+ $ cat synth.ys
145
+ read -sv tests/simple/fiedler-cooley.v
146
+ hierarchy -top up3down5
147
+ proc; opt; techmap; opt
148
+ write_verilog synth.v
149
+
150
+ $ ./yosys synth.ys
151
+
152
+ If ABC is enabled in the Yosys build configuration and a cell library is given
153
+ in the liberty file ``mycells.lib``, the following synthesis script will
154
+ synthesize for the given cell library:
155
+
156
+ # read design
157
+ read -sv tests/simple/fiedler-cooley.v
158
+ hierarchy -top up3down5
159
+
160
+ # the high-level stuff
161
+ proc; fsm; opt; memory; opt
162
+
163
+ # mapping to internal cell library
164
+ techmap; opt
165
+
166
+ # mapping flip-flops to mycells.lib
167
+ dfflibmap -liberty mycells.lib
168
+
169
+ # mapping logic to mycells.lib
170
+ abc -liberty mycells.lib
171
+
172
+ # cleanup
173
+ clean
174
+
175
+ If you do not have a liberty file but want to test this synthesis script,
176
+ you can use the file ``examples/cmos/cmos_cells.lib`` from the yosys sources
177
+ as simple example.
178
+
179
+ Liberty file downloads for and information about free and open ASIC standard
180
+ cell libraries can be found here:
181
+
182
+ - http://www.vlsitechnology.org/html/libraries.html
183
+ - http://www.vlsitechnology.org/synopsys/vsclib013.lib
184
+
185
+ The command ``synth`` provides a good default synthesis script (see
186
+ ``help synth``):
187
+
188
+ read -sv tests/simple/fiedler-cooley.v
189
+ synth -top up3down5
190
+
191
+ # mapping to target cells
192
+ dfflibmap -liberty mycells.lib
193
+ abc -liberty mycells.lib
194
+ clean
195
+
196
+ The command ``prep`` provides a good default word-level synthesis script, as
197
+ used in SMT-based formal verification.
198
+
199
+
200
+ Additional information
201
+ ======================
202
+
203
+ The ``read_verilog`` command, used by default when calling ``read`` with Verilog
204
+ source input, does not perform syntax checking. You should instead lint your
205
+ source with another tool such as
206
+ [Verilator](https://www.veripool.org/verilator/) first, e.g. by calling
207
+ ``verilator --lint-only``.
208
+
209
+
210
+ Building the documentation
211
+ ==========================
212
+
213
+ Note that there is no need to build the manual if you just want to read it.
214
+ Simply visit https://yosys.readthedocs.io/en/latest/ instead.
215
+ If you're offline, you can read the sources, replacing `.../en/latest`
216
+ with `docs/source`.
217
+
218
+ In addition to those packages listed above for building Yosys from source, the
219
+ following are used for building the website:
220
+
221
+ $ sudo apt install pdf2svg faketime
222
+
223
+ Or for MacOS, using homebrew:
224
+
225
+ $ brew install pdf2svg libfaketime
226
+
227
+ PDFLaTeX, included with most LaTeX distributions, is also needed during the
228
+ build process for the website. Or, run the following:
229
+
230
+ $ sudo apt install texlive-latex-base texlive-latex-extra latexmk
231
+
232
+ Or for MacOS, using homebrew:
233
+
234
+ $ brew install basictex
235
+ $ sudo tlmgr update --self
236
+ $ sudo tlmgr install collection-latexextra latexmk tex-gyre
237
+
238
+ The Python package, Sphinx, is needed along with those listed in
239
+ `docs/source/requirements.txt`:
240
+
241
+ $ pip install -U sphinx -r docs/source/requirements.txt
242
+
243
+ DOCS (e.g.)
244
+
245
+ $ cmake --build build --target docs-html --parallel
246
+
247
+ This will build/rebuild yosys as necessary before generating the website
248
+ documentation from the yosys help commands. To build for pdf instead of html,
249
+ use the `docs-latexpdf` target.
chips/yosys/SOURCE.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "chips/yosys",
3
+ "licence": "ISC (YosysHQ Yosys open synthesis suite)",
4
+ "url": "https://github.com/YosysHQ/yosys",
5
+ "fetched_at_utc": "2026-11-20T08:12:19Z",
6
+ "fetch_exit": 0,
7
+ "files": 3372,
8
+ "bytes": 18740183
9
+ }
chips/yosys/backends/CMakeLists.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ add_subdirectory(aiger)
2
+ add_subdirectory(aiger2)
3
+ add_subdirectory(blif)
4
+ add_subdirectory(btor)
5
+ add_subdirectory(cxxrtl)
6
+ add_subdirectory(edif)
7
+ add_subdirectory(firrtl)
8
+ add_subdirectory(functional)
9
+ add_subdirectory(intersynth)
10
+ add_subdirectory(jny)
11
+ add_subdirectory(json)
12
+ add_subdirectory(rtlil)
13
+ add_subdirectory(simplec)
14
+ add_subdirectory(smt2)
15
+ add_subdirectory(smv)
16
+ add_subdirectory(spice)
17
+ add_subdirectory(table)
18
+ add_subdirectory(verilog)
chips/yosys/backends/aiger/CMakeLists.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ yosys_backend(aiger
2
+ aiger.cc
3
+ REQUIRES
4
+ json11
5
+ )
6
+ yosys_backend(xaiger
7
+ xaiger.cc
8
+ )
chips/yosys/backends/aiger/aiger.cc ADDED
@@ -0,0 +1,1062 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * yosys -- Yosys Open SYnthesis Suite
3
+ *
4
+ * Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
5
+ *
6
+ * Permission to use, copy, modify, and/or distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ *
18
+ */
19
+
20
+ #include "kernel/yosys.h"
21
+ #include "kernel/sigtools.h"
22
+ #include "kernel/json.h"
23
+ #include "kernel/yw.h"
24
+ #include "libs/json11/json11.hpp"
25
+
26
+ USING_YOSYS_NAMESPACE
27
+ PRIVATE_NAMESPACE_BEGIN
28
+
29
+ void aiger_encode(std::ostream &f, int x)
30
+ {
31
+ log_assert(x >= 0);
32
+
33
+ while (x & ~0x7f) {
34
+ f.put((x & 0x7f) | 0x80);
35
+ x = x >> 7;
36
+ }
37
+
38
+ f.put(x);
39
+ }
40
+
41
+ struct AigerWriter
42
+ {
43
+ Module *module;
44
+ bool zinit_mode;
45
+ SigMap sigmap;
46
+
47
+ dict<SigBit, bool> init_map;
48
+ pool<SigBit> input_bits, output_bits;
49
+ dict<SigBit, SigBit> not_map, ff_map, alias_map;
50
+ dict<SigBit, pair<SigBit, SigBit>> and_map;
51
+ vector<pair<SigBit, SigBit>> asserts, assumes;
52
+ vector<pair<SigBit, SigBit>> liveness, fairness;
53
+ pool<SigBit> initstate_bits;
54
+
55
+ vector<pair<int, int>> aig_gates;
56
+ vector<int> aig_latchin, aig_latchinit, aig_outputs;
57
+ vector<SigBit> bit2aig_stack;
58
+ size_t next_loop_check = 1024;
59
+ int aig_m = 0, aig_i = 0, aig_l = 0, aig_o = 0, aig_a = 0;
60
+ int aig_b = 0, aig_c = 0, aig_j = 0, aig_f = 0;
61
+
62
+ dict<SigBit, int> aig_map;
63
+ dict<SigBit, int> ordered_outputs;
64
+ dict<SigBit, int> ordered_latches;
65
+
66
+ dict<SigBit, int> init_inputs;
67
+ int initstate_ff = 0;
68
+
69
+ dict<SigBit, int> ywmap_clocks;
70
+ vector<Cell *> ywmap_asserts;
71
+ vector<Cell *> ywmap_assumes;
72
+
73
+ int mkgate(int a0, int a1)
74
+ {
75
+ aig_m++, aig_a++;
76
+ aig_gates.push_back(a0 > a1 ? make_pair(a0, a1) : make_pair(a1, a0));
77
+ return 2*aig_m;
78
+ }
79
+
80
+ int bit2aig(SigBit bit)
81
+ {
82
+ auto it = aig_map.find(bit);
83
+ if (it != aig_map.end()) {
84
+ log_assert(it->second >= 0);
85
+ return it->second;
86
+ }
87
+
88
+ if (bit2aig_stack.size() == next_loop_check) {
89
+ for (size_t i = 0; i < next_loop_check; ++i)
90
+ {
91
+ SigBit report_bit = bit2aig_stack[i];
92
+ if (report_bit != bit)
93
+ continue;
94
+ for (size_t j = i; j < next_loop_check; ++j) {
95
+ report_bit = bit2aig_stack[j];
96
+ if (report_bit.is_wire() && report_bit.wire->name.isPublic())
97
+ break;
98
+ }
99
+ log_error("Found combinational logic loop while processing signal %s.\n", log_signal(report_bit));
100
+ }
101
+ next_loop_check *= 2;
102
+ }
103
+ bit2aig_stack.push_back(bit);
104
+
105
+ // NB: Cannot use iterator returned from aig_map.insert()
106
+ // since this function is called recursively
107
+
108
+ int a = -1;
109
+ if (not_map.count(bit)) {
110
+ a = bit2aig(not_map.at(bit)) ^ 1;
111
+ } else
112
+ if (and_map.count(bit)) {
113
+ auto args = and_map.at(bit);
114
+ int a0 = bit2aig(args.first);
115
+ int a1 = bit2aig(args.second);
116
+ a = mkgate(a0, a1);
117
+ } else
118
+ if (alias_map.count(bit)) {
119
+ a = bit2aig(alias_map.at(bit));
120
+ } else
121
+ if (initstate_bits.count(bit)) {
122
+ a = initstate_ff;
123
+ }
124
+
125
+ bit2aig_stack.pop_back();
126
+
127
+ if (bit == State::Sx || bit == State::Sz)
128
+ log_error("Design contains 'x' or 'z' bits. Use 'setundef' to replace those constants.\n");
129
+
130
+ log_assert(a >= 0);
131
+ aig_map[bit] = a;
132
+ return a;
133
+ }
134
+
135
+ AigerWriter(Module *module, bool no_sort, bool zinit_mode, bool imode, bool omode, bool bmode, bool lmode) : module(module), zinit_mode(zinit_mode), sigmap(module)
136
+ {
137
+ pool<SigBit> undriven_bits;
138
+ pool<SigBit> unused_bits;
139
+
140
+ // promote public wires
141
+ for (auto wire : module->wires())
142
+ if (wire->name.isPublic())
143
+ sigmap.add(wire);
144
+
145
+ // promote output wires
146
+ for (auto wire : module->wires())
147
+ if (wire->port_output)
148
+ sigmap.add(wire);
149
+
150
+ // promote input wires
151
+ for (auto wire : module->wires())
152
+ if (wire->port_input)
153
+ sigmap.add(wire);
154
+
155
+ // handle ports
156
+ // provided the input_bits and output_bits don't get sorted they
157
+ // will be returned in reverse order, so add them in reverse to
158
+ // match
159
+ for (auto riter = module->ports.rbegin(); riter != module->ports.rend(); ++riter) {
160
+ auto *wire = module->wire(*riter);
161
+ for (int i = 0; i < GetSize(wire); i++)
162
+ {
163
+ SigBit wirebit(wire, i);
164
+ SigBit bit = sigmap(wirebit);
165
+
166
+ if (bit.wire == nullptr) {
167
+ if (wire->port_output) {
168
+ aig_map[wirebit] = (bit == State::S1) ? 1 : 0;
169
+ output_bits.insert(wirebit);
170
+ }
171
+ continue;
172
+ }
173
+
174
+ if (wire->port_input)
175
+ input_bits.insert(bit);
176
+
177
+ if (wire->port_output) {
178
+ if (bit != wirebit)
179
+ alias_map[wirebit] = bit;
180
+ output_bits.insert(wirebit);
181
+ }
182
+ }
183
+ }
184
+
185
+ // handle wires
186
+ for (auto wire : module->wires())
187
+ {
188
+ if (wire->attributes.count(ID::init)) {
189
+ SigSpec initsig = sigmap(wire);
190
+ Const initval = wire->attributes.at(ID::init);
191
+ for (int i = 0; i < GetSize(wire) && i < GetSize(initval); i++)
192
+ if (initval[i] == State::S0 || initval[i] == State::S1)
193
+ init_map[initsig[i]] = initval[i] == State::S1;
194
+ }
195
+
196
+ for (int i = 0; i < GetSize(wire); i++)
197
+ {
198
+ SigBit wirebit(wire, i);
199
+ SigBit bit = sigmap(wirebit);
200
+
201
+ if (bit.wire == nullptr)
202
+ continue;
203
+ if (wire->port_input || wire->port_output)
204
+ continue;
205
+
206
+ undriven_bits.insert(bit);
207
+ unused_bits.insert(bit);
208
+ }
209
+
210
+ if (wire->width == 1) {
211
+ auto gclk_attr = wire->attributes.find(ID::replaced_by_gclk);
212
+ if (gclk_attr != wire->attributes.end()) {
213
+ SigBit bit = sigmap(wire);
214
+ if (gclk_attr->second == State::S1)
215
+ ywmap_clocks[bit] |= 1;
216
+ else if (gclk_attr->second == State::S0)
217
+ ywmap_clocks[bit] |= 2;
218
+ }
219
+ }
220
+ }
221
+
222
+ for (auto cell : module->cells())
223
+ {
224
+ if (cell->type == ID($_NOT_))
225
+ {
226
+ SigBit A = sigmap(cell->getPort(ID::A).as_bit());
227
+ SigBit Y = sigmap(cell->getPort(ID::Y).as_bit());
228
+ unused_bits.erase(A);
229
+ undriven_bits.erase(Y);
230
+ not_map[Y] = A;
231
+ continue;
232
+ }
233
+
234
+ if (cell->type.in(ID($_FF_), ID($_DFF_N_), ID($_DFF_P_)))
235
+ {
236
+ SigBit D = sigmap(cell->getPort(ID::D).as_bit());
237
+ SigBit Q = sigmap(cell->getPort(ID::Q).as_bit());
238
+ unused_bits.erase(D);
239
+ undriven_bits.erase(Q);
240
+ ff_map[Q] = D;
241
+
242
+ if (cell->type != ID($_FF_)) {
243
+ auto sig_clk = sigmap(cell->getPort(ID::C).as_bit());
244
+ ywmap_clocks[sig_clk] |= cell->type == ID($_DFF_N_) ? 2 : 1;
245
+ }
246
+ continue;
247
+ }
248
+
249
+ if (cell->type == ID($anyinit))
250
+ {
251
+ auto sig_d = sigmap(cell->getPort(ID::D));
252
+ auto sig_q = sigmap(cell->getPort(ID::Q));
253
+ for (int i = 0; i < sig_d.size(); i++) {
254
+ undriven_bits.erase(sig_q[i]);
255
+ ff_map[sig_q[i]] = sig_d[i];
256
+ }
257
+ continue;
258
+ }
259
+
260
+ if (cell->type == ID($_AND_))
261
+ {
262
+ SigBit A = sigmap(cell->getPort(ID::A).as_bit());
263
+ SigBit B = sigmap(cell->getPort(ID::B).as_bit());
264
+ SigBit Y = sigmap(cell->getPort(ID::Y).as_bit());
265
+ unused_bits.erase(A);
266
+ unused_bits.erase(B);
267
+ undriven_bits.erase(Y);
268
+ and_map[Y] = make_pair(A, B);
269
+ continue;
270
+ }
271
+
272
+ if (cell->type == ID($initstate))
273
+ {
274
+ SigBit Y = sigmap(cell->getPort(ID::Y).as_bit());
275
+ undriven_bits.erase(Y);
276
+ initstate_bits.insert(Y);
277
+ continue;
278
+ }
279
+
280
+ if (cell->type == ID($assert))
281
+ {
282
+ SigBit A = sigmap(cell->getPort(ID::A).as_bit());
283
+ SigBit EN = sigmap(cell->getPort(ID::EN).as_bit());
284
+ unused_bits.erase(A);
285
+ unused_bits.erase(EN);
286
+ asserts.push_back(make_pair(A, EN));
287
+ ywmap_asserts.push_back(cell);
288
+ continue;
289
+ }
290
+
291
+ if (cell->type == ID($assume))
292
+ {
293
+ SigBit A = sigmap(cell->getPort(ID::A).as_bit());
294
+ SigBit EN = sigmap(cell->getPort(ID::EN).as_bit());
295
+ unused_bits.erase(A);
296
+ unused_bits.erase(EN);
297
+ assumes.push_back(make_pair(A, EN));
298
+ ywmap_assumes.push_back(cell);
299
+ continue;
300
+ }
301
+
302
+ if (cell->type == ID($live))
303
+ {
304
+ SigBit A = sigmap(cell->getPort(ID::A).as_bit());
305
+ SigBit EN = sigmap(cell->getPort(ID::EN).as_bit());
306
+ unused_bits.erase(A);
307
+ unused_bits.erase(EN);
308
+ liveness.push_back(make_pair(A, EN));
309
+ continue;
310
+ }
311
+
312
+ if (cell->type == ID($fair))
313
+ {
314
+ SigBit A = sigmap(cell->getPort(ID::A).as_bit());
315
+ SigBit EN = sigmap(cell->getPort(ID::EN).as_bit());
316
+ unused_bits.erase(A);
317
+ unused_bits.erase(EN);
318
+ fairness.push_back(make_pair(A, EN));
319
+ continue;
320
+ }
321
+
322
+ if (cell->type == ID($anyconst))
323
+ {
324
+ for (auto bit : sigmap(cell->getPort(ID::Y))) {
325
+ undriven_bits.erase(bit);
326
+ ff_map[bit] = bit;
327
+ }
328
+ continue;
329
+ }
330
+
331
+ if (cell->type == ID($anyseq))
332
+ {
333
+ for (auto bit : sigmap(cell->getPort(ID::Y))) {
334
+ undriven_bits.erase(bit);
335
+ input_bits.insert(bit);
336
+ }
337
+ continue;
338
+ }
339
+
340
+ if (cell->type == ID($scopeinfo))
341
+ continue;
342
+
343
+ log_error("Unsupported cell type: %s (%s)\n", cell->type.unescape(), cell);
344
+ }
345
+
346
+ for (auto bit : unused_bits)
347
+ undriven_bits.erase(bit);
348
+
349
+ if (!undriven_bits.empty()) {
350
+ undriven_bits.sort();
351
+ for (auto bit : undriven_bits) {
352
+ log_warning("Treating undriven bit %s.%s like $anyseq.\n", module, log_signal(bit));
353
+ input_bits.insert(bit);
354
+ }
355
+ log_warning("Treating a total of %d undriven bits in %s like $anyseq.\n", GetSize(undriven_bits), module);
356
+ }
357
+
358
+ init_map.sort();
359
+ // we are relying here on unsorted pools iterating last-in-first-out
360
+ if (!no_sort) {
361
+ input_bits.sort();
362
+ output_bits.sort();
363
+ }
364
+ not_map.sort();
365
+ ff_map.sort();
366
+ and_map.sort();
367
+
368
+ aig_map[State::S0] = 0;
369
+ aig_map[State::S1] = 1;
370
+
371
+ for (auto bit : input_bits) {
372
+ aig_m++, aig_i++;
373
+ aig_map[bit] = 2*aig_m;
374
+ }
375
+
376
+ if (imode && input_bits.empty()) {
377
+ aig_m++, aig_i++;
378
+ }
379
+
380
+ if (zinit_mode)
381
+ {
382
+ for (auto it : ff_map) {
383
+ if (init_map.count(it.first))
384
+ continue;
385
+ aig_m++, aig_i++;
386
+ init_inputs[it.first] = 2*aig_m;
387
+ }
388
+ }
389
+
390
+ int fair_live_inputs_cnt = GetSize(liveness);
391
+ int fair_live_inputs_m = aig_m;
392
+
393
+ aig_m += fair_live_inputs_cnt;
394
+ aig_i += fair_live_inputs_cnt;
395
+
396
+ for (auto it : ff_map) {
397
+ aig_m++, aig_l++;
398
+ aig_map[it.first] = 2*aig_m;
399
+ ordered_latches[it.first] = aig_l-1;
400
+ if (init_map.count(it.first) == 0)
401
+ aig_latchinit.push_back(2);
402
+ else
403
+ aig_latchinit.push_back(init_map.at(it.first) ? 1 : 0);
404
+ }
405
+
406
+ if (!initstate_bits.empty() || !init_inputs.empty()) {
407
+ aig_m++, aig_l++;
408
+ initstate_ff = 2*aig_m+1;
409
+ aig_latchinit.push_back(0);
410
+ }
411
+
412
+ int fair_live_latches_cnt = GetSize(fairness) + 2*GetSize(liveness);
413
+ int fair_live_latches_m = aig_m;
414
+ int fair_live_latches_l = aig_l;
415
+
416
+ aig_m += fair_live_latches_cnt;
417
+ aig_l += fair_live_latches_cnt;
418
+
419
+ for (int i = 0; i < fair_live_latches_cnt; i++)
420
+ aig_latchinit.push_back(0);
421
+
422
+ if (zinit_mode)
423
+ {
424
+ for (auto it : ff_map)
425
+ {
426
+ int l = ordered_latches[it.first];
427
+
428
+ if (aig_latchinit.at(l) == 1)
429
+ aig_map[it.first] ^= 1;
430
+
431
+ if (aig_latchinit.at(l) == 2)
432
+ {
433
+ int gated_ffout = mkgate(aig_map[it.first], initstate_ff^1);
434
+ int gated_initin = mkgate(init_inputs[it.first], initstate_ff);
435
+ aig_map[it.first] = mkgate(gated_ffout^1, gated_initin^1)^1;
436
+ }
437
+ }
438
+ }
439
+
440
+ for (auto it : ff_map) {
441
+ int a = bit2aig(it.second);
442
+ int l = ordered_latches[it.first];
443
+ if (zinit_mode && aig_latchinit.at(l) == 1)
444
+ aig_latchin.push_back(a ^ 1);
445
+ else
446
+ aig_latchin.push_back(a);
447
+ }
448
+
449
+ if (lmode && aig_l == 0) {
450
+ aig_m++, aig_l++;
451
+ aig_latchinit.push_back(0);
452
+ aig_latchin.push_back(0);
453
+ }
454
+
455
+ if (!initstate_bits.empty() || !init_inputs.empty())
456
+ aig_latchin.push_back(1);
457
+
458
+ for (auto bit : output_bits) {
459
+ aig_o++;
460
+ ordered_outputs[bit] = aig_o-1;
461
+ aig_outputs.push_back(bit2aig(bit));
462
+ }
463
+
464
+ if (omode && output_bits.empty()) {
465
+ aig_o++;
466
+ aig_outputs.push_back(0);
467
+ }
468
+
469
+ for (auto it : asserts) {
470
+ aig_b++;
471
+ int bit_a = bit2aig(it.first);
472
+ int bit_en = bit2aig(it.second);
473
+ aig_outputs.push_back(mkgate(bit_a^1, bit_en));
474
+ }
475
+
476
+ if (bmode && asserts.empty()) {
477
+ aig_b++;
478
+ aig_outputs.push_back(0);
479
+ }
480
+
481
+ for (auto it : assumes) {
482
+ aig_c++;
483
+ int bit_a = bit2aig(it.first);
484
+ int bit_en = bit2aig(it.second);
485
+ aig_outputs.push_back(mkgate(bit_a^1, bit_en)^1);
486
+ }
487
+
488
+ for (auto it : liveness)
489
+ {
490
+ int input_m = ++fair_live_inputs_m;
491
+ int latch_m1 = ++fair_live_latches_m;
492
+ int latch_m2 = ++fair_live_latches_m;
493
+
494
+ log_assert(GetSize(aig_latchin) == fair_live_latches_l);
495
+ fair_live_latches_l += 2;
496
+
497
+ int bit_a = bit2aig(it.first);
498
+ int bit_en = bit2aig(it.second);
499
+ int bit_s = 2*input_m;
500
+ int bit_q1 = 2*latch_m1;
501
+ int bit_q2 = 2*latch_m2;
502
+
503
+ int bit_d1 = mkgate(mkgate(bit_s, bit_en)^1, bit_q1^1)^1;
504
+ int bit_d2 = mkgate(mkgate(bit_d1, bit_a)^1, bit_q2^1)^1;
505
+
506
+ aig_j++;
507
+ aig_latchin.push_back(bit_d1);
508
+ aig_latchin.push_back(bit_d2);
509
+ aig_outputs.push_back(mkgate(bit_q1, bit_q2^1));
510
+ }
511
+
512
+ for (auto it : fairness)
513
+ {
514
+ int latch_m = ++fair_live_latches_m;
515
+
516
+ log_assert(GetSize(aig_latchin) == fair_live_latches_l);
517
+ fair_live_latches_l += 1;
518
+
519
+ int bit_a = bit2aig(it.first);
520
+ int bit_en = bit2aig(it.second);
521
+ int bit_q = 2*latch_m;
522
+
523
+ aig_f++;
524
+ aig_latchin.push_back(mkgate(mkgate(bit_q^1, bit_en^1)^1, bit_a^1));
525
+ aig_outputs.push_back(bit_q^1);
526
+ }
527
+ }
528
+
529
+ void write_aiger(std::ostream &f, bool ascii_mode, bool miter_mode, bool symbols_mode)
530
+ {
531
+ int aig_obc = aig_o + aig_b + aig_c;
532
+ int aig_obcj = aig_obc + aig_j;
533
+ int aig_obcjf = aig_obcj + aig_f;
534
+
535
+ log_assert(aig_m == aig_i + aig_l + aig_a);
536
+ log_assert(aig_l == GetSize(aig_latchin));
537
+ log_assert(aig_l == GetSize(aig_latchinit));
538
+ log_assert(aig_obcjf == GetSize(aig_outputs));
539
+
540
+ if (miter_mode) {
541
+ if (aig_b || aig_c || aig_j || aig_f)
542
+ log_error("Running AIGER back-end in -miter mode, but design contains $assert, $assume, $live and/or $fair cells!\n");
543
+ f << stringf("%s %d %d %d 0 %d %d\n", ascii_mode ? "aag" : "aig", aig_m, aig_i, aig_l, aig_a, aig_o);
544
+ } else {
545
+ f << stringf("%s %d %d %d %d %d", ascii_mode ? "aag" : "aig", aig_m, aig_i, aig_l, aig_o, aig_a);
546
+ if (aig_b || aig_c || aig_j || aig_f)
547
+ f << stringf(" %d %d %d %d", aig_b, aig_c, aig_j, aig_f);
548
+ f << stringf("\n");
549
+ }
550
+
551
+ if (ascii_mode)
552
+ {
553
+ for (int i = 0; i < aig_i; i++)
554
+ f << stringf("%d\n", 2*i+2);
555
+
556
+ for (int i = 0; i < aig_l; i++) {
557
+ if (zinit_mode || aig_latchinit.at(i) == 0)
558
+ f << stringf("%d %d\n", 2*(aig_i+i)+2, aig_latchin.at(i));
559
+ else if (aig_latchinit.at(i) == 1)
560
+ f << stringf("%d %d 1\n", 2*(aig_i+i)+2, aig_latchin.at(i));
561
+ else if (aig_latchinit.at(i) == 2)
562
+ f << stringf("%d %d %d\n", 2*(aig_i+i)+2, aig_latchin.at(i), 2*(aig_i+i)+2);
563
+ }
564
+
565
+ for (int i = 0; i < aig_obc; i++)
566
+ f << stringf("%d\n", aig_outputs.at(i));
567
+
568
+ for (int i = aig_obc; i < aig_obcj; i++)
569
+ f << stringf("1\n");
570
+
571
+ for (int i = aig_obc; i < aig_obcj; i++)
572
+ f << stringf("%d\n", aig_outputs.at(i));
573
+
574
+ for (int i = aig_obcj; i < aig_obcjf; i++)
575
+ f << stringf("%d\n", aig_outputs.at(i));
576
+
577
+ for (int i = 0; i < aig_a; i++)
578
+ f << stringf("%d %d %d\n", 2*(aig_i+aig_l+i)+2, aig_gates.at(i).first, aig_gates.at(i).second);
579
+ }
580
+ else
581
+ {
582
+ for (int i = 0; i < aig_l; i++) {
583
+ if (zinit_mode || aig_latchinit.at(i) == 0)
584
+ f << stringf("%d\n", aig_latchin.at(i));
585
+ else if (aig_latchinit.at(i) == 1)
586
+ f << stringf("%d 1\n", aig_latchin.at(i));
587
+ else if (aig_latchinit.at(i) == 2)
588
+ f << stringf("%d %d\n", aig_latchin.at(i), 2*(aig_i+i)+2);
589
+ }
590
+
591
+ for (int i = 0; i < aig_obc; i++)
592
+ f << stringf("%d\n", aig_outputs.at(i));
593
+
594
+ for (int i = aig_obc; i < aig_obcj; i++)
595
+ f << stringf("1\n");
596
+
597
+ for (int i = aig_obc; i < aig_obcj; i++)
598
+ f << stringf("%d\n", aig_outputs.at(i));
599
+
600
+ for (int i = aig_obcj; i < aig_obcjf; i++)
601
+ f << stringf("%d\n", aig_outputs.at(i));
602
+
603
+ for (int i = 0; i < aig_a; i++) {
604
+ int lhs = 2*(aig_i+aig_l+i)+2;
605
+ int rhs0 = aig_gates.at(i).first;
606
+ int rhs1 = aig_gates.at(i).second;
607
+ int delta0 = lhs - rhs0;
608
+ int delta1 = rhs0 - rhs1;
609
+ aiger_encode(f, delta0);
610
+ aiger_encode(f, delta1);
611
+ }
612
+ }
613
+
614
+ if (symbols_mode)
615
+ {
616
+ dict<string, vector<string>> symbols;
617
+
618
+ for (auto wire : module->wires())
619
+ {
620
+ if (!wire->name.isPublic())
621
+ continue;
622
+
623
+ SigSpec sig = sigmap(wire);
624
+
625
+ for (int i = 0; i < GetSize(wire); i++)
626
+ {
627
+ if (sig[i].wire == nullptr) {
628
+ if (wire->port_output)
629
+ sig[i] = SigBit(wire, i);
630
+ else
631
+ continue;
632
+ }
633
+
634
+ if (wire->port_input) {
635
+ int a = aig_map.at(sig[i]);
636
+ log_assert((a & 1) == 0);
637
+ if (GetSize(wire) != 1)
638
+ symbols[stringf("i%d", (a >> 1)-1)].push_back(stringf("%s[%d]", wire, i));
639
+ else
640
+ symbols[stringf("i%d", (a >> 1)-1)].push_back(stringf("%s", wire));
641
+ }
642
+
643
+ if (wire->port_output) {
644
+ int o = ordered_outputs.at(SigSpec(wire, i));
645
+ if (GetSize(wire) != 1)
646
+ symbols[stringf("%c%d", miter_mode ? 'b' : 'o', o)].push_back(stringf("%s[%d]", wire, i));
647
+ else
648
+ symbols[stringf("%c%d", miter_mode ? 'b' : 'o', o)].push_back(stringf("%s", wire));
649
+ }
650
+
651
+ if (init_inputs.count(sig[i])) {
652
+ int a = init_inputs.at(sig[i]);
653
+ log_assert((a & 1) == 0);
654
+ if (GetSize(wire) != 1)
655
+ symbols[stringf("i%d", (a >> 1)-1)].push_back(stringf("init:%s[%d]", wire, i));
656
+ else
657
+ symbols[stringf("i%d", (a >> 1)-1)].push_back(stringf("init:%s", wire));
658
+ }
659
+
660
+ if (ordered_latches.count(sig[i])) {
661
+ int l = ordered_latches.at(sig[i]);
662
+ const char *p = (zinit_mode && (aig_latchinit.at(l) == 1)) ? "!" : "";
663
+ if (GetSize(wire) != 1)
664
+ symbols[stringf("l%d", l)].push_back(stringf("%s%s[%d]", p, wire, i));
665
+ else
666
+ symbols[stringf("l%d", l)].push_back(stringf("%s%s", p, wire));
667
+ }
668
+ }
669
+ }
670
+
671
+ symbols.sort();
672
+
673
+ for (auto &sym : symbols) {
674
+ f << sym.first;
675
+ std::sort(sym.second.begin(), sym.second.end());
676
+ for (auto &s : sym.second)
677
+ f << " " << s;
678
+ f << std::endl;
679
+ }
680
+ }
681
+ f << stringf("c\nGenerated by %s\n", yosys_maybe_version());
682
+ }
683
+
684
+ void write_map(std::ostream &f, bool verbose_map, bool no_startoffset)
685
+ {
686
+ dict<int, string> input_lines;
687
+ dict<int, string> init_lines;
688
+ dict<int, string> output_lines;
689
+ dict<int, string> latch_lines;
690
+ dict<int, string> wire_lines;
691
+
692
+ for (auto wire : module->wires())
693
+ {
694
+ if (!verbose_map && !wire->name.isPublic())
695
+ continue;
696
+
697
+ SigSpec sig = sigmap(wire);
698
+
699
+ for (int i = 0; i < GetSize(wire); i++)
700
+ {
701
+ if (aig_map.count(sig[i]) == 0 || sig[i].wire == nullptr)
702
+ continue;
703
+
704
+ int a = aig_map.at(sig[i]);
705
+ int index = no_startoffset ? i : (wire->start_offset+i);
706
+
707
+ if (verbose_map)
708
+ wire_lines[a] += stringf("wire %d %d %s\n", a, index, wire);
709
+
710
+ if (wire->port_input) {
711
+ log_assert((a & 1) == 0);
712
+ input_lines[a] += stringf("input %d %d %s\n", (a >> 1)-1, index, wire);
713
+ }
714
+
715
+ if (wire->port_output) {
716
+ int o = ordered_outputs.at(SigSpec(wire, i));
717
+ output_lines[o] += stringf("output %d %d %s\n", o, index, wire);
718
+ }
719
+
720
+ if (init_inputs.count(sig[i])) {
721
+ int a = init_inputs.at(sig[i]);
722
+ log_assert((a & 1) == 0);
723
+ init_lines[a] += stringf("init %d %d %s\n", (a >> 1)-1, index, wire);
724
+ }
725
+
726
+ if (ordered_latches.count(sig[i])) {
727
+ int l = ordered_latches.at(sig[i]);
728
+ if (zinit_mode && (aig_latchinit.at(l) == 1))
729
+ latch_lines[l] += stringf("invlatch %d %d %s\n", l, index, wire);
730
+ else
731
+ latch_lines[l] += stringf("latch %d %d %s\n", l, index, wire);
732
+ }
733
+ }
734
+ }
735
+
736
+ input_lines.sort();
737
+ for (auto &it : input_lines)
738
+ f << it.second;
739
+
740
+ init_lines.sort();
741
+ for (auto &it : init_lines)
742
+ f << it.second;
743
+
744
+ output_lines.sort();
745
+ for (auto &it : output_lines)
746
+ f << it.second;
747
+
748
+ latch_lines.sort();
749
+ for (auto &it : latch_lines)
750
+ f << it.second;
751
+
752
+ if (initstate_ff)
753
+ f << stringf("ninitff %d\n", ((initstate_ff >> 1)-1-aig_i));
754
+
755
+ wire_lines.sort();
756
+ for (auto &it : wire_lines)
757
+ f << it.second;
758
+ }
759
+
760
+ void write_ywmap(PrettyJson &json)
761
+ {
762
+ json.begin_object();
763
+ json.entry("version", "Yosys Witness Aiger map");
764
+ json.entry("gennerator", yosys_maybe_version());
765
+
766
+ json.entry("latch_count", aig_l);
767
+ json.entry("input_count", aig_i);
768
+
769
+ dict<int, Json> clock_lines;
770
+ dict<int, Json> input_lines;
771
+ dict<int, Json> init_lines;
772
+ dict<int, Json> seq_lines;
773
+
774
+ for (auto cell : module->cells())
775
+ {
776
+ if (cell->type.in(ID($_FF_), ID($_DFF_N_), ID($_DFF_P_), ID($anyinit), ID($anyconst), ID($anyseq)))
777
+ {
778
+ // Use sig_q to get the FF output name, but sig to lookup aiger bits
779
+ auto sig_qy = cell->getPort(cell->type.in(ID($anyconst), ID($anyseq)) ? ID::Y : ID::Q);
780
+ SigSpec sig = sigmap(sig_qy);
781
+
782
+ if (cell->get_bool_attribute(ID(clk2fflogic)))
783
+ sig_qy = cell->getPort(ID::D); // For a clk2fflogic $_FF_ the named signal is the D input not the Q output
784
+
785
+ for (int i = 0; i < GetSize(sig_qy); i++) {
786
+ if (sig_qy[i].wire == nullptr || sig[i].wire == nullptr)
787
+ continue;
788
+
789
+ auto wire = sig_qy[i].wire;
790
+
791
+ if (init_inputs.count(sig[i])) {
792
+ int a = init_inputs.at(sig[i]);
793
+ log_assert((a & 1) == 0);
794
+ init_lines[a] = json11::Json(json11::Json::object {
795
+ { "path", witness_path(wire) },
796
+ { "input", (a >> 1) - 1 },
797
+ { "offset", sig_qy[i].offset },
798
+ });
799
+ }
800
+
801
+ if (input_bits.count(sig[i])) {
802
+ int a = aig_map.at(sig[i]);
803
+ log_assert((a & 1) == 0);
804
+ seq_lines[a] = json11::Json(json11::Json::object {
805
+ { "path", witness_path(wire) },
806
+ { "input", (a >> 1) - 1 },
807
+ { "offset", sig_qy[i].offset },
808
+ });
809
+ }
810
+ }
811
+ }
812
+ }
813
+
814
+ for (auto wire : module->wires())
815
+ {
816
+ SigSpec sig = sigmap(wire);
817
+ if (wire->port_input)
818
+ {
819
+ auto path = witness_path(wire);
820
+ for (int i = 0; i < GetSize(wire); i++) {
821
+ if (aig_map.count(sig[i]) == 0 || sig[i].wire == nullptr)
822
+ continue;
823
+
824
+ int a = aig_map.at(sig[i]);
825
+ log_assert((a & 1) == 0);
826
+ input_lines[a] = json11::Json(json11::Json::object {
827
+ { "path", path },
828
+ { "input", (a >> 1) - 1 },
829
+ { "offset", i },
830
+ });
831
+
832
+ if (ywmap_clocks.count(sig[i])) {
833
+ int clock_mode = ywmap_clocks[sig[i]];
834
+ if (clock_mode != 3) {
835
+ clock_lines[a] = json11::Json(json11::Json::object {
836
+ { "path", path },
837
+ { "input", (a >> 1) - 1 },
838
+ { "offset", i },
839
+ { "edge", clock_mode == 1 ? "posedge" : "negedge" },
840
+ });
841
+ }
842
+ }
843
+ }
844
+ }
845
+ }
846
+
847
+ json.name("clocks");
848
+ json.begin_array();
849
+ clock_lines.sort();
850
+ for (auto &it : clock_lines)
851
+ json.value(it.second);
852
+ json.end_array();
853
+
854
+ json.name("inputs");
855
+ json.begin_array();
856
+ input_lines.sort();
857
+ for (auto &it : input_lines)
858
+ json.value(it.second);
859
+ json.end_array();
860
+
861
+ json.name("seqs");
862
+ json.begin_array();
863
+ input_lines.sort();
864
+ for (auto &it : seq_lines)
865
+ json.value(it.second);
866
+ json.end_array();
867
+
868
+ json.name("inits");
869
+ json.begin_array();
870
+ input_lines.sort();
871
+ for (auto &it : init_lines)
872
+ json.value(it.second);
873
+ json.end_array();
874
+
875
+ json.name("asserts");
876
+ json.begin_array();
877
+ for (Cell *cell : ywmap_asserts)
878
+ json.value(witness_path(cell));
879
+ json.end_array();
880
+
881
+ json.name("assumes");
882
+ json.begin_array();
883
+ for (Cell *cell : ywmap_assumes)
884
+ json.value(witness_path(cell));
885
+ json.end_array();
886
+
887
+ json.end_object();
888
+ }
889
+
890
+ };
891
+
892
+ struct AigerBackend : public Backend {
893
+ AigerBackend() : Backend("aiger", "write design to AIGER file") { }
894
+ void help() override
895
+ {
896
+ // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
897
+ log("\n");
898
+ log(" write_aiger [options] [filename]\n");
899
+ log("\n");
900
+ log("Write the current design to an AIGER file. The design must be flattened and\n");
901
+ log("must not contain any cell types except $_AND_, $_NOT_, simple FF types,\n");
902
+ log("$assert and $assume cells, and $initstate cells.\n");
903
+ log("\n");
904
+ log("$assert and $assume cells are converted to AIGER bad state properties and\n");
905
+ log("invariant constraints.\n");
906
+ log("\n");
907
+ log(" -ascii\n");
908
+ log(" write ASCII version of AIGER format\n");
909
+ log("\n");
910
+ log(" -zinit\n");
911
+ log(" convert FFs to zero-initialized FFs, adding additional inputs for\n");
912
+ log(" uninitialized FFs.\n");
913
+ log("\n");
914
+ log(" -miter\n");
915
+ log(" design outputs are AIGER bad state properties\n");
916
+ log("\n");
917
+ log(" -symbols\n");
918
+ log(" include a symbol table in the generated AIGER file\n");
919
+ log("\n");
920
+ log(" -no-sort\n");
921
+ log(" don't sort input/output ports\n");
922
+ log("\n");
923
+ log(" -map <filename>\n");
924
+ log(" write an extra file with port and latch symbols\n");
925
+ log("\n");
926
+ log(" -vmap <filename>\n");
927
+ log(" like -map, but more verbose\n");
928
+ log("\n");
929
+ log(" -no-startoffset\n");
930
+ log(" make indexes zero based, enable using map files with smt solvers.\n");
931
+ log("\n");
932
+ log(" -ywmap <filename>\n");
933
+ log(" write a map file for conversion to and from yosys witness traces,\n");
934
+ log(" also allows for mapping AIGER bad-state properties and invariant\n");
935
+ log(" constraints back to individual formal properties by name.\n");
936
+ log("\n");
937
+ log(" -I, -O, -B, -L\n");
938
+ log(" If the design contains no input/output/assert/flip-flop then create one\n");
939
+ log(" dummy input/output/bad_state-pin or latch to make the tools reading the\n");
940
+ log(" AIGER file happy.\n");
941
+ log("\n");
942
+ }
943
+ void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
944
+ {
945
+ bool ascii_mode = false;
946
+ bool zinit_mode = false;
947
+ bool miter_mode = false;
948
+ bool symbols_mode = false;
949
+ bool no_sort = false;
950
+ bool verbose_map = false;
951
+ bool imode = false;
952
+ bool omode = false;
953
+ bool bmode = false;
954
+ bool lmode = false;
955
+ bool no_startoffset = false;
956
+ std::string map_filename;
957
+ std::string yw_map_filename;
958
+
959
+ log_header(design, "Executing AIGER backend.\n");
960
+
961
+ size_t argidx;
962
+ for (argidx = 1; argidx < args.size(); argidx++)
963
+ {
964
+ if (args[argidx] == "-ascii") {
965
+ ascii_mode = true;
966
+ continue;
967
+ }
968
+ if (args[argidx] == "-zinit") {
969
+ zinit_mode = true;
970
+ continue;
971
+ }
972
+ if (args[argidx] == "-miter") {
973
+ miter_mode = true;
974
+ continue;
975
+ }
976
+ if (args[argidx] == "-symbols") {
977
+ symbols_mode = true;
978
+ continue;
979
+ }
980
+ if (args[argidx] == "-no-sort") {
981
+ no_sort = true;
982
+ continue;
983
+ }
984
+ if (map_filename.empty() && args[argidx] == "-map" && argidx+1 < args.size()) {
985
+ map_filename = args[++argidx];
986
+ continue;
987
+ }
988
+ if (map_filename.empty() && args[argidx] == "-vmap" && argidx+1 < args.size()) {
989
+ map_filename = args[++argidx];
990
+ verbose_map = true;
991
+ continue;
992
+ }
993
+ if (yw_map_filename.empty() && args[argidx] == "-ywmap" && argidx+1 < args.size()) {
994
+ yw_map_filename = args[++argidx];
995
+ continue;
996
+ }
997
+ if (args[argidx] == "-no-startoffset") {
998
+ no_startoffset = true;
999
+ continue;
1000
+ }
1001
+ if (args[argidx] == "-I") {
1002
+ imode = true;
1003
+ continue;
1004
+ }
1005
+ if (args[argidx] == "-O") {
1006
+ omode = true;
1007
+ continue;
1008
+ }
1009
+ if (args[argidx] == "-B") {
1010
+ bmode = true;
1011
+ continue;
1012
+ }
1013
+ if (args[argidx] == "-L") {
1014
+ lmode = true;
1015
+ continue;
1016
+ }
1017
+ break;
1018
+ }
1019
+ extra_args(f, filename, args, argidx, !ascii_mode);
1020
+
1021
+ if (!yw_map_filename.empty() && !zinit_mode)
1022
+ log_error("Currently -ywmap requires -zinit.\n");
1023
+
1024
+ Module *top_module = design->top_module();
1025
+
1026
+ if (top_module == nullptr)
1027
+ log_error("Can't find top module in current design!\n");
1028
+
1029
+ if (!design->selected_whole_module(top_module))
1030
+ log_cmd_error("Can't handle partially selected module %s!\n", top_module);
1031
+
1032
+ if (!top_module->processes.empty())
1033
+ log_error("Found unmapped processes in module %s: unmapped processes are not supported in AIGER backend!\n", top_module);
1034
+ if (!top_module->memories.empty())
1035
+ log_error("Found unmapped memories in module %s: unmapped memories are not supported in AIGER backend!\n", top_module);
1036
+
1037
+ AigerWriter writer(top_module, no_sort, zinit_mode, imode, omode, bmode, lmode);
1038
+ writer.write_aiger(*f, ascii_mode, miter_mode, symbols_mode);
1039
+
1040
+ if (!map_filename.empty()) {
1041
+ rewrite_filename(filename);
1042
+ std::ofstream mapf;
1043
+ mapf.open(map_filename.c_str(), std::ofstream::trunc);
1044
+ if (mapf.fail())
1045
+ log_error("Can't open file `%s' for writing: %s\n", map_filename, strerror(errno));
1046
+ writer.write_map(mapf, verbose_map, no_startoffset);
1047
+ }
1048
+
1049
+ if (!yw_map_filename.empty()) {
1050
+ std::ofstream mapf;
1051
+ mapf.open(yw_map_filename.c_str(), std::ofstream::trunc);
1052
+
1053
+ PrettyJson json;
1054
+
1055
+ if (!json.write_to_file(yw_map_filename))
1056
+ log_error("Can't open file `%s' for writing: %s\n", yw_map_filename, strerror(errno));
1057
+ writer.write_ywmap(json);
1058
+ }
1059
+ }
1060
+ } AigerBackend;
1061
+
1062
+ PRIVATE_NAMESPACE_END
chips/yosys/backends/aiger/xaiger.cc ADDED
@@ -0,0 +1,815 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * yosys -- Yosys Open SYnthesis Suite
3
+ *
4
+ * Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
5
+ * 2019 Eddie Hung <eddie@fpgeh.com>
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
+ *
19
+ */
20
+
21
+ #include "kernel/yosys.h"
22
+ #include "kernel/sigtools.h"
23
+ #include "kernel/utils.h"
24
+ #include "kernel/timinginfo.h"
25
+
26
+ USING_YOSYS_NAMESPACE
27
+ PRIVATE_NAMESPACE_BEGIN
28
+
29
+ void aiger_encode(std::ostream &f, int x)
30
+ {
31
+ log_assert(x >= 0);
32
+
33
+ while (x & ~0x7f) {
34
+ f.put((x & 0x7f) | 0x80);
35
+ x = x >> 7;
36
+ }
37
+
38
+ f.put(x);
39
+ }
40
+
41
+ struct XAigerWriter
42
+ {
43
+ Design *design;
44
+ Module *module;
45
+ SigMap sigmap;
46
+
47
+ dict<SigBit, State> init_map;
48
+ pool<SigBit> input_bits, output_bits;
49
+ dict<SigBit, SigBit> not_map, alias_map;
50
+ dict<SigBit, pair<SigBit, SigBit>> and_map;
51
+ vector<SigBit> ci_bits, co_bits;
52
+ vector<Cell*> ff_list;
53
+ dict<SigBit, float> arrival_times;
54
+
55
+ vector<pair<int, int>> aig_gates;
56
+ vector<SigBit> bit2aig_stack;
57
+ int next_loop_check = 1024;
58
+ vector<int> aig_outputs;
59
+ int aig_m = 0, aig_i = 0, aig_l = 0, aig_o = 0, aig_a = 0;
60
+
61
+ dict<SigBit, int> aig_map;
62
+ dict<SigBit, int> ordered_outputs;
63
+
64
+ vector<Cell*> box_list;
65
+
66
+ int mkgate(int a0, int a1)
67
+ {
68
+ aig_m++, aig_a++;
69
+ aig_gates.push_back(a0 > a1 ? make_pair(a0, a1) : make_pair(a1, a0));
70
+ return 2*aig_m;
71
+ }
72
+
73
+ int bit2aig(SigBit bit)
74
+ {
75
+ auto it = aig_map.find(bit);
76
+ if (it != aig_map.end()) {
77
+ log_assert(it->second >= 0);
78
+ return it->second;
79
+ }
80
+
81
+ if (GetSize(bit2aig_stack)== next_loop_check) {
82
+ for (int i = 0; i < next_loop_check; ++i)
83
+ {
84
+ SigBit report_bit = bit2aig_stack[i];
85
+ if (report_bit != bit)
86
+ continue;
87
+ for (int j = i; j < next_loop_check; ++j) {
88
+ report_bit = bit2aig_stack[j];
89
+ if (report_bit.is_wire() && report_bit.wire->name.isPublic())
90
+ break;
91
+ }
92
+ log_error("Found combinatorial logic loop while processing signal %s.\n", log_signal(report_bit));
93
+ }
94
+ next_loop_check *= 2;
95
+ }
96
+
97
+ bit2aig_stack.push_back(bit);
98
+
99
+ // NB: Cannot use iterator returned from aig_map.insert()
100
+ // since this function is called recursively
101
+
102
+ int a = -1;
103
+ if (not_map.count(bit)) {
104
+ a = bit2aig(not_map.at(bit)) ^ 1;
105
+ } else
106
+ if (and_map.count(bit)) {
107
+ auto args = and_map.at(bit);
108
+ int a0 = bit2aig(args.first);
109
+ int a1 = bit2aig(args.second);
110
+ a = mkgate(a0, a1);
111
+ } else
112
+ if (alias_map.count(bit)) {
113
+ a = bit2aig(alias_map.at(bit));
114
+ }
115
+
116
+ bit2aig_stack.pop_back();
117
+
118
+ if (bit == State::Sx || bit == State::Sz) {
119
+ log_debug("Design contains 'x' or 'z' bits. Treating as 1'b0.\n");
120
+ a = aig_map.at(State::S0);
121
+ }
122
+
123
+ log_assert(a >= 0);
124
+ aig_map[bit] = a;
125
+ return a;
126
+ }
127
+
128
+ XAigerWriter(Module *module, bool dff_mode) : design(module->design), module(module), sigmap(module)
129
+ {
130
+ #ifndef NDEBUG
131
+ pool<std::pair<IdString,TimingInfo::NameBit>> seen;
132
+ #endif
133
+ pool<SigBit> undriven_bits;
134
+ pool<SigBit> unused_bits;
135
+
136
+ // promote public wires
137
+ for (auto wire : module->wires())
138
+ if (wire->name.isPublic())
139
+ sigmap.add(wire);
140
+
141
+ // promote input wires
142
+ for (auto wire : module->wires())
143
+ if (wire->port_input)
144
+ sigmap.add(wire);
145
+
146
+ // promote keep wires
147
+ for (auto wire : module->wires())
148
+ if (wire->get_bool_attribute(ID::keep))
149
+ sigmap.add(wire);
150
+
151
+ for (auto wire : module->wires()) {
152
+ auto it = wire->attributes.find(ID::init);
153
+ for (int i = 0; i < GetSize(wire); i++)
154
+ {
155
+ SigBit wirebit(wire, i);
156
+ SigBit bit = sigmap(wirebit);
157
+
158
+ if (bit.wire == nullptr) {
159
+ if (wire->port_output) {
160
+ aig_map[wirebit] = (bit == State::S1) ? 1 : 0;
161
+ output_bits.insert(wirebit);
162
+ }
163
+ continue;
164
+ }
165
+
166
+ undriven_bits.insert(bit);
167
+ unused_bits.insert(bit);
168
+
169
+ if (wire->port_input)
170
+ input_bits.insert(bit);
171
+
172
+ bool keep = wire->get_bool_attribute(ID::keep);
173
+ if (wire->port_output || keep) {
174
+ if (bit != wirebit)
175
+ alias_map[wirebit] = bit;
176
+ output_bits.insert(wirebit);
177
+ }
178
+
179
+ if (it != wire->attributes.end()) {
180
+ auto s = it->second[i];
181
+ if (s != State::Sx) {
182
+ auto r = init_map.insert(std::make_pair(bit, it->second[i]));
183
+ if (!r.second && r.first->second != it->second[i])
184
+ log_error("Bit '%s' has a conflicting (* init *) value.\n", log_signal(bit));
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ TimingInfo timing;
191
+
192
+ for (auto cell : module->cells()) {
193
+ if (!cell->has_keep_attr()) {
194
+ if (cell->type == ID($_NOT_))
195
+ {
196
+ SigBit A = sigmap(cell->getPort(ID::A).as_bit());
197
+ SigBit Y = sigmap(cell->getPort(ID::Y).as_bit());
198
+ unused_bits.erase(A);
199
+ undriven_bits.erase(Y);
200
+ not_map[Y] = A;
201
+ continue;
202
+ }
203
+
204
+ if (cell->type == ID($_AND_))
205
+ {
206
+ SigBit A = sigmap(cell->getPort(ID::A).as_bit());
207
+ SigBit B = sigmap(cell->getPort(ID::B).as_bit());
208
+ SigBit Y = sigmap(cell->getPort(ID::Y).as_bit());
209
+ unused_bits.erase(A);
210
+ unused_bits.erase(B);
211
+ undriven_bits.erase(Y);
212
+ and_map[Y] = make_pair(A, B);
213
+ continue;
214
+ }
215
+
216
+ if (dff_mode && cell->type.in(ID($_DFF_N_), ID($_DFF_P_)) && !cell->get_bool_attribute(ID::abc9_keep))
217
+ {
218
+ SigBit D = sigmap(cell->getPort(ID::D).as_bit());
219
+ SigBit Q = sigmap(cell->getPort(ID::Q).as_bit());
220
+ unused_bits.erase(D);
221
+ undriven_bits.erase(Q);
222
+ alias_map[Q] = D;
223
+ ff_list.emplace_back(cell);
224
+ continue;
225
+ }
226
+
227
+ if (cell->type.in(ID($specify2), ID($specify3), ID($specrule)))
228
+ continue;
229
+ }
230
+
231
+ RTLIL::Module* inst_module = design->module(cell->type);
232
+ if (inst_module && inst_module->get_blackbox_attribute()) {
233
+ bool abc9_flop = false;
234
+
235
+ auto it = cell->attributes.find(ID::abc9_box_seq);
236
+ if (it != cell->attributes.end()) {
237
+ log_assert(!cell->has_keep_attr());
238
+ log_assert(cell->parameters.empty());
239
+ int abc9_box_seq = it->second.as_int();
240
+ if (GetSize(box_list) <= abc9_box_seq)
241
+ box_list.resize(abc9_box_seq+1);
242
+ box_list[abc9_box_seq] = cell;
243
+ // Only flop boxes may have arrival times
244
+ // (all others are combinatorial)
245
+ log_assert(cell->parameters.empty());
246
+ abc9_flop = inst_module->get_bool_attribute(ID::abc9_flop);
247
+ if (!abc9_flop)
248
+ continue;
249
+ }
250
+
251
+ if (!timing.count(inst_module->name))
252
+ timing.setup_module(inst_module);
253
+
254
+ for (auto &i : timing.at(inst_module->name).arrival) {
255
+ if (!cell->hasPort(i.first.name))
256
+ continue;
257
+
258
+ auto port_wire = inst_module->wire(i.first.name);
259
+ log_assert(port_wire->port_output);
260
+
261
+ auto d = i.second.first;
262
+ if (d == 0)
263
+ continue;
264
+ auto offset = i.first.offset;
265
+
266
+ auto rhs = cell->getPort(i.first.name);
267
+ if (offset >= rhs.size())
268
+ continue;
269
+
270
+ #ifndef NDEBUG
271
+ if (ys_debug(1)) {
272
+ if (seen.emplace(inst_module->name, i.first).second) log("%s.%s[%d] abc9_arrival = %d\n",
273
+ cell->type.unescape(), cell->twines().unescaped_str(i.first.name), offset, d);
274
+ }
275
+ #endif
276
+ arrival_times[rhs[offset]] = d;
277
+ }
278
+
279
+ if (abc9_flop)
280
+ continue;
281
+ }
282
+
283
+ bool cell_known = inst_module || cell->known();
284
+ for (const auto &c : cell->connections()) {
285
+ if (c.second.is_fully_const()) continue;
286
+ auto port_wire = inst_module ? inst_module->wire(c.first) : nullptr;
287
+ auto is_input = (port_wire && port_wire->port_input) || !cell_known || cell->input(c.first);
288
+ auto is_output = (port_wire && port_wire->port_output) || !cell_known || cell->output(c.first);
289
+ if (!is_input && !is_output)
290
+ log_error("Connection '%s' on cell '%s' (type '%s') not recognised!\n", cell->twines().unescaped_str(c.first), cell, cell->type.unescape());
291
+
292
+ if (is_input)
293
+ for (auto b : c.second) {
294
+ Wire *w = b.wire;
295
+ if (!w) continue;
296
+ // Do not add as PO if bit is already a PI
297
+ if (input_bits.count(b))
298
+ continue;
299
+ if (!w->port_output || !cell_known) {
300
+ SigBit I = sigmap(b);
301
+ if (I != b)
302
+ alias_map[b] = I;
303
+ output_bits.insert(b);
304
+ }
305
+ }
306
+ }
307
+
308
+ //log_warning("Unsupported cell type: %s (%s)\n", cell->type.unescape(), cell);
309
+ }
310
+
311
+ dict<IdString, std::vector<IdString>> box_ports;
312
+ for (auto cell : box_list) {
313
+ log_assert(cell);
314
+
315
+ RTLIL::Module* box_module = design->module(cell->type);
316
+ log_assert(box_module);
317
+ log_assert(box_module->has_attribute(ID::abc9_box_id));
318
+
319
+ auto r = box_ports.insert(cell->type);
320
+ if (r.second) {
321
+ // Make carry in the last PI, and carry out the last PO
322
+ // since ABC requires it this way
323
+ IdString carry_in, carry_out;
324
+ for (const auto &port_name : box_module->ports) {
325
+ auto w = box_module->wire(port_name);
326
+ log_assert(w);
327
+ if (w->get_bool_attribute(ID::abc9_carry)) {
328
+ if (w->port_input) {
329
+ if (carry_in != IdString())
330
+ log_error("Module '%s' contains more than one 'abc9_carry' input port.\n", box_module);
331
+ carry_in = port_name;
332
+ }
333
+ if (w->port_output) {
334
+ if (carry_out != IdString())
335
+ log_error("Module '%s' contains more than one 'abc9_carry' output port.\n", box_module);
336
+ carry_out = port_name;
337
+ }
338
+ }
339
+ else
340
+ r.first->second.push_back(port_name);
341
+ }
342
+
343
+ if (carry_in != IdString() && carry_out == IdString())
344
+ log_error("Module '%s' contains an 'abc9_carry' input port but no output port.\n", box_module);
345
+ if (carry_in == IdString() && carry_out != IdString())
346
+ log_error("Module '%s' contains an 'abc9_carry' output port but no input port.\n", box_module);
347
+ if (carry_in != IdString()) {
348
+ r.first->second.push_back(carry_in);
349
+ r.first->second.push_back(carry_out);
350
+ }
351
+ }
352
+
353
+ for (auto port_name : r.first->second) {
354
+ auto w = box_module->wire(port_name);
355
+ log_assert(w);
356
+ auto rhs = cell->connections_.at(port_name, SigSpec());
357
+ rhs.append(Const(State::Sx, GetSize(w)-GetSize(rhs)));
358
+ if (w->port_input)
359
+ for (auto b : rhs) {
360
+ SigBit I = sigmap(b);
361
+ if (b == RTLIL::Sx)
362
+ b = State::S0;
363
+ else if (I != b) {
364
+ if (I == RTLIL::Sx)
365
+ alias_map[b] = State::S0;
366
+ else
367
+ alias_map[b] = I;
368
+ }
369
+ co_bits.emplace_back(b);
370
+ unused_bits.erase(I);
371
+ }
372
+ if (w->port_output)
373
+ for (const auto &b : rhs) {
374
+ SigBit O = sigmap(b);
375
+ if (O != b)
376
+ alias_map[O] = b;
377
+ ci_bits.emplace_back(b);
378
+ undriven_bits.erase(O);
379
+ }
380
+ }
381
+ }
382
+
383
+ for (auto bit : input_bits)
384
+ undriven_bits.erase(bit);
385
+ for (auto bit : output_bits)
386
+ unused_bits.erase(sigmap(bit));
387
+ for (auto bit : unused_bits)
388
+ undriven_bits.erase(bit);
389
+
390
+ // Make all undriven bits a primary input
391
+ for (auto bit : undriven_bits) {
392
+ input_bits.insert(bit);
393
+ undriven_bits.erase(bit);
394
+ }
395
+
396
+ struct sort_by_port_id {
397
+ bool operator()(const RTLIL::SigBit& a, const RTLIL::SigBit& b) const {
398
+ return std::tie(a.wire->port_id, a.wire->name, a.offset) <
399
+ std::tie(b.wire->port_id, b.wire->name, b.offset);
400
+ }
401
+ };
402
+ input_bits.sort(sort_by_port_id());
403
+ output_bits.sort(sort_by_port_id());
404
+
405
+ aig_map[State::S0] = 0;
406
+ aig_map[State::S1] = 1;
407
+
408
+ for (const auto &bit : input_bits) {
409
+ aig_m++, aig_i++;
410
+ log_assert(!aig_map.count(bit));
411
+ aig_map[bit] = 2*aig_m;
412
+ }
413
+
414
+ for (auto cell : ff_list) {
415
+ const SigBit &q = sigmap(cell->getPort(ID::Q));
416
+ aig_m++, aig_i++;
417
+ log_assert(!aig_map.count(q));
418
+ aig_map[q] = 2*aig_m;
419
+ }
420
+
421
+ for (auto &bit : ci_bits) {
422
+ aig_m++, aig_i++;
423
+ // 1'bx may exist here due to a box output
424
+ // that has been padded to its full width
425
+ if (bit == State::Sx)
426
+ continue;
427
+ if (aig_map.count(bit))
428
+ log_error("Visited AIG node more than once; this could be a combinatorial loop that has not been broken\n");
429
+ aig_map[bit] = 2*aig_m;
430
+ }
431
+
432
+ for (auto bit : co_bits) {
433
+ ordered_outputs[bit] = aig_o++;
434
+ aig_outputs.push_back(bit2aig(bit));
435
+ }
436
+
437
+ for (const auto &bit : output_bits) {
438
+ ordered_outputs[bit] = aig_o++;
439
+ int aig;
440
+ // Unlike bit2aig() which checks aig_map first for
441
+ // inout/scc bits, since aig_map will point to
442
+ // the PI, first attempt to find the NOT/AND driver
443
+ // before resorting to an aig_map lookup (which
444
+ // could be another PO)
445
+ if (input_bits.count(bit)) {
446
+ if (not_map.count(bit)) {
447
+ aig = bit2aig(not_map.at(bit)) ^ 1;
448
+ } else if (and_map.count(bit)) {
449
+ auto args = and_map.at(bit);
450
+ int a0 = bit2aig(args.first);
451
+ int a1 = bit2aig(args.second);
452
+ aig = mkgate(a0, a1);
453
+ }
454
+ else
455
+ aig = aig_map.at(bit);
456
+ }
457
+ else
458
+ aig = bit2aig(bit);
459
+ aig_outputs.push_back(aig);
460
+ }
461
+
462
+ for (auto cell : ff_list) {
463
+ const SigBit &d = sigmap(cell->getPort(ID::D));
464
+ aig_o++;
465
+ aig_outputs.push_back(aig_map.at(d));
466
+ }
467
+ }
468
+
469
+ void write_aiger(std::ostream &f, bool ascii_mode)
470
+ {
471
+ int aig_obc = aig_o;
472
+ int aig_obcj = aig_obc;
473
+ int aig_obcjf = aig_obcj;
474
+
475
+ log_assert(aig_m == aig_i + aig_l + aig_a);
476
+ log_assert(aig_obcjf == GetSize(aig_outputs));
477
+
478
+ f << stringf("%s %d %d %d %d %d", ascii_mode ? "aag" : "aig", aig_m, aig_i, aig_l, aig_o, aig_a);
479
+ f << stringf("\n");
480
+
481
+ if (ascii_mode)
482
+ {
483
+ for (int i = 0; i < aig_i; i++)
484
+ f << stringf("%d\n", 2*i+2);
485
+
486
+ for (int i = 0; i < aig_obc; i++)
487
+ f << stringf("%d\n", aig_outputs.at(i));
488
+
489
+ for (int i = aig_obc; i < aig_obcj; i++)
490
+ f << stringf("1\n");
491
+
492
+ for (int i = aig_obc; i < aig_obcj; i++)
493
+ f << stringf("%d\n", aig_outputs.at(i));
494
+
495
+ for (int i = aig_obcj; i < aig_obcjf; i++)
496
+ f << stringf("%d\n", aig_outputs.at(i));
497
+
498
+ for (int i = 0; i < aig_a; i++)
499
+ f << stringf("%d %d %d\n", 2*(aig_i+aig_l+i)+2, aig_gates.at(i).first, aig_gates.at(i).second);
500
+ }
501
+ else
502
+ {
503
+ for (int i = 0; i < aig_obc; i++)
504
+ f << stringf("%d\n", aig_outputs.at(i));
505
+
506
+ for (int i = aig_obc; i < aig_obcj; i++)
507
+ f << stringf("1\n");
508
+
509
+ for (int i = aig_obc; i < aig_obcj; i++)
510
+ f << stringf("%d\n", aig_outputs.at(i));
511
+
512
+ for (int i = aig_obcj; i < aig_obcjf; i++)
513
+ f << stringf("%d\n", aig_outputs.at(i));
514
+
515
+ for (int i = 0; i < aig_a; i++) {
516
+ int lhs = 2*(aig_i+aig_l+i)+2;
517
+ int rhs0 = aig_gates.at(i).first;
518
+ int rhs1 = aig_gates.at(i).second;
519
+ int delta0 = lhs - rhs0;
520
+ int delta1 = rhs0 - rhs1;
521
+ aiger_encode(f, delta0);
522
+ aiger_encode(f, delta1);
523
+ }
524
+ }
525
+
526
+ f << "c";
527
+
528
+ auto write_buffer = [](std::ostream &buffer, unsigned int u32) {
529
+ typedef unsigned char uchar;
530
+ unsigned char u32_be[4] = {
531
+ (uchar) (u32 >> 24), (uchar) (u32 >> 16), (uchar) (u32 >> 8), (uchar) u32
532
+ };
533
+ buffer.write((char *) u32_be, sizeof(u32_be));
534
+ };
535
+ std::stringstream h_buffer;
536
+ auto write_h_buffer = std::bind(write_buffer, std::ref(h_buffer), std::placeholders::_1);
537
+ write_h_buffer(1);
538
+ log_debug("ciNum = %d\n", GetSize(input_bits) + GetSize(ff_list) + GetSize(ci_bits));
539
+ write_h_buffer(GetSize(input_bits) + GetSize(ff_list) + GetSize(ci_bits));
540
+ log_debug("coNum = %d\n", GetSize(output_bits) + GetSize(ff_list) + GetSize(co_bits));
541
+ write_h_buffer(GetSize(output_bits) + GetSize(ff_list) + GetSize(co_bits));
542
+ log_debug("piNum = %d\n", GetSize(input_bits) + GetSize(ff_list));
543
+ write_h_buffer(GetSize(input_bits) + GetSize(ff_list));
544
+ log_debug("poNum = %d\n", GetSize(output_bits) + GetSize(ff_list));
545
+ write_h_buffer(GetSize(output_bits) + GetSize(ff_list));
546
+ log_debug("boxNum = %d\n", GetSize(box_list));
547
+ write_h_buffer(GetSize(box_list));
548
+
549
+ auto write_buffer_float = [](std::stringstream &buffer, float f32) {
550
+ buffer.write(reinterpret_cast<const char*>(&f32), sizeof(f32));
551
+ };
552
+ std::stringstream i_buffer;
553
+ auto write_i_buffer = std::bind(write_buffer_float, std::ref(i_buffer), std::placeholders::_1);
554
+ for (auto bit : input_bits)
555
+ write_i_buffer(arrival_times.at(bit, 0));
556
+ //std::stringstream o_buffer;
557
+ //auto write_o_buffer = std::bind(write_buffer_float, std::ref(o_buffer), std::placeholders::_1);
558
+ //for (auto bit : output_bits)
559
+ // write_o_buffer(0);
560
+
561
+ if (!box_list.empty() || !ff_list.empty()) {
562
+ dict<IdString, std::tuple<int,int,int>> cell_cache;
563
+
564
+ int box_count = 0;
565
+ for (auto cell : box_list) {
566
+ log_assert(cell);
567
+ log_assert(cell->parameters.empty());
568
+
569
+ auto r = cell_cache.insert(cell->type);
570
+ auto &v = r.first->second;
571
+ if (r.second) {
572
+ RTLIL::Module* box_module = design->module(cell->type);
573
+ log_assert(box_module);
574
+
575
+ int box_inputs = 0, box_outputs = 0;
576
+ for (auto port_name : box_module->ports) {
577
+ RTLIL::Wire *w = box_module->wire(port_name);
578
+ log_assert(w);
579
+ if (w->port_input)
580
+ box_inputs += GetSize(w);
581
+ if (w->port_output)
582
+ box_outputs += GetSize(w);
583
+ }
584
+
585
+ std::get<0>(v) = box_inputs;
586
+ std::get<1>(v) = box_outputs;
587
+ std::get<2>(v) = box_module->attributes.at(ID::abc9_box_id).as_int();
588
+ }
589
+
590
+ write_h_buffer(std::get<0>(v));
591
+ write_h_buffer(std::get<1>(v));
592
+ write_h_buffer(std::get<2>(v));
593
+ write_h_buffer(box_count++);
594
+ }
595
+
596
+ std::stringstream r_buffer;
597
+ auto write_r_buffer = std::bind(write_buffer, std::ref(r_buffer), std::placeholders::_1);
598
+ log_debug("flopNum = %d\n", GetSize(ff_list));
599
+ write_r_buffer(ff_list.size());
600
+
601
+ std::stringstream s_buffer;
602
+ auto write_s_buffer = std::bind(write_buffer, std::ref(s_buffer), std::placeholders::_1);
603
+ write_s_buffer(ff_list.size());
604
+
605
+ dict<SigSpec, int> clk_to_mergeability;
606
+ for (const auto cell : ff_list) {
607
+ const SigBit &d = sigmap(cell->getPort(ID::D));
608
+ const SigBit &q = sigmap(cell->getPort(ID::Q));
609
+
610
+ SigSpec clk_and_pol{sigmap(cell->getPort(ID::C)), cell->type[6] == 'P' ? State::S1 : State::S0};
611
+ auto r = clk_to_mergeability.insert(std::make_pair(clk_and_pol, clk_to_mergeability.size()+1));
612
+ int mergeability = r.first->second;
613
+ log_assert(mergeability > 0);
614
+ write_r_buffer(mergeability);
615
+
616
+ State init = init_map.at(q, State::Sx);
617
+ log_debug("Cell '%s' (type %s) has (* init *) value '%s'.\n", cell, cell->type.unescape(), log_signal(init));
618
+ if (init == State::S1)
619
+ write_s_buffer(1);
620
+ else if (init == State::S0)
621
+ write_s_buffer(0);
622
+ else {
623
+ log_assert(init == State::Sx);
624
+ write_s_buffer(2);
625
+ }
626
+
627
+ // Use arrival time from output of flop box
628
+ write_i_buffer(arrival_times.at(d, 0));
629
+ //write_o_buffer(0);
630
+ }
631
+
632
+ f << "r";
633
+ std::string buffer_str = r_buffer.str();
634
+ write_buffer(f, buffer_str.size());
635
+ f.write(buffer_str.data(), buffer_str.size());
636
+
637
+ f << "s";
638
+ buffer_str = s_buffer.str();
639
+ write_buffer(f, buffer_str.size());
640
+ f.write(buffer_str.data(), buffer_str.size());
641
+
642
+ RTLIL::Design *holes_design;
643
+ auto it = saved_designs.find("$abc9_holes");
644
+ if (it != saved_designs.end())
645
+ holes_design = it->second.get();
646
+ else
647
+ holes_design = nullptr;
648
+ RTLIL::Module *holes_module = holes_design ?
649
+ holes_design->module(holes_design->twines().find_from(module->twines(), module->name)) : nullptr;
650
+ if (holes_module) {
651
+ std::stringstream a_buffer;
652
+ XAigerWriter writer(holes_module, false /* dff_mode */);
653
+ writer.write_aiger(a_buffer, false /*ascii_mode*/);
654
+
655
+ f << "a";
656
+ std::string buffer_str = a_buffer.str();
657
+ write_buffer(f, buffer_str.size());
658
+ f.write(buffer_str.data(), buffer_str.size());
659
+ }
660
+ }
661
+
662
+ f << "h";
663
+ std::string buffer_str = h_buffer.str();
664
+ write_buffer(f, buffer_str.size());
665
+ f.write(buffer_str.data(), buffer_str.size());
666
+
667
+ f << "i";
668
+ buffer_str = i_buffer.str();
669
+ write_buffer(f, buffer_str.size());
670
+ f.write(buffer_str.data(), buffer_str.size());
671
+ //f << "o";
672
+ //buffer_str = o_buffer.str();
673
+ //buffer_size_be = to_big_endian(buffer_str.size());
674
+ //f.write(reinterpret_cast<const char*>(&buffer_size_be), sizeof(buffer_size_be));
675
+ //f.write(buffer_str.data(), buffer_str.size());
676
+
677
+ f << stringf("Generated by %s\n", yosys_maybe_version());
678
+
679
+ design->scratchpad_set_int("write_xaiger.num_ands", and_map.size());
680
+ design->scratchpad_set_int("write_xaiger.num_wires", aig_map.size());
681
+ design->scratchpad_set_int("write_xaiger.num_inputs", input_bits.size());
682
+ design->scratchpad_set_int("write_xaiger.num_outputs", output_bits.size());
683
+ }
684
+
685
+ void write_map(std::ostream &f, bool name_mode)
686
+ {
687
+ dict<int, string> input_lines;
688
+ dict<int, string> output_lines;
689
+
690
+ for (auto wire : module->wires())
691
+ {
692
+ std::string sym = name_mode ? wire->name.unescape() : design->twines().ref_token(wire->name);
693
+ for (int i = 0; i < GetSize(wire); i++)
694
+ {
695
+ RTLIL::SigBit b(wire, i);
696
+ if (input_bits.count(b)) {
697
+ int a = aig_map.at(b);
698
+ log_assert((a & 1) == 0);
699
+ input_lines[a] += stringf("input %d %d %s\n", (a >> 1)-1, wire->start_offset+i, sym);
700
+ }
701
+
702
+ if (output_bits.count(b)) {
703
+ int o = ordered_outputs.at(b);
704
+ output_lines[o] += stringf("output %d %d %s\n", o - GetSize(co_bits), wire->start_offset+i, sym);
705
+ }
706
+ }
707
+ }
708
+
709
+ input_lines.sort();
710
+ for (auto &it : input_lines)
711
+ f << it.second;
712
+ log_assert(input_lines.size() == input_bits.size());
713
+
714
+ int box_count = 0;
715
+ for (auto cell : box_list)
716
+ f << stringf("box %d %d %s\n", box_count++, 0,
717
+ name_mode ? cell->name.unescape() : design->twines().ref_token(cell->name));
718
+
719
+ output_lines.sort();
720
+ for (auto &it : output_lines)
721
+ f << it.second;
722
+ log_assert(output_lines.size() == output_bits.size());
723
+ }
724
+ };
725
+
726
+ struct XAigerBackend : public Backend {
727
+ XAigerBackend() : Backend("xaiger", "write design to XAIGER file") { }
728
+ void help() override
729
+ {
730
+ // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
731
+ log("\n");
732
+ log(" write_xaiger [options] [filename]\n");
733
+ log("\n");
734
+ log("Write the top module (according to the (* top *) attribute or if only one module\n");
735
+ log("is currently selected) to an XAIGER file. Any non $_NOT_, $_AND_, (optionally\n");
736
+ log("$_DFF_N_, $_DFF_P_), or non (* abc9_box *) cells will be converted into psuedo-\n");
737
+ log("inputs and pseudo-outputs. Whitebox contents will be taken from the equivalent\n");
738
+ log("module in the '$abc9_holes' design, if it exists.\n");
739
+ log("\n");
740
+ log(" -ascii\n");
741
+ log(" write ASCII version of AIGER format\n");
742
+ log("\n");
743
+ log(" -map <filename>\n");
744
+ log(" write an extra file with port and box symbols, as opaque name\n");
745
+ log(" references that 'abc_ops_reintegrate' resolves. They are only\n");
746
+ log(" valid within the run of yosys that wrote them.\n");
747
+ log("\n");
748
+ log(" -map-strings\n");
749
+ log(" write strings into the -map file instead of internal ID integers.\n");
750
+ log(" Not readable with read_xaiger, for debugging only.\n");
751
+ log("\n");
752
+ log(" -dff\n");
753
+ log(" write $_DFF_[NP]_ cells\n");
754
+ log("\n");
755
+ }
756
+ void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
757
+ {
758
+ bool ascii_mode = false, dff_mode = false, map_names_mode = false;
759
+ std::string map_filename;
760
+
761
+ log_header(design, "Executing XAIGER backend.\n");
762
+
763
+ size_t argidx;
764
+ for (argidx = 1; argidx < args.size(); argidx++)
765
+ {
766
+ if (args[argidx] == "-ascii") {
767
+ ascii_mode = true;
768
+ continue;
769
+ }
770
+ if (map_filename.empty() && args[argidx] == "-map" && argidx+1 < args.size()) {
771
+ map_filename = args[++argidx];
772
+ continue;
773
+ }
774
+ if (args[argidx] == "-map-strings") {
775
+ map_names_mode = true;
776
+ continue;
777
+ }
778
+ if (args[argidx] == "-dff") {
779
+ dff_mode = true;
780
+ continue;
781
+ }
782
+ break;
783
+ }
784
+ extra_args(f, filename, args, argidx, !ascii_mode);
785
+
786
+ if (map_names_mode && map_filename.empty())
787
+ log_cmd_error("The -map-names option requires -map.\n");
788
+
789
+ Module *top_module = design->top_module();
790
+
791
+ if (top_module == nullptr)
792
+ log_error("Can't find top module in current design!\n");
793
+
794
+ if (!design->selected_whole_module(top_module))
795
+ log_cmd_error("Can't handle partially selected module %s!\n", top_module);
796
+
797
+ if (!top_module->processes.empty())
798
+ log_error("Found unmapped processes in module %s: unmapped processes are not supported in XAIGER backend!\n", top_module);
799
+ if (!top_module->memories.empty())
800
+ log_error("Found unmapped memories in module %s: unmapped memories are not supported in XAIGER backend!\n", top_module);
801
+
802
+ XAigerWriter writer(top_module, dff_mode);
803
+ writer.write_aiger(*f, ascii_mode);
804
+
805
+ if (!map_filename.empty()) {
806
+ std::ofstream mapf;
807
+ mapf.open(map_filename.c_str(), std::ofstream::trunc);
808
+ if (mapf.fail())
809
+ log_error("Can't open file `%s' for writing: %s\n", map_filename, strerror(errno));
810
+ writer.write_map(mapf, map_names_mode);
811
+ }
812
+ }
813
+ } XAigerBackend;
814
+
815
+ PRIVATE_NAMESPACE_END
chips/yosys/backends/aiger2/CMakeLists.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ yosys_backend(aiger2
2
+ aiger.cc
3
+ PROVIDES
4
+ write_xaiger2
5
+ )
chips/yosys/backends/aiger2/aiger.cc ADDED
@@ -0,0 +1,1978 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * yosys -- Yosys Open SYnthesis Suite
3
+ *
4
+ * Copyright (C) Martin Povišer <povik@cutebit.org>
5
+ *
6
+ * Permission to use, copy, modify, and/or distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ *
18
+ */
19
+
20
+ // TODOs:
21
+ // - gracefully handling inout ports (an error message probably)
22
+ // - undriven wires
23
+ // - zero-width operands
24
+ // - decide how to unify this with cellaigs
25
+ // - break up Index into something smaller
26
+ // - (C++20) remove snprintf-into-std::ostream weirdness
27
+
28
+ #include "kernel/register.h"
29
+ #include "kernel/newcelltypes.h"
30
+ #include "kernel/rtlil.h"
31
+ #include "kernel/utils.h"
32
+
33
+ USING_YOSYS_NAMESPACE
34
+ PRIVATE_NAMESPACE_BEGIN
35
+
36
+ #define BITWISE_OPS ID($buf), ID($barrier), ID($not), ID($mux), ID($and), ID($or), ID($xor), ID($xnor), \
37
+ ID($fa), ID($bwmux)
38
+
39
+ #define REDUCE_OPS ID($reduce_and), ID($reduce_or), ID($reduce_xor), ID($reduce_xnor), ID($reduce_bool)
40
+
41
+ #define LOGIC_OPS ID($logic_and), ID($logic_or), ID($logic_not)
42
+
43
+ #define GATE_OPS ID($_BUF_), ID($_NOT_), ID($_AND_), ID($_NAND_), ID($_OR_), ID($_NOR_), \
44
+ ID($_XOR_), ID($_XNOR_), ID($_ANDNOT_), ID($_ORNOT_), ID($_MUX_), ID($_NMUX_), \
45
+ ID($_AOI3_), ID($_OAI3_), ID($_AOI4_), ID($_OAI4_)
46
+
47
+ #define CMP_OPS ID($eq), ID($ne), ID($eqx), ID($nex), ID($lt), ID($le), ID($ge), ID($gt)
48
+
49
+ #define ARITH_OPS ID($add), ID($sub), ID($neg)
50
+
51
+ #define SHIFT_OPS ID($shl), ID($shr), ID($sshl), ID($sshr), ID($shift), ID($shiftx)
52
+
53
+ static constexpr auto known_ops = []() constexpr {
54
+ StaticCellTypes::Categories::Category c{};
55
+ for (auto id : {BITWISE_OPS})
56
+ c.set_id(id);
57
+ for (auto id : {REDUCE_OPS})
58
+ c.set_id(id);
59
+ for (auto id : {LOGIC_OPS})
60
+ c.set_id(id);
61
+ for (auto id : {GATE_OPS})
62
+ c.set_id(id);
63
+ for (auto id : {CMP_OPS})
64
+ c.set_id(id);
65
+ for (auto id : {ARITH_OPS})
66
+ c.set_id(id);
67
+ for (auto id : {SHIFT_OPS})
68
+ c.set_id(id);
69
+ for (auto id : {ID($pos), ID($pmux), ID($bmux), ID($mul)})
70
+ c.set_id(id);
71
+ return c;
72
+ }();
73
+
74
+ // Resolve a cell to the module we should descend into
75
+ Module *cell_def(Design *design, Cell *cell)
76
+ {
77
+ Module *def = design->module(cell->type);
78
+
79
+ if (def && !cell->parameters.empty()) {
80
+ def = design->module(def->derive(design, cell->parameters));
81
+ if (def)
82
+ def->bufNormalize();
83
+ }
84
+
85
+ return def;
86
+ }
87
+
88
+ template<typename Writer, typename Lit, Lit CFALSE, Lit CTRUE>
89
+ struct Index {
90
+ struct HierCursor;
91
+ struct ModuleInfo {
92
+ Module *module;
93
+ int len;
94
+ dict<Wire *, int> windices;
95
+ dict<Cell *, int> suboffsets;
96
+ pool<Cell *> found_blackboxes;
97
+
98
+ bool indexing = false;
99
+ bool indexed = false;
100
+ };
101
+
102
+ dict<Module *, ModuleInfo> modules;
103
+
104
+ int index_wires(ModuleInfo &info, RTLIL::Module *m)
105
+ {
106
+ int sum = 0;
107
+ for (auto w : m->wires()) {
108
+ info.windices[w] = sum;
109
+ sum += w->width;
110
+ }
111
+ return sum;
112
+ }
113
+
114
+ bool flatten = false;
115
+ bool inline_whiteboxes = false;
116
+ bool allow_blackboxes = false;
117
+
118
+ bool is_known_op(Cell *cell)
119
+ {
120
+ if (cell->type == ID($barrier))
121
+ return !allow_blackboxes;
122
+ return known_ops(cell->type);
123
+ }
124
+
125
+ int index_module(RTLIL::Module *m)
126
+ {
127
+ ModuleInfo &info = modules[m];
128
+
129
+ if (info.indexed)
130
+ return info.len;
131
+
132
+ if (info.indexing && !info.indexed)
133
+ log_error("Hierarchy error\n");
134
+
135
+ info.module = m;
136
+ int pos = index_wires(info, m);
137
+
138
+ for (auto cell : m->cells()) {
139
+ if (is_known_op(cell) || cell->type.in(ID($scopeinfo), ID($specify2), ID($specify3), ID($specrule), ID($input_port)))
140
+ continue;
141
+
142
+ Module *submodule = cell_def(m->design, cell);
143
+
144
+ if (submodule && flatten &&
145
+ !submodule->get_bool_attribute(ID::keep_hierarchy) &&
146
+ !submodule->get_blackbox_attribute(inline_whiteboxes)) {
147
+ info.suboffsets[cell] = pos;
148
+ pos += index_module(submodule);
149
+ } else {
150
+ if (allow_blackboxes) {
151
+ info.found_blackboxes.insert(cell);
152
+ } else {
153
+ // Even if we don't allow blackboxes these might still be
154
+ // present outside of any traversed input cones, so we
155
+ // can't bail at this point. If they are hit by a traversal
156
+ // (which can only really happen with $tribuf not
157
+ // $connect), we can still detect this as an error later.
158
+ if (cell->type == ID($connect) || (cell->type == ID($tribuf) && cell->has_attribute(ID(aiger2_zbuf))))
159
+ continue;
160
+ if (!submodule || submodule->get_blackbox_attribute())
161
+ log_error("Unsupported cell type: %s (%s in %s)\n",
162
+ cell->type.unescape(), cell, m);
163
+ }
164
+ }
165
+ }
166
+
167
+ info.len = pos;
168
+ return info.len;
169
+ }
170
+
171
+ Design *design;
172
+ Module *top;
173
+ ModuleInfo *top_minfo;
174
+ std::vector<Lit> lits;
175
+
176
+ Index()
177
+ {
178
+ }
179
+
180
+ void setup(RTLIL::Module *top)
181
+ {
182
+ design = top->design;
183
+ this->top = top;
184
+
185
+ modules.reserve(top->design->modules().size());
186
+ int nlits = index_module(top);
187
+ log_debug("allocating for %d literals\n", nlits);
188
+ lits.resize(nlits, Writer::EMPTY_LIT);
189
+ top_minfo = &modules.at(top);
190
+ }
191
+
192
+ bool const_folding = true;
193
+ bool strashing = false;
194
+ dict<std::pair<Lit, Lit>, Lit> cache;
195
+
196
+ Lit AND(Lit a, Lit b)
197
+ {
198
+ if (const_folding) {
199
+ if (a == CFALSE || b == CFALSE)
200
+ return CFALSE;
201
+ if (a == CTRUE)
202
+ return b;
203
+ if (b == CTRUE)
204
+ return a;
205
+ }
206
+
207
+ if (!strashing) {
208
+ return (static_cast<Writer*>(this))->emit_gate(a, b);
209
+ } else {
210
+ // AigMaker::node2index
211
+
212
+ // In XAIGER, the ordering of inputs is used to distinguish between AND
213
+ // and XOR gates. AND gates have their first input literal be larger
214
+ // than their second, and vice-versa for XORs.
215
+ if (a < b) std::swap(a, b);
216
+ auto pair = std::make_pair(a, b);
217
+
218
+ if (!cache.count(pair)) {
219
+ Lit nl = (static_cast<Writer*>(this))->emit_gate(a, b);
220
+ cache[pair] = nl;
221
+ return nl;
222
+ } else {
223
+ return cache.at(pair);
224
+ }
225
+ }
226
+ }
227
+
228
+ Lit NOT(Lit lit)
229
+ {
230
+ return Writer::negate(lit);
231
+ }
232
+
233
+ Lit OR(Lit a, Lit b)
234
+ {
235
+ Lit not_a = NOT(a);
236
+ Lit not_b = NOT(b);
237
+ return NOT(AND(not_a, not_b));
238
+ }
239
+
240
+ Lit MUX(Lit a, Lit b, Lit s)
241
+ {
242
+ if (const_folding) {
243
+ if (a == b)
244
+ return a;
245
+ if (s == CFALSE)
246
+ return a;
247
+ if (s == CTRUE)
248
+ return b;
249
+ }
250
+
251
+ Lit not_s = NOT(s);
252
+ Lit a_active = AND(a, not_s);
253
+ Lit b_active = AND(b, s);
254
+ return OR(a_active, b_active);
255
+ }
256
+
257
+ Lit XOR(Lit a, Lit b)
258
+ {
259
+ Lit not_a = NOT(a);
260
+ Lit not_b = NOT(b);
261
+ Lit a_and_not_b = AND(a, not_b);
262
+ Lit not_a_and_b = AND(not_a, b);
263
+ return OR(a_and_not_b, not_a_and_b);
264
+ }
265
+
266
+ Lit XNOR(Lit a, Lit b)
267
+ {
268
+ return NOT(XOR(a, b));
269
+ }
270
+
271
+ Lit CARRY(Lit a, Lit b, Lit c)
272
+ {
273
+ if (const_folding) {
274
+ if (c == CTRUE) {
275
+ return OR(a, b);
276
+ } else if (c == CFALSE) {
277
+ return AND(a, b);
278
+ }
279
+ }
280
+ Lit a_or_b = OR(a, b);
281
+ Lit a_or_b_and_c = AND(c, a_or_b);
282
+ Lit a_and_b = AND(a, b);
283
+ return OR(a_and_b, a_or_b_and_c);
284
+ }
285
+
286
+ Lit REDUCE(std::vector<Lit> lits, bool op_xor=false)
287
+ {
288
+ std::vector<Lit> next;
289
+ while (lits.size() > 1) {
290
+ next.clear();
291
+ for (int i = 0; i < (int) lits.size(); i += 2) {
292
+ if (i + 1 >= (int) lits.size()) {
293
+ next.push_back(lits[i]);
294
+ } else {
295
+ Lit a = lits[i], b = lits[i + 1];
296
+ next.push_back(op_xor ? XOR(a, b) : AND(a, b));
297
+ }
298
+ }
299
+ next.swap(lits);
300
+ }
301
+
302
+ if (lits.empty())
303
+ return op_xor ? CFALSE : CTRUE;
304
+ else
305
+ return lits.front();
306
+ }
307
+
308
+ void arith_operands(Cell *cell, SigSpec &aport, SigSpec &bport)
309
+ {
310
+ int width = cell->getParam(ID::Y_WIDTH).as_int();
311
+
312
+ if (cell->type == ID($neg)) {
313
+ aport = SigSpec(State::S0, width);
314
+ bport = cell->getPort(ID::A);
315
+ bport.extend_u0(width, cell->getParam(ID::A_SIGNED).as_bool());
316
+ } else {
317
+ aport = cell->getPort(ID::A);
318
+ aport.extend_u0(width, cell->getParam(ID::A_SIGNED).as_bool());
319
+ bport = cell->getPort(ID::B);
320
+ bport.extend_u0(width, cell->getParam(ID::B_SIGNED).as_bool());
321
+ }
322
+ }
323
+
324
+ // A cell reached through one specific instance path
325
+ using CellInstance = std::pair<int, Cell *>;
326
+
327
+ // Carry out of each bit of an arithmetic cell
328
+ dict<CellInstance, std::vector<Lit>> carry_chains;
329
+
330
+ // Product bits of a multiplier cell
331
+ dict<CellInstance, std::vector<Lit>> mul_products;
332
+
333
+ // Carry into obit
334
+ Lit arith_carry(HierCursor &cursor, Cell *cell, SigSpec &aport, SigSpec &bport,
335
+ bool complement, int obit)
336
+ {
337
+ CellInstance key(cursor.instance_offset, cell);
338
+ Lit carry_in = complement ? CTRUE : CFALSE;
339
+
340
+ while (GetSize(carry_chains[key]) < obit) {
341
+ int i = GetSize(carry_chains[key]);
342
+ Lit prev = i ? carry_chains[key][i - 1] : carry_in;
343
+ Lit a = visit(cursor, aport[i]);
344
+ Lit b = visit(cursor, bport[i]);
345
+ Lit carry = CARRY(a, complement ? NOT(b) : b, prev);
346
+ carry_chains[key].push_back(carry);
347
+ }
348
+
349
+ return obit ? carry_chains[key][obit - 1] : carry_in;
350
+ }
351
+
352
+ Lit impl_arith(HierCursor &cursor, Cell *cell, int obit)
353
+ {
354
+ SigSpec aport, bport;
355
+ arith_operands(cell, aport, bport);
356
+
357
+ if (obit >= aport.size())
358
+ return CFALSE;
359
+
360
+ bool complement = cell->type.in(ID($sub), ID($neg));
361
+ Lit carry = arith_carry(cursor, cell, aport, bport, complement, obit);
362
+ Lit a = visit(cursor, aport[obit]);
363
+ Lit b = visit(cursor, bport[obit]);
364
+ return XOR(XOR(a, complement ? NOT(b) : b), carry);
365
+ }
366
+
367
+ // Shift-add multiplier
368
+ Lit impl_mul(HierCursor &cursor, Cell *cell, int obit)
369
+ {
370
+ CellInstance key(cursor.instance_offset, cell);
371
+
372
+ if (!mul_products.count(key)) {
373
+ int width = cell->getParam(ID::Y_WIDTH).as_int();
374
+ SigSpec aport, bport;
375
+ arith_operands(cell, aport, bport);
376
+
377
+ std::vector<Lit> alits;
378
+ for (int i = 0; i < width; i++)
379
+ alits.push_back(visit(cursor, aport[i]));
380
+
381
+ std::vector<Lit> acc(width, CFALSE);
382
+ for (int j = 0; j < width; j++) {
383
+ Lit b = visit(cursor, bport[j]);
384
+ Lit carry = CFALSE;
385
+ for (int i = j; i < width; i++) {
386
+ Lit p = AND(alits[i - j], b);
387
+ Lit sum = XOR(XOR(acc[i], p), carry);
388
+ if (i != width - 1)
389
+ carry = CARRY(acc[i], p, carry);
390
+ acc[i] = sum;
391
+ }
392
+ }
393
+ mul_products[key] = acc;
394
+ }
395
+
396
+ auto &products = mul_products.at(key);
397
+ if (obit >= (int) products.size())
398
+ return CFALSE;
399
+ return products[obit];
400
+ }
401
+
402
+ struct ShiftDesc {
403
+ SigSpec aport;
404
+ SigSpec bport;
405
+ int width; // width of the vector being shifted
406
+ Lit pad;
407
+ Lit fill;
408
+ bool left;
409
+ };
410
+
411
+ Lit shift_source_bit(HierCursor &cursor, ShiftDesc &desc, long long idx)
412
+ {
413
+ if (idx < 0)
414
+ return CFALSE;
415
+ if (idx < desc.aport.size())
416
+ return visit(cursor, desc.aport[(int) idx]);
417
+ if (idx < desc.width)
418
+ return desc.pad;
419
+ return desc.fill;
420
+ }
421
+
422
+ Lit shift_bit(HierCursor &cursor, ShiftDesc &desc, long long idx, int nbits)
423
+ {
424
+ if (!desc.left && idx >= desc.width)
425
+ return desc.fill;
426
+ if (!desc.left && idx + (1LL << nbits) <= 0)
427
+ return CFALSE;
428
+ if (desc.left && idx < 0)
429
+ return CFALSE;
430
+ if (nbits == 0)
431
+ return shift_source_bit(cursor, desc, idx);
432
+
433
+ int k = nbits - 1;
434
+ Lit b = visit(cursor, desc.bport[k]);
435
+ Lit low = shift_bit(cursor, desc, idx, k);
436
+ long long step = 1LL << k;
437
+ if (desc.left)
438
+ step = -step;
439
+ Lit high = shift_bit(cursor, desc, idx + step, k);
440
+ return MUX(low, high, b);
441
+ }
442
+
443
+ Lit impl_shift(HierCursor &cursor, Cell *cell, int obit)
444
+ {
445
+ ShiftDesc desc;
446
+ desc.aport = cell->getPort(ID::A);
447
+ desc.bport = cell->getPort(ID::B);
448
+ bool a_signed = cell->getParam(ID::A_SIGNED).as_bool();
449
+ bool b_signed = cell->getParam(ID::B_SIGNED).as_bool();
450
+ int ywidth = cell->getParam(ID::Y_WIDTH).as_int();
451
+
452
+ log_assert(!b_signed || cell->type.in(ID($shift), ID($shiftx)));
453
+
454
+ desc.left = cell->type.in(ID($shl), ID($sshl));
455
+ desc.width = std::max(desc.aport.size(), ywidth);
456
+
457
+ desc.pad = CFALSE;
458
+ if (a_signed && !desc.aport.empty())
459
+ desc.pad = visit(cursor, desc.aport.msb());
460
+ desc.fill = CFALSE;
461
+ if (cell->type == ID($sshr))
462
+ desc.fill = desc.pad;
463
+
464
+ // number of shift amount bits to mux over
465
+ int bb = ceil_log2(desc.width) + 1;
466
+ if (b_signed)
467
+ bb++;
468
+ if (bb > desc.bport.size())
469
+ bb = desc.bport.size();
470
+
471
+ Lit bsign = CFALSE;
472
+ if (b_signed && bb > 0)
473
+ bsign = visit(cursor, desc.bport[bb - 1]);
474
+
475
+ Lit overflow = CFALSE;
476
+ for (int i = bb; i < desc.bport.size(); i++) {
477
+ Lit b = visit(cursor, desc.bport[i]);
478
+ if (b_signed)
479
+ b = XOR(b, bsign);
480
+ overflow = OR(overflow, b);
481
+ }
482
+
483
+ Lit y;
484
+ if (b_signed && bb > 0) {
485
+ // top bit of a signed shift amount has negative weight
486
+ Lit bpos = shift_bit(cursor, desc, obit, bb - 1);
487
+ Lit bneg = shift_bit(cursor, desc, (long long) obit - (1LL << (bb - 1)), bb - 1);
488
+ y = MUX(bpos, bneg, bsign);
489
+ } else {
490
+ y = shift_bit(cursor, desc, obit, bb);
491
+ }
492
+
493
+ return MUX(y, desc.fill, overflow);
494
+ }
495
+
496
+ Lit impl_op(HierCursor &cursor, Cell *cell, IdString oport, int obit)
497
+ {
498
+ if (cell->type.in(ARITH_OPS))
499
+ return impl_arith(cursor, cell, obit);
500
+
501
+ if (cell->type.in(SHIFT_OPS))
502
+ return impl_shift(cursor, cell, obit);
503
+
504
+ if (cell->type == ID($mul))
505
+ return impl_mul(cursor, cell, obit);
506
+
507
+ if (cell->type.in(REDUCE_OPS, LOGIC_OPS, CMP_OPS) && obit != 0) {
508
+ return CFALSE;
509
+ } else if (cell->type.in(CMP_OPS)) {
510
+ SigSpec aport = cell->getPort(ID::A);
511
+ bool asigned = cell->getParam(ID::A_SIGNED).as_bool();
512
+ SigSpec bport = cell->getPort(ID::B);
513
+ bool bsigned = cell->getParam(ID::B_SIGNED).as_bool();
514
+
515
+ int width = std::max(aport.size(), bport.size()) + 1;
516
+ aport.extend_u0(width, asigned);
517
+ bport.extend_u0(width, bsigned);
518
+
519
+ if (cell->type.in(ID($eq), ID($ne), ID($eqx), ID($nex))) {
520
+ int carry = CTRUE;
521
+ for (int i = 0; i < width; i++) {
522
+ Lit a = visit(cursor, aport[i]);
523
+ Lit b = visit(cursor, bport[i]);
524
+ carry = AND(carry, XNOR(a, b));
525
+ }
526
+ return cell->type.in(ID($eq), ID($eqx)) ? carry : /* $ne, $nex */ NOT(carry);
527
+ } else if (cell->type.in(ID($lt), ID($le), ID($gt), ID($ge))) {
528
+ if (cell->type.in(ID($gt), ID($ge)))
529
+ std::swap(aport, bport);
530
+ int carry = cell->type.in(ID($le), ID($ge)) ? CFALSE : CTRUE;
531
+ Lit a = Writer::EMPTY_LIT;
532
+ Lit b = Writer::EMPTY_LIT;
533
+ // TODO: this might not be the most economic structure; revisit at a later date
534
+ for (int i = 0; i < width; i++) {
535
+ a = visit(cursor, aport[i]);
536
+ b = visit(cursor, bport[i]);
537
+ if (i != width - 1)
538
+ carry = CARRY(a, NOT(b), carry);
539
+ }
540
+ return XOR(carry, XNOR(a, b));
541
+ } else {
542
+ log_abort();
543
+ }
544
+ } else if (cell->type.in(REDUCE_OPS, ID($logic_not))) {
545
+ SigSpec inport = cell->getPort(ID::A);
546
+
547
+ std::vector<Lit> lits;
548
+ for (int i = 0; i < inport.size(); i++) {
549
+ Lit lit = visit(cursor, inport[i]);
550
+ if (cell->type.in(ID($reduce_and), ID($reduce_xor), ID($reduce_xnor))) {
551
+ lits.push_back(lit);
552
+ } else if (cell->type.in(ID($reduce_or), ID($reduce_bool), ID($logic_not))) {
553
+ lits.push_back(NOT(lit));
554
+ } else {
555
+ log_abort();
556
+ }
557
+ }
558
+
559
+ Lit acc = REDUCE(lits, cell->type.in(ID($reduce_xor), ID($reduce_xnor)));
560
+
561
+ if (!cell->type.in(ID($reduce_xnor), ID($reduce_or), ID($reduce_bool)))
562
+ return acc;
563
+ else
564
+ return NOT(acc);
565
+ } else if (cell->type.in(ID($logic_and), ID($logic_or))) {
566
+ SigSpec aport = cell->getPort(ID::A);
567
+ SigSpec bport = cell->getPort(ID::B);
568
+
569
+ log_assert(aport.size() > 0 && bport.size() > 0); // TODO
570
+
571
+ Lit a = visit(cursor, aport[0]);
572
+ for (int i = 1; i < aport.size(); i++) {
573
+ Lit l = visit(cursor, aport[i]);
574
+ a = OR(a, l);
575
+ }
576
+
577
+ Lit b = visit(cursor, bport[0]);
578
+ for (int i = 1; i < bport.size(); i++) {
579
+ Lit l = visit(cursor, bport[i]);
580
+ b = OR(b, l);
581
+ }
582
+
583
+ if (cell->type == ID($logic_and))
584
+ return AND(a, b);
585
+ else if (cell->type == ID($logic_or))
586
+ return OR(a, b);
587
+ else
588
+ log_abort();
589
+ } else if (cell->type.in(ID($mux), ID($bwmux), ID($_MUX_), ID($_NMUX_))) {
590
+ Lit s;
591
+ if (cell->type.in(ID($mux), ID($_MUX_)))
592
+ s = visit(cursor, cell->getPort(ID::S));
593
+ else
594
+ s = visit(cursor, cell->getPort(ID::S)[obit]);
595
+
596
+ Lit y;
597
+ if (const_folding && s == CFALSE) {
598
+ y = visit(cursor, cell->getPort(ID::A)[obit]);
599
+ } else if (const_folding && s == CTRUE) {
600
+ y = visit(cursor, cell->getPort(ID::B)[obit]);
601
+ } else {
602
+ Lit a = visit(cursor, cell->getPort(ID::A)[obit]);
603
+ Lit b = visit(cursor, cell->getPort(ID::B)[obit]);
604
+ y = MUX(a, b, s);
605
+ }
606
+ if (cell->type == ID($_NMUX_))
607
+ y = NOT(y);
608
+ return y;
609
+ } else if (cell->type.in(BITWISE_OPS, GATE_OPS, ID($pos))) {
610
+ SigSpec aport = cell->getPort(ID::A);
611
+ Lit a;
612
+ if (obit < aport.size()) {
613
+ a = visit(cursor, aport[obit]);
614
+ } else {
615
+ if (cell->getParam(ID::A_SIGNED).as_bool())
616
+ a = visit(cursor, aport.msb());
617
+ else
618
+ a = CFALSE;
619
+ }
620
+
621
+ if (cell->type.in(ID($buf), ID($barrier), ID($pos), ID($_BUF_))) {
622
+ return a;
623
+ } else if (cell->type.in(ID($not), ID($_NOT_))) {
624
+ return NOT(a);
625
+ } else {
626
+ SigSpec bport = cell->getPort(ID::B);
627
+ Lit b;
628
+ if (obit < bport.size()) {
629
+ b = visit(cursor, bport[obit]);
630
+ } else {
631
+ if (cell->getParam(ID::B_SIGNED).as_bool())
632
+ b = visit(cursor, bport.msb());
633
+ else
634
+ b = CFALSE;
635
+ }
636
+
637
+ if (cell->type.in(ID($and), ID($_AND_))) {
638
+ return AND(a, b);
639
+ } else if (cell->type.in(ID($_NAND_))) {
640
+ return NOT(AND(a, b));
641
+ } else if (cell->type.in(ID($or), ID($_OR_))) {
642
+ return OR(a, b);
643
+ } else if (cell->type.in(ID($_NOR_))) {
644
+ return NOT(OR(a, b));
645
+ } else if (cell->type.in(ID($xor), ID($_XOR_))) {
646
+ return XOR(a, b);
647
+ } else if (cell->type.in(ID($xnor), ID($_XNOR_))) {
648
+ return XNOR(a, b);
649
+ } else if (cell->type.in(ID($_ANDNOT_))) {
650
+ return AND(a, NOT(b));
651
+ } else if (cell->type.in(ID($_ORNOT_))) {
652
+ return OR(a, NOT(b));
653
+ } else if (cell->type.in(ID($fa))) {
654
+ Lit c = visit(cursor, cell->getPort(ID::C)[obit]);
655
+ Lit ab = XOR(a, b);
656
+ if (oport == ID::Y) {
657
+ return XOR(ab, c);
658
+ } else /* oport == ID::X */ {
659
+ Lit a_and_b = AND(a, b);
660
+ Lit c_and_ab = AND(c, ab);
661
+ return OR(a_and_b, c_and_ab);
662
+ }
663
+ } else if (cell->type.in(ID($_AOI3_), ID($_OAI3_), ID($_AOI4_), ID($_OAI4_))) {
664
+ Lit c, d;
665
+
666
+ c = visit(cursor, cell->getPort(ID::C)[obit]);
667
+ if (/* 4 input types */ cell->type.in(ID($_AOI4_), ID($_OAI4_)))
668
+ d = visit(cursor, cell->getPort(ID::D)[obit]);
669
+ else
670
+ d = cell->type == ID($_AOI3_) ? CTRUE : CFALSE;
671
+
672
+ if (/* aoi */ cell->type.in(ID($_AOI3_), ID($_AOI4_))) {
673
+ Lit a_and_b = AND(a, b);
674
+ Lit c_and_d = AND(c, d);
675
+ return NOT(OR(a_and_b, c_and_d));
676
+ } else {
677
+ Lit a_or_b = OR(a, b);
678
+ Lit c_or_d = OR(c, d);
679
+ return NOT(AND(a_or_b, c_or_d));
680
+ }
681
+ } else {
682
+ log_abort();
683
+ }
684
+ }
685
+ } else if (cell->type == ID($pmux)) {
686
+ SigSpec aport = cell->getPort(ID::A);
687
+ SigSpec bport = cell->getPort(ID::B);
688
+ SigSpec sport = cell->getPort(ID::S);
689
+ int width = aport.size();
690
+
691
+ std::vector<Lit> bar, sels;
692
+ bool a_selectable = true;
693
+ for (int i = 0; i < sport.size(); i++) {
694
+ Lit s = visit(cursor, sport[i]);
695
+ if (const_folding && s == CFALSE)
696
+ continue;
697
+ if (const_folding && s == CTRUE)
698
+ a_selectable = false;
699
+ Lit b = visit(cursor, bport[width * i + obit]);
700
+ bar.push_back(NOT(AND(s, b)));
701
+ sels.push_back(NOT(s));
702
+ }
703
+
704
+ Lit a = CFALSE;
705
+ if (a_selectable)
706
+ a = visit(cursor, aport[obit]);
707
+
708
+ Lit reduce_sels = REDUCE(sels);
709
+ Lit reduce_sels_and_a = AND(reduce_sels, a);
710
+ Lit reduce_bar = NOT(REDUCE(bar));
711
+
712
+ return OR(reduce_sels_and_a, reduce_bar);
713
+ } else if (cell->type == ID($bmux)) {
714
+ SigSpec aport = cell->getPort(ID::A);
715
+ SigSpec sport = cell->getPort(ID::S);
716
+ int width = cell->getParam(ID::WIDTH).as_int();
717
+
718
+ std::vector<Lit> data;
719
+ for (int i = obit; i < aport.size(); i += width)
720
+ data.push_back(visit(cursor, aport[i]));
721
+
722
+ std::vector<Lit> next;
723
+ for (int i = 0; i < sport.size(); i++) {
724
+ Lit s = visit(cursor, sport[i]);
725
+ next.clear();
726
+ for (int j = 0; j < (int) data.size(); j += 2)
727
+ next.push_back(MUX(data[j], data[j + 1], s));
728
+ data.swap(next);
729
+ }
730
+ log_assert(data.size() == 1);
731
+ return data[0];
732
+ } else {
733
+ log_abort();
734
+ }
735
+ }
736
+
737
+ struct HierCursor {
738
+ typedef std::pair<ModuleInfo&, Cell*> Level;
739
+ std::vector<Level> levels;
740
+ int instance_offset = 0;
741
+
742
+ HierCursor()
743
+ {
744
+ }
745
+
746
+ ModuleInfo &leaf_minfo(Index &index)
747
+ {
748
+ if (levels.empty())
749
+ return *index.top_minfo;
750
+ else
751
+ return levels.back().first;
752
+ }
753
+
754
+ Module *leaf_module(Index &index)
755
+ {
756
+ return leaf_minfo(index).module;
757
+ }
758
+
759
+ int bitwire_index(Index &index, SigBit bit)
760
+ {
761
+ log_assert(bit.wire != nullptr);
762
+ return instance_offset + leaf_minfo(index).windices[bit.wire] + bit.offset;
763
+ }
764
+
765
+ Cell *exit(Index &index)
766
+ {
767
+ log_assert(!levels.empty());
768
+ Cell *instance = levels.back().second;
769
+
770
+ levels.pop_back();
771
+ instance_offset -= leaf_minfo(index).suboffsets.at(instance);
772
+
773
+ // return the instance we just exited
774
+ return instance;
775
+ }
776
+
777
+ Module *enter(Index &index, Cell *cell)
778
+ {
779
+ Design *design = index.design;
780
+ auto &minfo = leaf_minfo(index);
781
+ if (!minfo.suboffsets.count(cell))
782
+ log_error("Reached unsupported cell %s (%s in %s)\n", cell->type.unescape(), cell, cell->module);
783
+ Module *def = cell_def(design, cell);
784
+ log_assert(def);
785
+ levels.push_back(Level(index.modules.at(def), cell));
786
+ instance_offset += minfo.suboffsets.at(cell);
787
+
788
+ // return the module definition we just entered
789
+ return def;
790
+ }
791
+
792
+ bool is_top()
793
+ {
794
+ return levels.empty();
795
+ }
796
+
797
+ std::string path()
798
+ {
799
+ std::string ret;
800
+ bool first = true;
801
+ for (auto [minfo, cell] : levels) {
802
+ if (!first)
803
+ ret += ".";
804
+ if (!cell)
805
+ ret += minfo.module->name.unescape();
806
+ else
807
+ ret += cell->name.unescape();
808
+ first = false;
809
+ }
810
+ return ret;
811
+ }
812
+
813
+ int hash() const
814
+ {
815
+ int hash = 0;
816
+ for (auto [_, cell] : levels)
817
+ hash += (uintptr_t) cell;
818
+ return hash;
819
+ }
820
+
821
+ bool operator==(const HierCursor &other) const
822
+ {
823
+ if (levels.size() != other.levels.size())
824
+ return false;
825
+
826
+ for (int i = 0; i < levels.size(); i++) {
827
+ auto* cell = levels[i].second;
828
+ auto* other_cell = other.levels[i].second;
829
+ if (cell != other_cell)
830
+ return false;
831
+ }
832
+
833
+ return true;
834
+ }
835
+ };
836
+
837
+ bool visit_hook(int, HierCursor&, SigBit)
838
+ {
839
+ return false;
840
+ }
841
+
842
+ Lit visit(HierCursor &cursor, SigBit bit)
843
+ {
844
+ if (!bit.wire) {
845
+ if (bit == State::S1)
846
+ return CTRUE;
847
+ else if (bit == State::S0)
848
+ return CFALSE;
849
+ else if (bit == State::Sx || bit == State::Sz)
850
+ return CFALSE;
851
+ else
852
+ log_error("Unhandled state %s\n", log_signal(bit));
853
+ }
854
+
855
+ int idx = cursor.bitwire_index(*this, bit);
856
+ if (lits[idx] == Writer::EMPTY_LIT - 1)
857
+ log_error("Combinational cycle through %s in %s\n", log_signal(bit), cursor.leaf_module(*this));
858
+ if (lits[idx] != Writer::EMPTY_LIT) {
859
+ // literal already assigned
860
+ return lits[idx];
861
+ }
862
+ lits[idx] = Writer::EMPTY_LIT - 1;
863
+
864
+ // provide means for the derived class to override
865
+ // the visit behavior
866
+ if ((static_cast<Writer*>(this))->visit_hook(idx, cursor, bit)) {
867
+ return lits[idx];
868
+ }
869
+
870
+ Lit ret;
871
+ if (!bit.wire->port_input || bit.wire->port_output) {
872
+ // an output of a cell
873
+ Cell *driver = bit.wire->driverCell();
874
+
875
+ if (is_known_op(driver)) {
876
+ ret = impl_op(cursor, driver, bit.wire->driverPort(), bit.offset);
877
+ } else {
878
+ Module *def = cursor.enter(*this, driver);
879
+ {
880
+ IdString portname = bit.wire->driverPort();
881
+ Wire *w = def->wire(portname);
882
+ if (!w)
883
+ log_error("Output port %s on instance %s of %s doesn't exist\n",
884
+ design->twines().unescaped_str(portname), driver, def);
885
+ if (bit.offset >= w->width)
886
+ log_error("Bit position %d of output port %s on instance %s of %s is out of range (port has width %d)\n",
887
+ bit.offset, design->twines().unescaped_str(portname), driver, def, w->width);
888
+ ret = visit(cursor, SigBit(w, bit.offset));
889
+ }
890
+ cursor.exit(*this);
891
+ }
892
+ } else {
893
+ // a module input: we cannot be the top module, otherwise
894
+ // the branch for pre-existing literals would have been taken
895
+ log_assert(!cursor.is_top());
896
+
897
+ // step into the upper module
898
+ Cell *instance = cursor.exit(*this);
899
+ {
900
+ IdString portname = bit.wire->name;
901
+ if (!instance->hasPort(portname))
902
+ log_error("Input port %s on instance %s of %s unconnected\n",
903
+ design->twines().unescaped_str(portname), instance, instance->type);
904
+ auto &port = instance->getPort(portname);
905
+ if (bit.offset >= port.size())
906
+ log_error("Bit %d of input port %s on instance %s of %s unconnected\n",
907
+ bit.offset, design->twines().unescaped_str(portname), instance, instance->type.unescape());
908
+ ret = visit(cursor, port[bit.offset]);
909
+ }
910
+ cursor.enter(*this, instance);
911
+ }
912
+
913
+ lits[idx] = ret;
914
+ return ret;
915
+ }
916
+
917
+ Lit &pi_literal(SigBit bit, HierCursor *cursor=nullptr)
918
+ {
919
+ log_assert(bit.wire);
920
+
921
+ if (!cursor) {
922
+ log_assert(bit.wire->module == top);
923
+ log_assert(bit.wire->port_input && !bit.wire->port_output);
924
+ return lits[top_minfo->windices[bit.wire] + bit.offset];
925
+ } else {
926
+ log_assert(bit.wire->module == cursor->leaf_module(*this));
927
+ return lits[cursor->bitwire_index(*this, bit)];
928
+ }
929
+ }
930
+
931
+ Lit eval_po(SigBit bit, HierCursor *cursor=nullptr)
932
+ {
933
+ Lit ret;
934
+ if (!cursor) {
935
+ HierCursor cursor_;
936
+ ret = visit(cursor_, bit);
937
+ log_assert(cursor_.is_top());
938
+ log_assert(cursor_.instance_offset == 0);
939
+ } else {
940
+ ret = visit(*cursor, bit);
941
+ }
942
+ return ret;
943
+ }
944
+
945
+ void visit_hierarchy(std::function<void(HierCursor&)> f,
946
+ HierCursor &cursor)
947
+ {
948
+ f(cursor);
949
+
950
+ ModuleInfo &minfo = cursor.leaf_minfo(*this);
951
+ for (auto cell : minfo.module->cells()) {
952
+ if (minfo.suboffsets.count(cell)) {
953
+ cursor.enter(*this, cell);
954
+ visit_hierarchy(f, cursor);
955
+ cursor.exit(*this);
956
+ }
957
+ }
958
+ }
959
+
960
+ void visit_hierarchy(std::function<void(HierCursor&)> f)
961
+ {
962
+ HierCursor cursor;
963
+ visit_hierarchy(f, cursor);
964
+ }
965
+ };
966
+
967
+ struct AigerWriter : Index<AigerWriter, unsigned int, 0, 1> {
968
+ typedef unsigned int Lit;
969
+
970
+ const static constexpr Lit EMPTY_LIT = std::numeric_limits<Lit>::max();
971
+
972
+ static Lit negate(Lit lit) {
973
+ return lit ^ 1;
974
+ }
975
+
976
+ std::ostream *f;
977
+ Lit lit_counter;
978
+ int ninputs, nlatches, noutputs, nands;
979
+
980
+ void encode(int delta)
981
+ {
982
+ log_assert(delta >= 0);
983
+ unsigned int x = delta;
984
+ while (x & ~0x7f) {
985
+ f->put((x & 0x7f) | 0x80);
986
+ x = x >> 7;
987
+ }
988
+ f->put(x);
989
+ }
990
+
991
+ Lit emit_gate(Lit a, Lit b)
992
+ {
993
+ Lit out = lit_counter;
994
+ nands++;
995
+ lit_counter += 2;
996
+
997
+ // In XAIGER, the ordering of inputs is used to distinguish between AND
998
+ // and XOR gates. AND gates have their first input literal be larger
999
+ // than their second, and vice-versa for XORs.
1000
+ if (a < b) std::swap(a, b);
1001
+ encode(out - a);
1002
+ encode(a - b);
1003
+ return out;
1004
+ }
1005
+
1006
+ void reset_counters()
1007
+ {
1008
+ lit_counter = 2;
1009
+ ninputs = nlatches = noutputs = nands = 0;
1010
+ }
1011
+
1012
+ void write_header() {
1013
+ log_assert(lit_counter == (Lit) (ninputs + nlatches + nands) * 2 + 2);
1014
+
1015
+ char buf[128];
1016
+ snprintf(buf, sizeof(buf), "aig %08d %08d %08d %08d %08d\n",
1017
+ ninputs + nlatches + nands, ninputs, nlatches, noutputs, nands);
1018
+ f->write(buf, strlen(buf));
1019
+ }
1020
+
1021
+ void write(std::ostream *f) {
1022
+ reset_counters();
1023
+
1024
+ auto file_start = f->tellp();
1025
+
1026
+ // populate inputs
1027
+ std::vector<SigBit> inputs;
1028
+ for (auto id : top->ports) {
1029
+ Wire *w = top->wire(id);
1030
+ log_assert(w);
1031
+ if (w->port_input && !w->port_output)
1032
+ for (int i = 0; i < w->width; i++) {
1033
+ auto bit = SigBit(w, i);
1034
+ pi_literal(bit) = lit_counter;
1035
+ inputs.push_back(bit);
1036
+ lit_counter += 2;
1037
+ ninputs++;
1038
+ }
1039
+ }
1040
+
1041
+ this->f = f;
1042
+ // start with the header
1043
+ write_header();
1044
+ // insert padding where output literals will go (once known)
1045
+ for (auto id : top->ports) {
1046
+ Wire *w = top->wire(id);
1047
+ log_assert(w);
1048
+ if (w->port_output) {
1049
+ for (auto bit : SigSpec(w)) {
1050
+ (void) bit;
1051
+ char buf[16];
1052
+ snprintf(buf, sizeof(buf), "%08d\n", 0);
1053
+ f->write(buf, strlen(buf));
1054
+ noutputs++;
1055
+ }
1056
+ }
1057
+ }
1058
+ auto data_start = f->tellp();
1059
+
1060
+ // now the guts
1061
+ std::vector<std::pair<SigBit, int>> outputs;
1062
+ for (auto id : top->ports) {
1063
+ Wire *w = top->wire(id);
1064
+ log_assert(w);
1065
+ if (w->port_output) {
1066
+ for (auto bit : SigSpec(w))
1067
+ // Each call to eval_po eventually reaches emit_gate and
1068
+ // encode which writes to f.
1069
+ outputs.push_back({bit, eval_po(bit)});
1070
+ }
1071
+ }
1072
+
1073
+ auto data_end = f->tellp();
1074
+
1075
+ // revisit header and the list of outputs
1076
+ f->seekp(file_start);
1077
+ write_header();
1078
+ for (auto [_, po] : outputs) {
1079
+ char buf[16];
1080
+ snprintf(buf, sizeof(buf), "%08d\n", po);
1081
+ f->write(buf, strlen(buf));
1082
+ }
1083
+ // double check we arrived at the same offset for the
1084
+ // main data section
1085
+ log_assert(data_start == f->tellp());
1086
+
1087
+ f->seekp(data_end);
1088
+ int i = 0;
1089
+ for (auto [bit, _] : outputs) {
1090
+ if (SigSpec(bit).is_wire()) {
1091
+ // primary output symbol
1092
+ char buf[32];
1093
+ snprintf(buf, sizeof(buf), "o%d ", i);
1094
+ f->write(buf, strlen(buf));
1095
+ std::string name = bit.wire->name.unescape();
1096
+ f->write(name.data(), name.size());
1097
+ f->put('\n');
1098
+ }
1099
+ i++;
1100
+ }
1101
+ i = 0;
1102
+ for (auto bit : inputs) {
1103
+ if (SigSpec(bit).is_wire()) {
1104
+ // primary input symbol
1105
+ char buf[32];
1106
+ snprintf(buf, sizeof(buf), "i%d ", i);
1107
+ f->write(buf, strlen(buf));
1108
+ std::string name = bit.wire->name.unescape();
1109
+ f->write(name.data(), name.size());
1110
+ f->put('\n');
1111
+ }
1112
+ i++;
1113
+ }
1114
+ }
1115
+ };
1116
+
1117
+ bool opaque_box_input(RTLIL::PortDir dir)
1118
+ {
1119
+ return dir != RTLIL::PD_OUTPUT;
1120
+ }
1121
+
1122
+ bool opaque_box_output(RTLIL::PortDir dir)
1123
+ {
1124
+ return dir != RTLIL::PD_INPUT;
1125
+ }
1126
+
1127
+ bool ambiguous_dir(RTLIL::PortDir dir)
1128
+ {
1129
+ return opaque_box_input(dir) && opaque_box_output(dir);
1130
+ }
1131
+
1132
+ bool box_drives(Cell *box, Wire *wire)
1133
+ {
1134
+ return wire && wire->known_driver() && wire->driverCell() == box;
1135
+ }
1136
+
1137
+ struct XAigerAnalysis : Index<XAigerAnalysis, int, 0, 0> {
1138
+ const static constexpr int EMPTY_LIT = -1;
1139
+
1140
+ XAigerAnalysis()
1141
+ {
1142
+ allow_blackboxes = true;
1143
+ const_folding = false; // non unique
1144
+ strashing = false;
1145
+ }
1146
+
1147
+ static int negate(int lit)
1148
+ {
1149
+ return lit;
1150
+ }
1151
+
1152
+ int emit_gate(int a, int b)
1153
+ {
1154
+ return max(a, b) + 1;
1155
+ }
1156
+
1157
+ pool<Cell *> seen;
1158
+
1159
+ bool visit_hook(int idx, HierCursor &cursor, SigBit bit)
1160
+ {
1161
+ log_assert(cursor.is_top()); // TOOD: fix analyzer to work with hierarchy
1162
+
1163
+ if (bit.wire->port_input && !bit.wire->port_output)
1164
+ return false;
1165
+
1166
+ Cell *driver = bit.wire->driverCell();
1167
+ Module *mod = design->module(driver->type);
1168
+ if (!mod || !mod->has_attribute(ID::abc9_box_id))
1169
+ return false;
1170
+
1171
+ int max = 1;
1172
+ for (auto wire : mod->wires()) {
1173
+ if (wire->port_input && !wire->port_output) {
1174
+ SigSpec port = driver->hasPort(wire->name) ? driver->getPort(wire->name) : SigSpec{};
1175
+ for (int i = 0; i < std::min(wire->width, port.size()); i++) {
1176
+ int ilevel = visit(cursor, port[i]);
1177
+ max = std::max(max, ilevel + 1);
1178
+ }
1179
+ }
1180
+ }
1181
+ lits[idx] = max;
1182
+
1183
+ if (!seen.count(driver))
1184
+ seen.insert(driver);
1185
+
1186
+ return true;
1187
+ }
1188
+
1189
+ void analyze(Module *top)
1190
+ {
1191
+ setup(top);
1192
+
1193
+ for (auto id : top->ports) {
1194
+ Wire *w = top->wire(id);
1195
+ log_assert(w);
1196
+ if (w->port_input && !w->port_output)
1197
+ for (int i = 0; i < w->width; i++)
1198
+ pi_literal(SigBit(w, i)) = 0;
1199
+ }
1200
+
1201
+ HierCursor cursor;
1202
+ for (auto box : top_minfo->found_blackboxes) {
1203
+ Module *def = design->module(box->type);
1204
+ if (!(def && def->has_attribute(ID::abc9_box_id)))
1205
+ for (auto &conn : box->connections_) {
1206
+ RTLIL::PortDir dir = box->port_dir(conn.first);
1207
+ if (!opaque_box_output(dir))
1208
+ continue;
1209
+
1210
+ for (auto bit : conn.second) {
1211
+ // A constant carries no CI
1212
+ if (!bit.wire || (ambiguous_dir(dir) && !box_drives(box, bit.wire)))
1213
+ continue;
1214
+
1215
+ pi_literal(bit, &cursor) = 0;
1216
+ }
1217
+ }
1218
+ }
1219
+
1220
+ for (auto w : top->wires()) {
1221
+ if (w->port_output || (!w->port_input && w->get_bool_attribute(ID::keep))) {
1222
+ for (auto bit : SigSpec(w))
1223
+ (void) eval_po(bit);
1224
+ }
1225
+ }
1226
+
1227
+ for (auto box : top_minfo->found_blackboxes) {
1228
+ Module *def = design->module(box->type);
1229
+ if (!(def && def->has_attribute(ID::abc9_box_id)))
1230
+ for (auto &conn : box->connections_)
1231
+ if (opaque_box_input(box->port_dir(conn.first)))
1232
+ for (auto bit : conn.second)
1233
+ (void) eval_po(bit);
1234
+ }
1235
+ }
1236
+ };
1237
+
1238
+ std::vector<IdString> box_ports(Module *def)
1239
+ {
1240
+ std::vector<IdString> ports;
1241
+ IdString carry_in, carry_out;
1242
+
1243
+ for (auto port_id : def->ports) {
1244
+ Wire *w = def->wire(port_id);
1245
+ log_assert(w);
1246
+
1247
+ if (!w->get_bool_attribute(ID::abc9_carry)) {
1248
+ ports.push_back(port_id);
1249
+ continue;
1250
+ }
1251
+
1252
+ log_assert(w->port_input != w->port_output);
1253
+ if (w->port_input)
1254
+ carry_in = port_id;
1255
+ else
1256
+ carry_out = port_id;
1257
+ }
1258
+
1259
+ if (carry_in != IdString()) {
1260
+ ports.push_back(carry_in);
1261
+ ports.push_back(carry_out);
1262
+ }
1263
+
1264
+ return ports;
1265
+ }
1266
+
1267
+ struct XAigerWriter : AigerWriter {
1268
+ XAigerWriter()
1269
+ {
1270
+ allow_blackboxes = true;
1271
+ }
1272
+
1273
+ bool mapping_prep = false;
1274
+ pool<Wire *> keep_wires;
1275
+ pool<Cell *> keep_cells;
1276
+ std::ofstream map_file;
1277
+ dict<SigBit, SigBit> named_alias; // map from anonymous wire to named wire
1278
+
1279
+ void index_named_aliases()
1280
+ {
1281
+ for (auto cell : top->cells()) {
1282
+ if (cell->type != ID($buf))
1283
+ continue;
1284
+
1285
+ SigSpec sig_a = cell->getPort(ID::A);
1286
+ SigSpec sig_y = cell->getPort(ID::Y);
1287
+
1288
+ if (!sig_y.is_wire())
1289
+ continue;
1290
+
1291
+ // A port names itself in the mapping file
1292
+ Wire *named = sig_y.as_wire();
1293
+ if (!named->name.isPublic() || named->port_input || named->port_output)
1294
+ continue;
1295
+
1296
+ for (int i = 0; i < GetSize(sig_a); i++)
1297
+ if (sig_a[i].wire)
1298
+ named_alias.emplace(sig_a[i], sig_y[i]);
1299
+ }
1300
+ }
1301
+
1302
+ void move_init_to_kept(const pool<Wire *> &to_remove)
1303
+ {
1304
+ for (auto wire : to_remove) {
1305
+ auto it = wire->attributes.find(ID::init);
1306
+ if (it == wire->attributes.end())
1307
+ continue;
1308
+ for (int i = 0; i < GetSize(wire) && i < GetSize(it->second); i++) {
1309
+ SigBit bit(wire, i);
1310
+ for (int n = 0; n < GetSize(to_remove) && bit.wire && to_remove.count(bit.wire) &&
1311
+ bit.wire->known_driver() && bit.wire->driverCell()->type == ID($buf); n++)
1312
+ bit = bit.wire->driverCell()->getPort(ID::A)[bit.offset];
1313
+ if (!bit.wire || to_remove.count(bit.wire) || it->second[i] == State::Sx)
1314
+ continue;
1315
+ Const &init = bit.wire->attributes[ID::init];
1316
+ init.resize(GetSize(bit.wire), State::Sx);
1317
+ if (init[bit.offset] == State::Sx)
1318
+ init.set(bit.offset, it->second[i]);
1319
+ }
1320
+ }
1321
+ }
1322
+
1323
+ SigBit mapped_name(SigBit bit)
1324
+ {
1325
+ auto found = named_alias.find(bit);
1326
+ if (found == named_alias.end())
1327
+ return bit;
1328
+
1329
+ Wire *named = found->second.wire;
1330
+ keep_wires.insert(named);
1331
+ keep_cells.insert(named->driverCell());
1332
+ return found->second;
1333
+ }
1334
+
1335
+ typedef std::pair<SigBit, HierCursor> HierBit;
1336
+ std::vector<HierBit> pos;
1337
+ std::vector<HierBit> pis;
1338
+ int proper_pos_counter = 0;
1339
+
1340
+ pool<SigBit> driven_by_opaque_box;
1341
+
1342
+ void ensure_pi(SigBit bit, HierCursor cursor={},
1343
+ bool box_port=false)
1344
+ {
1345
+ Lit &lit = pi_literal(bit, &cursor);
1346
+ if (lit == EMPTY_LIT) {
1347
+ lit = lit_counter;
1348
+ pis.push_back(std::make_pair(bit, cursor));
1349
+ lit_counter += 2;
1350
+ if (map_file.is_open() && !box_port) {
1351
+ log_assert(cursor.is_top()); // TODO
1352
+ driven_by_opaque_box.insert(bit);
1353
+ SigBit named = mapped_name(bit);
1354
+ map_file << "input " << pis.size() - 1 << " " << named.wire->start_offset + named.offset
1355
+ << " " << design->twines().ref_token(named.wire->name) << "\n";
1356
+ }
1357
+ } else {
1358
+ log_assert(!box_port);
1359
+ }
1360
+ }
1361
+
1362
+ bool is_pi(SigBit bit, HierCursor cursor={})
1363
+ {
1364
+ return pi_literal(bit, &cursor) != EMPTY_LIT;
1365
+ }
1366
+
1367
+ void pad_pi()
1368
+ {
1369
+ pis.push_back(std::make_pair(RTLIL::Sx, HierCursor{}));
1370
+ lit_counter += 2;
1371
+ }
1372
+
1373
+ void append_opaque_box_ports(Cell *box, HierCursor &cursor, bool inputs)
1374
+ {
1375
+ for (auto &conn : box->connections_) {
1376
+ RTLIL::PortDir dir = box->port_dir(conn.first);
1377
+
1378
+ if (opaque_box_input(dir) && inputs) {
1379
+ int bitp = 0;
1380
+ for (auto bit : conn.second) {
1381
+ // On an ambiguous port, a bit with a CI needs no CO
1382
+ if (!bit.wire || (ambiguous_dir(dir) && is_pi(bit, cursor))) {
1383
+ bitp++;
1384
+ continue;
1385
+ }
1386
+
1387
+ // Inputs to opaque boxes are proper POs as far as abc is concerned
1388
+ if (map_file.is_open()) {
1389
+ log_assert(cursor.is_top());
1390
+ map_file << "pseudopo " << proper_pos_counter << " " << bitp
1391
+ << " " << design->twines().ref_token(box->name)
1392
+ << " " << design->twines().ref_token(conn.first) << "\n";
1393
+ }
1394
+ proper_pos_counter++;
1395
+ pos.push_back(std::make_pair(bit, cursor));
1396
+
1397
+ if (mapping_prep)
1398
+ conn.second[bitp] = RTLIL::Sx;
1399
+
1400
+ bitp++;
1401
+ }
1402
+ } else if (opaque_box_output(dir) && !inputs) {
1403
+ for (auto &bit : conn.second) {
1404
+ if (ambiguous_dir(dir) && !box_drives(box, bit.wire))
1405
+ continue;
1406
+
1407
+ // If the following log_errors fire, make sure your design/flow passes `check -assert` before `write_xaiger2`.
1408
+ if (!bit.wire)
1409
+ log_error("Bad connection: %s/%s connected to non-wire %s\n", box, design->twines().unescaped_str(conn.first), log_signal(bit));
1410
+ if (bit.wire->port_input && !bit.wire->port_output)
1411
+ log_error("Bad connection: %s/%s with non-input port direction connected to wire %s marked as port input\n", box, design->twines().unescaped_str(conn.first), log_signal(bit));
1412
+
1413
+
1414
+ ensure_pi(bit, cursor);
1415
+ keep_wires.insert(bit.wire);
1416
+ }
1417
+ }
1418
+ }
1419
+ }
1420
+
1421
+ RTLIL::Module *holes_module;
1422
+
1423
+ std::stringstream h_buffer;
1424
+ static void write_be32(std::ostream &buffer, uint32_t u32)
1425
+ {
1426
+ typedef unsigned char uchar;
1427
+ unsigned char u32_be[4] = {
1428
+ (uchar) (u32 >> 24), (uchar) (u32 >> 16), (uchar) (u32 >> 8), (uchar) u32
1429
+ };
1430
+ buffer.write((char *) u32_be, sizeof(u32_be));
1431
+ }
1432
+
1433
+ void prep_boxes(int pending_pos_num)
1434
+ {
1435
+ XAigerAnalysis analysis;
1436
+ log_debug("preforming analysis on '%s'\n", top);
1437
+ analysis.analyze(top);
1438
+ log_debug("analysis on '%s' done\n", top);
1439
+
1440
+ // boxes which have timing data, maybe a whitebox model
1441
+ std::vector<std::tuple<HierCursor, Cell *, Module *>> nonopaque_boxes;
1442
+ // boxes which are fully opaque
1443
+ std::vector<std::tuple<HierCursor, Cell *, Module *>> opaque_boxes;
1444
+
1445
+ log_debug("found boxes:\n");
1446
+ visit_hierarchy([&](HierCursor &cursor) {
1447
+ auto &minfo = cursor.leaf_minfo(*this);
1448
+
1449
+ for (auto box : minfo.found_blackboxes) {
1450
+ Module *box_module = design->module(box->type), *box_derived;
1451
+
1452
+ if (box_module && !box->parameters.empty()) {
1453
+ // TODO: This is potentially costly even if a cached derivation exists
1454
+ box_derived = design->module(box_module->derive(design, box->parameters));
1455
+ log_assert(box_derived);
1456
+ } else {
1457
+ box_derived = box_module;
1458
+ }
1459
+
1460
+ std::string box_type = "opaque";
1461
+ if (box_derived && box_derived->has_attribute(ID::abc9_box_id)) {
1462
+ // This is an ABC9 box, we have timing data, maybe even a whitebox model
1463
+ // These need to go last in the AIGER port list.
1464
+ nonopaque_boxes.push_back(std::make_tuple(cursor, box, box_derived));
1465
+ box_type = "non-opaque";
1466
+ } else {
1467
+ opaque_boxes.push_back(std::make_tuple(cursor, box, box_derived));
1468
+ }
1469
+ log_debug(" - %s.%s (type %s): %s\n", cursor.path(),
1470
+ box,
1471
+ box->type.unescape(), box_type);
1472
+ }
1473
+ });
1474
+
1475
+ for (auto [cursor, box, def] : opaque_boxes)
1476
+ append_opaque_box_ports(box, cursor, false);
1477
+
1478
+ holes_module = design->addModule(NEW_ID);
1479
+ std::vector<RTLIL::Wire *> holes_pis;
1480
+ int boxes_ci_num = 0, boxes_co_num = 0;
1481
+
1482
+ int box_seq = 0;
1483
+
1484
+ std::vector<Cell *> boxes_order(analysis.seen.begin(), analysis.seen.end());
1485
+ std::reverse(boxes_order.begin(), boxes_order.end());
1486
+
1487
+ nonopaque_boxes.clear();
1488
+ for (auto box : boxes_order) {
1489
+ HierCursor cursor;
1490
+ Module *def = design->module(box->type);
1491
+ nonopaque_boxes.push_back(std::make_tuple(cursor, box, def));
1492
+ }
1493
+
1494
+ for (auto [cursor, box, def] : nonopaque_boxes) {
1495
+ // no whitebox model: holes outputs are tied to zero
1496
+ bool have_model = def->get_bool_attribute(ID::whitebox);
1497
+ // use `def->name` not `box->type` as we want the derived type
1498
+ Cell *holes_wb = have_model ? holes_module->addCell(NEW_ID, def->name) : nullptr;
1499
+ int holes_pi_idx = 0;
1500
+
1501
+ if (map_file.is_open()) {
1502
+ log_assert(cursor.is_top());
1503
+ map_file << "box " << box_seq << " 0 " << design->twines().ref_token(box->name) << "\n";
1504
+ }
1505
+ box_seq++;
1506
+
1507
+ for (auto port_id : box_ports(def)) {
1508
+ Wire *port = def->wire(port_id);
1509
+ log_assert(port);
1510
+
1511
+ SigSpec conn = box->hasPort(port_id) ? box->getPort(port_id) : SigSpec{};
1512
+
1513
+ if (port->port_input && !port->port_output) {
1514
+ // primary
1515
+ for (int i = 0; i < port->width; i++) {
1516
+ SigBit bit;
1517
+ if (i < conn.size()) {
1518
+ bit = conn[i];
1519
+ } else {
1520
+ // FIXME: hierarchical path
1521
+ log_debug("connection on port %s[%d] of instance %s (type %s) missing, using 1'bx\n",
1522
+ design->twines().unescaped_str(port_id), i, box, box->type.unescape());
1523
+ bit = RTLIL::Sx;
1524
+ }
1525
+
1526
+ // Nonopaque box inputs come first and are not part of
1527
+ // the PO numbering used by the mapping file.
1528
+ pos.push_back(std::make_pair(bit, cursor));
1529
+ }
1530
+ boxes_co_num += port->width;
1531
+
1532
+ if (mapping_prep && !conn.empty())
1533
+ box->setPort(port_id, SigSpec(RTLIL::Sx, conn.size()));
1534
+
1535
+ // holes
1536
+ SigSpec in_conn;
1537
+ for (int i = 0; i < port->width; i++) {
1538
+ while (holes_pi_idx >= (int) holes_pis.size()) {
1539
+ Wire *w = holes_module->addWire(NEW_ID, 1);
1540
+ w->port_input = true;
1541
+ holes_module->ports.push_back(w->name);
1542
+ holes_pis.push_back(w);
1543
+ }
1544
+ in_conn.append(holes_pis[holes_pi_idx]);
1545
+ holes_pi_idx++;
1546
+ }
1547
+ if (holes_wb)
1548
+ holes_wb->setPort(port_id, in_conn);
1549
+ } else if (port->port_output) {
1550
+ // primary
1551
+ for (int i = 0; i < port->width; i++) {
1552
+ SigBit bit;
1553
+ if (i < conn.size() && conn[i].is_wire()) {
1554
+ bit = conn[i];
1555
+ } else {
1556
+ // FIXME: hierarchical path
1557
+ log_debug("connection on port %s[%d] of instance %s (type %s) missing\n",
1558
+ design->twines().unescaped_str(port_id), i, box, box->type.unescape());
1559
+ pad_pi();
1560
+ continue;
1561
+ }
1562
+
1563
+ ensure_pi(bit, cursor, true);
1564
+ keep_wires.insert(bit.wire);
1565
+ }
1566
+ boxes_ci_num += port->width;
1567
+
1568
+ // holes
1569
+ Wire *w = holes_module->addWire(NEW_ID, port->width);
1570
+ w->port_output = true;
1571
+ holes_module->ports.push_back(w->name);
1572
+ if (holes_wb)
1573
+ holes_wb->setPort(port_id, w);
1574
+ else if (port->width)
1575
+ holes_module->addBuf(NEW_ID, SigSpec(State::S0, port->width), w);
1576
+ } else {
1577
+ log_error("Ambiguous port direction on %s/%s\n",
1578
+ box->type.unescape(), design->twines().unescaped_str(port_id));
1579
+ }
1580
+ }
1581
+ }
1582
+
1583
+ for (auto [cursor, box, def] : opaque_boxes)
1584
+ append_opaque_box_ports(box, cursor, true);
1585
+
1586
+ write_be32(h_buffer, 1);
1587
+ write_be32(h_buffer, pis.size());
1588
+ log_debug("ciNum = %zu\n", pis.size());
1589
+ write_be32(h_buffer, pending_pos_num + pos.size());
1590
+ log_debug("coNum = %zu\n", pending_pos_num + pos.size());
1591
+ write_be32(h_buffer, pis.size() - boxes_ci_num);
1592
+ log_debug("piNum = %zu\n", pis.size() - boxes_ci_num);
1593
+ write_be32(h_buffer, pending_pos_num + pos.size() - boxes_co_num);
1594
+ log_debug("poNum = %zu\n", pending_pos_num + pos.size() - boxes_co_num);
1595
+ write_be32(h_buffer, nonopaque_boxes.size());
1596
+
1597
+ box_seq = 0;
1598
+ for (auto [cursor, box, def] : nonopaque_boxes) {
1599
+ int box_ci_num = 0, box_co_num = 0;
1600
+ for (auto port_id : def->ports) {
1601
+ Wire *port = def->wire(port_id);
1602
+ log_assert(port);
1603
+ if (port->port_input && !port->port_output) {
1604
+ box_co_num += port->width;
1605
+ } else if (port->port_output) {
1606
+ box_ci_num += port->width;
1607
+ } else {
1608
+ log_abort();
1609
+ }
1610
+ }
1611
+
1612
+ write_be32(h_buffer, box_co_num);
1613
+ write_be32(h_buffer, box_ci_num);
1614
+ write_be32(h_buffer, def->attributes.at(ID::abc9_box_id).as_int());
1615
+ write_be32(h_buffer, box_seq++);
1616
+ }
1617
+ }
1618
+
1619
+ void clear_boxes()
1620
+ {
1621
+ design->remove(holes_module);
1622
+ }
1623
+
1624
+ // a kept $buf only means anything on its CI bits, so the mapping replaces
1625
+ // whatever drove the rest
1626
+ void prune_kept_cells(const pool<Wire *> &to_remove)
1627
+ {
1628
+ for (auto cell : keep_cells) {
1629
+ SigSpec sig_a = cell->getPort(ID::A);
1630
+ for (auto &bit : sig_a)
1631
+ if (bit.wire && to_remove.count(bit.wire))
1632
+ bit = State::Sx;
1633
+ cell->setPort(ID::A, sig_a);
1634
+ }
1635
+ }
1636
+
1637
+ static bool is_keep_po(Wire *w)
1638
+ {
1639
+ return !w->port_input && !w->port_output && w->get_bool_attribute(ID::keep);
1640
+ }
1641
+
1642
+ void add_proper_po(Wire *w, int i, const char *symbol)
1643
+ {
1644
+ if (map_file.is_open())
1645
+ map_file << symbol << " " << proper_pos_counter << " " << w->start_offset + i
1646
+ << " " << design->twines().ref_token(w->name) << "\n";
1647
+ proper_pos_counter++;
1648
+ pos.push_back(std::make_pair(SigBit(w, i), HierCursor{}));
1649
+ }
1650
+
1651
+ void write(std::ostream *f) {
1652
+ reset_counters();
1653
+
1654
+ if (map_file.is_open())
1655
+ index_named_aliases();
1656
+
1657
+ for (auto w : top->wires())
1658
+ if (w->port_input && !w->port_output)
1659
+ for (int i = 0; i < w->width; i++)
1660
+ ensure_pi(SigBit(w, i));
1661
+
1662
+ int proper_po_num = 0;
1663
+ for (auto w : top->wires())
1664
+ if (w->port_output || is_keep_po(w))
1665
+ proper_po_num += w->width;
1666
+
1667
+ prep_boxes(proper_po_num);
1668
+ for (auto w : top->wires())
1669
+ if (w->port_output)
1670
+ for (int i = 0; i < w->width; i++)
1671
+ add_proper_po(w, i, "output");
1672
+
1673
+ for (auto w : top->wires())
1674
+ if (is_keep_po(w)) {
1675
+ keep_wires.insert(w);
1676
+ for (int i = 0; i < w->width; i++)
1677
+ add_proper_po(w, i, "keepwire");
1678
+ }
1679
+
1680
+ this->f = f;
1681
+ // start with the header
1682
+ ninputs = pis.size();
1683
+ noutputs = pos.size();
1684
+ write_header();
1685
+ // insert padding where output literals will go (once known)
1686
+ for (auto _ : pos) {
1687
+ char buf[16];
1688
+ snprintf(buf, sizeof(buf), "%08d\n", 0);
1689
+ f->write(buf, strlen(buf));
1690
+ }
1691
+ auto data_start = f->tellp();
1692
+
1693
+ // now the guts
1694
+ std::vector<Lit> outlits;
1695
+ for (auto &pair : pos)
1696
+ outlits.push_back(eval_po(pair.first, &pair.second));
1697
+
1698
+ // revisit header and the list of outputs
1699
+ f->seekp(0);
1700
+ ninputs = pis.size();
1701
+ noutputs = pos.size();
1702
+ write_header();
1703
+ for (auto lit : outlits) {
1704
+ char buf[16];
1705
+ snprintf(buf, sizeof(buf), "%08d\n", lit);
1706
+ f->write(buf, strlen(buf));
1707
+ }
1708
+ // double check we arrived at the same offset for the
1709
+ // main data section
1710
+ log_assert(data_start == f->tellp());
1711
+
1712
+ // XAIGER extensions
1713
+ f->seekp(0, std::ios::end);
1714
+
1715
+ f->put('c'); // 'c': comment (marks beginning of extensions)
1716
+
1717
+ // insert empty 'r' and 's' sections (abc crashes if we provide 'a' without those)
1718
+ f->put('r'); // 'r': register classes
1719
+ write_be32(*f, 4); // length in bytes
1720
+ write_be32(*f, 0); // no register classes
1721
+
1722
+ f->put('s'); // 's': register initial values
1723
+ write_be32(*f, 4); // length in bytes
1724
+ write_be32(*f, 0); // no register initial values
1725
+
1726
+ f->put('h'); // 'h': hierarchy information
1727
+ // TODO: get rid of std::string copy
1728
+ std::string h_buffer_str = h_buffer.str();
1729
+ write_be32(*f, h_buffer_str.size()); // length in bytes
1730
+ f->write(h_buffer_str.data(), h_buffer_str.size()); // data
1731
+
1732
+ #if 1
1733
+ f->put('a'); // 'a': additional AIG (used for holes)
1734
+ write_be32(*f, 0); // length in bytes (to be filled later)
1735
+ auto holes_aiger_start = f->tellp();
1736
+ {
1737
+ AigerWriter holes_writer;
1738
+ holes_writer.flatten = true;
1739
+ holes_writer.inline_whiteboxes = true;
1740
+ holes_writer.setup(holes_module);
1741
+ holes_writer.write(f);
1742
+ }
1743
+ auto holes_aiger_size = f->tellp() - holes_aiger_start;
1744
+ f->seekp(holes_aiger_start, std::ios::beg);
1745
+ f->seekp(-4, std::ios::cur);
1746
+ write_be32(*f, holes_aiger_size); // length in bytes
1747
+ #endif
1748
+ f->seekp(0, std::ios::end);
1749
+
1750
+ if (mapping_prep) {
1751
+ pool<Wire *> to_remove;
1752
+ for (auto wire : top->wires())
1753
+ if (!wire->port_input && !wire->port_output && !keep_wires.count(wire))
1754
+ to_remove.insert(wire);
1755
+ move_init_to_kept(to_remove);
1756
+ std::vector<Cell *> to_remove_cells;
1757
+ for (auto cell : top->cells())
1758
+ // $scopeinfo isn't part of the mapping
1759
+ if (cell->type != ID($scopeinfo) &&
1760
+ !top_minfo->found_blackboxes.count(cell) && !keep_cells.count(cell))
1761
+ to_remove_cells.push_back(cell);
1762
+ for (auto cell : to_remove_cells)
1763
+ top->remove(cell);
1764
+ prune_kept_cells(to_remove);
1765
+ top->remove(to_remove);
1766
+ }
1767
+
1768
+ clear_boxes();
1769
+
1770
+ design->scratchpad_set_int("write_xaiger.num_inputs", ninputs);
1771
+ design->scratchpad_set_int("write_xaiger.num_outputs", noutputs);
1772
+ design->scratchpad_set_int("write_xaiger.num_ands", lit_counter / 2);
1773
+ }
1774
+ };
1775
+
1776
+ // $input_port cells only encode buffer-normalized form, but bufNormalize(false)
1777
+ // leaves the cells in the design
1778
+ void remove_input_port_cells(Design *design)
1779
+ {
1780
+ std::vector<Cell *> to_remove;
1781
+
1782
+ for (auto module : design->modules()) {
1783
+ to_remove.clear();
1784
+ for (auto cell : module->cells())
1785
+ if (cell->type == ID($input_port))
1786
+ to_remove.push_back(cell);
1787
+
1788
+ for (auto cell : to_remove)
1789
+ module->remove(cell);
1790
+ }
1791
+ }
1792
+
1793
+ struct Aiger2Backend : Backend {
1794
+ Aiger2Backend() : Backend("aiger2", "(experimental) write design to AIGER file")
1795
+ {
1796
+ experimental();
1797
+ }
1798
+
1799
+ void help() override
1800
+ {
1801
+ // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
1802
+ log("\n");
1803
+ log(" write_aiger2 [options] [filename]\n");
1804
+ log("\n");
1805
+ log("Write the selected module to an AIGER file.\n");
1806
+ log("\n");
1807
+ log(" -strash\n");
1808
+ log(" perform structural hashing while writing\n");
1809
+ log("\n");
1810
+ log(" -flatten\n");
1811
+ log(" allow descending into submodules and write a flattened view of the design\n");
1812
+ log(" hierarchy starting at the selected top\n");
1813
+ log("\n");
1814
+ log("This command is able to ingest all combinational cells except for:\n");
1815
+ log("\n");
1816
+ std::string message;
1817
+ int col = 0;
1818
+ for (size_t i = 0; i < StaticCellTypes::builder.count; i++) {
1819
+ auto &cell = StaticCellTypes::builder.cells[i];
1820
+ if (!cell.features.is_evaluable)
1821
+ continue;
1822
+ if (cell.features.is_stdcell)
1823
+ continue;
1824
+ if (known_ops(cell.type))
1825
+ continue;
1826
+ std::string name = ID::unescaped_str(cell.type);
1827
+ if (col + name.size() + 2 > 72) {
1828
+ log(" %s\n", message);
1829
+ message = "";
1830
+ col = 0;
1831
+ }
1832
+ col += name.size() + 2;
1833
+ message += stringf("%s, ", name);
1834
+ }
1835
+ if (!message.empty())
1836
+ log(" %s\n", message);
1837
+ log("\n");
1838
+ log("And all combinational gates except for:\n");
1839
+ log("\n");
1840
+ message = "";
1841
+ col = 0;
1842
+ for (size_t i = 0; i < StaticCellTypes::builder.count; i++) {
1843
+ auto &cell = StaticCellTypes::builder.cells[i];
1844
+ if (!cell.features.is_evaluable)
1845
+ continue;
1846
+ if (!cell.features.is_stdcell)
1847
+ continue;
1848
+ if (known_ops(cell.type))
1849
+ continue;
1850
+ std::string name = ID::unescaped_str(cell.type);
1851
+ if (col + name.size() + 2 > 72) {
1852
+ log(" %s\n", message);
1853
+ message = "";
1854
+ col = 0;
1855
+ }
1856
+ col += name.size() + 2;
1857
+ message += stringf("%s, ", name);
1858
+ }
1859
+ if (!message.empty())
1860
+ log(" %s\n", message);
1861
+ log("\n");
1862
+ }
1863
+
1864
+ void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, Design *design) override
1865
+ {
1866
+ log_header(design, "Executing AIGER2 backend.\n");
1867
+
1868
+ size_t argidx;
1869
+ AigerWriter writer;
1870
+ writer.const_folding = true;
1871
+ for (argidx = 1; argidx < args.size(); argidx++) {
1872
+ if (args[argidx] == "-strash")
1873
+ writer.strashing = true;
1874
+ else if (args[argidx] == "-flatten")
1875
+ writer.flatten = true;
1876
+ else
1877
+ break;
1878
+ }
1879
+ extra_args(f, filename, args, argidx, true);
1880
+
1881
+ Module *top = design->top_module();
1882
+
1883
+ if (!top || !design->selected_whole_module(top))
1884
+ log_cmd_error("No top module selected\n");
1885
+
1886
+ design->bufNormalize(true);
1887
+ writer.setup(top);
1888
+ writer.write(f);
1889
+
1890
+ // we are leaving the sacred land, un-bufnormalize
1891
+ // (if not, this will lead to bugs: the buf-normalized
1892
+ // flag must not be kept on past the code that can work
1893
+ // with it)
1894
+ design->bufNormalize(false);
1895
+ remove_input_port_cells(design);
1896
+ }
1897
+ } Aiger2Backend;
1898
+
1899
+ struct XAiger2Backend : Backend {
1900
+ XAiger2Backend() : Backend("xaiger2", "write module to XAIGER file") { }
1901
+
1902
+ void help() override
1903
+ {
1904
+ // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
1905
+ log("\n");
1906
+ log(" write_xaiger2 [options] [filename]\n");
1907
+ log("\n");
1908
+ log("Write the selected module to a XAIGER file including the 'h' and 'a' extensions\n");
1909
+ log("with box information for ABC.\n");
1910
+ log("\n");
1911
+ log(" -strash\n");
1912
+ log(" perform structural hashing while writing\n");
1913
+ log("\n");
1914
+ log(" -flatten\n");
1915
+ log(" allow descending into submodules and write a flattened view of the design\n");
1916
+ log(" hierarchy starting at the selected top\n");
1917
+ log("\n");
1918
+ log(" -mapping_prep\n");
1919
+ log(" after the file is written, prepare the module for reintegration of\n");
1920
+ log(" a mapping in a subsequent command. all cells which are not blackboxed nor\n");
1921
+ log(" whiteboxed are removed from the design as well as all wires which only\n");
1922
+ log(" connect to removed cells\n");
1923
+ log(" (conflicts with -flatten)\n");
1924
+ log("\n");
1925
+ log(" -map2 <file>\n");
1926
+ log(" write a map2 file which 'abc_ops_reintegrate' can read to\n");
1927
+ log(" reintegrate a mapping\n");
1928
+ log(" (conflicts with -flatten)\n");
1929
+ log("\n");
1930
+ }
1931
+
1932
+ void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, Design *design) override
1933
+ {
1934
+ log_header(design, "Executing XAIGER2 backend.\n");
1935
+
1936
+ size_t argidx;
1937
+ XAigerWriter writer;
1938
+ std::string map_filename;
1939
+ writer.const_folding = true;
1940
+ for (argidx = 1; argidx < args.size(); argidx++) {
1941
+ if (args[argidx] == "-strash")
1942
+ writer.strashing = true;
1943
+ else if (args[argidx] == "-flatten")
1944
+ writer.flatten = true;
1945
+ else if (args[argidx] == "-mapping_prep")
1946
+ writer.mapping_prep = true;
1947
+ else if (args[argidx] == "-map2" && argidx + 1 < args.size())
1948
+ map_filename = args[++argidx];
1949
+ else
1950
+ break;
1951
+ }
1952
+ extra_args(f, filename, args, argidx, true);
1953
+
1954
+ Module *top = design->top_module();
1955
+
1956
+ if (!top || !design->selected_whole_module(top))
1957
+ log_cmd_error("No top module selected\n");
1958
+
1959
+ if (!map_filename.empty()) {
1960
+ writer.map_file.open(map_filename);
1961
+ if (!writer.map_file)
1962
+ log_cmd_error("Failed to open '%s' for writing\n", map_filename);
1963
+ }
1964
+
1965
+ design->bufNormalize(true);
1966
+ writer.setup(top);
1967
+ writer.write(f);
1968
+
1969
+ // we are leaving the sacred land, un-bufnormalize
1970
+ // (if not, this will lead to bugs: the buf-normalized
1971
+ // flag must not be kept on past the code that can work
1972
+ // with it)
1973
+ design->bufNormalize(false);
1974
+ remove_input_port_cells(design);
1975
+ }
1976
+ } XAiger2Backend;
1977
+
1978
+ PRIVATE_NAMESPACE_END
chips/yosys/backends/blif/CMakeLists.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ yosys_backend(blif
2
+ blif.cc
3
+ )
chips/yosys/backends/blif/blif.cc ADDED
@@ -0,0 +1,742 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * yosys -- Yosys Open SYnthesis Suite
3
+ *
4
+ * Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
5
+ *
6
+ * Permission to use, copy, modify, and/or distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ *
18
+ */
19
+
20
+ // [[CITE]] Berkeley Logic Interchange Format (BLIF)
21
+ // University of California. Berkeley. July 28, 1992
22
+ // http://www.ece.cmu.edu/~ee760/760docs/blif.pdf
23
+
24
+ #include "kernel/rtlil.h"
25
+ #include "kernel/register.h"
26
+ #include "kernel/sigtools.h"
27
+ #include "kernel/newcelltypes.h"
28
+ #include "kernel/log.h"
29
+ #include <string>
30
+
31
+ USING_YOSYS_NAMESPACE
32
+ PRIVATE_NAMESPACE_BEGIN
33
+
34
+ struct BlifDumperConfig
35
+ {
36
+ bool icells_mode;
37
+ bool conn_mode;
38
+ bool impltf_mode;
39
+ bool gates_mode;
40
+ bool cname_mode;
41
+ bool iname_mode;
42
+ bool param_mode;
43
+ bool attr_mode;
44
+ bool iattr_mode;
45
+ bool blackbox_mode;
46
+ bool noalias_mode;
47
+ bool gatesi_mode;
48
+
49
+ std::string buf_type, buf_in, buf_out;
50
+ std::vector<std::array<std::string, 3>> unbuf_args;
51
+ std::map<RTLIL::IdString, std::pair<RTLIL::IdString, RTLIL::IdString>> unbuf_types;
52
+ std::string true_type, true_out, false_type, false_out, undef_type, undef_out;
53
+ RTLIL::Module *buf_module = nullptr, *true_module = nullptr, *false_module = nullptr, *undef_module = nullptr;
54
+
55
+ void resolve(RTLIL::Design *design);
56
+
57
+ BlifDumperConfig() : icells_mode(false), conn_mode(false), impltf_mode(false), gates_mode(false),
58
+ cname_mode(false), iname_mode(false), param_mode(false), attr_mode(false), iattr_mode(false),
59
+ blackbox_mode(false), noalias_mode(false), gatesi_mode(false) { }
60
+ };
61
+
62
+ static IdString match_port(RTLIL::Cell *cell, const std::string &escaped_name)
63
+ {
64
+ for (auto &conn : cell->connections())
65
+ if (cell->twines().name_equal(conn.first, escaped_name))
66
+ return conn.first;
67
+ return IdString();
68
+ }
69
+
70
+ void BlifDumperConfig::resolve(RTLIL::Design *design)
71
+ {
72
+ if (RTLIL::Module *module = design->module(RTLIL::escape_id(buf_type)))
73
+ buf_module = module;
74
+ if (RTLIL::Module *module = design->module(RTLIL::escape_id(true_type)))
75
+ true_module = module;
76
+ if (RTLIL::Module *module = design->module(RTLIL::escape_id(false_type)))
77
+ false_module = module;
78
+ if (RTLIL::Module *module = design->module(RTLIL::escape_id(undef_type)))
79
+ undef_module = module;
80
+
81
+ std::vector<std::array<std::string, 3>> escaped_unbuf;
82
+ for (auto &names : unbuf_args)
83
+ escaped_unbuf.push_back({RTLIL::escape_id(names[0]), RTLIL::escape_id(names[1]), RTLIL::escape_id(names[2])});
84
+
85
+ for (auto module : design->modules()) {
86
+ for (auto cell : module->cells())
87
+ for (auto &names : escaped_unbuf) {
88
+ if (unbuf_types.count(cell->type) || !design->twines().name_equal(cell->type, names[0]))
89
+ continue;
90
+ IdString in_port = match_port(cell, names[1]);
91
+ IdString out_port = match_port(cell, names[2]);
92
+ if (in_port != IdString::Null && out_port != IdString::Null)
93
+ unbuf_types[cell->type] = std::make_pair(in_port, out_port);
94
+ }
95
+ }
96
+ }
97
+
98
+ struct BlifDumper
99
+ {
100
+ std::ostream &f;
101
+ RTLIL::Module *module;
102
+ RTLIL::Design *design;
103
+ BlifDumperConfig *config;
104
+ NewCellTypes ct;
105
+
106
+ SigMap sigmap;
107
+ dict<SigBit, int> init_bits;
108
+
109
+ BlifDumper(std::ostream &f, RTLIL::Module *module, RTLIL::Design *design, BlifDumperConfig *config) :
110
+ f(f), module(module), design(design), config(config), ct(design), sigmap(module)
111
+ {
112
+ for (Wire *wire : module->wires())
113
+ if (wire->attributes.count(ID::init)) {
114
+ SigSpec initsig = sigmap(wire);
115
+ Const initval = wire->attributes.at(ID::init);
116
+ for (int i = 0; i < GetSize(initsig) && i < GetSize(initval); i++)
117
+ switch (initval[i]) {
118
+ case State::S0:
119
+ init_bits[initsig[i]] = 0;
120
+ break;
121
+ case State::S1:
122
+ init_bits[initsig[i]] = 1;
123
+ break;
124
+ default:
125
+ break;
126
+ }
127
+ }
128
+ }
129
+
130
+ pool<SigBit> cstr_bits_seen;
131
+
132
+ const std::string str(RTLIL::IdString id)
133
+ {
134
+ std::string str = design->twines().unescaped_str(id);
135
+ for (size_t i = 0; i < str.size(); i++)
136
+ if (str[i] == '#' || str[i] == '=' || str[i] == '<' || str[i] == '>')
137
+ str[i] = '?';
138
+ return str;
139
+ }
140
+
141
+ const std::string str(RTLIL::SigBit sig)
142
+ {
143
+ cstr_bits_seen.insert(sig);
144
+
145
+ if (sig.wire == NULL) {
146
+ if (sig == RTLIL::State::S0) return config->false_type == "-" || config->false_type == "+" ? config->false_out.c_str() : "$false";
147
+ if (sig == RTLIL::State::S1) return config->true_type == "-" || config->true_type == "+" ? config->true_out.c_str() : "$true";
148
+ return config->undef_type == "-" || config->undef_type == "+" ? config->undef_out.c_str() : "$undef";
149
+ }
150
+
151
+ std::string str = this->str(sig.wire->name);
152
+
153
+ if (sig.wire->width != 1)
154
+ str += stringf("[%d]", sig.wire->upto ? sig.wire->start_offset+sig.wire->width-sig.offset-1 : sig.wire->start_offset+sig.offset);
155
+
156
+ return str;
157
+ }
158
+
159
+ template <bool Space = true> const std::string str_init(RTLIL::SigBit sig)
160
+ {
161
+ sigmap.apply(sig);
162
+
163
+ if (init_bits.count(sig) == 0) {
164
+ if constexpr (Space)
165
+ return " 2";
166
+ else
167
+ return "2";
168
+ }
169
+
170
+ if constexpr (Space)
171
+ return stringf(" %d", init_bits.at(sig));
172
+ else
173
+ return stringf("%d", init_bits.at(sig));
174
+ }
175
+
176
+ const char *subckt_or_gate(RTLIL::Module *cell_module)
177
+ {
178
+ if (!config->gates_mode)
179
+ return "subckt";
180
+ if (cell_module == nullptr || cell_module->get_blackbox_attribute())
181
+ return "gate";
182
+ return "subckt";
183
+ }
184
+
185
+ const char *subckt_or_gate(IdString cell_type)
186
+ {
187
+ return subckt_or_gate(config->gates_mode ? design->module(cell_type) : nullptr);
188
+ }
189
+
190
+ void dump_params(const char *command, dict<IdString, Const> &params)
191
+ {
192
+ for (auto &param : params) {
193
+ f << stringf("%s %s ", command, design->twines().unescaped_str(param.first));
194
+ if (param.second.flags & RTLIL::CONST_FLAG_STRING) {
195
+ std::string str = param.second.decode_string();
196
+ f << stringf("\"");
197
+ for (char ch : str)
198
+ if (ch == '"' || ch == '\\')
199
+ f << stringf("\\%c", ch);
200
+ else if (ch < 32 || ch >= 127)
201
+ f << stringf("\\%03o", ch);
202
+ else
203
+ f << stringf("%c", ch);
204
+ f << stringf("\"\n");
205
+ } else
206
+ f << stringf("%s\n", param.second.as_string());
207
+ }
208
+ }
209
+
210
+ void dump()
211
+ {
212
+ f << stringf("\n");
213
+ f << stringf(".model %s\n", str(module->name));
214
+
215
+ std::map<int, RTLIL::Wire*> inputs, outputs;
216
+
217
+ for (auto wire : module->wires()) {
218
+ if (wire->port_input)
219
+ inputs[wire->port_id] = wire;
220
+ if (wire->port_output)
221
+ outputs[wire->port_id] = wire;
222
+ }
223
+
224
+ f << stringf(".inputs");
225
+ for (auto &it : inputs) {
226
+ RTLIL::Wire *wire = it.second;
227
+ for (int i = 0; i < wire->width; i++)
228
+ f << stringf(" %s", str(RTLIL::SigSpec(wire, i)));
229
+ }
230
+ f << stringf("\n");
231
+
232
+ f << stringf(".outputs");
233
+ for (auto &it : outputs) {
234
+ RTLIL::Wire *wire = it.second;
235
+ for (int i = 0; i < wire->width; i++)
236
+ f << stringf(" %s", str(RTLIL::SigSpec(wire, i)));
237
+ }
238
+ f << stringf("\n");
239
+
240
+ if (module->get_blackbox_attribute()) {
241
+ f << stringf(".blackbox\n");
242
+ f << stringf(".end\n");
243
+ return;
244
+ }
245
+
246
+ if (!config->impltf_mode) {
247
+ if (!config->false_type.empty()) {
248
+ if (config->false_type == "+")
249
+ f << stringf(".names %s\n", config->false_out);
250
+ else if (config->false_type != "-")
251
+ f << stringf(".%s %s %s=$false\n", subckt_or_gate(config->false_module),
252
+ config->false_type, config->false_out);
253
+ } else
254
+ f << stringf(".names $false\n");
255
+ if (!config->true_type.empty()) {
256
+ if (config->true_type == "+")
257
+ f << stringf(".names %s\n1\n", config->true_out);
258
+ else if (config->true_type != "-")
259
+ f << stringf(".%s %s %s=$true\n", subckt_or_gate(config->true_module),
260
+ config->true_type, config->true_out);
261
+ } else
262
+ f << stringf(".names $true\n1\n");
263
+ if (!config->undef_type.empty()) {
264
+ if (config->undef_type == "+")
265
+ f << stringf(".names %s\n", config->undef_out);
266
+ else if (config->undef_type != "-")
267
+ f << stringf(".%s %s %s=$undef\n", subckt_or_gate(config->undef_module),
268
+ config->undef_type, config->undef_out);
269
+ } else
270
+ f << stringf(".names $undef\n");
271
+ }
272
+
273
+ for (auto cell : module->cells())
274
+ {
275
+ if (cell->type == ID($scopeinfo))
276
+ continue;
277
+
278
+ if (config->unbuf_types.count(cell->type)) {
279
+ auto portnames = config->unbuf_types.at(cell->type);
280
+ f << stringf(".names %s %s\n1 1\n",
281
+ str(cell->getPort(portnames.first)), str(cell->getPort(portnames.second)));
282
+ continue;
283
+ }
284
+
285
+ if (!config->icells_mode && cell->type == ID($_NOT_)) {
286
+ f << stringf(".names %s %s\n0 1\n",
287
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::Y)));
288
+ goto internal_cell;
289
+ }
290
+
291
+ if (!config->icells_mode && cell->type == ID($_AND_)) {
292
+ f << stringf(".names %s %s %s\n11 1\n",
293
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::Y)));
294
+ goto internal_cell;
295
+ }
296
+
297
+ if (!config->icells_mode && cell->type == ID($_OR_)) {
298
+ f << stringf(".names %s %s %s\n1- 1\n-1 1\n",
299
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::Y)));
300
+ goto internal_cell;
301
+ }
302
+
303
+ if (!config->icells_mode && cell->type == ID($_XOR_)) {
304
+ f << stringf(".names %s %s %s\n10 1\n01 1\n",
305
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::Y)));
306
+ goto internal_cell;
307
+ }
308
+
309
+ if (!config->icells_mode && cell->type == ID($_NAND_)) {
310
+ f << stringf(".names %s %s %s\n0- 1\n-0 1\n",
311
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::Y)));
312
+ goto internal_cell;
313
+ }
314
+
315
+ if (!config->icells_mode && cell->type == ID($_NOR_)) {
316
+ f << stringf(".names %s %s %s\n00 1\n",
317
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::Y)));
318
+ goto internal_cell;
319
+ }
320
+
321
+ if (!config->icells_mode && cell->type == ID($_XNOR_)) {
322
+ f << stringf(".names %s %s %s\n11 1\n00 1\n",
323
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::Y)));
324
+ goto internal_cell;
325
+ }
326
+
327
+ if (!config->icells_mode && cell->type == ID($_ANDNOT_)) {
328
+ f << stringf(".names %s %s %s\n10 1\n",
329
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::Y)));
330
+ goto internal_cell;
331
+ }
332
+
333
+ if (!config->icells_mode && cell->type == ID($_ORNOT_)) {
334
+ f << stringf(".names %s %s %s\n1- 1\n-0 1\n",
335
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::Y)));
336
+ goto internal_cell;
337
+ }
338
+
339
+ if (!config->icells_mode && cell->type == ID($_AOI3_)) {
340
+ f << stringf(".names %s %s %s %s\n-00 1\n0-0 1\n",
341
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::C)), str(cell->getPort(ID::Y)));
342
+ goto internal_cell;
343
+ }
344
+
345
+ if (!config->icells_mode && cell->type == ID($_OAI3_)) {
346
+ f << stringf(".names %s %s %s %s\n00- 1\n--0 1\n",
347
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)), str(cell->getPort(ID::C)), str(cell->getPort(ID::Y)));
348
+ goto internal_cell;
349
+ }
350
+
351
+ if (!config->icells_mode && cell->type == ID($_AOI4_)) {
352
+ f << stringf(".names %s %s %s %s %s\n-0-0 1\n-00- 1\n0--0 1\n0-0- 1\n",
353
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)),
354
+ str(cell->getPort(ID::C)), str(cell->getPort(ID::D)), str(cell->getPort(ID::Y)));
355
+ goto internal_cell;
356
+ }
357
+
358
+ if (!config->icells_mode && cell->type == ID($_OAI4_)) {
359
+ f << stringf(".names %s %s %s %s %s\n00-- 1\n--00 1\n",
360
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)),
361
+ str(cell->getPort(ID::C)), str(cell->getPort(ID::D)), str(cell->getPort(ID::Y)));
362
+ goto internal_cell;
363
+ }
364
+
365
+ if (!config->icells_mode && cell->type == ID($_MUX_)) {
366
+ f << stringf(".names %s %s %s %s\n1-0 1\n-11 1\n",
367
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)),
368
+ str(cell->getPort(ID::S)), str(cell->getPort(ID::Y)));
369
+ goto internal_cell;
370
+ }
371
+
372
+ if (!config->icells_mode && cell->type == ID($_NMUX_)) {
373
+ f << stringf(".names %s %s %s %s\n0-0 1\n-01 1\n",
374
+ str(cell->getPort(ID::A)), str(cell->getPort(ID::B)),
375
+ str(cell->getPort(ID::S)), str(cell->getPort(ID::Y)));
376
+ goto internal_cell;
377
+ }
378
+
379
+ if (!config->icells_mode && cell->type == ID($_FF_)) {
380
+ f << stringf(".latch %s %s%s\n", str(cell->getPort(ID::D)), str(cell->getPort(ID::Q)),
381
+ str_init(cell->getPort(ID::Q)));
382
+ goto internal_cell;
383
+ }
384
+
385
+ if (!config->icells_mode && cell->type == ID($_DFF_N_)) {
386
+ f << stringf(".latch %s %s fe %s%s\n", str(cell->getPort(ID::D)), str(cell->getPort(ID::Q)),
387
+ str(cell->getPort(ID::C)), str_init(cell->getPort(ID::Q)));
388
+ goto internal_cell;
389
+ }
390
+
391
+ if (!config->icells_mode && cell->type == ID($_DFF_P_)) {
392
+ f << stringf(".latch %s %s re %s%s\n", str(cell->getPort(ID::D)), str(cell->getPort(ID::Q)),
393
+ str(cell->getPort(ID::C)), str_init(cell->getPort(ID::Q)));
394
+ goto internal_cell;
395
+ }
396
+
397
+ if (!config->icells_mode && cell->type == ID($_DLATCH_N_)) {
398
+ f << stringf(".latch %s %s al %s%s\n", str(cell->getPort(ID::D)), str(cell->getPort(ID::Q)),
399
+ str(cell->getPort(ID::E)), str_init(cell->getPort(ID::Q)));
400
+ goto internal_cell;
401
+ }
402
+
403
+ if (!config->icells_mode && cell->type == ID($_DLATCH_P_)) {
404
+ f << stringf(".latch %s %s ah %s%s\n", str(cell->getPort(ID::D)), str(cell->getPort(ID::Q)),
405
+ str(cell->getPort(ID::E)), str_init(cell->getPort(ID::Q)));
406
+ goto internal_cell;
407
+ }
408
+
409
+ if (!config->icells_mode && cell->type == ID($lut)) {
410
+ f << stringf(".names");
411
+ auto &inputs = cell->getPort(ID::A);
412
+ auto width = cell->parameters.at(ID::WIDTH).as_int();
413
+ log_assert(inputs.size() == width);
414
+ for (int i = width-1; i >= 0; i--)
415
+ f << stringf(" %s", str(inputs.extract(i, 1)));
416
+ auto &output = cell->getPort(ID::Y);
417
+ log_assert(output.size() == 1);
418
+ f << stringf(" %s", str(output));
419
+ f << stringf("\n");
420
+ RTLIL::SigSpec mask = cell->parameters.at(ID::LUT);
421
+ for (int i = 0; i < (1 << width); i++)
422
+ if (mask[i] == State::S1) {
423
+ for (int j = width-1; j >= 0; j--) {
424
+ f << ((i>>j)&1 ? '1' : '0');
425
+ }
426
+ f << " 1\n";
427
+ }
428
+ goto internal_cell;
429
+ }
430
+
431
+ if (!config->icells_mode && cell->type == ID($sop)) {
432
+ f << stringf(".names");
433
+ auto &inputs = cell->getPort(ID::A);
434
+ auto width = cell->parameters.at(ID::WIDTH).as_int();
435
+ auto depth = cell->parameters.at(ID::DEPTH).as_int();
436
+ vector<State> table = cell->parameters.at(ID::TABLE).to_bits();
437
+ while (GetSize(table) < 2*width*depth)
438
+ table.push_back(State::S0);
439
+ log_assert(inputs.size() == width);
440
+ for (int i = 0; i < width; i++)
441
+ f << stringf(" %s", str(inputs.extract(i, 1)));
442
+ auto &output = cell->getPort(ID::Y);
443
+ log_assert(output.size() == 1);
444
+ f << stringf(" %s", str(output));
445
+ f << stringf("\n");
446
+ for (int i = 0; i < depth; i++) {
447
+ for (int j = 0; j < width; j++) {
448
+ bool pat0 = table.at(2*width*i + 2*j + 0) == State::S1;
449
+ bool pat1 = table.at(2*width*i + 2*j + 1) == State::S1;
450
+ if (pat0 && !pat1) f << "0";
451
+ else if (!pat0 && pat1) f << "1";
452
+ else f << "-";
453
+ }
454
+ f << " 1\n";
455
+ }
456
+ goto internal_cell;
457
+ }
458
+
459
+ f << stringf(".%s %s", subckt_or_gate(cell->type), str(cell->type));
460
+ for (auto &conn : cell->connections())
461
+ {
462
+ if (conn.second.size() == 1) {
463
+ f << stringf(" %s=%s", str(conn.first), str(conn.second[0]));
464
+ continue;
465
+ }
466
+
467
+ Module *m = design->module(cell->type);
468
+ Wire *w = m ? m->wire(conn.first) : nullptr;
469
+
470
+ if (w == nullptr) {
471
+ for (int i = 0; i < GetSize(conn.second); i++)
472
+ f << stringf(" %s[%d]=%s", str(conn.first), i, str(conn.second[i]));
473
+ } else {
474
+ for (int i = 0; i < std::min(GetSize(conn.second), GetSize(w)); i++) {
475
+ SigBit sig(w, i);
476
+ f << stringf(" %s[%d]=%s", str(conn.first), sig.wire->upto ?
477
+ sig.wire->start_offset+sig.wire->width-sig.offset-1 :
478
+ sig.wire->start_offset+sig.offset, str(conn.second[i]));
479
+ }
480
+ }
481
+ }
482
+ f << stringf("\n");
483
+
484
+ if (config->cname_mode)
485
+ f << stringf(".cname %s\n", str(cell->name));
486
+ if (config->attr_mode)
487
+ dump_params(".attr", cell->attributes);
488
+ if (config->param_mode)
489
+ dump_params(".param", cell->parameters);
490
+
491
+ if (0) {
492
+ internal_cell:
493
+ if (config->iname_mode)
494
+ f << stringf(".cname %s\n", str(cell->name));
495
+ if (config->iattr_mode)
496
+ dump_params(".attr", cell->attributes);
497
+ }
498
+ }
499
+
500
+ for (auto &conn : module->connections())
501
+ for (int i = 0; i < conn.first.size(); i++)
502
+ {
503
+ SigBit lhs_bit = conn.first[i];
504
+ SigBit rhs_bit = conn.second[i];
505
+
506
+ if (config->noalias_mode && cstr_bits_seen.count(lhs_bit) == 0)
507
+ continue;
508
+
509
+ if (config->conn_mode)
510
+ f << stringf(".conn %s %s\n", str(rhs_bit), str(lhs_bit));
511
+ else if (!config->buf_type.empty())
512
+ f << stringf(".%s %s %s=%s %s=%s\n", subckt_or_gate(config->buf_module), config->buf_type,
513
+ config->buf_in, str(rhs_bit), config->buf_out, str(lhs_bit));
514
+ else
515
+ f << stringf(".names %s %s\n1 1\n", str(rhs_bit), str(lhs_bit));
516
+ }
517
+
518
+ if (config->gatesi_mode) {
519
+ for (auto &&init_bit : init_bits)
520
+ f << stringf(".gateinit %s=%s\n", str(init_bit.first), str_init<false>(init_bit.first));
521
+ }
522
+
523
+ f << stringf(".end\n");
524
+ }
525
+
526
+ static void dump(std::ostream &f, RTLIL::Module *module, RTLIL::Design *design, BlifDumperConfig &config)
527
+ {
528
+ BlifDumper dumper(f, module, design, &config);
529
+ dumper.dump();
530
+ }
531
+ };
532
+
533
+ struct BlifBackend : public Backend {
534
+ BlifBackend() : Backend("blif", "write design to BLIF file") { }
535
+ void help() override
536
+ {
537
+ // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
538
+ log("\n");
539
+ log(" write_blif [options] [filename]\n");
540
+ log("\n");
541
+ log("Write the current design to an BLIF file.\n");
542
+ log("\n");
543
+ log(" -top top_module\n");
544
+ log(" set the specified module as design top module\n");
545
+ log("\n");
546
+ log(" -buf <cell-type> <in-port> <out-port>\n");
547
+ log(" use cells of type <cell-type> with the specified port names for buffers\n");
548
+ log("\n");
549
+ log(" -unbuf <cell-type> <in-port> <out-port>\n");
550
+ log(" replace buffer cells with the specified name and port names with\n");
551
+ log(" a .names statement that models a buffer\n");
552
+ log("\n");
553
+ log(" -true <cell-type> <out-port>\n");
554
+ log(" -false <cell-type> <out-port>\n");
555
+ log(" -undef <cell-type> <out-port>\n");
556
+ log(" use the specified cell types to drive nets that are constant 1, 0, or\n");
557
+ log(" undefined. when '-' is used as <cell-type>, then <out-port> specifies\n");
558
+ log(" the wire name to be used for the constant signal and no cell driving\n");
559
+ log(" that wire is generated. when '+' is used as <cell-type>, then <out-port>\n");
560
+ log(" specifies the wire name to be used for the constant signal and a .names\n");
561
+ log(" statement is generated to drive the wire.\n");
562
+ log("\n");
563
+ log(" -noalias\n");
564
+ log(" if a net name is aliasing another net name, then by default a net\n");
565
+ log(" without fanout is created that is driven by the other net. This option\n");
566
+ log(" suppresses the generation of this nets without fanout.\n");
567
+ log("\n");
568
+ log("The following options can be useful when the generated file is not going to be\n");
569
+ log("read by a BLIF parser but a custom tool. It is recommended not to name the\n");
570
+ log("output file *.blif when any of these options are used.\n");
571
+ log("\n");
572
+ log(" -icells\n");
573
+ log(" do not translate Yosys's internal gates to generic BLIF logic\n");
574
+ log(" functions. Instead create .subckt or .gate lines for all cells.\n");
575
+ log("\n");
576
+ log(" -gates\n");
577
+ log(" print .gate instead of .subckt lines for all cells that are not\n");
578
+ log(" instantiations of other modules from this design.\n");
579
+ log("\n");
580
+ log(" -conn\n");
581
+ log(" do not generate buffers for connected wires. instead use the\n");
582
+ log(" non-standard .conn statement.\n");
583
+ log("\n");
584
+ log(" -attr\n");
585
+ log(" use the non-standard .attr statement to write cell attributes\n");
586
+ log("\n");
587
+ log(" -param\n");
588
+ log(" use the non-standard .param statement to write cell parameters\n");
589
+ log("\n");
590
+ log(" -cname\n");
591
+ log(" use the non-standard .cname statement to write cell names\n");
592
+ log("\n");
593
+ log(" -iname, -iattr\n");
594
+ log(" enable -cname and -attr functionality for .names statements\n");
595
+ log(" (the .cname and .attr statements will be included in the BLIF\n");
596
+ log(" output after the truth table for the .names statement)\n");
597
+ log("\n");
598
+ log(" -blackbox\n");
599
+ log(" write blackbox cells with .blackbox statement.\n");
600
+ log("\n");
601
+ log(" -impltf\n");
602
+ log(" do not write definitions for the $true, $false and $undef wires.\n");
603
+ log("\n");
604
+ log(" -gatesi\n");
605
+ log(" write initial bit(s) with .gateinit for gates that needs to be initialized.\n");
606
+ log("\n");
607
+ }
608
+ void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
609
+ {
610
+ std::string top_module_name;
611
+ std::string buf_type, buf_in, buf_out;
612
+ std::string true_type, true_out;
613
+ std::string false_type, false_out;
614
+ BlifDumperConfig config;
615
+
616
+ log_header(design, "Executing BLIF backend.\n");
617
+
618
+ size_t argidx;
619
+ for (argidx = 1; argidx < args.size(); argidx++)
620
+ {
621
+ if (args[argidx] == "-top" && argidx+1 < args.size()) {
622
+ top_module_name = args[++argidx];
623
+ continue;
624
+ }
625
+ if (args[argidx] == "-buf" && argidx+3 < args.size()) {
626
+ config.buf_type = args[++argidx];
627
+ config.buf_in = args[++argidx];
628
+ config.buf_out = args[++argidx];
629
+ continue;
630
+ }
631
+ if (args[argidx] == "-unbuf" && argidx+3 < args.size()) {
632
+ config.unbuf_args.push_back({args[argidx+1], args[argidx+2], args[argidx+3]});
633
+ argidx += 3;
634
+ continue;
635
+ }
636
+ if (args[argidx] == "-true" && argidx+2 < args.size()) {
637
+ config.true_type = args[++argidx];
638
+ config.true_out = args[++argidx];
639
+ continue;
640
+ }
641
+ if (args[argidx] == "-false" && argidx+2 < args.size()) {
642
+ config.false_type = args[++argidx];
643
+ config.false_out = args[++argidx];
644
+ continue;
645
+ }
646
+ if (args[argidx] == "-undef" && argidx+2 < args.size()) {
647
+ config.undef_type = args[++argidx];
648
+ config.undef_out = args[++argidx];
649
+ continue;
650
+ }
651
+ if (args[argidx] == "-icells") {
652
+ config.icells_mode = true;
653
+ continue;
654
+ }
655
+ if (args[argidx] == "-gates") {
656
+ config.gates_mode = true;
657
+ continue;
658
+ }
659
+ if (args[argidx] == "-conn") {
660
+ config.conn_mode = true;
661
+ continue;
662
+ }
663
+ if (args[argidx] == "-cname") {
664
+ config.cname_mode = true;
665
+ continue;
666
+ }
667
+ if (args[argidx] == "-param") {
668
+ config.param_mode = true;
669
+ continue;
670
+ }
671
+ if (args[argidx] == "-attr") {
672
+ config.attr_mode = true;
673
+ continue;
674
+ }
675
+ if (args[argidx] == "-iname") {
676
+ config.iname_mode = true;
677
+ continue;
678
+ }
679
+ if (args[argidx] == "-iattr") {
680
+ config.iattr_mode = true;
681
+ continue;
682
+ }
683
+ if (args[argidx] == "-blackbox") {
684
+ config.blackbox_mode = true;
685
+ continue;
686
+ }
687
+ if (args[argidx] == "-impltf") {
688
+ config.impltf_mode = true;
689
+ continue;
690
+ }
691
+ if (args[argidx] == "-noalias") {
692
+ config.noalias_mode = true;
693
+ continue;
694
+ }
695
+ if (args[argidx] == "-gatesi") {
696
+ config.gatesi_mode = true;
697
+ continue;
698
+ }
699
+ break;
700
+ }
701
+ extra_args(f, filename, args, argidx);
702
+ config.resolve(design);
703
+
704
+ if (top_module_name.empty())
705
+ for (auto module : design->modules())
706
+ if (module->get_bool_attribute(ID::top))
707
+ top_module_name = module->name.str();
708
+
709
+ *f << stringf("# Generated by %s\n", yosys_maybe_version());
710
+
711
+ std::string escaped_top_name = RTLIL::escape_id(top_module_name);
712
+ std::vector<RTLIL::Module*> mod_list;
713
+
714
+ design->sort();
715
+ for (auto module : design->modules())
716
+ {
717
+ if (module->get_blackbox_attribute() && !config.blackbox_mode)
718
+ continue;
719
+
720
+ if (module->processes.size() != 0)
721
+ log_error("Found unmapped processes in module %s: unmapped processes are not supported in BLIF backend!\n", module);
722
+ if (module->memories.size() != 0)
723
+ log_error("Found unmapped memories in module %s: unmapped memories are not supported in BLIF backend!\n", module);
724
+
725
+ if (design->twines().name_equal(module->name, escaped_top_name)) {
726
+ BlifDumper::dump(*f, module, design, config);
727
+ top_module_name.clear();
728
+ continue;
729
+ }
730
+
731
+ mod_list.push_back(module);
732
+ }
733
+
734
+ if (!top_module_name.empty())
735
+ log_error("Can't find top module `%s'!\n", top_module_name);
736
+
737
+ for (auto module : mod_list)
738
+ BlifDumper::dump(*f, module, design, config);
739
+ }
740
+ } BlifBackend;
741
+
742
+ PRIVATE_NAMESPACE_END
chips/yosys/backends/btor/.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ /test_cells.tmp/