From 5659a2672a775689b60c5bc347a5381da5d4b8c4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 5 Sep 2024 13:18:49 -0500 Subject: [PATCH] Improve error handling of origin & mov_status directives --- adafruit_pioasm.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/adafruit_pioasm.py b/adafruit_pioasm.py index 4b2308b..dc943e6 100644 --- a/adafruit_pioasm.py +++ b/adafruit_pioasm.py @@ -101,7 +101,7 @@ def int_in_range(arg, low, high, what, radix=0): pio_version = int_in_range(words[1], 0, 2, ".pio_version") elif line.startswith(".origin"): require_before_instruction() - offset = int(line.split()[1], 0) + offset = int_in_range(words[1], 0, 32, ".origin") elif line.startswith(".wrap_target"): wrap_target = len(instructions) elif line.startswith(".wrap"): @@ -126,7 +126,7 @@ def int_in_range(arg, low, high, what, radix=0): if words[1] in ("txfifo", "rxfifo"): if words[2] != "<": raise RuntimeError(f"Invalid {line}") - mov_status_count = int(words[3]) + mov_status_count = int_in_range(words[3], 0, 16, words[1]) elif words[1] == "irq": required_version = 1 idx = 2 @@ -139,9 +139,6 @@ def int_in_range(arg, low, high, what, radix=0): if words[idx] != "set": raise RuntimeError(f"Invalid {line})") mov_status_count = int(words[idx + 1]) - - if not 0 <= mov_status_count < 16: - raise RuntimeError(f"Invalid mov_status count {mov_status_count}") require_version(required_version, line) elif words[0] == ".in": require_before_instruction()