From 88e12c5d01264fc0903196a92015e8c68758038b Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 10 Feb 2022 19:48:38 -0800 Subject: [PATCH] scons: Work around a SCons bug in Glob. The recent change to add an "exclude" pattern to Glob in SCons also seems to have triggered a bug where SCons has decided directories that don't exist are files, and then gets upset later when we try to treat them as directories. To avoid that bug, and to also make recursive searching for isa parser .py files work, we can replace the call to Glob with a loop based on os.walk. Also, tell the microcode assembler not to generate the parsetab.py file in the first place. This comes with a minor performance overhead, but shouldn't matter for us since there are *much* bigger overheads when processing ISA descriptions. Change-Id: Ia84e97dab72723ad3f4350798ad70178e231144c Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/56749 Maintainer: Bobby Bruce Tested-by: kokoro Reviewed-by: Gabe Black --- src/arch/SConscript | 12 ++++++++---- src/arch/micro_asm.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/arch/SConscript b/src/arch/SConscript index 017875033f..2321b9a2be 100644 --- a/src/arch/SConscript +++ b/src/arch/SConscript @@ -40,6 +40,7 @@ import sys import os +import os.path import re from gem5_scons import Transform @@ -103,9 +104,12 @@ SCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner) # Now create a Builder object that uses isa_parser.py to generate C++ # output from the ISA description (*.isa) files. # - -# parsetab.py is a file generated by PLY which we don't want to add as a dep. -parser_files = Glob('isa_parser/*.py', exclude=['*/parsetab.py']) +parser_files = [] +for root, dirnames, filenames in os.walk(Dir("isa_parser").srcnode().abspath): + for name in filenames: + _, ext = os.path.splitext(name) + if ext == '.py': + parser_files.append(os.path.join(root, name)) micro_asm_py = File('micro_asm.py') # import ply here because SCons screws with sys.path when performing actions. @@ -115,7 +119,7 @@ arch_dir = Dir('.') def run_parser(target, source, env): # Add the current directory to the system path so we can import files. - sys.path[0:0] = [ arch_dir.abspath ] + sys.path[0:0] = [ arch_dir.srcnode().abspath ] import isa_parser parser = isa_parser.ISAParser(target[0].dir.abspath) diff --git a/src/arch/micro_asm.py b/src/arch/micro_asm.py index 5eac33d4aa..448bf17dc4 100644 --- a/src/arch/micro_asm.py +++ b/src/arch/micro_asm.py @@ -486,7 +486,7 @@ class MicroAssembler(object): def __init__(self, macro_type, microops, rom = None, rom_macroop_type = None): self.lexer = lex.lex() - self.parser = yacc.yacc() + self.parser = yacc.yacc(write_tables=False) self.parser.macro_type = macro_type self.parser.macroops = {} self.parser.microops = microops