upeepz80 0.2.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.
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.4
2
+ Name: upeepz80
3
+ Version: 0.2.0
4
+ Summary: Universal peephole optimizer for Z80 compilers - pure Z80 assembly input/output
5
+ Author: upeepz80 project
6
+ License: GPLv2
7
+ Project-URL: Homepage, https://github.com/avwohl/upeepz80
8
+ Project-URL: Repository, https://github.com/avwohl/upeepz80
9
+ Project-URL: Documentation, https://github.com/avwohl/upeepz80/tree/main/docs
10
+ Project-URL: Bug Tracker, https://github.com/avwohl/upeepz80/issues
11
+ Keywords: compiler,optimization,z80,peephole,retro
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Compilers
20
+ Classifier: Topic :: Software Development :: Code Generators
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
25
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
26
+ Requires-Dist: pytest-benchmark>=4.0.0; extra == "dev"
27
+ Requires-Dist: mypy>=1.5.0; extra == "dev"
28
+ Requires-Dist: black>=23.7.0; extra == "dev"
29
+ Requires-Dist: ruff>=0.0.285; extra == "dev"
30
+
31
+ # upeepz80 - Universal Peephole Optimizer for Z80
32
+
33
+ A language-agnostic peephole optimization library for Z80 compilers that generate pure Z80 assembly.
34
+
35
+ ## Overview
36
+
37
+ upeepz80 provides high-quality optimization passes for compilers targeting the Zilog Z80 processor. Unlike upeep80, this library expects **pure Z80 mnemonics in lowercase** as input (ld, jp, jr, etc.) and produces optimized Z80 assembly output with lowercase mnemonics.
38
+
39
+ If your compiler generates 8080 mnemonics (MOV, MVI, LXI, etc.) that need translation to Z80, use [upeep80](https://github.com/avwohl/upeep80) instead.
40
+
41
+ ## Features
42
+
43
+ ### Peephole Optimizations
44
+ - **Pattern-based optimization** on Z80 assembly
45
+ - **Redundant load/store elimination**
46
+ - **Jump optimization** (jp to jr conversion, jump threading)
47
+ - **djnz conversion** (dec b; jr nz → djnz)
48
+ - **Stack operation combining** (push/pop to ld conversions)
49
+ - **Dead store elimination**
50
+ - **Tail call optimization** (call x; ret → jp x)
51
+ - **Register copy optimization** (push hl; pop de → ld d,h; ld e,l)
52
+
53
+ ### Z80-Specific Features
54
+ - Relative jump optimization (jp → jr where in range)
55
+ - djnz loop optimization
56
+ - Z80 block instruction awareness
57
+ - Direct ld de,(addr) usage (Z80-only instruction)
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ pip install upeepz80
63
+ ```
64
+
65
+ Or for development:
66
+
67
+ ```bash
68
+ git clone https://github.com/avwohl/upeepz80.git
69
+ cd upeepz80
70
+ pip install -e ".[dev]"
71
+ ```
72
+
73
+ ## Usage
74
+
75
+ ### Basic Usage
76
+
77
+ ```python
78
+ from upeepz80 import optimize
79
+
80
+ # Optimize Z80 assembly code
81
+ assembly = """
82
+ ld a,0
83
+ push hl
84
+ pop de
85
+ jp LABEL
86
+ LABEL:
87
+ ret
88
+ """
89
+
90
+ optimized = optimize(assembly)
91
+ print(optimized)
92
+ # Output:
93
+ # xor a ; ld a,0 → xor a (smaller)
94
+ # ld d,h ; push/pop → register moves (faster)
95
+ # ld e,l
96
+ # ret ; jp to next instruction eliminated
97
+ ```
98
+
99
+ ### Using the Optimizer Class
100
+
101
+ ```python
102
+ from upeepz80 import PeepholeOptimizer
103
+
104
+ # Create optimizer
105
+ optimizer = PeepholeOptimizer()
106
+
107
+ # Optimize assembly code
108
+ optimized_asm = optimizer.optimize(assembly_text)
109
+
110
+ # Check statistics
111
+ print(f"xor a conversions: {optimizer.stats.get('xor_a', 0)}")
112
+ print(f"Jump threading: {optimizer.stats.get('jump_thread', 0)}")
113
+ print(f"djnz conversions: {optimizer.stats.get('djnz', 0)}")
114
+ ```
115
+
116
+ ## Optimization Phases
117
+
118
+ The optimizer runs multiple phases:
119
+
120
+ 1. **Pattern Matching** - Apply peephole patterns (up to 10 passes)
121
+ 2. **Z80-Specific Optimizations** - Inline patterns for Z80 instructions
122
+ 3. **Jump Threading** - Thread through intermediate jumps
123
+ 4. **Relative Jump Conversion** - Convert jp to jr where possible
124
+ 5. **djnz Optimization** - Convert dec b; jr nz to djnz
125
+ 6. **Dead Store Elimination** - Remove unused stores
126
+
127
+ ## Architecture
128
+
129
+ upeepz80 is designed to be language-agnostic:
130
+
131
+ - Works directly on Z80 assembly text
132
+ - No knowledge of source language required
133
+ - Pattern-based transformation engine
134
+ - Zero runtime dependencies
135
+
136
+ ## Comparison with upeep80
137
+
138
+ | Feature | upeep80 | upeepz80 |
139
+ |---------|---------|----------|
140
+ | Input | 8080 or Z80 mnemonics | Z80 mnemonics only |
141
+ | Output | Z80 or 8080 (configurable) | Z80 only |
142
+ | Translation | 8080 → Z80 translation | None needed |
143
+ | Use case | Compilers generating 8080 code | Compilers generating Z80 code |
144
+
145
+ Choose **upeepz80** if your compiler already generates Z80 mnemonics.
146
+ Choose **upeep80** if your compiler generates 8080 mnemonics.
147
+
148
+ ## Used By
149
+
150
+ - **[uplm80](https://github.com/avwohl/uplm80)** - PL/M-80 compiler for Z80 (after migration)
151
+ - **[uada80](https://github.com/avwohl/uada80)** - Ada compiler for Z80 (after migration)
152
+
153
+ ## Development
154
+
155
+ ### Running Tests
156
+
157
+ ```bash
158
+ pytest
159
+ ```
160
+
161
+ ### Type Checking
162
+
163
+ ```bash
164
+ mypy upeepz80
165
+ ```
166
+
167
+ ### Code Formatting
168
+
169
+ ```bash
170
+ black upeepz80
171
+ ruff check upeepz80
172
+ ```
173
+
174
+ ## Performance
175
+
176
+ Benchmarks on typical compiler workloads:
177
+
178
+ - Peephole optimization: ~50,000 instructions/second
179
+ - Memory usage: Minimal (pattern-based, no large data structures)
180
+
181
+ ## Contributing
182
+
183
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
184
+
185
+ ## License
186
+
187
+ This project is licensed under the GNU General Public License v2.0 - see [LICENSE](LICENSE) for details.
188
+
189
+ ## History
190
+
191
+ upeepz80 is a sibling project to upeep80, designed for compilers that generate native Z80 assembly. It shares the same optimization algorithms but removes the 8080 translation layer for cleaner, more efficient code when 8080 support isn't needed.
192
+
193
+ ## See Also
194
+
195
+ - [upeep80](https://github.com/avwohl/upeep80) - Optimizer with 8080 input support
196
+ - [Z80 CPU User Manual](http://www.z80.info/zip/z80cpu_um.pdf)
@@ -0,0 +1,166 @@
1
+ # upeepz80 - Universal Peephole Optimizer for Z80
2
+
3
+ A language-agnostic peephole optimization library for Z80 compilers that generate pure Z80 assembly.
4
+
5
+ ## Overview
6
+
7
+ upeepz80 provides high-quality optimization passes for compilers targeting the Zilog Z80 processor. Unlike upeep80, this library expects **pure Z80 mnemonics in lowercase** as input (ld, jp, jr, etc.) and produces optimized Z80 assembly output with lowercase mnemonics.
8
+
9
+ If your compiler generates 8080 mnemonics (MOV, MVI, LXI, etc.) that need translation to Z80, use [upeep80](https://github.com/avwohl/upeep80) instead.
10
+
11
+ ## Features
12
+
13
+ ### Peephole Optimizations
14
+ - **Pattern-based optimization** on Z80 assembly
15
+ - **Redundant load/store elimination**
16
+ - **Jump optimization** (jp to jr conversion, jump threading)
17
+ - **djnz conversion** (dec b; jr nz → djnz)
18
+ - **Stack operation combining** (push/pop to ld conversions)
19
+ - **Dead store elimination**
20
+ - **Tail call optimization** (call x; ret → jp x)
21
+ - **Register copy optimization** (push hl; pop de → ld d,h; ld e,l)
22
+
23
+ ### Z80-Specific Features
24
+ - Relative jump optimization (jp → jr where in range)
25
+ - djnz loop optimization
26
+ - Z80 block instruction awareness
27
+ - Direct ld de,(addr) usage (Z80-only instruction)
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pip install upeepz80
33
+ ```
34
+
35
+ Or for development:
36
+
37
+ ```bash
38
+ git clone https://github.com/avwohl/upeepz80.git
39
+ cd upeepz80
40
+ pip install -e ".[dev]"
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ### Basic Usage
46
+
47
+ ```python
48
+ from upeepz80 import optimize
49
+
50
+ # Optimize Z80 assembly code
51
+ assembly = """
52
+ ld a,0
53
+ push hl
54
+ pop de
55
+ jp LABEL
56
+ LABEL:
57
+ ret
58
+ """
59
+
60
+ optimized = optimize(assembly)
61
+ print(optimized)
62
+ # Output:
63
+ # xor a ; ld a,0 → xor a (smaller)
64
+ # ld d,h ; push/pop → register moves (faster)
65
+ # ld e,l
66
+ # ret ; jp to next instruction eliminated
67
+ ```
68
+
69
+ ### Using the Optimizer Class
70
+
71
+ ```python
72
+ from upeepz80 import PeepholeOptimizer
73
+
74
+ # Create optimizer
75
+ optimizer = PeepholeOptimizer()
76
+
77
+ # Optimize assembly code
78
+ optimized_asm = optimizer.optimize(assembly_text)
79
+
80
+ # Check statistics
81
+ print(f"xor a conversions: {optimizer.stats.get('xor_a', 0)}")
82
+ print(f"Jump threading: {optimizer.stats.get('jump_thread', 0)}")
83
+ print(f"djnz conversions: {optimizer.stats.get('djnz', 0)}")
84
+ ```
85
+
86
+ ## Optimization Phases
87
+
88
+ The optimizer runs multiple phases:
89
+
90
+ 1. **Pattern Matching** - Apply peephole patterns (up to 10 passes)
91
+ 2. **Z80-Specific Optimizations** - Inline patterns for Z80 instructions
92
+ 3. **Jump Threading** - Thread through intermediate jumps
93
+ 4. **Relative Jump Conversion** - Convert jp to jr where possible
94
+ 5. **djnz Optimization** - Convert dec b; jr nz to djnz
95
+ 6. **Dead Store Elimination** - Remove unused stores
96
+
97
+ ## Architecture
98
+
99
+ upeepz80 is designed to be language-agnostic:
100
+
101
+ - Works directly on Z80 assembly text
102
+ - No knowledge of source language required
103
+ - Pattern-based transformation engine
104
+ - Zero runtime dependencies
105
+
106
+ ## Comparison with upeep80
107
+
108
+ | Feature | upeep80 | upeepz80 |
109
+ |---------|---------|----------|
110
+ | Input | 8080 or Z80 mnemonics | Z80 mnemonics only |
111
+ | Output | Z80 or 8080 (configurable) | Z80 only |
112
+ | Translation | 8080 → Z80 translation | None needed |
113
+ | Use case | Compilers generating 8080 code | Compilers generating Z80 code |
114
+
115
+ Choose **upeepz80** if your compiler already generates Z80 mnemonics.
116
+ Choose **upeep80** if your compiler generates 8080 mnemonics.
117
+
118
+ ## Used By
119
+
120
+ - **[uplm80](https://github.com/avwohl/uplm80)** - PL/M-80 compiler for Z80 (after migration)
121
+ - **[uada80](https://github.com/avwohl/uada80)** - Ada compiler for Z80 (after migration)
122
+
123
+ ## Development
124
+
125
+ ### Running Tests
126
+
127
+ ```bash
128
+ pytest
129
+ ```
130
+
131
+ ### Type Checking
132
+
133
+ ```bash
134
+ mypy upeepz80
135
+ ```
136
+
137
+ ### Code Formatting
138
+
139
+ ```bash
140
+ black upeepz80
141
+ ruff check upeepz80
142
+ ```
143
+
144
+ ## Performance
145
+
146
+ Benchmarks on typical compiler workloads:
147
+
148
+ - Peephole optimization: ~50,000 instructions/second
149
+ - Memory usage: Minimal (pattern-based, no large data structures)
150
+
151
+ ## Contributing
152
+
153
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
154
+
155
+ ## License
156
+
157
+ This project is licensed under the GNU General Public License v2.0 - see [LICENSE](LICENSE) for details.
158
+
159
+ ## History
160
+
161
+ upeepz80 is a sibling project to upeep80, designed for compilers that generate native Z80 assembly. It shares the same optimization algorithms but removes the 8080 translation layer for cleaner, more efficient code when 8080 support isn't needed.
162
+
163
+ ## See Also
164
+
165
+ - [upeep80](https://github.com/avwohl/upeep80) - Optimizer with 8080 input support
166
+ - [Z80 CPU User Manual](http://www.z80.info/zip/z80cpu_um.pdf)
@@ -0,0 +1,96 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "upeepz80"
7
+ version = "0.2.0"
8
+ description = "Universal peephole optimizer for Z80 compilers - pure Z80 assembly input/output"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = {text = "GPLv2"}
12
+ authors = [
13
+ {name = "upeepz80 project"}
14
+ ]
15
+ keywords = ["compiler", "optimization", "z80", "peephole", "retro"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Topic :: Software Development :: Compilers",
25
+ "Topic :: Software Development :: Code Generators",
26
+ ]
27
+
28
+ dependencies = []
29
+
30
+ [project.optional-dependencies]
31
+ dev = [
32
+ "pytest>=7.4.0",
33
+ "pytest-cov>=4.1.0",
34
+ "pytest-benchmark>=4.0.0",
35
+ "mypy>=1.5.0",
36
+ "black>=23.7.0",
37
+ "ruff>=0.0.285",
38
+ ]
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/avwohl/upeepz80"
42
+ Repository = "https://github.com/avwohl/upeepz80"
43
+ Documentation = "https://github.com/avwohl/upeepz80/tree/main/docs"
44
+ "Bug Tracker" = "https://github.com/avwohl/upeepz80/issues"
45
+
46
+ [tool.setuptools.packages.find]
47
+ where = ["."]
48
+ include = ["upeepz80*"]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+ python_files = ["test_*.py"]
53
+ python_classes = ["Test*"]
54
+ python_functions = ["test_*"]
55
+ addopts = [
56
+ "--verbose",
57
+ ]
58
+
59
+ [tool.mypy]
60
+ python_version = "3.10"
61
+ warn_return_any = true
62
+ warn_unused_configs = true
63
+ disallow_untyped_defs = true
64
+ disallow_incomplete_defs = true
65
+ check_untyped_defs = true
66
+ no_implicit_optional = true
67
+ warn_redundant_casts = true
68
+ warn_unused_ignores = true
69
+ warn_no_return = true
70
+ strict_equality = true
71
+
72
+ [tool.black]
73
+ line-length = 100
74
+ target-version = ['py310']
75
+ include = '\.pyi?$'
76
+
77
+ [tool.ruff]
78
+ line-length = 100
79
+ target-version = "py310"
80
+ select = [
81
+ "E", # pycodestyle errors
82
+ "W", # pycodestyle warnings
83
+ "F", # pyflakes
84
+ "I", # isort
85
+ "N", # pep8-naming
86
+ "UP", # pyupgrade
87
+ "B", # flake8-bugbear
88
+ "C4", # flake8-comprehensions
89
+ ]
90
+ ignore = [
91
+ "E501", # line too long (handled by black)
92
+ ]
93
+
94
+ [tool.ruff.per-file-ignores]
95
+ "__init__.py" = ["F401"]
96
+ "tests/*.py" = ["N802", "N806"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,28 @@
1
+ """
2
+ upeepz80 - Universal Peephole Optimizer for Z80
3
+
4
+ A language-agnostic optimization library for compilers targeting
5
+ the Zilog Z80 processor with pure Z80 assembly input/output.
6
+
7
+ For compilers that generate 8080 mnemonics (MOV, MVI, etc.),
8
+ use upeep80 instead.
9
+ """
10
+
11
+ __version__ = "0.1.0"
12
+ __author__ = "upeepz80 project"
13
+
14
+ from .peephole import (
15
+ PeepholeOptimizer,
16
+ PeepholePattern,
17
+ optimize,
18
+ )
19
+
20
+ __all__ = [
21
+ # Version
22
+ "__version__",
23
+
24
+ # Peephole Optimization
25
+ "PeepholeOptimizer",
26
+ "PeepholePattern",
27
+ "optimize",
28
+ ]