SConscript revision 8453:82fc1267d3bb
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# Authors: Nathan Binkert 30955SN/A 315522Snate@binkert.orgimport os 326143Snate@binkert.orgimport re 334762Snate@binkert.orgimport sys 345522Snate@binkert.org 35955SN/Afrom os.path import isdir, isfile, join as joinpath 365522Snate@binkert.org 37955SN/Afrom SCons.Scanner import Classic 385522Snate@binkert.org 394202Sbinkertn@umich.eduImport('*') 405742Snate@binkert.org 41955SN/Aif not env['RUBY']: 424381Sbinkertn@umich.edu Return() 434381Sbinkertn@umich.edu 44955SN/Aprotocol_dir = Dir('.') 45955SN/Ahtml_dir = Dir('html') 46955SN/Aslicc_dir = Dir('../slicc') 474202Sbinkertn@umich.edu 48955SN/Asys.path[1:1] = [ Dir('..').srcnode().abspath ] 494382Sbinkertn@umich.edufrom slicc.parser import SLICC 504382Sbinkertn@umich.edu 514382Sbinkertn@umich.eduslicc_depends = [] 526654Snate@binkert.orgfor root,dirs,files in os.walk(slicc_dir.srcnode().abspath): 535517Snate@binkert.org for f in files: 547674Snate@binkert.org if f.endswith('.py'): 557674Snate@binkert.org slicc_depends.append(File(joinpath(root, f))) 566143Snate@binkert.org 576143Snate@binkert.org# 586143Snate@binkert.org# Use SLICC 598233Snate@binkert.org# 608233Snate@binkert.orgenv['SLICC_PATH'] = str(protocol_dir) 618233Snate@binkert.orgslicc_scanner = Classic("SliccScanner", ['.sm', '.slicc'], "SLICC_PATH", 628233Snate@binkert.org r'''include[ \t]["'](.*)["'];''') 638233Snate@binkert.orgenv.Append(SCANNERS=slicc_scanner) 648233Snate@binkert.org 658233Snate@binkert.orgdef slicc_emitter(target, source, env): 668233Snate@binkert.org protocol = source[0].get_contents() 678233Snate@binkert.org files = [s.srcnode().abspath for s in source[1:]] 688233Snate@binkert.org slicc = SLICC(protocol, verbose=False) 698233Snate@binkert.org slicc.load(files) 708233Snate@binkert.org slicc.process() 718233Snate@binkert.org slicc.writeCodeFiles(protocol_dir.abspath) 726143Snate@binkert.org if not env['NO_HTML']: 738233Snate@binkert.org slicc.writeHTMLFiles(html_dir.abspath) 748233Snate@binkert.org 758233Snate@binkert.org target.extend([protocol_dir.File(f) for f in sorted(slicc.files())]) 766143Snate@binkert.org return target, source 776143Snate@binkert.org 786143Snate@binkert.orgdef slicc_action(target, source, env): 796143Snate@binkert.org protocol = source[0].get_contents() 808233Snate@binkert.org files = [s.srcnode().abspath for s in source[1:]] 818233Snate@binkert.org slicc = SLICC(protocol, verbose=True) 828233Snate@binkert.org slicc.load(files) 836143Snate@binkert.org slicc.process() 848233Snate@binkert.org slicc.writeCodeFiles(protocol_dir.abspath) 858233Snate@binkert.org if not env['NO_HTML']: 868233Snate@binkert.org slicc.writeHTMLFiles(html_dir.abspath) 878233Snate@binkert.org 886143Snate@binkert.orgslicc_builder = Builder(action=MakeAction(slicc_action, Transform("SLICC")), 896143Snate@binkert.org emitter=slicc_emitter) 906143Snate@binkert.org 914762Snate@binkert.orgprotocol = env['PROTOCOL'] 926143Snate@binkert.orgsources = [ protocol_dir.File("RubySlicc_interfaces.slicc"), 938233Snate@binkert.org protocol_dir.File("%s.slicc" % protocol) ] 948233Snate@binkert.org 958233Snate@binkert.orgenv.Append(BUILDERS={'SLICC' : slicc_builder}) 968233Snate@binkert.orgnodes = env.SLICC([], [ Value(protocol) ] + sources) 978233Snate@binkert.orgenv.Depends(nodes, slicc_depends) 986143Snate@binkert.org 998233Snate@binkert.orgfor f in nodes: 1008233Snate@binkert.org s = str(f) 1018233Snate@binkert.org if s.endswith('.cc'): 1028233Snate@binkert.org Source(f) 1036143Snate@binkert.org elif s.endswith('.py'): 1046143Snate@binkert.org SimObject(f) 1056143Snate@binkert.org 1066143Snate@binkert.org