16157Snate@binkert.org# -*- mode:python -*-
26157Snate@binkert.org
36157Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company
46157Snate@binkert.org# All rights reserved.
56157Snate@binkert.org#
66157Snate@binkert.org# Redistribution and use in source and binary forms, with or without
76157Snate@binkert.org# modification, are permitted provided that the following conditions are
86157Snate@binkert.org# met: redistributions of source code must retain the above copyright
96157Snate@binkert.org# notice, this list of conditions and the following disclaimer;
106157Snate@binkert.org# redistributions in binary form must reproduce the above copyright
116157Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
126157Snate@binkert.org# documentation and/or other materials provided with the distribution;
136157Snate@binkert.org# neither the name of the copyright holders nor the names of its
146157Snate@binkert.org# contributors may be used to endorse or promote products derived from
156157Snate@binkert.org# this software without specific prior written permission.
166157Snate@binkert.org#
176157Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186157Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196157Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206157Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216157Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226157Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236157Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246157Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256157Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266157Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276157Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286157Snate@binkert.org#
296157Snate@binkert.org# Authors: Nathan Binkert
306157Snate@binkert.org
3112563Sgabeblack@google.comfrom __future__ import print_function
3212563Sgabeblack@google.com
336157Snate@binkert.orgimport os
346157Snate@binkert.orgimport sys
356157Snate@binkert.org
366157Snate@binkert.orgfrom os.path import basename, isdir, join as joinpath
376157Snate@binkert.org
386157Snate@binkert.orgimport SCons
396157Snate@binkert.org
4012246Sgabeblack@google.comfrom gem5_scons import Transform
4112246Sgabeblack@google.com
426157Snate@binkert.orgImport('*')
436157Snate@binkert.org
4412892Sbrandon.potter@amd.comif env['PROTOCOL'] == 'None':
4512892Sbrandon.potter@amd.com    Return()
4612892Sbrandon.potter@amd.com
4710133Sandreas.hansson@arm.comDebugFlag('ProtocolTrace')
4810133Sandreas.hansson@arm.comDebugFlag('RubyCache')
4910133Sandreas.hansson@arm.comDebugFlag('RubyCacheTrace')
5010133Sandreas.hansson@arm.comDebugFlag('RubyDma')
5110133Sandreas.hansson@arm.comDebugFlag('RubyGenerated')
5210133Sandreas.hansson@arm.comDebugFlag('RubyNetwork')
5310133Sandreas.hansson@arm.comDebugFlag('RubyPort')
5410133Sandreas.hansson@arm.comDebugFlag('RubyPrefetcher')
5510133Sandreas.hansson@arm.comDebugFlag('RubyQueue')
5610133Sandreas.hansson@arm.comDebugFlag('RubySequencer')
5710133Sandreas.hansson@arm.comDebugFlag('RubySlicc')
5810133Sandreas.hansson@arm.comDebugFlag('RubySystem')
5910133Sandreas.hansson@arm.comDebugFlag('RubyTester')
6010133Sandreas.hansson@arm.comDebugFlag('RubyStats')
6110133Sandreas.hansson@arm.comDebugFlag('RubyResourceStalls')
6210133Sandreas.hansson@arm.com
6310133Sandreas.hansson@arm.comCompoundFlag('Ruby', [ 'RubyQueue', 'RubyNetwork', 'RubyTester',
6410133Sandreas.hansson@arm.com    'RubyGenerated', 'RubySlicc', 'RubySystem', 'RubyCache',
6511755Sandreas.hansson@arm.com    'RubyDma', 'RubyPort', 'RubySequencer', 'RubyCacheTrace',
6610133Sandreas.hansson@arm.com    'RubyPrefetcher'])
6710133Sandreas.hansson@arm.com
686157Snate@binkert.orgdef do_embed_text(target, source, env):
696157Snate@binkert.org    """convert a text file into a file that can be embedded in C
706157Snate@binkert.org    using an #include statement, that defines a \"const char *\" pointing
716157Snate@binkert.org    to the same text.
726157Snate@binkert.org
736157Snate@binkert.org    This is useful to embed scripts and configuration files in object files.
746157Snate@binkert.org    """
756157Snate@binkert.org
766157Snate@binkert.org    escape = [ "\'", "\"", "\\", "\?" ]
776157Snate@binkert.org
786157Snate@binkert.org    # reads the text file in, line by line, converting it to a C string
796157Snate@binkert.org    fin = open(str(source[0]), 'r')
806157Snate@binkert.org    fout = open(str(target[0]), 'w' )
816157Snate@binkert.org    fout.write("static const char *%s =\n" % source[1].get_contents());
826157Snate@binkert.org    for l in fin:
836157Snate@binkert.org        # add escape sequences for the characters in escape
846157Snate@binkert.org        fout.write("\"")
856157Snate@binkert.org        for char in l:
866157Snate@binkert.org            if char == "\n":
876157Snate@binkert.org                break
886157Snate@binkert.org            if char in escape:
896157Snate@binkert.org                fout.write("\\")
906157Snate@binkert.org                fout.write(char)
916157Snate@binkert.org            else:
926157Snate@binkert.org                fout.write(char)
936157Snate@binkert.org        fout.write("\\n\"\n");
946157Snate@binkert.org    fout.write(";\n");
956157Snate@binkert.org    fin.close()
966157Snate@binkert.org    fout.close()
976157Snate@binkert.org
986157Snate@binkert.org#
996157Snate@binkert.org# Link includes
1006157Snate@binkert.org#
10114184Sgabeblack@google.comgenerated_dir = Dir('protocol')
1026157Snate@binkert.org
1036157Snate@binkert.orgdef MakeIncludeAction(target, source, env):
1046157Snate@binkert.org    f = file(str(target[0]), 'w')
1056157Snate@binkert.org    for s in source:
10612563Sgabeblack@google.com        print('#include "%s"' % str(s.abspath), file=f)
1076157Snate@binkert.org    f.close()
1086157Snate@binkert.org
1096157Snate@binkert.orgdef MakeInclude(source):
1106157Snate@binkert.org    target = generated_dir.File(basename(source))
1118483Sgblack@eecs.umich.edu    include_action = MakeAction(MakeIncludeAction, Transform("MAKE INC", 1))
1128483Sgblack@eecs.umich.edu    env.Command(target, source, include_action)
1136157Snate@binkert.org
1146882SBrad.Beckmann@amd.comMakeInclude('slicc_interface/AbstractEntry.hh')
1156286Snate@binkert.orgMakeInclude('slicc_interface/AbstractCacheEntry.hh')
1166286Snate@binkert.orgMakeInclude('slicc_interface/Message.hh')
1178092Snilay@cs.wisc.eduMakeInclude('slicc_interface/RubyRequest.hh')
1186286Snate@binkert.org
1196286Snate@binkert.org# External types
1206157Snate@binkert.orgMakeInclude('common/Address.hh')
12111208Sjoseph.gross@amd.comMakeInclude('common/BoolVec.hh')
1226157Snate@binkert.orgMakeInclude('common/DataBlock.hh')
12311210SBrad.Beckmann@amd.comMakeInclude('common/IntVec.hh')
12410301Snilay@cs.wisc.eduMakeInclude('common/MachineID.hh')
1256157Snate@binkert.orgMakeInclude('common/NetDest.hh')
1266157Snate@binkert.orgMakeInclude('common/Set.hh')
12711307Santhony.gutierrez@amd.comMakeInclude('common/WriteMask.hh')
12810301Snilay@cs.wisc.eduMakeInclude('network/MessageBuffer.hh')
12910301Snilay@cs.wisc.eduMakeInclude('structures/CacheMemory.hh')
13010301Snilay@cs.wisc.eduMakeInclude('structures/DirectoryMemory.hh')
13110301Snilay@cs.wisc.eduMakeInclude('structures/PerfectCacheMemory.hh')
13210301Snilay@cs.wisc.eduMakeInclude('structures/PersistentTable.hh')
13311308Santhony.gutierrez@amd.comMakeInclude('structures/Prefetcher.hh')
13410301Snilay@cs.wisc.eduMakeInclude('structures/TBETable.hh')
13510301Snilay@cs.wisc.eduMakeInclude('structures/TimerTable.hh')
13611308Santhony.gutierrez@amd.comMakeInclude('structures/WireBuffer.hh')
13711308Santhony.gutierrez@amd.comMakeInclude('system/DMASequencer.hh')
13811308Santhony.gutierrez@amd.comMakeInclude('system/Sequencer.hh')
13911308Santhony.gutierrez@amd.com
14014184Sgabeblack@google.com# External types : Group "mem/ruby/protocol" : include "header.hh" to the
14114184Sgabeblack@google.com# bottom of this MakeIncludes if it is referenced as
14214184Sgabeblack@google.com# <# include "mem/ruby/protocol/header.hh"> in any file
14314184Sgabeblack@google.com# generated_dir = Dir('protocol')
14411308Santhony.gutierrez@amd.comMakeInclude('system/GPUCoalescer.hh')
14511308Santhony.gutierrez@amd.comMakeInclude('system/VIPERCoalescer.hh')
146