Skip to content

Commit ff1f57d

Browse files
committed
Check directives that must come before an instruction
1 parent 9874ce3 commit ff1f57d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

adafruit_pioasm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None:
6565
mov_status_count = None
6666
mov_status_param = None
6767

68+
def require_before_instruction():
69+
if len(instructions) != 0:
70+
raise RuntimeError(f"{words[0]} must be before first instruction")
71+
6872
def require_version(required_version, instruction):
6973
if pio_version < required_version:
7074
raise RuntimeError(
@@ -89,8 +93,10 @@ def int_in_range(arg, low, high, what, radix=0):
8993
raise RuntimeError("Multiple programs not supported")
9094
program_name = line.split()[1]
9195
elif line.startswith(".pio_version"):
96+
require_before_instruction()
9297
pio_version = int_in_range(words[1], 0, 2, ".pio_version")
9398
elif line.startswith(".origin"):
99+
require_before_instruction()
94100
offset = int(line.split()[1], 0)
95101
elif line.startswith(".wrap_target"):
96102
wrap_target = len(instructions)
@@ -102,12 +108,14 @@ def int_in_range(arg, low, high, what, radix=0):
102108
sideset_count = int(line.split()[1], 0)
103109
sideset_enable = "opt" in line
104110
elif line.startswith(".fifo"):
111+
require_before_instruction()
105112
fifo_type = line.split()[1]
106113
required_version = FIFO_TYPES.get(fifo_type)
107114
if required_version is None:
108115
raise RuntimeError(f"Invalid fifo type {fifo_type}")
109116
require_version(required_version, line)
110117
elif line.startswith(".mov_status"):
118+
require_before_instruction()
111119
required_version = 0
112120
mov_status_param = 0
113121
mov_status_type = words[1]

tests/test_pseudo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
Tests pseudo-ops
77
"""
88

9-
from pytest_helpers import assert_pio_kwargs
9+
from pytest_helpers import assert_pio_kwargs, assert_assembly_fails
1010

1111

1212
def test_offset() -> None:
1313
assert_pio_kwargs(".origin 7", offset=7, sideset_enable=False)
14+
assert_assembly_fails("nop\n.origin 7")

0 commit comments

Comments
 (0)