Skip to content

Commit d16bd7e

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 fde6fcc commit d16bd7e

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

adafruit_pioasm.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def __init__(self, text_program: str, *, build_debuginfo=False) -> None:
5050
instructions = []
5151
sideset_count = 0
5252
sideset_enable = 0
53+
wrap = None
54+
wrap_target = None
5355
for i, line in enumerate(text_program.split("\n")):
5456
line = line.strip()
5557
if not line:
@@ -61,13 +63,14 @@ def __init__(self, text_program: str, *, build_debuginfo=False) -> None:
6163
raise RuntimeError("Multiple programs not supported")
6264
program_name = line.split()[1]
6365
elif line.startswith(".wrap_target"):
64-
if len(instructions) > 0:
65-
raise RuntimeError("wrap_target not supported")
66+
wrap_target = len(instructions)
6667
elif line.startswith(".wrap"):
67-
pass
68+
if len(instructions) == 0:
69+
raise RuntimeError("Cannot have .wrap as first instruction")
70+
wrap = len(instructions) - 1
6871
elif line.startswith(".side_set"):
6972
sideset_count = int(line.split()[1])
70-
sideset_enable = 1 if "opt" in line else 0
73+
sideset_enable = "opt" in line
7174
elif line.endswith(":"):
7275
label = line[:-1]
7376
if label in labels:
@@ -225,6 +228,11 @@ def __init__(self, text_program: str, *, build_debuginfo=False) -> None:
225228
"sideset_enable": sideset_enable,
226229
}
227230

231+
if wrap is not None:
232+
self.pio_kwargs["wrap"] = wrap
233+
if wrap_target is not None:
234+
self.pio_kwargs["wrap_target"] = wrap_target
235+
228236
self.assembled = array.array("H", assembled)
229237

230238
if build_debuginfo:
@@ -241,6 +249,12 @@ def print_c_program(self, name, qualifier="const"):
241249
linemap = self.debuginfo[0][:] # Use a copy since we destroy it
242250
program_lines = self.debuginfo[1].split("\n")
243251

252+
print(
253+
f"{qualifier} int {name}_wrap = {self.pio_kwargs.get('wrap', len(self.assembled)-1)};"
254+
)
255+
print(
256+
f"{qualifier} int {name}_wrap_target = {self.pio_kwargs.get('wrap_target', 0)};"
257+
)
244258
print(
245259
f"{qualifier} int {name}_sideset_pin_count = {self.pio_kwargs['sideset_pin_count']};"
246260
)

tests/testpioasm.py

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

140+
140141
class TestWrap(AssembleChecks):
141142
def testWrap(self):
142143
self.assertAssemblyFails(".wrap")
143-
self.assertPioKwargs("nop\n.wrap_target\nnop\nnop\n.wrap",
144-
sideset_count=0, sideset_enable=False, wrap=2, wrap_target=1)
144+
self.assertPioKwargs(
145+
"nop\n.wrap_target\nnop\nnop\n.wrap",
146+
sideset_pin_count=0,
147+
sideset_enable=False,
148+
wrap=2,
149+
wrap_target=1,
150+
)

0 commit comments

Comments
 (0)