SConscript revision 6878:c3a3c09af8be
12139SN/A# -*- mode:python -*-
22139SN/A
32139SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
42139SN/A# All rights reserved.
52139SN/A#
62139SN/A# Redistribution and use in source and binary forms, with or without
72139SN/A# modification, are permitted provided that the following conditions are
82139SN/A# met: redistributions of source code must retain the above copyright
92139SN/A# notice, this list of conditions and the following disclaimer;
102139SN/A# redistributions in binary form must reproduce the above copyright
112139SN/A# notice, this list of conditions and the following disclaimer in the
122139SN/A# documentation and/or other materials provided with the distribution;
132139SN/A# neither the name of the copyright holders nor the names of its
142139SN/A# contributors may be used to endorse or promote products derived from
152139SN/A# this software without specific prior written permission.
162139SN/A#
172139SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192139SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202139SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212139SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232139SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242139SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252139SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262139SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272139SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Nathan Binkert
302139SN/A
314202Sbinkertn@umich.eduimport os
322139SN/Aimport sys
334202Sbinkertn@umich.edu
342152SN/Afrom os.path import isdir, isfile, join as joinpath
352152SN/A
362139SN/AImport('*')
372139SN/A
382139SN/Aif not env['RUBY']:
392139SN/A    Return()
402139SN/A
412152SN/Aprotocol_dir = Dir('.')
422152SN/Ahtml_dir = Dir('html')
432139SN/Aslicc_dir = Dir('../slicc')
442139SN/A
452139SN/Asys.path[1:1] = [ Dir('..').srcnode().abspath ]
464781Snate@binkert.orgfrom slicc.parser import SLICC
474781Snate@binkert.org
484781Snate@binkert.orgslicc_depends = []
494781Snate@binkert.orgfor root,dirs,files in os.walk(slicc_dir.srcnode().abspath):
504781Snate@binkert.org    for f in files:
513170Sstever@eecs.umich.edu        if f.endswith('.py'):
525664Sgblack@eecs.umich.edu            slicc_depends.append(File(joinpath(root, f)))
533806Ssaidi@eecs.umich.edu
544781Snate@binkert.org#
554781Snate@binkert.org# Use SLICC
564781Snate@binkert.org#
574781Snate@binkert.org
584781Snate@binkert.orgdef slicc_scanner(node, env, path):
594781Snate@binkert.org    contents = node.get_contents()
604781Snate@binkert.org    files = [ line.strip() for line in contents.splitlines() if line ]
614781Snate@binkert.org    return files
624781Snate@binkert.org
634781Snate@binkert.orgenv.Append(SCANNERS=Scanner(function=slicc_scanner,skeys=['.slicc']))
642139SN/A
652139SN/Adef slicc_emitter(target, source, env):
663546Sgblack@eecs.umich.edu    files = [s.srcnode().abspath for s in source[1:]]
674202Sbinkertn@umich.edu    slicc = SLICC(debug=True)
682152SN/A    print "SLICC parsing..."
692152SN/A    for name in slicc.load(files, verbose=True):
702152SN/A        print "    %s" % name
712152SN/A
722152SN/A    target.extend(sorted(slicc.files()))
732152SN/A    pdir = str(protocol_dir)
742152SN/A    hdir = str(html_dir)
752152SN/A
762152SN/A    if not isdir(pdir):
772152SN/A        os.mkdir(pdir)
782152SN/A    if not isdir(hdir):
792152SN/A        os.mkdir(hdir)
802504SN/A
812504SN/A    print "SLICC Generator pass 1..."
822504SN/A    slicc.findMachines()
832504SN/A
842152SN/A    print "SLICC Generator pass 2..."
852504SN/A    slicc.generate()
862152SN/A
872152SN/A    print "SLICC writing C++ files..."
882152SN/A    slicc.writeCodeFiles(pdir)
892152SN/A
902152SN/A    print "SLICC writing HTML files..."
912152SN/A    slicc.writeHTMLFiles(hdir)
922152SN/A    return target, source
932152SN/A
942632Sstever@eecs.umich.edudef slicc_action(target, source, env):
952155SN/A    protocol = source[0].get_contents()
962155SN/A    pdir = str(protocol_dir)
972155SN/A    hdir = str(html_dir)
982155SN/A
992155SN/A    if not isdir(pdir):
1002155SN/A        os.mkdir(pdir)
1015228Sgblack@eecs.umich.edu    if not isdir(hdir):
1022155SN/A        os.mkdir(hdir)
1032155SN/A
1042155SN/A    slicc = SLICC(debug=True)
1052152SN/A    files = [str(s) for s in source[1:]]
1062766Sktlim@umich.edu    slicc.load(files, verbose=False)
1072766Sktlim@umich.edu
1082766Sktlim@umich.edu    print "SLICC Generator pass 1..."
1092766Sktlim@umich.edu    slicc.findMachines()
1102766Sktlim@umich.edu
1112152SN/A    print "SLICC Generator pass 2..."
1122152SN/A    slicc.generate()
1132152SN/A
1142155SN/A    print "SLICC writing C++ files..."
1152152SN/A    slicc.writeCodeFiles(pdir)
1162152SN/A
1172718Sstever@eecs.umich.edu    print "SLICC writing HTML files..."
1182921Sktlim@umich.edu    slicc.writeHTMLFiles(hdir)
1192921Sktlim@umich.edu
1202921Sktlim@umich.eduslicc_builder = Builder(action=slicc_action, emitter=slicc_emitter)
1212921Sktlim@umich.edu
1222921Sktlim@umich.eduprotocol = env['PROTOCOL']
1232921Sktlim@umich.edusources = [ protocol_dir.File("RubySlicc_interfaces.slicc"),
1242921Sktlim@umich.edu            protocol_dir.File("%s.slicc" % protocol) ]
1252921Sktlim@umich.edu
1262921Sktlim@umich.eduenv.Append(BUILDERS={'SLICC' : slicc_builder})
1272152SN/Anodes = env.SLICC([], [ Value(protocol) ] + sources)
1282152SN/Aenv.Depends(nodes, slicc_depends)
129
130for f in nodes:
131    s = str(f)
132    if s.endswith('.cc'):
133        Source(f)
134    elif s.endswith('.py'):
135        SimObject(f)
136
137