12
12
"""
13
13
14
14
try :
15
- from typing import List , MutableSequence
15
+ from typing import List , Sequence , Any
16
16
except ImportError :
17
17
pass
18
18
@@ -55,12 +55,20 @@ class Program: # pylint: disable=too-few-public-methods
55
55
56
56
"""
57
57
58
+ assembled : array .array
59
+ """The assembled PIO program instructions"""
60
+ public_labels : dict [str , int ]
61
+ """The offset of any labels declared public"""
62
+ pio_kwargs : dict [str , Any ]
63
+ """Settings from assembler directives to pass to the StateMachine constructor"""
64
+
58
65
def __init__ (self , text_program : str , * , build_debuginfo : bool = False ) -> None :
59
66
"""Converts pioasm text to encoded instruction bytes"""
60
67
# pylint: disable=too-many-branches,too-many-statements,too-many-locals
61
68
assembled : List [int ] = []
62
69
program_name = None
63
70
labels = {}
71
+ public_labels = {}
64
72
linemap = []
65
73
instructions : List [str ] = []
66
74
sideset_count = 0
@@ -219,6 +227,9 @@ def parse_rxfifo_brackets(arg, fifo_dir):
219
227
220
228
elif line .endswith (":" ):
221
229
label = line [:- 1 ]
230
+ if line .startswith ("public " ):
231
+ label = label [7 :]
232
+ public_labels [label ] = len (instructions )
222
233
if label in labels :
223
234
raise SyntaxError (f"Duplicate label { repr (label )} " )
224
235
labels [label ] = len (instructions )
@@ -227,6 +238,7 @@ def parse_rxfifo_brackets(arg, fifo_dir):
227
238
instructions .append (line )
228
239
linemap .append (i )
229
240
241
+ mov_destinations : Sequence [str | None ]
230
242
if pio_version >= 1 :
231
243
mov_destinations = MOV_DESTINATIONS_V1
232
244
else :
@@ -502,6 +514,8 @@ def parse_rxfifo_brackets(arg, fifo_dir):
502
514
503
515
self .debuginfo = (linemap , text_program ) if build_debuginfo else None
504
516
517
+ self .public_labels = public_labels
518
+
505
519
@classmethod
506
520
def from_file (cls , filename : str , ** kwargs ) -> "Program" :
507
521
"""Assemble a PIO program in a file"""
@@ -557,7 +571,7 @@ def print_c_program(self, name: str, qualifier: str = "const") -> None:
557
571
print ()
558
572
559
573
560
- def assemble (program_text : str ) -> MutableSequence [ int ] :
574
+ def assemble (program_text : str ) -> array . array :
561
575
"""Converts pioasm text to encoded instruction bytes
562
576
563
577
In new code, prefer to use the `Program` class so that the extra arguments
0 commit comments