Skip to content

Commit ee58c5a

Browse files
committed
amaranth.hdl: start all private names with an underscore.
This change completes commit 9dc0617 and makes all the tests pass. It corresponds with the ongoing langauge reference documentation effort. Fixes #781.
1 parent 9dc0617 commit ee58c5a

34 files changed

+167
-162
lines changed

amaranth/asserts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .hdl.ast import AnyConst, AnySeq, Initial, Assert, Assume, Cover
1+
from .hdl._ast import AnyConst, AnySeq, Initial, Assert, Assume, Cover
22

33

44
__all__ = ["AnyConst", "AnySeq", "Initial", "Assert", "Assume", "Cover"]

amaranth/back/rtlil.py

Lines changed: 70 additions & 70 deletions
Large diffs are not rendered by default.

amaranth/back/verilog.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .._toolchain.yosys import *
2-
from ..hdl import ast, ir
2+
from ..hdl import _ast, _ir
33
from ..lib import wiring
44
from . import rtlil
55

@@ -49,12 +49,12 @@ def convert(elaboratable, name="top", platform=None, *, ports=None, emit_src=Tru
4949
isinstance(elaboratable.signature, wiring.Signature)):
5050
ports = []
5151
for path, member, value in elaboratable.signature.flatten(elaboratable):
52-
if isinstance(value, ast.ValueCastable):
52+
if isinstance(value, _ast.ValueCastable):
5353
value = value.as_value()
54-
if isinstance(value, ast.Value):
54+
if isinstance(value, _ast.Value):
5555
ports.append(value)
5656
elif ports is None:
5757
raise TypeError("The `convert()` function requires a `ports=` argument")
58-
fragment = ir.Fragment.get(elaboratable, platform).prepare(ports=ports, **kwargs)
58+
fragment = _ir.Fragment.get(elaboratable, platform).prepare(ports=ports, **kwargs)
5959
verilog_text, name_map = convert_fragment(fragment, name, emit_src=emit_src, strip_internal_attrs=strip_internal_attrs)
6060
return verilog_text

amaranth/build/plat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .. import __version__
1010
from .._toolchain import *
1111
from ..hdl import *
12-
from ..hdl.xfrm import DomainLowerer
12+
from ..hdl._xfrm import DomainLowerer
1313
from ..lib.cdc import ResetSynchronizer
1414
from ..back import rtlil, verilog
1515
from .res import *

amaranth/build/res.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import OrderedDict
22
import warnings
33

4-
from ..hdl.ast import *
4+
from ..hdl._ast import *
55
with warnings.catch_warnings():
66
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
77
from ..hdl.rec import *

amaranth/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import argparse
22

3-
from .hdl.ir import Fragment
3+
from .hdl._ir import Fragment
44
from .back import rtlil, cxxrtl, verilog
55
from .sim import Simulator
66

amaranth/hdl/__init__.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
import warnings
2-
3-
from .ast import Shape, unsigned, signed
4-
from .ast import Value, Const, C, Mux, Cat, Repl, Array, Signal, ClockSignal, ResetSignal
5-
from .dsl import Module
6-
from .cd import ClockDomain
7-
from .ir import Elaboratable, Fragment, Instance
8-
from .mem import Memory
9-
with warnings.catch_warnings():
10-
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
11-
from .rec import Record
12-
from .xfrm import DomainRenamer, ResetInserter, EnableInserter
1+
from ._ast import Shape, unsigned, signed, ShapeCastable, ShapeLike
2+
from ._ast import Value, ValueCastable, ValueLike
3+
from ._ast import Const, C, Mux, Cat, Repl, Array, Signal, ClockSignal, ResetSignal
4+
from ._dsl import SyntaxError, SyntaxWarning, Module
5+
from ._cd import DomainError, ClockDomain
6+
from ._ir import UnusedElaboratable, Elaboratable, DriverConflict, Fragment, Instance
7+
from ._mem import Memory, ReadPort, WritePort, DummyPort
8+
from ._rec import Record
9+
from ._xfrm import DomainRenamer, ResetInserter, EnableInserter
1310

1411

1512
__all__ = [
16-
"Shape", "unsigned", "signed",
17-
"Value", "Const", "C", "Mux", "Cat", "Repl", "Array", "Signal", "ClockSignal", "ResetSignal",
18-
"Module",
19-
"ClockDomain",
20-
"Elaboratable", "Fragment", "Instance",
21-
"Memory",
13+
# _ast
14+
"Shape", "unsigned", "signed", "ShapeCastable", "ShapeLike",
15+
"Value", "ValueCastable", "ValueLike",
16+
"Const", "C", "Mux", "Cat", "Repl", "Array", "Signal", "ClockSignal", "ResetSignal",
17+
# _dsl
18+
"SyntaxError", "SyntaxWarning", "Module",
19+
# _cd
20+
"DomainError", "ClockDomain",
21+
# _ir
22+
"UnusedElaboratable", "Elaboratable", "DriverConflict", "Fragment", "Instance",
23+
# _mem
24+
"Memory", "ReadPort", "WritePort", "DummyPort",
25+
# _rec
2226
"Record",
27+
# _xfrm
2328
"DomainRenamer", "ResetInserter", "EnableInserter",
2429
]

