SConscript revision 14184:11ac1337c5e2
111384Ssteve.reinhardt@amd.com# -*- mode:python -*- 211384Ssteve.reinhardt@amd.com 38464SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 48464SN/A# All rights reserved. 57860SN/A# 611960Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 711960Sgabeblack@google.com# modification, are permitted provided that the following conditions are 811960Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 911954Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 1010798Ssteve.reinhardt@amd.com# redistributions in binary form must reproduce the above copyright 117860SN/A# notice, this list of conditions and the following disclaimer in the 1210798Ssteve.reinhardt@amd.com# documentation and/or other materials provided with the distribution; 1310798Ssteve.reinhardt@amd.com# neither the name of the copyright holders nor the names of its 1410798Ssteve.reinhardt@amd.com# contributors may be used to endorse or promote products derived from 1510798Ssteve.reinhardt@amd.com# this software without specific prior written permission. 1610798Ssteve.reinhardt@amd.com# 1710798Ssteve.reinhardt@amd.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1810798Ssteve.reinhardt@amd.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1910798Ssteve.reinhardt@amd.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2010798Ssteve.reinhardt@amd.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2110798Ssteve.reinhardt@amd.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2210798Ssteve.reinhardt@amd.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2310798Ssteve.reinhardt@amd.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2410798Ssteve.reinhardt@amd.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2510798Ssteve.reinhardt@amd.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2610798Ssteve.reinhardt@amd.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2710798Ssteve.reinhardt@amd.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2810798Ssteve.reinhardt@amd.com# 2910798Ssteve.reinhardt@amd.com# Authors: Nathan Binkert 3010798Ssteve.reinhardt@amd.com 3110798Ssteve.reinhardt@amd.comimport os 3210798Ssteve.reinhardt@amd.comimport re 3310798Ssteve.reinhardt@amd.comimport sys 3410798Ssteve.reinhardt@amd.com 3510798Ssteve.reinhardt@amd.comfrom os.path import isdir, isfile, join as joinpath 3610798Ssteve.reinhardt@amd.com 3710798Ssteve.reinhardt@amd.comfrom SCons.Scanner import Classic 3810798Ssteve.reinhardt@amd.com 3910798Ssteve.reinhardt@amd.comfrom gem5_scons import Transform 4010798Ssteve.reinhardt@amd.com 4110798Ssteve.reinhardt@amd.comImport('*') 4210798Ssteve.reinhardt@amd.com 4310798Ssteve.reinhardt@amd.comif env['PROTOCOL'] == 'None': 4410798Ssteve.reinhardt@amd.com Return() 4510798Ssteve.reinhardt@amd.com 4610798Ssteve.reinhardt@amd.comoutput_dir = Dir('.') 4710798Ssteve.reinhardt@amd.comhtml_dir = Dir('html') 4810798Ssteve.reinhardt@amd.comslicc_dir = Dir('../slicc') 4910798Ssteve.reinhardt@amd.com 5010798Ssteve.reinhardt@amd.comsys.path[1:1] = [ Dir('..').Dir('..').srcnode().abspath ] 5110798Ssteve.reinhardt@amd.comfrom slicc.parser import SLICC 5210798Ssteve.reinhardt@amd.com 5310798Ssteve.reinhardt@amd.comslicc_depends = [] 5410798Ssteve.reinhardt@amd.comfor root,dirs,files in os.walk(slicc_dir.srcnode().abspath): 5510798Ssteve.reinhardt@amd.com for f in files: 5610798Ssteve.reinhardt@amd.com if f.endswith('.py'): 5710798Ssteve.reinhardt@amd.com slicc_depends.append(File(joinpath(root, f))) 5810798Ssteve.reinhardt@amd.com 5910798Ssteve.reinhardt@amd.com# 6010798Ssteve.reinhardt@amd.com# Use SLICC 6110798Ssteve.reinhardt@amd.com# 6210798Ssteve.reinhardt@amd.comenv["SLICC_PATH"] = protocol_dirs 6310798Ssteve.reinhardt@amd.comslicc_scanner = Classic("SliccScanner", ['.sm', '.slicc'], "SLICC_PATH", 6410798Ssteve.reinhardt@amd.com r'''include[ \t]["'](.*)["'];''') 6510798Ssteve.reinhardt@amd.comenv.Append(SCANNERS=slicc_scanner) 6610798Ssteve.reinhardt@amd.com 6710798Ssteve.reinhardt@amd.comdef slicc_emitter(target, source, env): 6810798Ssteve.reinhardt@amd.com assert len(source) == 1 6910798Ssteve.reinhardt@amd.com filepath = source[0].srcnode().abspath 7010798Ssteve.reinhardt@amd.com 7110798Ssteve.reinhardt@amd.com slicc = SLICC(filepath, protocol_base.abspath, verbose=False) 7210798Ssteve.reinhardt@amd.com slicc.process() 7310798Ssteve.reinhardt@amd.com slicc.writeCodeFiles(output_dir.abspath, slicc_includes) 7410798Ssteve.reinhardt@amd.com if env['SLICC_HTML']: 7510798Ssteve.reinhardt@amd.com slicc.writeHTMLFiles(html_dir.abspath) 7610798Ssteve.reinhardt@amd.com 7710798Ssteve.reinhardt@amd.com target.extend([output_dir.File(f) for f in sorted(slicc.files())]) 7810798Ssteve.reinhardt@amd.com return target, source 7910798Ssteve.reinhardt@amd.com 8010798Ssteve.reinhardt@amd.comdef slicc_action(target, source, env): 8110798Ssteve.reinhardt@amd.com assert len(source) == 1 8210798Ssteve.reinhardt@amd.com filepath = source[0].srcnode().abspath 8310798Ssteve.reinhardt@amd.com 8410798Ssteve.reinhardt@amd.com slicc = SLICC(filepath, protocol_base.abspath, verbose=True) 8510798Ssteve.reinhardt@amd.com slicc.process() 8610798Ssteve.reinhardt@amd.com slicc.writeCodeFiles(output_dir.abspath, slicc_includes) 8710798Ssteve.reinhardt@amd.com if env['SLICC_HTML']: 8810798Ssteve.reinhardt@amd.com slicc.writeHTMLFiles(html_dir.abspath) 8910798Ssteve.reinhardt@amd.com 9010798Ssteve.reinhardt@amd.comslicc_builder = Builder(action=MakeAction(slicc_action, Transform("SLICC")), 9110798Ssteve.reinhardt@amd.com emitter=slicc_emitter) 9210798Ssteve.reinhardt@amd.com 9310798Ssteve.reinhardt@amd.comprotocol = env['PROTOCOL'] 9410798Ssteve.reinhardt@amd.comprotocol_dir = None 9510798Ssteve.reinhardt@amd.comfor path in protocol_dirs: 9610798Ssteve.reinhardt@amd.com if os.path.exists(os.path.join(path, "%s.slicc" % protocol)): 9710798Ssteve.reinhardt@amd.com protocol_dir = Dir(path) 9810798Ssteve.reinhardt@amd.com break 9910798Ssteve.reinhardt@amd.com 10010798Ssteve.reinhardt@amd.comif not protocol_dir: 10110798Ssteve.reinhardt@amd.com raise ValueError, "Could not find %s.slicc in protocol_dirs" % protocol 10210798Ssteve.reinhardt@amd.com 10310798Ssteve.reinhardt@amd.comsources = [ protocol_dir.File("%s.slicc" % protocol) ] 10410798Ssteve.reinhardt@amd.com 10510798Ssteve.reinhardt@amd.comenv.Append(BUILDERS={'SLICC' : slicc_builder}) 10610798Ssteve.reinhardt@amd.comnodes = env.SLICC([], sources) 10710798Ssteve.reinhardt@amd.comenv.Depends(nodes, slicc_depends) 10810798Ssteve.reinhardt@amd.com 10910798Ssteve.reinhardt@amd.comfor f in nodes: 11010798Ssteve.reinhardt@amd.com s = str(f) 11110798Ssteve.reinhardt@amd.com if s.endswith('.cc'): 11210798Ssteve.reinhardt@amd.com Source(f) 11310798Ssteve.reinhardt@amd.com elif s.endswith('.py'): 11410798Ssteve.reinhardt@amd.com SimObject(f) 11510798Ssteve.reinhardt@amd.com 11610798Ssteve.reinhardt@amd.com