cerilog 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.
cerilog-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 R0mba-Na11avan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
cerilog-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.4
2
+ Name: cerilog
3
+ Version: 0.1.0
4
+ Summary: A C-flavored HDL that transpiles to SystemVerilog or Verilog-2005
5
+ Author: R0mba-Na11avan
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/R0mba-Na11avan/Cerilog
8
+ Project-URL: Documentation, https://github.com/R0mba-Na11avan/Cerilog/blob/main/docs/language_spec.md
9
+ Project-URL: Issues, https://github.com/R0mba-Na11avan/Cerilog/issues
10
+ Keywords: verilog,systemverilog,hdl,fpga,transpiler
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Software Development :: Compilers
17
+ Classifier: Topic :: System :: Hardware
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: lark>=1.1
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.0; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # Cerilog
27
+
28
+ Cerilog is a C-flavored hardware description language that transpiles to
29
+ **SystemVerilog** (`.sv`) or **Verilog-2005** (`.v`). Curly braces instead of
30
+ `begin`/`end`, ports declared in the module header, one `logic` type, one
31
+ `always` keyword. The output is plain, readable HDL that goes into Quartus,
32
+ Vivado, Verilator or Icarus unchanged.
33
+
34
+ ```
35
+ counter.cel ──cerilog──▶ counter.sv / counter.v ──▶ Quartus / Vivado / Verilator
36
+ ```
37
+
38
+ ## Example
39
+
40
+ ```cerilog
41
+ // counter.cel
42
+ module Counter(
43
+ input logic clk,
44
+ input logic rst,
45
+ output logic[7:0] count
46
+ ) {
47
+ always(posedge clk) {
48
+ if (rst) count <= 0;
49
+ else count <= count + 1;
50
+ }
51
+ }
52
+ ```
53
+
54
+ `cerilog counter.cel -o counter.sv`:
55
+
56
+ ```systemverilog
57
+ module Counter (
58
+ input logic clk,
59
+ input logic rst,
60
+ output logic [7:0] count
61
+ );
62
+ always_ff @(posedge clk) begin
63
+ if (rst) begin
64
+ count <= 0;
65
+ end else begin
66
+ count <= count + 1;
67
+ end
68
+ end
69
+ endmodule
70
+ ```
71
+
72
+ `cerilog counter.cel -o counter.v`, for tools without SystemVerilog support:
73
+
74
+ ```verilog
75
+ module Counter (
76
+ input wire clk,
77
+ input wire rst,
78
+ output reg [7:0] count
79
+ );
80
+ always @(posedge clk) begin
81
+ if (rst) begin
82
+ count <= 0;
83
+ end else begin
84
+ count <= count + 1;
85
+ end
86
+ end
87
+ endmodule
88
+ ```
89
+
90
+ (Real output also has a header line and `// source: counter.cel:N` comments,
91
+ which tie tool errors back to your source.)
92
+
93
+ ## Features
94
+
95
+ - `{ }` blocks; braces are optional around single statements, as in C
96
+ - Ports and parameters declared in the module header
97
+ - `logic` everywhere. For Verilog output, `wire` vs `reg` is worked out for you
98
+ - `always()` for combinational logic, `always(posedge clk)` for flip-flops
99
+ - C-style stacked `case` labels (fallthrough)
100
+ - `for` loops: inside `always` they're procedural, at module level they
101
+ become generate loops
102
+ - Multiple modules per file and SystemVerilog-style instances
103
+ - Memories, `localparam`, initial values, the full SystemVerilog operator set,
104
+ `$clog2` and friends
105
+ - Errors and warnings with `file:line:col`, the source line and a caret
106
+ - VS Code extension: highlighting, error squiggles on save, a ▶ compile
107
+ button and an `.sv`/`.v` target picker
108
+
109
+ The full language is described in [`docs/language_spec.md`](https://github.com/R0mba-Na11avan/Cerilog/blob/main/docs/language_spec.md).
110
+
111
+ ## Install
112
+
113
+ Requires Python 3.10+.
114
+
115
+ ```bash
116
+ pip install cerilog
117
+ ```
118
+
119
+ This installs the `cerilog` command and its one dependency, the `lark`
120
+ parser library.
121
+
122
+ To work on Cerilog itself:
123
+
124
+ ```bash
125
+ git clone https://github.com/R0mba-Na11avan/Cerilog.git
126
+ cd Cerilog
127
+ pip install -e ".[dev]"
128
+ ```
129
+
130
+ ## Usage
131
+
132
+ ```bash
133
+ cerilog counter.cel # SystemVerilog to stdout
134
+ cerilog counter.cel -o counter.sv # SystemVerilog to a file
135
+ cerilog counter.cel -o counter.v # Verilog-2005 (target taken from the extension)
136
+ cerilog counter.cel --target v # Verilog-2005 to stdout
137
+ cerilog counter.cel --check # only report errors and warnings
138
+ ```
139
+
140
+ | Flag | Meaning |
141
+ |---|---|
142
+ | `-o FILE` | write to `FILE`; a `.sv` or `.v` extension picks the target |
143
+ | `--target sv\|v` | choose the output language (also `systemverilog` / `verilog`); overrides the extension |
144
+ | `--check` | parse and check only; write nothing |
145
+ | `--no-source-maps` | leave out the `// source: file.cel:N` comments |
146
+ | `--tokens`, `--ast` | print the token stream or the syntax tree (debugging) |
147
+
148
+ Errors and warnings go to stderr. The exit status is 1 if there were errors.
149
+
150
+ ```
151
+ counter.cel:8:28: error: expected ';' before 'else'
152
+ if (rst) count <= 0
153
+ ^
154
+ ```
155
+
156
+ ## VS Code
157
+
158
+ The extension in [`editors/vscode`](https://github.com/R0mba-Na11avan/Cerilog/blob/main/editors/vscode) adds syntax highlighting,
159
+ error checking on save, a ▶ compile button, and a status-bar switch between
160
+ `.sv` and `.v` output. See its [README](https://github.com/R0mba-Na11avan/Cerilog/blob/main/editors/vscode/README.md) to install it.
161
+
162
+ ## Project layout
163
+
164
+ ```
165
+ cerilog/
166
+ ├── __main__.py command line
167
+ ├── compiler.py compile_source(): parse → analyse → emit
168
+ ├── errors.py diagnostics and their formatting
169
+ ├── lexer/lexer.py token stream (debugging, --tokens)
170
+ ├── parser/grammar.lark the grammar: every token and syntax rule
171
+ ├── parser/parser.py Lark parse tree → AST, syntax error messages
172
+ ├── ast/nodes.py AST node dataclasses
173
+ ├── analysis/checks.py symbol checks, drivers, wire/reg inference, warnings
174
+ └── codegen/emitter.py SystemVerilog and Verilog output
175
+ examples/ example .cel programs
176
+ tests/ pytest suite, golden outputs, Verilator lint
177
+ editors/vscode/ VS Code extension
178
+ docs/language_spec.md language reference
179
+ ```
180
+
181
+ ## Tests
182
+
183
+ ```bash
184
+ python -m pytest
185
+ ```
186
+
187
+ - `tests/golden/` compiles every file in `examples/` to both targets and
188
+ compares the result with `tests/golden/expected/`. After an intended output
189
+ change, regenerate with `CERILOG_UPDATE_GOLDEN=1 python -m pytest tests/golden`
190
+ and review the diff.
191
+ - `tests/lint/` runs `verilator --lint-only` on every example in both
192
+ targets. It is skipped when Verilator isn't installed.
193
+
194
+ ## License
195
+
196
+ MIT
@@ -0,0 +1,171 @@
1
+ # Cerilog
2
+
3
+ Cerilog is a C-flavored hardware description language that transpiles to
4
+ **SystemVerilog** (`.sv`) or **Verilog-2005** (`.v`). Curly braces instead of
5
+ `begin`/`end`, ports declared in the module header, one `logic` type, one
6
+ `always` keyword. The output is plain, readable HDL that goes into Quartus,
7
+ Vivado, Verilator or Icarus unchanged.
8
+
9
+ ```
10
+ counter.cel ──cerilog──▶ counter.sv / counter.v ──▶ Quartus / Vivado / Verilator
11
+ ```
12
+
13
+ ## Example
14
+
15
+ ```cerilog
16
+ // counter.cel
17
+ module Counter(
18
+ input logic clk,
19
+ input logic rst,
20
+ output logic[7:0] count
21
+ ) {
22
+ always(posedge clk) {
23
+ if (rst) count <= 0;
24
+ else count <= count + 1;
25
+ }
26
+ }
27
+ ```
28
+
29
+ `cerilog counter.cel -o counter.sv`:
30
+
31
+ ```systemverilog
32
+ module Counter (
33
+ input logic clk,
34
+ input logic rst,
35
+ output logic [7:0] count
36
+ );
37
+ always_ff @(posedge clk) begin
38
+ if (rst) begin
39
+ count <= 0;
40
+ end else begin
41
+ count <= count + 1;
42
+ end
43
+ end
44
+ endmodule
45
+ ```
46
+
47
+ `cerilog counter.cel -o counter.v`, for tools without SystemVerilog support:
48
+
49
+ ```verilog
50
+ module Counter (
51
+ input wire clk,
52
+ input wire rst,
53
+ output reg [7:0] count
54
+ );
55
+ always @(posedge clk) begin
56
+ if (rst) begin
57
+ count <= 0;
58
+ end else begin
59
+ count <= count + 1;
60
+ end
61
+ end
62
+ endmodule
63
+ ```
64
+
65
+ (Real output also has a header line and `// source: counter.cel:N` comments,
66
+ which tie tool errors back to your source.)
67
+
68
+ ## Features
69
+
70
+ - `{ }` blocks; braces are optional around single statements, as in C
71
+ - Ports and parameters declared in the module header
72
+ - `logic` everywhere. For Verilog output, `wire` vs `reg` is worked out for you
73
+ - `always()` for combinational logic, `always(posedge clk)` for flip-flops
74
+ - C-style stacked `case` labels (fallthrough)
75
+ - `for` loops: inside `always` they're procedural, at module level they
76
+ become generate loops
77
+ - Multiple modules per file and SystemVerilog-style instances
78
+ - Memories, `localparam`, initial values, the full SystemVerilog operator set,
79
+ `$clog2` and friends
80
+ - Errors and warnings with `file:line:col`, the source line and a caret
81
+ - VS Code extension: highlighting, error squiggles on save, a ▶ compile
82
+ button and an `.sv`/`.v` target picker
83
+
84
+ The full language is described in [`docs/language_spec.md`](https://github.com/R0mba-Na11avan/Cerilog/blob/main/docs/language_spec.md).
85
+
86
+ ## Install
87
+
88
+ Requires Python 3.10+.
89
+
90
+ ```bash
91
+ pip install cerilog
92
+ ```
93
+
94
+ This installs the `cerilog` command and its one dependency, the `lark`
95
+ parser library.
96
+
97
+ To work on Cerilog itself:
98
+
99
+ ```bash
100
+ git clone https://github.com/R0mba-Na11avan/Cerilog.git
101
+ cd Cerilog
102
+ pip install -e ".[dev]"
103
+ ```
104
+
105
+ ## Usage
106
+
107
+ ```bash
108
+ cerilog counter.cel # SystemVerilog to stdout
109
+ cerilog counter.cel -o counter.sv # SystemVerilog to a file
110
+ cerilog counter.cel -o counter.v # Verilog-2005 (target taken from the extension)
111
+ cerilog counter.cel --target v # Verilog-2005 to stdout
112
+ cerilog counter.cel --check # only report errors and warnings
113
+ ```
114
+
115
+ | Flag | Meaning |
116
+ |---|---|
117
+ | `-o FILE` | write to `FILE`; a `.sv` or `.v` extension picks the target |
118
+ | `--target sv\|v` | choose the output language (also `systemverilog` / `verilog`); overrides the extension |
119
+ | `--check` | parse and check only; write nothing |
120
+ | `--no-source-maps` | leave out the `// source: file.cel:N` comments |
121
+ | `--tokens`, `--ast` | print the token stream or the syntax tree (debugging) |
122
+
123
+ Errors and warnings go to stderr. The exit status is 1 if there were errors.
124
+
125
+ ```
126
+ counter.cel:8:28: error: expected ';' before 'else'
127
+ if (rst) count <= 0
128
+ ^
129
+ ```
130
+
131
+ ## VS Code
132
+
133
+ The extension in [`editors/vscode`](https://github.com/R0mba-Na11avan/Cerilog/blob/main/editors/vscode) adds syntax highlighting,
134
+ error checking on save, a ▶ compile button, and a status-bar switch between
135
+ `.sv` and `.v` output. See its [README](https://github.com/R0mba-Na11avan/Cerilog/blob/main/editors/vscode/README.md) to install it.
136
+
137
+ ## Project layout
138
+
139
+ ```
140
+ cerilog/
141
+ ├── __main__.py command line
142
+ ├── compiler.py compile_source(): parse → analyse → emit
143
+ ├── errors.py diagnostics and their formatting
144
+ ├── lexer/lexer.py token stream (debugging, --tokens)
145
+ ├── parser/grammar.lark the grammar: every token and syntax rule
146
+ ├── parser/parser.py Lark parse tree → AST, syntax error messages
147
+ ├── ast/nodes.py AST node dataclasses
148
+ ├── analysis/checks.py symbol checks, drivers, wire/reg inference, warnings
149
+ └── codegen/emitter.py SystemVerilog and Verilog output
150
+ examples/ example .cel programs
151
+ tests/ pytest suite, golden outputs, Verilator lint
152
+ editors/vscode/ VS Code extension
153
+ docs/language_spec.md language reference
154
+ ```
155
+
156
+ ## Tests
157
+
158
+ ```bash
159
+ python -m pytest
160
+ ```
161
+
162
+ - `tests/golden/` compiles every file in `examples/` to both targets and
163
+ compares the result with `tests/golden/expected/`. After an intended output
164
+ change, regenerate with `CERILOG_UPDATE_GOLDEN=1 python -m pytest tests/golden`
165
+ and review the diff.
166
+ - `tests/lint/` runs `verilator --lint-only` on every example in both
167
+ targets. It is skipped when Verilator isn't installed.
168
+
169
+ ## License
170
+
171
+ MIT
@@ -0,0 +1 @@
1
+ # Cerilog
@@ -0,0 +1,107 @@
1
+ """
2
+ Cerilog command line.
3
+
4
+ cerilog counter.cel SystemVerilog to stdout
5
+ cerilog counter.cel -o counter.sv SystemVerilog to a file
6
+ cerilog counter.cel -o counter.v Verilog-2005 (target from the extension)
7
+ cerilog counter.cel --target v Verilog-2005 to stdout
8
+ cerilog counter.cel --check check only, write nothing
9
+
10
+ Diagnostics go to stderr. Exit status is 1 if there were errors.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import argparse
16
+ import sys
17
+ from pathlib import Path
18
+
19
+ from cerilog.codegen.emitter import Target
20
+ from cerilog.compiler import compile_source
21
+ from cerilog.errors import CerilogError, format_diagnostic
22
+
23
+
24
+ def _parse_args(argv):
25
+ parser = argparse.ArgumentParser(
26
+ prog="cerilog",
27
+ description="Transpile Cerilog (.cel) to SystemVerilog (.sv) or Verilog-2005 (.v).",
28
+ )
29
+ parser.add_argument("input", help="input .cel file")
30
+ parser.add_argument("-o", "--output", help="output file; .sv or .v picks the target (default: stdout)")
31
+ parser.add_argument("--target", metavar="{sv,v}",
32
+ help="output language: sv/systemverilog or v/verilog "
33
+ "(default: from the -o extension, else sv)")
34
+ parser.add_argument("--check", action="store_true", help="report errors and warnings, write nothing")
35
+ parser.add_argument("--no-source-maps", action="store_true",
36
+ help="leave out the // source: file.cel:N comments")
37
+ parser.add_argument("--tokens", action="store_true", help="print the token stream and exit (debug)")
38
+ parser.add_argument("--ast", action="store_true", help="print the AST and exit (debug)")
39
+ return parser, parser.parse_args(argv)
40
+
41
+
42
+ def _resolve_target(parser, args) -> Target:
43
+ if args.target:
44
+ try:
45
+ return Target.parse(args.target)
46
+ except ValueError as e:
47
+ parser.error(str(e))
48
+ if args.output:
49
+ from_ext = Target.from_extension(args.output)
50
+ if from_ext is not None:
51
+ return from_ext
52
+ return Target.SYSTEMVERILOG
53
+
54
+
55
+ def main(argv=None) -> int:
56
+ parser, args = _parse_args(argv)
57
+ target = _resolve_target(parser, args)
58
+
59
+ input_path = Path(args.input)
60
+ if not input_path.is_file():
61
+ print(f"cerilog: error: file not found: {args.input}", file=sys.stderr)
62
+ return 1
63
+ if input_path.suffix != ".cel":
64
+ print(f"cerilog: warning: expected a .cel file, got '{input_path.suffix}'", file=sys.stderr)
65
+
66
+ source = input_path.read_text(encoding="utf-8")
67
+ display_name = args.input
68
+
69
+ if args.tokens or args.ast:
70
+ return _debug_dump(args, source, display_name)
71
+
72
+ result = compile_source(source, target=target, filename=input_path.name,
73
+ source_maps=not args.no_source_maps)
74
+ for diag in result.diagnostics:
75
+ print(format_diagnostic(diag, source, display_name), file=sys.stderr)
76
+ if not result.ok:
77
+ return 1
78
+ if args.check:
79
+ return 0
80
+
81
+ if args.output:
82
+ Path(args.output).write_text(result.code, encoding="utf-8", newline="\n")
83
+ print(f"cerilog: wrote {args.output} ({target.display_name})", file=sys.stderr)
84
+ else:
85
+ sys.stdout.write(result.code)
86
+ return 0
87
+
88
+
89
+ def _debug_dump(args, source: str, display_name: str) -> int:
90
+ from cerilog.ast.nodes import dump
91
+ from cerilog.lexer.lexer import Lexer
92
+ from cerilog.parser.parser import Parser
93
+
94
+ try:
95
+ if args.tokens:
96
+ for token in Lexer().tokenize(source):
97
+ print(token)
98
+ else:
99
+ print(dump(Parser().parse(source)))
100
+ except CerilogError as e:
101
+ print(format_diagnostic(e.diagnostic, source, display_name), file=sys.stderr)
102
+ return 1
103
+ return 0
104
+
105
+
106
+ if __name__ == "__main__":
107
+ sys.exit(main())
File without changes