Skip to content

Commit b76157c

Browse files
committed
Add support for wrap/wrap_target
.. This also needs support in the core for specifying them in the StateMachine constructor.
1 parent 8f7e3bf commit b76157c

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

adafruit_pioasm.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def __init__(self, text_program: str) -> None:
4848
labels = {}
4949
instructions = []
5050
sideset_count = 0
51-
sideset_enable = 0
51+
sideset_enable = False
52+
wrap = None
53+
wrap_target = 0
5254
for line in text_program.split("\n"):
5355
line = line.strip()
5456
if not line:
@@ -60,13 +62,14 @@ def __init__(self, text_program: str) -> None:
6062
raise RuntimeError("Multiple programs not supported")
6163
program_name = line.split()[1]
6264
elif line.startswith(".wrap_target"):
63-
if len(instructions) > 0:
64-
raise RuntimeError("wrap_target not supported")
65+
wrap_target = len(instructions)
6566
elif line.startswith(".wrap"):
66-
pass
67+
if len(instructions) == 0:
68+
raise RuntimeError("Cannot have .wrap as first instruction")
69+
wrap = len(instructions) - 1
6770
elif line.startswith(".side_set"):
6871
sideset_count = int(line.split()[1])
69-
sideset_enable = 1 if "opt" in line else 0
72+
sideset_enable = "opt" in line
7073
elif line.endswith(":"):
7174
label = line[:-1]
7275
if label in labels:
@@ -223,6 +226,10 @@ def __init__(self, text_program: str) -> None:
223226
"sideset_enable": sideset_enable,
224227
}
225228

229+
if wrap is not None:
230+
self.pio_kwargs["wrap"] = wrap
231+
self.pio_kwargs["wrap_target"] = wrap_target
232+
226233
self.assembled = array.array("H", assembled)
227234

228235

tests/testpioasm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,14 @@ def testMovReverse(self):
135135
self.assertAssemblesTo("mov x, :: x", [0b101_00000_001_10_001])
136136
self.assertAssemblesTo("mov x, ::x", [0b101_00000_001_10_001])
137137

138+
138139
class TestWrap(AssembleChecks):
139140
def testWrap(self):
140141
self.assertAssemblyFails(".wrap")
141-
self.assertPioKwargs("nop\n.wrap_target\nnop\nnop\n.wrap",
142-
sideset_count=0, sideset_enable=False, wrap=2, wrap_target=1)
142+
self.assertPioKwargs(
143+
"nop\n.wrap_target\nnop\nnop\n.wrap",
144+
sideset_count=0,
145+
sideset_enable=False,
146+
wrap=2,
147+
wrap_target=1,
148+
)

0 commit comments

Comments
 (0)