@@ -207,7 +207,7 @@ def search_filename(fname: str, lineno: int, local_first: bool, arch: str = "")
207207
208208def include_file (filename : str , lineno : int , local_first : bool , arch : str = "" ) -> str :
209209 """Performs a file inclusion (#include) in the preprocessor.
210- Writes down that "filename" was included at the current file,
210+ Writes down that "filename" was included in the current file,
211211 at line <lineno>.
212212
213213 If local_first is True, then it will first search the file in the
@@ -216,7 +216,7 @@ def include_file(filename: str, lineno: int, local_first: bool, arch: str = "")
216216 """
217217 global CURRENT_DIR
218218
219- abs_filename = search_filename (filename , lineno , local_first )
219+ abs_filename = search_filename (filename , lineno , local_first , arch = arch )
220220 filename = utils .get_relative_filename_path (abs_filename )
221221
222222 if abs_filename not in INCLUDED :
@@ -236,7 +236,7 @@ def include_file(filename: str, lineno: int, local_first: bool, arch: str = "")
236236
237237def include_once (filename : str , lineno : int , local_first : bool , arch : str = "" ) -> str :
238238 """Performs a file inclusion (#include) in the preprocessor.
239- Writes down that "filename" was included at the current file,
239+ Writes down that "filename" was included in the current file,
240240 at line <lineno>.
241241
242242 The file is ignored if it was previously included (a warning will
@@ -246,7 +246,7 @@ def include_once(filename: str, lineno: int, local_first: bool, arch: str = "")
246246 local path before looking for it in the include path chain.
247247 This is used when doing a #include "filename".
248248 """
249- abs_filename = search_filename (filename , lineno , local_first )
249+ abs_filename = search_filename (filename , lineno , local_first , arch = arch )
250250
251251 if abs_filename not in INCLUDED : # If not already included
252252 return include_file (filename , lineno , local_first , arch ) # include it and return
@@ -395,34 +395,55 @@ def p_include_once_ok(p):
395395
396396
397397def p_include_fname (p ):
398- """include : INCLUDE FILENAME"""
398+ """include : INCLUDE include_modifier FILENAME"""
399+ modifier = p [2 ]
400+ if modifier is None :
401+ p [0 ] = []
402+ return
403+
404+ filename = p [3 ]
399405 if ENABLED :
400- p [0 ] = include_file (p [2 ], p .lineno (2 ), local_first = False )
406+ arch = modifier .get ("arch" , "" )
407+ p [0 ] = include_file (filename , p .lineno (3 ), local_first = False , arch = arch )
401408 else :
402409 p [0 ] = []
403410 p .lexer .next_token = "_ENDFILE_"
404411
405412
406413def p_include_macro (p ):
407- """include : INCLUDE expr"""
408- global_fist = RE_GLOBAL_FIRST_FILENAME .match (p [2 ])
409- local_first = RE_LOCAL_FIRST_FILENAME .match (p [2 ])
414+ """include : INCLUDE include_modifier expr"""
415+ modifier = p [2 ]
416+ if modifier is None :
417+ p [0 ] = []
418+ return
419+
420+ expr = p [3 ]
421+ global_fist = RE_GLOBAL_FIRST_FILENAME .match (expr )
422+ local_first = RE_LOCAL_FIRST_FILENAME .match (expr )
410423 if global_fist is None and local_first is None :
411- error (p .lineno (1 ), f"invalid filename { p [ 2 ] } " )
424+ error (p .lineno (1 ), f"invalid filename { expr } " )
412425 p [0 ] = []
413426 return
414427
415428 if ENABLED :
416- p [0 ] = include_file (p [2 ][1 :- 1 ], p .lineno (2 ), local_first = local_first is not None )
429+ arch = modifier .get ("arch" , "" )
430+ p [0 ] = include_file (expr [1 :- 1 ], p .lineno (3 ), local_first = local_first is not None , arch = arch )
417431 else :
418432 p [0 ] = []
419433 p .lexer .next_token = "_ENDFILE_"
420434
421435
422436def p_include_once (p ):
423- """include_once : INCLUDE ONCE STRING"""
437+ """include_once : INCLUDE ONCE include_modifier STRING"""
438+ modifier = p [3 ]
439+ if modifier is None :
440+ p [0 ] = []
441+ return
442+
443+ string = p [4 ]
424444 if ENABLED :
425- p [0 ] = include_once (p [3 ][1 :- 1 ], p .lineno (3 ), local_first = True )
445+ arch = modifier .get ("arch" , "" )
446+ p [0 ] = include_once (string [1 :- 1 ], p .lineno (4 ), local_first = True , arch = arch )
426447 else :
427448 p [0 ] = []
428449
@@ -431,18 +452,43 @@ def p_include_once(p):
431452
432453
433454def p_include_once_fname (p ):
434- """include_once : INCLUDE ONCE FILENAME"""
455+ """include_once : INCLUDE ONCE include_modifier FILENAME"""
435456 p [0 ] = []
457+ modifier = p [3 ]
458+ if modifier is None :
459+ return
436460
461+ filename = p [4 ]
437462 if ENABLED :
438- p [0 ] = include_once (p [3 ], p .lineno (3 ), local_first = False )
463+ arch = modifier .get ("arch" , "" )
464+ p [0 ] = include_once (filename , p .lineno (4 ), local_first = False , arch = arch )
439465 else :
440466 p [0 ] = []
441467
442468 if not p [0 ]:
443469 p .lexer .next_token = "_ENDFILE_"
444470
445471
472+ def p_include_modifier (p ):
473+ """include_modifier :
474+ | LB ID CO ID RB
475+ """
476+ if len (p ) == 1 :
477+ p [0 ] = {}
478+ return
479+
480+ modifier = p [2 ]
481+ value = p [4 ]
482+
483+ if modifier == "arch" :
484+ p [0 ] = {"arch" : value }
485+ else :
486+ p [0 ] = None
487+ error (p .lineno (1 ), f"unknown modifier { modifier } " )
488+
489+ return
490+
491+
446492def p_line (p ):
447493 """line : LINE INTEGER NEWLINE"""
448494 if ENABLED :
0 commit comments