amaranth/hdl/_cd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .. import tracer
2-
from .ast import Signal
2+
from ._ast import Signal
33

44

55
__all__ = ["ClockDomain", "DomainError"]

amaranth/hdl/_dsl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from .._utils import flatten
99
from ..utils import bits_for
1010
from .. import tracer
11-
from .ast import *
12-
from .ir import *
13-
from .cd import *
14-
from .xfrm import *
11+
from ._ast import *
12+
from ._ir import *
13+
from ._cd import *
14+
from ._xfrm import *
1515

1616

1717
__all__ = ["SyntaxError", "SyntaxWarning", "Module"]

amaranth/hdl/_ir.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from .. import tracer
77
from .._utils import *
88
from .._unused import *
9-
from .ast import *
10-
from .cd import *
9+
from ._ast import *
10+
from ._cd import *
1111

1212

1313
__all__ = ["UnusedElaboratable", "Elaboratable", "DriverConflict", "Fragment", "Instance"]
@@ -263,7 +263,7 @@ def flatten_subfrags_if_needed(subfrags):
263263
return SignalSet(driver_subfrags.keys())
264264

265265
def _propagate_domains_up(self, hierarchy=("top",)):
266-
from .xfrm import DomainRenamer
266+
from ._xfrm import DomainRenamer
267267

268268
domain_subfrags = defaultdict(set)
269269

@@ -327,7 +327,7 @@ def _propagate_domains_down(self):
327327
subfrag._propagate_domains_down()
328328

329329
def _create_missing_domains(self, missing_domain, *, platform=None):
330-
from .xfrm import DomainCollector
330+
from ._xfrm import DomainCollector
331331

332332
collector = DomainCollector()
333333
collector(self)
@@ -507,7 +507,7 @@ def lca_of(fragu, fragv):
507507
self.add_ports(sig, dir="i")
508508

509509
def prepare(self, ports=None, missing_domain=lambda name: ClockDomain(name)):
510-
from .xfrm import DomainLowerer
510+
from ._xfrm import DomainLowerer
511511

512512
new_domains = self._propagate_domains(missing_domain)
513513
fragment = DomainLowerer()(self)

amaranth/hdl/_mem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from collections import OrderedDict
33

44
from .. import tracer
5-
from .ast import *
6-
from .ir import Elaboratable, Instance, Fragment
5+
from ._ast import *
6+
from ._ir import Elaboratable, Instance, Fragment
77

88

99
__all__ = ["Memory", "ReadPort", "WritePort", "DummyPort"]

amaranth/hdl/_rec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .. import tracer
88
from .._utils import union
9-
from .ast import *
9+
from ._ast import *
1010
from ..lib import wiring
1111

1212

amaranth/hdl/_repr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def format(self, value):
3636

3737
class Repr:
3838
def __init__(self, format, value, *, path=()):
39-
from .ast import Value # avoid a circular dependency
39+
from ._ast import Value # avoid a circular dependency
4040
assert isinstance(format, Format)
4141
assert isinstance(value, Value)
4242
assert isinstance(path, tuple) and all(isinstance(part, (str, int)) for part in path)

amaranth/hdl/_xfrm.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
from .._utils import flatten, _ignore_deprecated
77
from .. import tracer
8-
from .ast import *
9-
from .ast import _StatementList
10-
from .cd import *
11-
from .ir import *
12-
from .mem import MemoryInstance
8+
from ._ast import *
9+
from ._ast import _StatementList
10+
from ._cd import *
11+
from ._ir import *
12+
from ._mem import MemoryInstance
1313

1414

