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
|
from gem5_scons import Transform
|
||||||
|
|
||||||
Import('*')
|
Import("*")
|
||||||
|
|
||||||
if not env['CONF']['RUBY']:
|
if not env["CONF"]["RUBY"]:
|
||||||
Return()
|
Return()
|
||||||
|
|
||||||
output_dir = Dir('.')
|
output_dir = Dir(".")
|
||||||
html_dir = Dir('html')
|
html_dir = Dir("html")
|
||||||
slicc_dir = Dir('../slicc')
|
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
|
from slicc.parser import SLICC
|
||||||
|
|
||||||
slicc_depends = []
|
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:
|
for f in files:
|
||||||
if f.endswith('.py'):
|
if f.endswith(".py"):
|
||||||
slicc_depends.append(File(os.path.join(root, f)))
|
slicc_depends.append(File(os.path.join(root, f)))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Use SLICC
|
# Use SLICC
|
||||||
#
|
#
|
||||||
env["SLICC_PATH"] = env["PROTOCOL_DIRS"]
|
env["SLICC_PATH"] = env["PROTOCOL_DIRS"]
|
||||||
slicc_scanner = Classic("SliccScanner", ['.sm', '.slicc'], "SLICC_PATH",
|
slicc_scanner = Classic(
|
||||||
r'''include[ \t]["'](.*)["'];''')
|
"SliccScanner",
|
||||||
|
[".sm", ".slicc"],
|
||||||
|
"SLICC_PATH",
|
||||||
|
r"""include[ \t]["'](.*)["'];""",
|
||||||
|
)
|
||||||
env.Append(SCANNERS=slicc_scanner)
|
env.Append(SCANNERS=slicc_scanner)
|
||||||
|
|
||||||
slicc_includes = ['mem/ruby/slicc_interface/RubySlicc_includes.hh'] + \
|
slicc_includes = ["mem/ruby/slicc_interface/RubySlicc_includes.hh"] + env[
|
||||||
env['SLICC_INCLUDES']
|
"SLICC_INCLUDES"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def slicc_emitter(target, source, env):
|
def slicc_emitter(target, source, env):
|
||||||
assert len(source) == 1
|
files = set(target)
|
||||||
filepath = source[0].srcnode().abspath
|
for s in source:
|
||||||
|
filepath = s.srcnode().abspath
|
||||||
|
|
||||||
slicc = SLICC(
|
slicc = SLICC(
|
||||||
filepath,
|
filepath,
|
||||||
[os.path.join(protocol_base.abspath, 'RubySlicc_interfaces.slicc')],
|
[
|
||||||
protocol_base.abspath,
|
os.path.join(
|
||||||
verbose=False
|
protocol_base.abspath, "RubySlicc_interfaces.slicc"
|
||||||
)
|
)
|
||||||
slicc.process()
|
],
|
||||||
slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
|
protocol_base.abspath,
|
||||||
if env['CONF']['SLICC_HTML']:
|
verbose=False,
|
||||||
slicc.writeHTMLFiles(html_dir.abspath)
|
)
|
||||||
|
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):
|
def slicc_action(target, source, env):
|
||||||
assert len(source) == 1
|
for s in source:
|
||||||
filepath = source[0].srcnode().abspath
|
filepath = s.srcnode().abspath
|
||||||
slicc = SLICC(
|
slicc = SLICC(
|
||||||
filepath,
|
filepath,
|
||||||
[os.path.join(protocol_base.abspath, 'RubySlicc_interfaces.slicc')],
|
[
|
||||||
protocol_base.abspath,
|
os.path.join(
|
||||||
verbose=True
|
protocol_base.abspath, "RubySlicc_interfaces.slicc"
|
||||||
)
|
)
|
||||||
slicc.process()
|
],
|
||||||
slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
|
protocol_base.abspath,
|
||||||
if env['CONF']['SLICC_HTML']:
|
verbose=True,
|
||||||
slicc.writeHTMLFiles(html_dir.abspath)
|
)
|
||||||
|
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']
|
slicc_builder = Builder(
|
||||||
protocol_dir = None
|
action=MakeAction(slicc_action, Transform("SLICC")), emitter=slicc_emitter
|
||||||
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:
|
protocol = env["CONF"]["PROTOCOL"]
|
||||||
raise ValueError("Could not find {}.slicc in PROTOCOL_DIRS".format(
|
|
||||||
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)
|
nodes = env.SLICC([], sources)
|
||||||
env.Depends(nodes, slicc_depends)
|
env.Depends(nodes, slicc_depends)
|
||||||
|
|
||||||
append = {}
|
append = {}
|
||||||
if env['CLANG']:
|
if env["CLANG"]:
|
||||||
append['CCFLAGS'] = '-Wno-parentheses'
|
append["CCFLAGS"] = "-Wno-parentheses"
|
||||||
for f in nodes:
|
for f in nodes:
|
||||||
s = str(f)
|
s = str(f)
|
||||||
if s.endswith('.cc'):
|
if s.endswith(".cc"):
|
||||||
Source(f, append=append)
|
Source(f, append=append)
|
||||||
elif s.endswith('.py'):
|
elif s.endswith(".py"):
|
||||||
filename = os.path.basename(s)
|
filename = os.path.basename(s)
|
||||||
# We currently only expect ${ident}_Controller.py to be generated, and
|
# We currently only expect ${ident}_Controller.py to be generated, and
|
||||||
# for it to contain a single SimObject with the same name.
|
# 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]])
|
SimObject(f, sim_objects=[os.path.splitext(filename)[0]])
|
||||||
|
|||||||
Reference in New Issue
Block a user