SConscript revision 6878:c3a3c09af8be
15390SN/A# -*- mode:python -*-
25390SN/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
315631Sgblack@eecs.umich.eduimport os
325630Sgblack@eecs.umich.eduimport sys
335390SN/A
345390SN/Afrom os.path import isdir, isfile, join as joinpath
355390SN/A
365390SN/AImport('*')
375631Sgblack@eecs.umich.edu
385631Sgblack@eecs.umich.eduif not env['RUBY']:
395631Sgblack@eecs.umich.edu    Return()
405631Sgblack@eecs.umich.edu
415631Sgblack@eecs.umich.eduprotocol_dir = Dir('.')
425631Sgblack@eecs.umich.eduhtml_dir = Dir('html')
435631Sgblack@eecs.umich.eduslicc_dir = Dir('../slicc')
445631Sgblack@eecs.umich.edu
455631Sgblack@eecs.umich.edusys.path[1:1] = [ Dir('..').srcnode().abspath ]
465631Sgblack@eecs.umich.edufrom slicc.parser import SLICC
475631Sgblack@eecs.umich.edu
485631Sgblack@eecs.umich.eduslicc_depends = []
495631Sgblack@eecs.umich.edufor root,dirs,files in os.walk(slicc_dir.srcnode().abspath):
505631Sgblack@eecs.umich.edu    for f in files:
515631Sgblack@eecs.umich.edu        if f.endswith('.py'):
525631Sgblack@eecs.umich.edu            slicc_depends.append(File(joinpath(root, f)))
535631Sgblack@eecs.umich.edu
545630Sgblack@eecs.umich.edu#
555390SN/A# Use SLICC
565390SN/A#
575390SN/A
585390SN/Adef slicc_scanner(node, env, path):
595390SN/A    contents = node.get_contents()
605631Sgblack@eecs.umich.edu    files = [ line.strip() for line in contents.splitlines() if line ]
615631Sgblack@eecs.umich.edu    return files
625631Sgblack@eecs.umich.edu
635631Sgblack@eecs.umich.eduenv.Append(SCANNERS=Scanner(function=slicc_scanner,skeys=['.slicc']))
645631Sgblack@eecs.umich.edu
655631Sgblack@eecs.umich.edudef slicc_emitter(target, source, env):
665631Sgblack@eecs.umich.edu    files = [s.srcnode().abspath for s in source[1:]]
675631Sgblack@eecs.umich.edu    slicc = SLICC(debug=True)
685631Sgblack@eecs.umich.edu    print "SLICC parsing..."
695631Sgblack@eecs.umich.edu    for name in slicc.load(files, verbose=True):
705631Sgblack@eecs.umich.edu        print "    %s" % name
715631Sgblack@eecs.umich.edu
725631Sgblack@eecs.umich.edu    target.extend(sorted(slicc.files()))
735631Sgblack@eecs.umich.edu    pdir = str(protocol_dir)
745631Sgblack@eecs.umich.edu    hdir = str(html_dir)
755631Sgblack@eecs.umich.edu
765631Sgblack@eecs.umich.edu    if not isdir(pdir):
775631Sgblack@eecs.umich.edu        os.mkdir(pdir)
785631Sgblack@eecs.umich.edu    if not isdir(hdir):
795631Sgblack@eecs.umich.edu        os.mkdir(hdir)
805631Sgblack@eecs.umich.edu
815631Sgblack@eecs.umich.edu    print "SLICC Generator pass 1..."
825631Sgblack@eecs.umich.edu    slicc.findMachines()
835631Sgblack@eecs.umich.edu
845631Sgblack@eecs.umich.edu    print "SLICC Generator pass 2..."
855631Sgblack@eecs.umich.edu    slicc.generate()
865631Sgblack@eecs.umich.edu
875631Sgblack@eecs.umich.edu    print "SLICC writing C++ files..."
885631Sgblack@eecs.umich.edu    slicc.writeCodeFiles(pdir)
895631Sgblack@eecs.umich.edu
905631Sgblack@eecs.umich.edu    print "SLICC writing HTML files..."
915631Sgblack@eecs.umich.edu    slicc.writeHTMLFiles(hdir)
925631Sgblack@eecs.umich.edu    return target, source
935631Sgblack@eecs.umich.edu
945631Sgblack@eecs.umich.edudef slicc_action(target, source, env):
955631Sgblack@eecs.umich.edu    protocol = source[0].get_contents()
965631Sgblack@eecs.umich.edu    pdir = str(protocol_dir)
975631Sgblack@eecs.umich.edu    hdir = str(html_dir)
985631Sgblack@eecs.umich.edu
995631Sgblack@eecs.umich.edu    if not isdir(pdir):
1005631Sgblack@eecs.umich.edu        os.mkdir(pdir)
1015631Sgblack@eecs.umich.edu    if not isdir(hdir):
1025631Sgblack@eecs.umich.edu        os.mkdir(hdir)
1035631Sgblack@eecs.umich.edu
1045631Sgblack@eecs.umich.edu    slicc = SLICC(debug=True)
1055631Sgblack@eecs.umich.edu    files = [str(s) for s in source[1:]]
1065631Sgblack@eecs.umich.edu    slicc.load(files, verbose=False)
1075631Sgblack@eecs.umich.edu
1085631Sgblack@eecs.umich.edu    print "SLICC Generator pass 1..."
1095631Sgblack@eecs.umich.edu    slicc.findMachines()
1105631Sgblack@eecs.umich.edu
1115631Sgblack@eecs.umich.edu    print "SLICC Generator pass 2..."
1125631Sgblack@eecs.umich.edu    slicc.generate()
1135631Sgblack@eecs.umich.edu
1145631Sgblack@eecs.umich.edu    print "SLICC writing C++ files..."
1155631Sgblack@eecs.umich.edu    slicc.writeCodeFiles(pdir)
1165631Sgblack@eecs.umich.edu
1175631Sgblack@eecs.umich.edu    print "SLICC writing HTML files..."
1185631Sgblack@eecs.umich.edu    slicc.writeHTMLFiles(hdir)
1195631Sgblack@eecs.umich.edu
1205631Sgblack@eecs.umich.eduslicc_builder = Builder(action=slicc_action, emitter=slicc_emitter)
1215631Sgblack@eecs.umich.edu
1225631Sgblack@eecs.umich.eduprotocol = env['PROTOCOL']
1235631Sgblack@eecs.umich.edusources = [ protocol_dir.File("RubySlicc_interfaces.slicc"),
1245631Sgblack@eecs.umich.edu            protocol_dir.File("%s.slicc" % protocol) ]
1255631Sgblack@eecs.umich.edu
1265631Sgblack@eecs.umich.eduenv.Append(BUILDERS={'SLICC' : slicc_builder})
1275631Sgblack@eecs.umich.edunodes = env.SLICC([], [ Value(protocol) ] + sources)
1285631Sgblack@eecs.umich.eduenv.Depends(nodes, slicc_depends)
1295631Sgblack@eecs.umich.edu
1305631Sgblack@eecs.umich.edufor f in nodes:
1315631Sgblack@eecs.umich.edu    s = str(f)
1325631Sgblack@eecs.umich.edu    if s.endswith('.cc'):
1335631Sgblack@eecs.umich.edu        Source(f)
1345631Sgblack@eecs.umich.edu    elif s.endswith('.py'):
1355631Sgblack@eecs.umich.edu        SimObject(f)
1365632Sgblack@eecs.umich.edu
1375631Sgblack@eecs.umich.edu