1515
__all__ = ["ValueVisitor", "ValueTransformer",
@@ -286,7 +286,7 @@ def on_fragment(self, fragment):
286286
if isinstance(fragment, MemoryInstance):
287287
new_fragment = MemoryInstance(fragment.memory, [], [])
288288
self.map_memory_ports(fragment, new_fragment)
289-
elif isinstance(fragment, Instance):
289+
elif isinstance(fragment, Instance):
290290
new_fragment = Instance(fragment.type, src_loc=fragment.src_loc)
291291
new_fragment.parameters = OrderedDict(fragment.parameters)
292292
self.map_named_ports(fragment, new_fragment)

amaranth/lib/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from amaranth._utils import final
77
from amaranth.hdl import *
88
from amaranth.hdl._repr import *
9-
from amaranth.hdl.ast import ShapeCastable, ValueCastable
9+
from amaranth.hdl._ast import ShapeCastable, ValueCastable
1010

1111

1212
__all__ = [

amaranth/lib/enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import warnings
33
import operator
44

5-
from ..hdl.ast import Value, ValueCastable, Shape, ShapeCastable, Const
5+
from ..hdl._ast import Value, ValueCastable, Shape, ShapeCastable, Const
66
from ..hdl._repr import *
77

88

amaranth/lib/wiring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import warnings
55

66
from .. import tracer
7-
from ..hdl.ast import Shape, ShapeCastable, Const, Signal, Value, ValueCastable
8-
from ..hdl.ir import Elaboratable
7+
from ..hdl._ast import Shape, ShapeCastable, Const, Signal, Value, ValueCastable
8+
from ..hdl._ir import Elaboratable
99
from .._utils import final
1010

1111

amaranth/sim/_pycoro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import inspect
22

33
from ..hdl import *
4-
from ..hdl.ast import Statement, SignalSet, ValueCastable
4+
from ..hdl._ast import Statement, SignalSet, ValueCastable
55
from .core import Tick, Settle, Delay, Passive, Active
66
from ._base import BaseProcess
77
from ._pyrtl import _ValueCompiler, _RHSValueCompiler, _StatementCompiler

amaranth/sim/_pyrtl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import sys
55

66
from ..hdl import *
7-
from ..hdl.ast import SignalSet
8-
from ..hdl.xfrm import ValueVisitor, StatementVisitor, LHSGroupFilter
7+
from ..hdl._ast import SignalSet
8+
from ..hdl._xfrm import ValueVisitor, StatementVisitor, LHSGroupFilter
99
from ._base import BaseProcess
1010

1111

amaranth/sim/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import warnings
33

44
from .._utils import deprecated
5-
from ..hdl.cd import *
6-
from ..hdl.ir import *
5+
from ..hdl._cd import *
6+
from ..hdl._ir import *
77
from ._base import BaseEngine
88

99

@@ -130,7 +130,7 @@ def add_clock(self, period, *, phase=None, domain="sync", if_exists=False):
130130
if domain in self._clocked:
131131
raise ValueError("Domain {!r} already has a clock driving it"
132132
.format(domain.name))
133-
133+
134134
# We represent times internally in 1 ps units, but users supply float quantities of seconds
135135
period = int(period * 1e12)
136136

amaranth/sim/pysim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from ..hdl import *
88
from ..hdl._repr import *
9-
from ..hdl.ast import SignalDict, Slice, Operator
9+
from ..hdl._ast import SignalDict, Slice, Operator
1010
from ._base import *
1111
from ._pyrtl import _FragmentCompiler
1212
from ._pycoro import PyCoroProcess

docs/stdlib/enum.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ Like the standard Python :class:`enum.IntEnum` and :class:`enum.IntFlag` classes
8686
.. doctest::
8787

8888
>>> a = Signal(TransparentEnum)
89-
>>> type(a)
90-
<class 'amaranth.hdl.ast.Signal'>
89+
>>> type(a) is Signal
90+
True
9191

9292
It is also possible to define a custom view class for a given enum:
9393

tests/test_hdl_ast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import warnings
22
from enum import Enum, EnumMeta
33

4-
from amaranth.hdl.ast import *
4+
from amaranth.hdl._ast import *
55
from amaranth.lib.enum import Enum as AmaranthEnum
66

77
from .utils import *
@@ -1024,10 +1024,10 @@ class MyValue(ValueCastable):
10241024
@ValueCastable.lowermethod
10251025
def as_value(self):
10261026
return Signal()
1027-
1027+
10281028
def shape():
10291029
return unsigned(1)
1030-
1030+
10311031
a = Array([1,2,3])
10321032
a[MyValue()]
10331033

tests/test_hdl_cd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from amaranth.hdl.cd import *
1+
from amaranth.hdl._cd import *
22

33
from .utils import *
44

tests/test_hdl_dsl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import sys
44
from collections import OrderedDict
55

6-
from amaranth.hdl.ast import *
7-
from amaranth.hdl.cd import *
8-
from amaranth.hdl.dsl import *
6+
from amaranth.hdl._ast import *
7+
from amaranth.hdl._cd import *
8+
from amaranth.hdl._dsl import *
99
from amaranth.lib.enum import Enum
1010

1111
from .utils import *

tests/test_hdl_ir.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from collections import OrderedDict
44

5-
from amaranth.hdl.ast import *
6-
from amaranth.hdl.cd import *
7-
from amaranth.hdl.ir import *
8-
from amaranth.hdl.mem import *
5+
from amaranth.hdl._ast import *
6+
from amaranth.hdl._cd import *
7+
from amaranth.hdl._ir import *
8+
from amaranth.hdl._mem import *
99

1010
from .utils import *
1111

tests/test_hdl_mem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# amaranth: UnusedElaboratable=no
22

3-
from amaranth.hdl.ast import *
4-
from amaranth.hdl.mem import *
3+
from amaranth.hdl._ast import *
4+
from amaranth.hdl._mem import *
55

66
from .utils import *
77

tests/test_hdl_rec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from enum import Enum
44

5-
from amaranth.hdl.ast import *
5+
from amaranth.hdl._ast import *
66
with warnings.catch_warnings():
77
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
88
from amaranth.hdl.rec import *

0 commit comments

Comments
 (0)