SConscript revision 8881:042d509574c1
12568SN/A# -*- mode:python -*-
22568SN/A
32568SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
42568SN/A# All rights reserved.
52568SN/A#
62568SN/A# Redistribution and use in source and binary forms, with or without
72568SN/A# modification, are permitted provided that the following conditions are
82568SN/A# met: redistributions of source code must retain the above copyright
92568SN/A# notice, this list of conditions and the following disclaimer;
102568SN/A# redistributions in binary form must reproduce the above copyright
112568SN/A# notice, this list of conditions and the following disclaimer in the
122568SN/A# documentation and/or other materials provided with the distribution;
132568SN/A# neither the name of the copyright holders nor the names of its
142568SN/A# contributors may be used to endorse or promote products derived from
152568SN/A# this software without specific prior written permission.
162568SN/A#
172568SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182568SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192568SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202568SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212568SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222568SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232568SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242568SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252568SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262568SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Nathan Binkert
302568SN/A
312568SN/Aimport os
322568SN/Aimport re
332568SN/Aimport sys
342568SN/A
352568SN/Afrom os.path import isdir, isfile, join as joinpath
362568SN/A
373260Ssaidi@eecs.umich.edufrom SCons.Scanner import Classic
383260Ssaidi@eecs.umich.edu
393918Ssaidi@eecs.umich.eduImport('*')
402590SN/A
413348Sbinkertn@umich.eduif env['PROTOCOL'] == 'None':
422568SN/A    Return()
432568SN/A
444022Sstever@eecs.umich.eduprotocol_dir = Dir('.')
454022Sstever@eecs.umich.eduhtml_dir = Dir('html')
464022Sstever@eecs.umich.eduslicc_dir = Dir('../slicc')
474022Sstever@eecs.umich.edu
484022Sstever@eecs.umich.edusys.path[1:1] = [ Dir('..').srcnode().abspath ]
494022Sstever@eecs.umich.edufrom slicc.parser import SLICC
504022Sstever@eecs.umich.edu
512641Sstever@eecs.umich.eduslicc_depends = []
524022Sstever@eecs.umich.edufor root,dirs,files in os.walk(slicc_dir.srcnode().abspath):
534022Sstever@eecs.umich.edu    for f in files:
542641Sstever@eecs.umich.edu        if f.endswith('.py'):
554022Sstever@eecs.umich.edu            slicc_depends.append(File(joinpath(root, f)))
564022Sstever@eecs.umich.edu
574022Sstever@eecs.umich.edu#
584022Sstever@eecs.umich.edu# Use SLICC
594473Sstever@eecs.umich.edu#
604473Sstever@eecs.umich.eduenv['SLICC_PATH'] = str(protocol_dir)
614022Sstever@eecs.umich.eduslicc_scanner = Classic("SliccScanner", ['.sm', '.slicc'], "SLICC_PATH",
624626Sstever@eecs.umich.edu                        r'''include[ \t]["'](.*)["'];''')
634022Sstever@eecs.umich.eduenv.Append(SCANNERS=slicc_scanner)
644022Sstever@eecs.umich.edu
654626Sstever@eecs.umich.edudef slicc_emitter(target, source, env):
664022Sstever@eecs.umich.edu    assert len(source) == 1
674628Sstever@eecs.umich.edu    filepath = source[0].srcnode().abspath
684628Sstever@eecs.umich.edu
694022Sstever@eecs.umich.edu    slicc = SLICC(filepath, verbose=False)
704022Sstever@eecs.umich.edu    slicc.process()
714022Sstever@eecs.umich.edu    slicc.writeCodeFiles(protocol_dir.abspath)
724022Sstever@eecs.umich.edu    if env['SLICC_HTML']:
734022Sstever@eecs.umich.edu        slicc.writeHTMLFiles(html_dir.abspath)
744022Sstever@eecs.umich.edu
754022Sstever@eecs.umich.edu    target.extend([protocol_dir.File(f) for f in sorted(slicc.files())])
764022Sstever@eecs.umich.edu    return target, source
774022Sstever@eecs.umich.edu
784022Sstever@eecs.umich.edudef slicc_action(target, source, env):
794022Sstever@eecs.umich.edu    assert len(source) == 1
804022Sstever@eecs.umich.edu    filepath = source[0].srcnode().abspath
814022Sstever@eecs.umich.edu
824626Sstever@eecs.umich.edu    slicc = SLICC(filepath, verbose=True)
834626Sstever@eecs.umich.edu    slicc.process()
844022Sstever@eecs.umich.edu    slicc.writeCodeFiles(protocol_dir.abspath)
854022Sstever@eecs.umich.edu    if env['SLICC_HTML']:
864626Sstever@eecs.umich.edu        slicc.writeHTMLFiles(html_dir.abspath)
874022Sstever@eecs.umich.edu
884022Sstever@eecs.umich.eduslicc_builder = Builder(action=MakeAction(slicc_action, Transform("SLICC")),
894628Sstever@eecs.umich.edu                        emitter=slicc_emitter)
904628Sstever@eecs.umich.edu
914628Sstever@eecs.umich.eduprotocol = env['PROTOCOL']
924628Sstever@eecs.umich.edusources = [ protocol_dir.File("%s.slicc" % protocol) ]
934628Sstever@eecs.umich.edu
944022Sstever@eecs.umich.eduenv.Append(BUILDERS={'SLICC' : slicc_builder})
954626Sstever@eecs.umich.edunodes = env.SLICC([], sources)
964022Sstever@eecs.umich.eduenv.Depends(nodes, slicc_depends)
974022Sstever@eecs.umich.edu
984626Sstever@eecs.umich.edufor f in nodes:
994040Ssaidi@eecs.umich.edu    s = str(f)
1004626Sstever@eecs.umich.edu    if s.endswith('.cc'):
1014626Sstever@eecs.umich.edu        Source(f)
1024626Sstever@eecs.umich.edu    elif s.endswith('.py'):
1034626Sstever@eecs.umich.edu        SimObject(f)
1044626Sstever@eecs.umich.edu
1054626Sstever@eecs.umich.edu