Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/56900 )
Change subject: arch: Add a -I mechanism for the microcode assembler.
......................................................................
arch: Add a -I mechanism for the microcode assembler.
Change-Id: I5953bf9e92242cb116e988e056026e48b33e6b3d
---
M src/arch/SConscript
M src/arch/micro_asm.py
M src/arch/ucasmlib/assembler.py
3 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/src/arch/SConscript b/src/arch/SConscript
index 4ebe3ec..e75238f 100644
--- a/src/arch/SConscript
+++ b/src/arch/SConscript
@@ -92,11 +92,13 @@
# Build a SCons scanner for ucode files
#
scanner = SCons.Scanner.Classic(name='UcodeScan', suffixes=['.ucode'],
- path_variable='BUILDDIR',
+ path_variable='UCODEINC',
regex=r'^\s*include\s+"((?:[^"\\]|
(?:\\.))*)"')
env.Append(SCANNERS=scanner)
+env.Append(UCODEINC=['${BUILDDIR}'])
+
#
# Set up a microcode assembler source file type.
#
@@ -111,7 +113,8 @@
class MicroCode(SourceFile):
'Add a microcode source file.'
- def __init__(self, source, lib_path, arch_name, tags=None,
add_tags=None):
+ def __init__(self, source, lib_path, arch_name, asm_include_paths=[],
+ tags=None, add_tags=None):
'Specify the microcode source file, ucasmlib path, name, and any
tags'
super().__init__(source, tags, add_tags)
@@ -134,10 +137,12 @@
if ext == '.py':
arch_lib_py.append(os.path.join(root, name))
+ ucode_env.Append(UCODEINC=asm_include_paths)
ucode_env.Command([cpp, hh],
[ '${UCODE}', '${MICROASM}', ucasmlib_py, arch_lib_py ],
MakeAction('"${MICROASM}" "${UCODE}" --cpp "${CPP}"
--hh "${HH}" '
- '--arch="${ARCH}"',
+ '--arch="${ARCH}" '
+ '${" ".join(list(["-I " + p for p in UCODEINC]))}',
Transform('UCODEASM', max_sources=1)),
MICROASM=micro_asm_py, UCODE=File(source),
CPP=cpp.abspath, HH=hh.abspath, ARCH=arch_name)
diff --git a/src/arch/micro_asm.py b/src/arch/micro_asm.py
index 50600aa..a95cea1 100755
--- a/src/arch/micro_asm.py
+++ b/src/arch/micro_asm.py
@@ -38,6 +38,7 @@
parser.add_argument('--hh', dest='hh', default=None,
help='output hh file')
parser.add_argument('-a', '--arch', help='microcode arch (ISA) to use')
+parser.add_argument('-I', dest='include_paths', action='append')
args = parser.parse_args()
@@ -52,7 +53,8 @@
from ucasmlib.assembler import MicroAssembler
main_rom = isa.Rom('main ROM')
-assembler = MicroAssembler(isa.Macroop, isa.microops, main_rom)
+assembler = MicroAssembler(isa.Macroop, isa.microops, main_rom,
+ include_paths=args.include_paths)
assembler.symbols.update(isa.symbols)
with open(args.source) as source, \
open(args.cpp, 'w') as cpp, \
diff --git a/src/arch/ucasmlib/assembler.py b/src/arch/ucasmlib/assembler.py
index 71827e7..739ba7e 100644
--- a/src/arch/ucasmlib/assembler.py
+++ b/src/arch/ucasmlib/assembler.py
@@ -205,9 +205,11 @@
t.lexer.pop_state()
curpath = self.lexers[-1][0]
- rel = os.path.realpath(os.path.abspath(os.path.join(curpath,
path)))
- raw = os.path.realpath(os.path.abspath(path))
- matches = list([p for p in (rel, raw) if os.path.exists(p)])
+ real_abs = lambda p: os.path.realpath(os.path.abspath(p))
+ prefixes = self.include_paths + [ curpath, '' ]
+ paths = [ os.path.join(prefix, path) for prefix in prefixes ]
+ paths = map(real_abs, paths)
+ matches = list(filter(os.path.exists, paths))
if not matches:
raise ValueError(f'Include "{path}" not found')
path = matches[0]
@@ -340,7 +342,7 @@
def input(self, *args, **kwargs):
return self.lexer.input(*args, **kwargs)
- def __init__(self, macro_type, microops, rom=None):
+ def __init__(self, macro_type, microops, rom=None, include_paths=[]):
# Set lexers to something so when lex.lex() scans for doc strings
the
# "lexer" property can return something.
self.lexers = [('dummy', None)]
@@ -353,6 +355,7 @@
self.macroops = {}
self.microops = microops
self.rom = rom
+ self.include_paths = include_paths
self.symbols = {}
def assemble(self, asm, path=None):
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56900
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I5953bf9e92242cb116e988e056026e48b33e6b3d
Gerrit-Change-Number: 56900
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s