plane-hdl 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. plane_hdl-0.1.0/LICENSE +201 -0
  2. plane_hdl-0.1.0/PKG-INFO +234 -0
  3. plane_hdl-0.1.0/README.md +210 -0
  4. plane_hdl-0.1.0/pyproject.toml +72 -0
  5. plane_hdl-0.1.0/setup.cfg +4 -0
  6. plane_hdl-0.1.0/src/plane/__init__.py +147 -0
  7. plane_hdl-0.1.0/src/plane/base.py +460 -0
  8. plane_hdl-0.1.0/src/plane/connect.py +20 -0
  9. plane_hdl-0.1.0/src/plane/control.py +228 -0
  10. plane_hdl-0.1.0/src/plane/emit.py +1017 -0
  11. plane_hdl-0.1.0/src/plane/ir.py +384 -0
  12. plane_hdl-0.1.0/src/plane/lib/__init__.py +0 -0
  13. plane_hdl-0.1.0/src/plane/lib/amba/__init__.py +0 -0
  14. plane_hdl-0.1.0/src/plane/lib/amba/apb/__init__.py +9 -0
  15. plane_hdl-0.1.0/src/plane/lib/amba/apb/adapters.py +71 -0
  16. plane_hdl-0.1.0/src/plane/lib/amba/apb/bundles.py +59 -0
  17. plane_hdl-0.1.0/src/plane/lib/csr/__init__.py +20 -0
  18. plane_hdl-0.1.0/src/plane/lib/csr/block.py +265 -0
  19. plane_hdl-0.1.0/src/plane/lib/csr/c_header.py +202 -0
  20. plane_hdl-0.1.0/src/plane/lib/csr/fields.py +282 -0
  21. plane_hdl-0.1.0/src/plane/lib/csr/html.py +593 -0
  22. plane_hdl-0.1.0/src/plane/lib/csr/register.py +31 -0
  23. plane_hdl-0.1.0/src/plane/lib/csr/system.py +129 -0
  24. plane_hdl-0.1.0/src/plane/lib/csr/uvm_ral.py +149 -0
  25. plane_hdl-0.1.0/src/plane/lib/csr/yaml_io.py +202 -0
  26. plane_hdl-0.1.0/src/plane/nodes.py +907 -0
  27. plane_hdl-0.1.0/src/plane/types.py +307 -0
  28. plane_hdl-0.1.0/src/plane/utils.py +167 -0
  29. plane_hdl-0.1.0/src/plane_hdl.egg-info/PKG-INFO +234 -0
  30. plane_hdl-0.1.0/src/plane_hdl.egg-info/SOURCES.txt +47 -0
  31. plane_hdl-0.1.0/src/plane_hdl.egg-info/dependency_links.txt +1 -0
  32. plane_hdl-0.1.0/src/plane_hdl.egg-info/requires.txt +6 -0
  33. plane_hdl-0.1.0/src/plane_hdl.egg-info/top_level.txt +1 -0
  34. plane_hdl-0.1.0/tests/test_basic.py +248 -0
  35. plane_hdl-0.1.0/tests/test_blackbox.py +297 -0
  36. plane_hdl-0.1.0/tests/test_bundle.py +903 -0
  37. plane_hdl-0.1.0/tests/test_conditionals.py +471 -0
  38. plane_hdl-0.1.0/tests/test_emit_comments.py +569 -0
  39. plane_hdl-0.1.0/tests/test_enum.py +844 -0
  40. plane_hdl-0.1.0/tests/test_fanout.py +247 -0
  41. plane_hdl-0.1.0/tests/test_instance.py +384 -0
  42. plane_hdl-0.1.0/tests/test_instance_array.py +220 -0
  43. plane_hdl-0.1.0/tests/test_module_naming.py +413 -0
  44. plane_hdl-0.1.0/tests/test_ops.py +1013 -0
  45. plane_hdl-0.1.0/tests/test_optimization.py +338 -0
  46. plane_hdl-0.1.0/tests/test_reg.py +580 -0
  47. plane_hdl-0.1.0/tests/test_slice_assign.py +321 -0
  48. plane_hdl-0.1.0/tests/test_validation.py +314 -0
  49. plane_hdl-0.1.0/tests/test_vec.py +229 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: plane-hdl
