SConscript revision 6714:028047200ff7
12SN/A# -*- mode:python -*-
21762SN/A
32SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
42SN/A# All rights reserved.
52SN/A#
62SN/A# Redistribution and use in source and binary forms, with or without
72SN/A# modification, are permitted provided that the following conditions are
82SN/A# met: redistributions of source code must retain the above copyright
92SN/A# notice, this list of conditions and the following disclaimer;
102SN/A# redistributions in binary form must reproduce the above copyright
112SN/A# notice, this list of conditions and the following disclaimer in the
122SN/A# documentation and/or other materials provided with the distribution;
132SN/A# neither the name of the copyright holders nor the names of its
142SN/A# contributors may be used to endorse or promote products derived from
152SN/A# this software without specific prior written permission.
162SN/A#
172SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272665SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665SN/A#
292SN/A# Authors: Nathan Binkert
302SN/A
312SN/Aimport os
322SN/Aimport sys
332SN/A
342SN/Afrom os.path import isdir, isfile, join as joinpath
352SN/A
3611263Sandreas.sandberg@arm.comImport('*')
3711263Sandreas.sandberg@arm.com
382SN/Aif not env['RUBY']:
392SN/A    Return()
402SN/A
4111263Sandreas.sandberg@arm.comprotocol_dir = Dir('.')
422SN/Ahtml_dir = Dir('html')
432SN/Aslicc_dir = Dir('../slicc')
442SN/A
452SN/Asys.path[1:1] = [ Dir('..').srcnode().abspath ]
462SN/Afrom slicc.parser import SLICC
472SN/A
484981SN/Aslicc_depends = []
492SN/Afor root,dirs,files in os.walk(slicc_dir.srcnode().abspath):
502SN/A    for f in files:
514981SN/A        if f.endswith('.py'):
522SN/A            slicc_depends.append(File(joinpath(root, f)))
532SN/A
542SN/A#
554981SN/A# Use SLICC
564981SN/A#
572SN/A
582SN/Adef slicc_scanner(node, env, path):
594981SN/A    contents = node.get_contents()
604981SN/A    files = [ line.strip() for line in contents.splitlines() ]
614981SN/A    return files
622SN/A
634981SN/Aenv.Append(SCANNERS=Scanner(function=slicc_scanner,skeys=['.slicc']))
641152SN/A
652SN/Adef slicc_emitter(target, source, env):
662SN/A    files = [s.srcnode().abspath for s in source[1:]]
671152SN/A    slicc = SLICC(debug=True)
682566SN/A    print "SLICC parsing..."
691152SN/A    for name in slicc.load(files, verbose=True):
702566SN/A        print "    %s" % name
714419SN/A
724419SN/A    target.extend(sorted(slicc.files()))
734419SN/A    return target, source
742SN/A
752SN/Adef slicc_action(target, source, env):
7611263Sandreas.sandberg@arm.com    protocol = source[0].get_contents()
77    pdir = str(protocol_dir)
78    hdir = str(html_dir)
79
80    if not isdir(pdir):
81        os.mkdir(pdir)
82    if not isdir(hdir):
83        os.mkdir(hdir)
84
85    slicc = SLICC(debug=True)
86    files = [str(s) for s in source[1:]]
87    slicc.load(files, verbose=False)
88
89    print "SLICC Generator pass 1..."
90    slicc.findMachines()
91
92    print "SLICC Generator pass 2..."
93    slicc.generate()
94
95    print "SLICC writing C++ files..."
96    slicc.writeCodeFiles(pdir)
97
98    print "SLICC writing HTML files..."
99    slicc.writeHTMLFiles(hdir)
100
101slicc_builder = Builder(action=slicc_action, emitter=slicc_emitter)
102
103protocol = env['PROTOCOL']
104sources = [ protocol_dir.File("RubySlicc_interfaces.slicc"),
105            protocol_dir.File("%s.slicc" % protocol) ]
106
107env.Append(BUILDERS={'SLICC' : slicc_builder})
108nodes = env.SLICC([], [ Value(protocol) ] + sources)
109env.Depends(nodes, slicc_depends)
110
111for f in sorted(s for s in nodes if str(s).endswith('.cc')):
112    Source(f)
113