@@ -50,6 +50,8 @@ def __init__(self, text_program: str, *, build_debuginfo=False) -> None:
5050 instructions = []
5151 sideset_count = 0
5252 sideset_enable = 0
53+ wrap = None
54+ wrap_target = None
5355 for i , line in enumerate (text_program .split ("\n " )):
5456 line = line .strip ()
5557 if not line :
@@ -61,13 +63,14 @@ def __init__(self, text_program: str, *, build_debuginfo=False) -> None:
6163 raise RuntimeError ("Multiple programs not supported" )
6264 program_name = line .split ()[1 ]
6365 elif line .startswith (".wrap_target" ):
64- if len (instructions ) > 0 :
65- raise RuntimeError ("wrap_target not supported" )
66+ wrap_target = len (instructions )
6667 elif line .startswith (".wrap" ):
67- pass
68+ if len (instructions ) == 0 :
69+ raise RuntimeError ("Cannot have .wrap as first instruction" )
70+ wrap = len (instructions ) - 1
6871 elif line .startswith (".side_set" ):
6972 sideset_count = int (line .split ()[1 ])
70- sideset_enable = 1 if "opt" in line else 0
73+ sideset_enable = "opt" in line
7174 elif line .endswith (":" ):
7275 label = line [:- 1 ]
7376 if label in labels :
@@ -225,6 +228,11 @@ def __init__(self, text_program: str, *, build_debuginfo=False) -> None:
225228 "sideset_enable" : sideset_enable ,
226229 }
227230
231+ if wrap is not None :
232+ self .pio_kwargs ["wrap" ] = wrap
233+ if wrap_target is not None :
234+ self .pio_kwargs ["wrap_target" ] = wrap_target
235+
228236 self .assembled = array .array ("H" , assembled )
229237
230238 if build_debuginfo :
@@ -241,6 +249,12 @@ def print_c_program(self, name, qualifier="const"):
241249 linemap = self .debuginfo [0 ][:] # Use a copy since we destroy it
242250 program_lines = self .debuginfo [1 ].split ("\n " )
243251
252+ print (
253+ f"{ qualifier } int { name } _wrap = { self .pio_kwargs .get ('wrap' , len (self .assembled )- 1 )} ;"
254+ )
255+ print (
256+ f"{ qualifier } int { name } _wrap_target = { self .pio_kwargs .get ('wrap_target' , 0 )} ;"
257+ )
244258 print (
245259 f"{ qualifier } int { name } _sideset_pin_count = { self .pio_kwargs ['sideset_pin_count' ]} ;"
246260 )
0 commit comments