3
+ Version: 0.1.0
4
+ Summary: A Python HDL inspired by Chisel
5
+ Author: lsteveol
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/lsteveol/plane
8
+ Project-URL: Repository, https://github.com/lsteveol/plane
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
15
+ Requires-Python: >=3.12
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: pyyaml>=6.0
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=9.0; extra == "dev"
21
+ Requires-Dist: pytest-cov>=7.0; extra == "dev"
22
+ Requires-Dist: ruff>=0.9; extra == "dev"
23
+ Dynamic: license-file
24
+
25
+ # plane
26
+
27
+ [![coverage](https://img.shields.io/badge/coverage-95%25-green)]()
28
+
29
+ <p align="center">
30
+ <img src="docs/plane_logo.png" alt="Plane Logo" width="400">
31
+ </p>
32
+
33
+ ## Install
34
+
35
+ Requires Python 3.12+.
36
+
37
+ ```bash
38
+ uv add plane
39
+ ```
40
+
41
+ ## Quick Start
42
+
43
+ ```python
44
+ from plane import *
45
+
46
+ class Blink(Module):
47
+ def elaborate(self):
48
+ self.clk = IO(Input(Clock()), name="clk")
49
+ self.rst = IO(Input(AsyncLowReset()), name="rst")
50
+ self.led = IO(Output(Bool()), name="led")
51
+ self.counter = Reg(UInt(24), init=0, name="counter")
52
+ self.counter @= self.counter + Literal(1, 24)
53
+ self.led @= self.counter[23]
54
+ ```
55
+
56
+ ```python
57
+ print(emitVerilog(Blink()))
58
+ ```
59
+
60
+ ```verilog
61
+ module Blink (
62
+ input logic clk,
63
+ input logic rst,
64
+ output logic led
65
+ );
66
+
67
+ logic [23:0] counter;
68
+
69
+ assign led = counter[23];
70
+
71
+ always_ff @(posedge clk or negedge rst) begin
72
+ if (!rst) begin
73
+ counter <= 24'd0;
74
+ end else begin
75
+ counter <= (counter + 24'd1);
76
+ end
77
+ end
78
+
79
+ endmodule
80
+ ```
81
+
82
+ See `docs/` for the full guide.
83
+
84
+ ## Motivation
85
+
86
+ A PythonHDL inspired by Chisel
87
+
88
+ Chisel is a powerful HDL based on Scala. While powerful, it being based on Scala has some downsides with regards to
89
+ interopting with various other flows in a semiconductor design cycle. For better or for worse, Python has become the dominant language
90
+ for scripting various flows (and now AI pipelines) and therefore it seemed prudent to have a way to build SystemVerilog
91
+ utilizing a Python based HDL. There are other Python HDLs out there [Amaranth](https://github.com/amaranth-lang/amaranth),
92
+ Migen, MyHDL, etc. This library was not created to supersede those, but meerly to coexist and offer another solution.
93
+
94
+ The name "Plane" is meant as a play on word in a few ways:
95
+
96
+ 1. Plane to sound similar to "plain", indicating this is a slightly simple library
97
+ 2. Plane as in a [plane](https://en.wikipedia.org/wiki/Plane_(tool)) woodworking tool, paying a homage to Chisel. Where a Chisel
98
+ would require precise, fine tune actions, a plane just uses brute forcce to get something done.
99
+
100
+ Many of Chisel's concepts have been used here in Plane. Certain structures are modified as necessary for the differences in Python and Scala.
101
+ Plane is not as feature rich as the Chisel ecosystem, and the long term plan is for it not to be.
102
+
103
+ ## Features
104
+
105
+ - **Data types**: `UInt`, `SInt`, `Bool`, `Clock`, `Reset`, `PlaneEnum`, `Vec`
106
+ - **Modules, ports, `Bundle` structured interfaces**
107
+ - **Combinational** (`AlwaysComb`) and **sequential** (`Reg`, `RegNext`) logic
108
+ - **Control flow**: `When`/`ElseWhen`/`Otherwise`, `Switch`/`Case`/`Default`
109
+ - **Parameters and blackboxes**
110
+ - **Comments** in emitted Verilog
111
+ - **CSR subsystem**: `RegisterBlock`/`RegisterSystem`, field types, APB adapters
112
+ - **Collateral generation**: YAML, UVM RAL, HTML
113
+
114
+ ## SystemVerilog Emission
115
+
116
+ Most issues with meta-language HDLs is the undoubtly the emitted RTL that is produced. FSMs in particular are quite difficult
117
+ to look at for Chisel-generated RTL. Plane's design was really built with verilog emission being a core principle. Most of the
118
+ lifecycle for some RTL is spent being _read_ versus _modified_. For this reason, we want the RTL that is produced to be
119
+ as close to human-readable as possible. There are times this is difficult depending on your usecases, however many of the
120
+ features and/or language decisions were chosen to aid in emission quality. If anything, this was the main motivation for Plane.
121
+ This means the Plane HDL looks similar to SV in nature. This was a design decision to make it clear what you were designing
122
+ and to ease the transition for regular RTL designers.
123
+
124
+ ## FSM Showcase
125
+
126
+ A simple 3-state FSM that advances to the next state when `advance` is high, otherwise holds. This shows `AlwaysComb`, `Switch`/`Case`, and `When` working together:
127
+
128
+ ```python
129
+ from plane import *
130
+
131
+ class State(PlaneEnum):
132
+ A = 0
133
+ B = 1
134
+ C = 2
135
+
136
+ class SimpleFSM(Module):
137
+ def elaborate(self):
138
+ self.clk = IO(Input(Clock()), name="clk")
139
+ self.rst = IO(Input(AsyncLowReset()), name="rst")
140
+ self.advance = IO(Input(Bool()), name="advance")
141
+ self.state = IO(Output(State), name="state")
142
+
143
+ self.state_reg = Reg(State, init=State.A, name="state_reg", optimize=False)
144
+ self.state_next = Wire(State, name="state_next")
145
+
146
+ with AlwaysComb():
147
+ self.state_next @= self.state_reg # default: hold
148
+ with Switch(self.state_reg):
149
+ with Case(State.A):
150
+ with When(self.advance):
151
+ self.state_next @= State.B
152
+ with Case(State.B):
153
+ with When(self.advance):
154
+ self.state_next @= State.C
155
+ with Case(State.C):
156
+ with When(self.advance):
157
+ self.state_next @= State.A
158
+
159
+ self.state_reg @= self.state_next
160
+ self.state @= self.state_reg
161
+ ```
162
+
163
+ Emitted Verilog:
164
+
165
+ ```verilog
166
+ package SimpleFSM_pkg;
167
+ typedef enum logic [1:0] { A, B, C } State_t;
168
+ endpackage
169
+
170
+ module SimpleFSM (
171
+ input logic clk,
172
+ input logic rst,
173
+ input logic advance,
174
+ output logic [1:0] state
175
+ );
176
+
177
+ import SimpleFSM_pkg::*;
178
+
179
+ State_t state_next;
180
+ State_t state_reg;
181
+
182
+ assign state = state_reg;
183
+
184
+ always_comb begin
185
+ state_next = state_reg;
186
+ case (state_reg)
187
+ State_t::A: begin
188
+ if (advance) begin
189
+ state_next = State_t::B;
190
+ end
191
+ end
192
+ State_t::B: begin
193
+ if (advance) begin
194
+ state_next = State_t::C;
195
+ end
196
+ end
197
+ State_t::C: begin
198
+ if (advance) begin
199
+ state_next = State_t::A;
200
+ end
201
+ end
202
+ endcase
203
+ end
204
+
205
+ always_ff @(posedge clk or negedge rst) begin
206
+ if (!rst) begin
207
+ state_reg <= State_t::A;
208
+ end else begin
209
+ state_reg <= state_next;
210
+ end
211
+ end
212
+
213
+ endmodule
214
+ ```
215
+
216
+ ## AI Usage
217
+
218
+ The base level library was coded using locally hosted models (Qwen3.5-27b-Q4_K_M and Qwen3.6-27b-Q4_K_M (with and without MTP)).
219
+ These were run on a server with a i7-6950X, 64GB 2400MHz DDR4, and using an AMD R9700 PRO 32GB. This setup allowed roughly 200k of
220
+ context and OpenCode was used as the coding harness.
221
+
222
+ As much as this was an exercise in creating an HDL library for simple usecases, it also was an exercise to see how powerful locally
223
+ hosted models have become and where their limits were. While certainly not the level of Sonnet/Opus/Gemini/OpenAI, these models
224
+ still punched above their weight (even if Qwen3.6 has this tendency to royally screw up the indentation on an edit).
225
+
226
+ Going forward, various models may be used depending on the feature, experiementation, or even just because I'm tired of my office
227
+ getting hot due to the GPU computing.
228
+
229
+ While a model did write the majority of this library, I would hesitate to call it "vibe coded". The model was never given complete
230
+ control to edit and changes were thoroughly reviewed. That being said, there will certainly be cases of areas that could be more robust.
231
+
232
+ ## Agent Skills
233
+
234
+ The `skills/` directory contains `SKILL.md` files for coding harnesses. Copy `skills/plane-hdl/` and `skills/plane-csr/` into your `~/.claude/skills/` or `~/.config/opencode/skills/` directory for auto-discovery when working with plane.
@@ -0,0 +1,210 @@
1
+ # plane
2
+
3
+ [![coverage](https://img.shields.io/badge/coverage-95%25-green)]()
4
+
5
+ <p align="center">
6
+ <img src="docs/plane_logo.png" alt="Plane Logo" width="400">
7
+ </p>
8
+
9
+ ## Install
10
+
11
+ Requires Python 3.12+.
12
+
13
+ ```bash
14
+ uv add plane
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```python
20
+ from plane import *
21
+
22
+ class Blink(Module):
23
+ def elaborate(self):
24
+ self.clk = IO(Input(Clock()), name="clk")
25
+ self.rst = IO(Input(AsyncLowReset()), name="rst")
26
+ self.led = IO(Output(Bool()), name="led")
27
+ self.counter = Reg(UInt(24), init=0, name="counter")
28
+ self.counter @= self.counter + Literal(1, 24)
29
+ self.led @= self.counter[23]
30
+ ```
31
+
32
+ ```python
33
+ print(emitVerilog(Blink()))
34
+ ```
35
+
36
+ ```verilog
37
+ module Blink (
38
+ input logic clk,
39
+ input logic rst,
40
+ output logic led
41
+ );
42
+
43
+ logic [23:0] counter;
44
+
45
+ assign led = counter[23];
46
+
47
+ always_ff @(posedge clk or negedge rst) begin
48
+ if (!rst) begin
49
+ counter <= 24'd0;
50
+ end else begin
51
+ counter <= (counter + 24'd1);
52
+ end
53
+ end
54
+
55
+ endmodule
56
+ ```
57
+
58
+ See `docs/` for the full guide.
59
+
60
+ ## Motivation
61
+
62
+ A PythonHDL inspired by Chisel
63
+
64
+ Chisel is a powerful HDL based on Scala. While powerful, it being based on Scala has some downsides with regards to
65
+ interopting with various other flows in a semiconductor design cycle. For better or for worse, Python has become the dominant language
66
+ for scripting various flows (and now AI pipelines) and therefore it seemed prudent to have a way to build SystemVerilog
67
+ utilizing a Python based HDL. There are other Python HDLs out there [Amaranth](https://github.com/amaranth-lang/amaranth),
68
+ Migen, MyHDL, etc. This library was not created to supersede those, but meerly to coexist and offer another solution.
69
+
70
+ The name "Plane" is meant as a play on word in a few ways:
71
+
72
+ 1. Plane to sound similar to "plain", indicating this is a slightly simple library
73
+ 2. Plane as in a [plane](https://en.wikipedia.org/wiki/Plane_(tool)) woodworking tool, paying a homage to Chisel. Where a Chisel
74
+ would require precise, fine tune actions, a plane just uses brute forcce to get something done.
75
+
76
+ Many of Chisel's concepts have been used here in Plane. Certain structures are modified as necessary for the differences in Python and Scala.
77
+ Plane is not as feature rich as the Chisel ecosystem, and the long term plan is for it not to be.
78
+
79
+ ## Features
80
+
81
+ - **Data types**: `UInt`, `SInt`, `Bool`, `Clock`, `Reset`, `PlaneEnum`, `Vec`
82
+ - **Modules, ports, `Bundle` structured interfaces**
83
+ - **Combinational** (`AlwaysComb`) and **sequential** (`Reg`, `RegNext`) logic
84
+ - **Control flow**: `When`/`ElseWhen`/`Otherwise`, `Switch`/`Case`/`Default`
85
+ - **Parameters and blackboxes**
86
+ - **Comments** in emitted Verilog
87
+ - **CSR subsystem**: `RegisterBlock`/`RegisterSystem`, field types, APB adapters
88
+ - **Collateral generation**: YAML, UVM RAL, HTML
89
+
90
+ ## SystemVerilog Emission
91
+
92
+ Most issues with meta-language HDLs is the undoubtly the emitted RTL that is produced. FSMs in particular are quite difficult
93
+ to look at for Chisel-generated RTL. Plane's design was really built with verilog emission being a core principle. Most of the
94
+ lifecycle for some RTL is spent being _read_ versus _modified_. For this reason, we want the RTL that is produced to be
95
+ as close to human-readable as possible. There are times this is difficult depending on your usecases, however many of the
96
+ features and/or language decisions were chosen to aid in emission quality. If anything, this was the main motivation for Plane.
97
+ This means the Plane HDL looks similar to SV in nature. This was a design decision to make it clear what you were designing
98
+ and to ease the transition for regular RTL designers.
99
+
100
+ ## FSM Showcase
101
+
102
+ A simple 3-state FSM that advances to the next state when `advance` is high, otherwise holds. This shows `AlwaysComb`, `Switch`/`Case`, and `When` working together:
103
+
104
+ ```python
105
+ from plane import *
106
+
107
+ class State(PlaneEnum):
108
+ A = 0
109
+ B = 1
110
+ C = 2
111
+
112
+ class SimpleFSM(Module):
113
+ def elaborate(self):
114
+ self.clk = IO(Input(Clock()), name="clk")
115
+ self.rst = IO(Input(AsyncLowReset()), name="rst")
116
+ self.advance = IO(Input(Bool()), name="advance")
117
+ self.state = IO(Output(State), name="state")
118
+
119
+ self.state_reg = Reg(State, init=State.A, name="state_reg", optimize=False)
120
+ self.state_next = Wire(State, name="state_next")
121
+
122
+ with AlwaysComb():
123
+ self.state_next @= self.state_reg # default: hold
124
+ with Switch(self.state_reg):
125
+ with Case(State.A):
126
+ with When(self.advance):
127
+ self.state_next @= State.B
128
+ with Case(State.B):
129
+ with When(self.advance):
130
+ self.state_next @= State.C
131
+ with Case(State.C):
132
+ with When(self.advance):
133
+ self.state_next @= State.A
134
+
135
+ self.state_reg @= self.state_next
136
+ self.state @= self.state_reg
137
+ ```
138
+
139
+ Emitted Verilog:
140
+
141
+ ```verilog
142
+ package SimpleFSM_pkg;
143
+ typedef enum logic [1:0] { A, B, C } State_t;
144
+ endpackage
145
+
146
+ module SimpleFSM (
147
+ input logic clk,
148
+ input logic rst,
149
+ input logic advance,
150
+ output logic [1:0] state
151
+ );
152
+
153
+ import SimpleFSM_pkg::*;
154
+
155
+ State_t state_next;
156
+ State_t state_reg;
157
+
158
+ assign state = state_reg;
159
+
160
+ always_comb begin
161
+ state_next = state_reg;
162
+ case (state_reg)
163
+ State_t::A: begin
164
+ if (advance) begin
165
+ state_next = State_t::B;
166
+ end
167
+ end
168
+ State_t::B: begin
169
+ if (advance) begin
170
+ state_next = State_t::C;
171
+ end
172
+ end
173
+ State_t::C: begin
174
+ if (advance) begin
175
+ state_next = State_t::A;
176
+ end
177
+ end
178
+ endcase
179
+ end
180
+
181
+ always_ff @(posedge clk or negedge rst) begin
182
+ if (!rst) begin
183
+ state_reg <= State_t::A;
184
+ end else begin
185
+ state_reg <= state_next;
186
+ end
187
+ end
188
+
189
+ endmodule
190
+ ```
191
+
192
+ ## AI Usage
193
+
194
+ The base level library was coded using locally hosted models (Qwen3.5-27b-Q4_K_M and Qwen3.6-27b-Q4_K_M (with and without MTP)).
195
+ These were run on a server with a i7-6950X, 64GB 2400MHz DDR4, and using an AMD R9700 PRO 32GB. This setup allowed roughly 200k of
196
+ context and OpenCode was used as the coding harness.
197
+
198
+ As much as this was an exercise in creating an HDL library for simple usecases, it also was an exercise to see how powerful locally
199
+ hosted models have become and where their limits were. While certainly not the level of Sonnet/Opus/Gemini/OpenAI, these models
200
+ still punched above their weight (even if Qwen3.6 has this tendency to royally screw up the indentation on an edit).
201
+
202
+ Going forward, various models may be used depending on the feature, experiementation, or even just because I'm tired of my office
203
+ getting hot due to the GPU computing.
204
+
205
+ While a model did write the majority of this library, I would hesitate to call it "vibe coded". The model was never given complete
206
+ control to edit and changes were thoroughly reviewed. That being said, there will certainly be cases of areas that could be more robust.
207
+
208
+ ## Agent Skills
209
+
210
+ The `skills/` directory contains `SKILL.md` files for coding harnesses. Copy `skills/plane-hdl/` and `skills/plane-csr/` into your `~/.claude/skills/` or `~/.config/opencode/skills/` directory for auto-discovery when working with plane.