Skip to content

Commit 5659a26

Browse files
committed
Improve error handling of origin & mov_status directives
1 parent 4deafa6 commit 5659a26

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

adafruit_pioasm.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def int_in_range(arg, low, high, what, radix=0):
101101
pio_version = int_in_range(words[1], 0, 2, ".pio_version")
102102
elif line.startswith(".origin"):
103103
require_before_instruction()
104-
offset = int(line.split()[1], 0)
104+
offset = int_in_range(words[1], 0, 32, ".origin")
105105
elif line.startswith(".wrap_target"):
106106
wrap_target = len(instructions)
107107
elif line.startswith(".wrap"):
@@ -126,7 +126,7 @@ def int_in_range(arg, low, high, what, radix=0):
126126
if words[1] in ("txfifo", "rxfifo"):
127127
if words[2] != "<":
128128
raise RuntimeError(f"Invalid {line}")
129-
mov_status_count = int(words[3])
129+
mov_status_count = int_in_range(words[3], 0, 16, words[1])
130130
elif words[1] == "irq":
131131
required_version = 1
132132
idx = 2
@@ -139,9 +139,6 @@ def int_in_range(arg, low, high, what, radix=0):
139139
if words[idx] != "set":
140140
raise RuntimeError(f"Invalid {line})")
141141
mov_status_count = int(words[idx + 1])
142-
143-
if not 0 <= mov_status_count < 16:
144-
raise RuntimeError(f"Invalid mov_status count {mov_status_count}")
145142
require_version(required_version, line)
146143
elif words[0] == ".in":
147144
require_before_instruction()

0 commit comments

Comments
 (0)