1212"""
1313
1414try :
15- from typing import List , MutableSequence
15+ from typing import List , Sequence , Any
1616except ImportError :
1717 pass
1818
@@ -55,12 +55,20 @@ class Program: # pylint: disable=too-few-public-methods
5555
5656 """
5757
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+
5865 def __init__ (self , text_program : str , * , build_debuginfo : bool = False ) -> None :
5966 """Converts pioasm text to encoded instruction bytes"""
6067 # pylint: disable=too-many-branches,too-many-statements,too-many-locals
6168 assembled : List [int ] = []
6269 program_name = None
6370 labels = {}
71+ public_labels = {}
6472 linemap = []
6573 instructions : List [str ] = []
6674 sideset_count = 0
@@ -219,6 +227,9 @@ def parse_rxfifo_brackets(arg, fifo_dir):
219227
220228 elif line .endswith (":" ):
221229 label = line [:- 1 ]
230+ if line .startswith ("public " ):
231+ label = label [7 :]
232+ public_labels [label ] = len (instructions )
222233 if label in labels :
223234 raise SyntaxError (f"Duplicate label { repr (label )} " )
224235 labels [label ] = len (instructions )
@@ -227,6 +238,7 @@ def parse_rxfifo_brackets(arg, fifo_dir):
227238 instructions .append (line )
228239 linemap .append (i )
229240
241+ mov_destinations : Sequence [str | None ]
230242 if pio_version >= 1 :
231243 mov_destinations = MOV_DESTINATIONS_V1
232244 else :
@@ -502,6 +514,8 @@ def parse_rxfifo_brackets(arg, fifo_dir):
502514
503515 self .debuginfo = (linemap , text_program ) if build_debuginfo else None
504516
517+ self .public_labels = public_labels
518+
505519 @classmethod
506520 def from_file (cls , filename : str , ** kwargs ) -> "Program" :
507521 """Assemble a PIO program in a file"""
@@ -557,7 +571,7 @@ def print_c_program(self, name: str, qualifier: str = "const") -> None:
557571 print ()
558572
559573
560- def assemble (program_text : str ) -> MutableSequence [ int ] :
574+ def assemble (program_text : str ) -> array . array :
561575 """Converts pioasm text to encoded instruction bytes
562576
563577 In new code, prefer to use the `Program` class so that the extra arguments
0 commit comments