SConscript revision 14184
113207Sgabeblack@google.com# -*- mode:python -*-
213207Sgabeblack@google.com
313207Sgabeblack@google.com# Copyright (c) 2009 The Hewlett-Packard Development Company
413207Sgabeblack@google.com# All rights reserved.
513207Sgabeblack@google.com#
613207Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
713207Sgabeblack@google.com# modification, are permitted provided that the following conditions are
813207Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
913207Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
1013207Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
1113207Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
1213207Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
1313207Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
1413207Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
1513207Sgabeblack@google.com# this software without specific prior written permission.
1613207Sgabeblack@google.com#
1713207Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1813207Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1913207Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2013207Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2113207Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2213207Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2313207Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2413207Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2513207Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2613207Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2713207Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2813207Sgabeblack@google.com#
2913207Sgabeblack@google.com# Authors: Nathan Binkert
3013207Sgabeblack@google.com
3113207Sgabeblack@google.comimport os
3213207Sgabeblack@google.comimport re
3313207Sgabeblack@google.comimport sys
3413273Sgabeblack@google.com
3513207Sgabeblack@google.comfrom os.path import isdir, isfile, join as joinpath
3613207Sgabeblack@google.com
3713239Sgabeblack@google.comfrom SCons.Scanner import Classic
3813207Sgabeblack@google.com
3913207Sgabeblack@google.comfrom gem5_scons import Transform
4013207Sgabeblack@google.com
4113207Sgabeblack@google.comImport('*')
4213207Sgabeblack@google.com
4313207Sgabeblack@google.comif env['PROTOCOL'] == 'None':
4413207Sgabeblack@google.com    Return()
4513207Sgabeblack@google.com
4613288Sgabeblack@google.comoutput_dir = Dir('.')
4713207Sgabeblack@google.comhtml_dir = Dir('html')
4813207Sgabeblack@google.comslicc_dir = Dir('../slicc')
4913207Sgabeblack@google.com
5013207Sgabeblack@google.comsys.path[1:1] = [ Dir('..').Dir('..').srcnode().abspath ]
5113207Sgabeblack@google.comfrom slicc.parser import SLICC
5213207Sgabeblack@google.com
5313207Sgabeblack@google.comslicc_depends = []
5413207Sgabeblack@google.comfor root,dirs,files in os.walk(slicc_dir.srcnode().abspath):
5513207Sgabeblack@google.com    for f in files:
5613207Sgabeblack@google.com        if f.endswith('.py'):
5713207Sgabeblack@google.com            slicc_depends.append(File(joinpath(root, f)))
5813207Sgabeblack@google.com
5913207Sgabeblack@google.com#
6013207Sgabeblack@google.com# Use SLICC
6113273Sgabeblack@google.com#
6213273Sgabeblack@google.comenv["SLICC_PATH"] = protocol_dirs
6313207Sgabeblack@google.comslicc_scanner = Classic("SliccScanner", ['.sm', '.slicc'], "SLICC_PATH",
6413207Sgabeblack@google.com                        r'''include[ \t]["'](.*)["'];''')
6513288Sgabeblack@google.comenv.Append(SCANNERS=slicc_scanner)
6613207Sgabeblack@google.com
6713207Sgabeblack@google.comdef slicc_emitter(target, source, env):
6813239Sgabeblack@google.com    assert len(source) == 1
6913207Sgabeblack@google.com    filepath = source[0].srcnode().abspath
7013321Sgabeblack@google.com
7113207Sgabeblack@google.com    slicc = SLICC(filepath, protocol_base.abspath, verbose=False)
7213207Sgabeblack@google.com    slicc.process()
7313207Sgabeblack@google.com    slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
7413207Sgabeblack@google.com    if env['SLICC_HTML']:
7513207Sgabeblack@google.com        slicc.writeHTMLFiles(html_dir.abspath)
7613207Sgabeblack@google.com
7713273Sgabeblack@google.com    target.extend([output_dir.File(f) for f in sorted(slicc.files())])
7813273Sgabeblack@google.com    return target, source
7913207Sgabeblack@google.com
8013207Sgabeblack@google.comdef slicc_action(target, source, env):
8113207Sgabeblack@google.com    assert len(source) == 1
8213207Sgabeblack@google.com    filepath = source[0].srcnode().abspath
8313207Sgabeblack@google.com
8413207Sgabeblack@google.com    slicc = SLICC(filepath, protocol_base.abspath, verbose=True)
8513207Sgabeblack@google.com    slicc.process()
8613207Sgabeblack@google.com    slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
8713207Sgabeblack@google.com    if env['SLICC_HTML']:
8813207Sgabeblack@google.com        slicc.writeHTMLFiles(html_dir.abspath)
8913207Sgabeblack@google.com
9013207Sgabeblack@google.comslicc_builder = Builder(action=MakeAction(slicc_action, Transform("SLICC")),
9113207Sgabeblack@google.com                        emitter=slicc_emitter)
9213207Sgabeblack@google.com
9313207Sgabeblack@google.comprotocol = env['PROTOCOL']
9413207Sgabeblack@google.comprotocol_dir = None
9513207Sgabeblack@google.comfor path in protocol_dirs:
9613207Sgabeblack@google.com    if os.path.exists(os.path.join(path, "%s.slicc" % protocol)):
9713207Sgabeblack@google.com        protocol_dir = Dir(path)
9813207Sgabeblack@google.com        break
9913207Sgabeblack@google.com
10013207Sgabeblack@google.comif not protocol_dir:
10113207Sgabeblack@google.com    raise ValueError, "Could not find %s.slicc in protocol_dirs" % protocol
10213207Sgabeblack@google.com
10313207Sgabeblack@google.comsources = [ protocol_dir.File("%s.slicc" % protocol) ]
10413207Sgabeblack@google.com
10513207Sgabeblack@google.comenv.Append(BUILDERS={'SLICC' : slicc_builder})
10613288Sgabeblack@google.comnodes = env.SLICC([], sources)
10713207Sgabeblack@google.comenv.Depends(nodes, slicc_depends)
10813207Sgabeblack@google.com
10913207Sgabeblack@google.comfor f in nodes:
11013288Sgabeblack@google.com    s = str(f)
11113207Sgabeblack@google.com    if s.endswith('.cc'):
11213207Sgabeblack@google.com        Source(f)
11313207Sgabeblack@google.com    elif s.endswith('.py'):
11413207Sgabeblack@google.com        SimObject(f)
11513207Sgabeblack@google.com
11613207Sgabeblack@google.com