SConscript revision 8453:82fc1267d3bb
15390SN/A# -*- mode:python -*- 25443SN/A 35390SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 45390SN/A# All rights reserved. 55390SN/A# 65390SN/A# Redistribution and use in source and binary forms, with or without 75390SN/A# modification, are permitted provided that the following conditions are 85390SN/A# met: redistributions of source code must retain the above copyright 95390SN/A# notice, this list of conditions and the following disclaimer; 105390SN/A# redistributions in binary form must reproduce the above copyright 115390SN/A# notice, this list of conditions and the following disclaimer in the 125390SN/A# documentation and/or other materials provided with the distribution; 135390SN/A# neither the name of the copyright holders nor the names of its 145390SN/A# contributors may be used to endorse or promote products derived from 155390SN/A# this software without specific prior written permission. 165390SN/A# 175390SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 185390SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 195390SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 205390SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215390SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 225390SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 235390SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 245390SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 255390SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 265390SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 275390SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 285390SN/A# 295390SN/A# Authors: Nathan Binkert 305390SN/A 315636Sgblack@eecs.umich.eduimport os 325636Sgblack@eecs.umich.eduimport re 335390SN/Aimport sys 345443SN/A 355636Sgblack@eecs.umich.edufrom os.path import isdir, isfile, join as joinpath 365636Sgblack@eecs.umich.edu 375443SN/Afrom SCons.Scanner import Classic 385390SN/A 395390SN/AImport('*') 405390SN/A 415636Sgblack@eecs.umich.eduif not env['RUBY']: 425636Sgblack@eecs.umich.edu Return() 435636Sgblack@eecs.umich.edu 445390SN/Aprotocol_dir = Dir('.') 455636Sgblack@eecs.umich.eduhtml_dir = Dir('html') 465636Sgblack@eecs.umich.eduslicc_dir = Dir('../slicc') 475642Sgblack@eecs.umich.edu 485642Sgblack@eecs.umich.edusys.path[1:1] = [ Dir('..').srcnode().abspath ] 495642Sgblack@eecs.umich.edufrom slicc.parser import SLICC 505642Sgblack@eecs.umich.edu 515642Sgblack@eecs.umich.eduslicc_depends = [] 525642Sgblack@eecs.umich.edufor root,dirs,files in os.walk(slicc_dir.srcnode().abspath): 535642Sgblack@eecs.umich.edu for f in files: 545642Sgblack@eecs.umich.edu if f.endswith('.py'): 555642Sgblack@eecs.umich.edu slicc_depends.append(File(joinpath(root, f))) 565642Sgblack@eecs.umich.edu 575642Sgblack@eecs.umich.edu# 585642Sgblack@eecs.umich.edu# Use SLICC 595642Sgblack@eecs.umich.edu# 605642Sgblack@eecs.umich.eduenv['SLICC_PATH'] = str(protocol_dir) 615642Sgblack@eecs.umich.eduslicc_scanner = Classic("SliccScanner", ['.sm', '.slicc'], "SLICC_PATH", 625642Sgblack@eecs.umich.edu r'''include[ \t]["'](.*)["'];''') 635642Sgblack@eecs.umich.eduenv.Append(SCANNERS=slicc_scanner) 645642Sgblack@eecs.umich.edu 655642Sgblack@eecs.umich.edudef slicc_emitter(target, source, env): 665390SN/A protocol = source[0].get_contents() 675636Sgblack@eecs.umich.edu files = [s.srcnode().abspath for s in source[1:]] 685642Sgblack@eecs.umich.edu slicc = SLICC(protocol, verbose=False) 695642Sgblack@eecs.umich.edu slicc.load(files) 705390SN/A slicc.process() 715636Sgblack@eecs.umich.edu slicc.writeCodeFiles(protocol_dir.abspath) 725636Sgblack@eecs.umich.edu if not env['NO_HTML']: 735636Sgblack@eecs.umich.edu slicc.writeHTMLFiles(html_dir.abspath) 745636Sgblack@eecs.umich.edu 755636Sgblack@eecs.umich.edu target.extend([protocol_dir.File(f) for f in sorted(slicc.files())]) 765636Sgblack@eecs.umich.edu return target, source 775636Sgblack@eecs.umich.edu 785636Sgblack@eecs.umich.edudef slicc_action(target, source, env): 795636Sgblack@eecs.umich.edu protocol = source[0].get_contents() 805636Sgblack@eecs.umich.edu files = [s.srcnode().abspath for s in source[1:]] 815642Sgblack@eecs.umich.edu slicc = SLICC(protocol, verbose=True) 825636Sgblack@eecs.umich.edu slicc.load(files) 835636Sgblack@eecs.umich.edu slicc.process() 845636Sgblack@eecs.umich.edu slicc.writeCodeFiles(protocol_dir.abspath) 855390SN/A if not env['NO_HTML']: 865390SN/A slicc.writeHTMLFiles(html_dir.abspath) 875390SN/A 885636Sgblack@eecs.umich.eduslicc_builder = Builder(action=MakeAction(slicc_action, Transform("SLICC")), 895636Sgblack@eecs.umich.edu emitter=slicc_emitter) 905636Sgblack@eecs.umich.edu 915636Sgblack@eecs.umich.eduprotocol = env['PROTOCOL'] 925636Sgblack@eecs.umich.edusources = [ protocol_dir.File("RubySlicc_interfaces.slicc"), 935636Sgblack@eecs.umich.edu protocol_dir.File("%s.slicc" % protocol) ] 945636Sgblack@eecs.umich.edu 955636Sgblack@eecs.umich.eduenv.Append(BUILDERS={'SLICC' : slicc_builder}) 965636Sgblack@eecs.umich.edunodes = env.SLICC([], [ Value(protocol) ] + sources) 975636Sgblack@eecs.umich.eduenv.Depends(nodes, slicc_depends) 985636Sgblack@eecs.umich.edu 995636Sgblack@eecs.umich.edufor f in nodes: 1005636Sgblack@eecs.umich.edu s = str(f) 1015636Sgblack@eecs.umich.edu if s.endswith('.cc'): 1025636Sgblack@eecs.umich.edu Source(f) 1035636Sgblack@eecs.umich.edu elif s.endswith('.py'): 1045636Sgblack@eecs.umich.edu SimObject(f) 1055636Sgblack@eecs.umich.edu 1065636Sgblack@eecs.umich.edu