scons: Change scons for multiple protocols in SLICC
This change is a step toward multiple protocols building at the same time in scons. Add functions and use lists instead of single protocol. Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
committed by
Bobby R. Bruce
parent
b925a6e57c
commit
3ba16adeff
@@ -34,96 +34,123 @@ from SCons.Scanner import Classic
|
||||
|
||||
from gem5_scons import Transform
|
||||
|
||||
Import('*')
|
||||
Import("*")
|
||||
|
||||
if not env['CONF']['RUBY']:
|
||||
if not env["CONF"]["RUBY"]:
|
||||
Return()
|
||||
|
||||
output_dir = Dir('.')
|
||||
html_dir = Dir('html')
|
||||
slicc_dir = Dir('../slicc')
|
||||
output_dir = Dir(".")
|
||||
html_dir = Dir("html")
|
||||
slicc_dir = Dir("../slicc")
|
||||
|
||||
sys.path[1:1] = [ Dir('..').Dir('..').srcnode().abspath ]
|
||||
sys.path[1:1] = [Dir("..").Dir("..").srcnode().abspath]
|
||||
from slicc.parser import SLICC
|
||||
|
||||
slicc_depends = []
|
||||
for root,dirs,files in os.walk(slicc_dir.srcnode().abspath):
|
||||
for root, dirs, files in os.walk(slicc_dir.srcnode().abspath):
|
||||
for f in files:
|
||||
if f.endswith('.py'):
|
||||
if f.endswith(".py"):
|
||||
slicc_depends.append(File(os.path.join(root, f)))
|
||||
|
||||
#
|
||||
# Use SLICC
|
||||
#
|
||||
env["SLICC_PATH"] = env["PROTOCOL_DIRS"]
|
||||
slicc_scanner = Classic("SliccScanner", ['.sm', '.slicc'], "SLICC_PATH",
|
||||
r'''include[ \t]["'](.*)["'];''')
|
||||
slicc_scanner = Classic(
|
||||
"SliccScanner",
|
||||
[".sm", ".slicc"],
|
||||
"SLICC_PATH",
|
||||
r"""include[ \t]["'](.*)["'];""",
|
||||
)
|
||||
env.Append(SCANNERS=slicc_scanner)
|
||||
|
||||
slicc_includes = ['mem/ruby/slicc_interface/RubySlicc_includes.hh'] + \
|
||||
env['SLICC_INCLUDES']
|
||||
slicc_includes = ["mem/ruby/slicc_interface/RubySlicc_includes.hh"] + env[
|
||||
"SLICC_INCLUDES"
|
||||
]
|
||||
|
||||
|
||||
def slicc_emitter(target, source, env):
|
||||
assert len(source) == 1
|
||||
filepath = source[0].srcnode().abspath
|
||||
files = set(target)
|
||||
for s in source:
|
||||
filepath = s.srcnode().abspath
|
||||
|
||||
slicc = SLICC(
|
||||
filepath,
|
||||
[os.path.join(protocol_base.abspath, 'RubySlicc_interfaces.slicc')],
|
||||
protocol_base.abspath,
|
||||
verbose=False
|
||||
)
|
||||
slicc.process()
|
||||
slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
|
||||
if env['CONF']['SLICC_HTML']:
|
||||
slicc.writeHTMLFiles(html_dir.abspath)
|
||||
slicc = SLICC(
|
||||
filepath,
|
||||
[
|
||||
os.path.join(
|
||||
protocol_base.abspath, "RubySlicc_interfaces.slicc"
|
||||
)
|
||||
],
|
||||
protocol_base.abspath,
|
||||
verbose=False,
|
||||
)
|
||||
slicc.process()
|
||||
slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
|
||||
if env["CONF"]["SLICC_HTML"]:
|
||||
slicc.writeHTMLFiles(html_dir.abspath)
|
||||
|
||||
files.update([output_dir.File(f) for f in sorted(slicc.files())])
|
||||
|
||||
return list(files), source
|
||||
|
||||
target.extend([output_dir.File(f) for f in sorted(slicc.files())])
|
||||
return target, source
|
||||
|
||||
def slicc_action(target, source, env):
|
||||
assert len(source) == 1
|
||||
filepath = source[0].srcnode().abspath
|
||||
slicc = SLICC(
|
||||
filepath,
|
||||
[os.path.join(protocol_base.abspath, 'RubySlicc_interfaces.slicc')],
|
||||
protocol_base.abspath,
|
||||
verbose=True
|
||||
)
|
||||
slicc.process()
|
||||
slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
|
||||
if env['CONF']['SLICC_HTML']:
|
||||
slicc.writeHTMLFiles(html_dir.abspath)
|
||||
for s in source:
|
||||
filepath = s.srcnode().abspath
|
||||
slicc = SLICC(
|
||||
filepath,
|
||||
[
|
||||
os.path.join(
|
||||
protocol_base.abspath, "RubySlicc_interfaces.slicc"
|
||||
)
|
||||
],
|
||||
protocol_base.abspath,
|
||||
verbose=True,
|
||||
)
|
||||
slicc.process()
|
||||
slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
|
||||
if env["CONF"]["SLICC_HTML"]:
|
||||
slicc.writeHTMLFiles(html_dir.abspath)
|
||||
|
||||
slicc_builder = Builder(action=MakeAction(slicc_action, Transform("SLICC")),
|
||||
emitter=slicc_emitter)
|
||||
|
||||
protocol = env['CONF']['PROTOCOL']
|
||||
protocol_dir = None
|
||||
for path in env['PROTOCOL_DIRS']:
|
||||
if os.path.exists(path.File("%s.slicc" % protocol).abspath):
|
||||
protocol_dir = Dir(path)
|
||||
break
|
||||
slicc_builder = Builder(
|
||||
action=MakeAction(slicc_action, Transform("SLICC")), emitter=slicc_emitter
|
||||
)
|
||||
|
||||
if not protocol_dir:
|
||||
raise ValueError("Could not find {}.slicc in PROTOCOL_DIRS".format(
|
||||
protocol))
|
||||
protocol = env["CONF"]["PROTOCOL"]
|
||||
|
||||
sources = [ protocol_dir.File("%s.slicc" % protocol) ]
|
||||
|
||||
env.Append(BUILDERS={'SLICC' : slicc_builder})
|
||||
def find_protocol_sources(protocol):
|
||||
protocol_dir = None
|
||||
for path in env["PROTOCOL_DIRS"]:
|
||||
if os.path.exists(path.File("%s.slicc" % protocol).abspath):
|
||||
protocol_dir = Dir(path)
|
||||
break
|
||||
|
||||
if not protocol_dir:
|
||||
raise ValueError(
|
||||
"Could not find {}.slicc in PROTOCOL_DIRS".format(protocol)
|
||||
)
|
||||
|
||||
return protocol_dir.File("%s.slicc" % protocol)
|
||||
|
||||
|
||||
sources = [find_protocol_sources(protocol)]
|
||||
|
||||
env.Append(BUILDERS={"SLICC": slicc_builder})
|
||||
nodes = env.SLICC([], sources)
|
||||
env.Depends(nodes, slicc_depends)
|
||||
|
||||
append = {}
|
||||
if env['CLANG']:
|
||||
append['CCFLAGS'] = '-Wno-parentheses'
|
||||
if env["CLANG"]:
|
||||
append["CCFLAGS"] = "-Wno-parentheses"
|
||||
for f in nodes:
|
||||
s = str(f)
|
||||
if s.endswith('.cc'):
|
||||
if s.endswith(".cc"):
|
||||
Source(f, append=append)
|
||||
elif s.endswith('.py'):
|
||||
elif s.endswith(".py"):
|
||||
filename = os.path.basename(s)
|
||||
# We currently only expect ${ident}_Controller.py to be generated, and
|
||||
# for it to contain a single SimObject with the same name.
|
||||
assert(filename.endswith('_Controller.py'))
|
||||
assert filename.endswith("_Controller.py")
|
||||
SimObject(f, sim_objects=[os.path.splitext(filename)[0]])
|
||||
|
||||
Reference in New Issue
Block a user