SConscript revision 2152
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2006 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu 294762Snate@binkert.orgimport os.path 30955SN/A 315522Snate@binkert.org# Import build environment variable from SConstruct. 326143Snate@binkert.orgImport('env') 334762Snate@binkert.org 345522Snate@binkert.org# Right now there are no source files immediately in this directory 35955SN/Asources = [] 365522Snate@binkert.org 37955SN/A################################################################# 385522Snate@binkert.org# 394202Sbinkertn@umich.edu# ISA "switch header" generation. 405742Snate@binkert.org# 41955SN/A# Auto-generate arch headers that include the right ISA-specific 424381Sbinkertn@umich.edu# header based on the setting of THE_ISA preprocessor variable. 434381Sbinkertn@umich.edu# 44955SN/A################################################################# 45955SN/A 46955SN/A# List of headers to generate 474202Sbinkertn@umich.eduisa_switch_hdrs = Split(''' 48955SN/A isa_traits.hh 494382Sbinkertn@umich.edu ''') 504382Sbinkertn@umich.edu 514382Sbinkertn@umich.edu# Generate the header. target[0] is the full path of the output 526654Snate@binkert.org# header to generate. 'source' is a dummy variable, since we get the 535517Snate@binkert.org# list of ISAs from env['ALL_ISA_LIST']. 546143Snate@binkert.orgdef gen_switch_hdr(target, source, env): 556143Snate@binkert.org fname = str(target[0]) 566143Snate@binkert.org basename = os.path.basename(fname) 576143Snate@binkert.org f = open(fname, 'w') 586143Snate@binkert.org f.write('#include "arch/isa_specific.hh"\n') 596143Snate@binkert.org cond = '#if' 606143Snate@binkert.org for isa in env['ALL_ISA_LIST']: 616143Snate@binkert.org f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 626143Snate@binkert.org % (cond, isa.upper(), isa, basename)) 636143Snate@binkert.org cond = '#elif' 646143Snate@binkert.org f.write('#else\n#error "THE_ISA not set"\n#endif\n') 656143Snate@binkert.org f.close() 666143Snate@binkert.org return 0 676143Snate@binkert.org 686143Snate@binkert.org# String to print when generating header 694762Snate@binkert.orgdef gen_switch_hdr_string(target, source, env): 706143Snate@binkert.org return "Generating ISA switch header " + str(target[0]) 716143Snate@binkert.org 726143Snate@binkert.org# Build SCons Action object. 'varlist' specifies env vars that this 736143Snate@binkert.org# action depdnds on; when env['ALL_ISA_LIST'] changes these actions 746143Snate@binkert.org# should get re-executed. 756143Snate@binkert.orgswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 766143Snate@binkert.org varlist=['ALL_ISA_LIST']) 776143Snate@binkert.org 786143Snate@binkert.org# Instantiate actions for each header 796143Snate@binkert.orgfor hdr in isa_switch_hdrs: 806143Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 816143Snate@binkert.org 826143Snate@binkert.org################################################################# 836143Snate@binkert.org# 846143Snate@binkert.org# Include architecture-specific files. 856143Snate@binkert.org# 866143Snate@binkert.org################################################################# 876143Snate@binkert.org 886143Snate@binkert.org# 896143Snate@binkert.org# Build a SCons scanner for ISA files 906143Snate@binkert.org# 917065Snate@binkert.orgimport SCons.Scanner 926143Snate@binkert.org 936143Snate@binkert.orgdef ISAScan(): 946143Snate@binkert.org return SCons.Scanner.Classic("ISAScan", 956143Snate@binkert.org "$ISASUFFIXES", 966143Snate@binkert.org "SRCDIR", 976143Snate@binkert.org '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"') 986143Snate@binkert.org 996143Snate@binkert.orgdef ISAPath(env, dir, target=None, source=None, a=None): 1006143Snate@binkert.org return (Dir(env['SRCDIR']), Dir('.')) 1016143Snate@binkert.org 1026143Snate@binkert.orgiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"], 1036143Snate@binkert.org path_function = ISAPath) 1046143Snate@binkert.orgenv.Append(SCANNERS = iscan) 1056143Snate@binkert.org 1066143Snate@binkert.org# 1076143Snate@binkert.org# Now create a Builder object that uses isa_parser.py to generate C++ 1086143Snate@binkert.org# output from the ISA description (*.isa) files. 1096143Snate@binkert.org# 1106143Snate@binkert.org 1116143Snate@binkert.org# several files are generated from the ISA description 1126143Snate@binkert.orgisa_desc_gen_files = Split(''' 1135522Snate@binkert.org decoder.cc 1146143Snate@binkert.org alpha_o3_exec.cc 1156143Snate@binkert.org fast_cpu_exec.cc 1166143Snate@binkert.org simple_cpu_exec.cc 1176143Snate@binkert.org full_cpu_exec.cc 1186143Snate@binkert.org decoder.hh 1196143Snate@binkert.org ''') 1206143Snate@binkert.org 1216143Snate@binkert.org# Convert to File node to fix path 1226143Snate@binkert.orgisa_parser = File('isa_parser.py') 1236143Snate@binkert.org 1245522Snate@binkert.org# The emitter patches up the sources & targets to include the 1255522Snate@binkert.org# autogenerated files as targets and isa parser itself as a source. 1265522Snate@binkert.orgdef isa_desc_emitter(target, source, env): 1275522Snate@binkert.org return (isa_desc_gen_files, [isa_parser] + source) 1285604Snate@binkert.org 1295604Snate@binkert.org# Pieces are in place, so create the builder. 1306143Snate@binkert.orgisa_desc_builder = Builder(action='${SOURCES[0]} ${SOURCES[1]} $TARGET.dir', 1316143Snate@binkert.org source_scanner = iscan, 1324762Snate@binkert.org emitter = isa_desc_emitter) 1334762Snate@binkert.org 1346143Snate@binkert.orgenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1356727Ssteve.reinhardt@amd.com 1366727Ssteve.reinhardt@amd.com# 1376727Ssteve.reinhardt@amd.com# Now include other ISA-specific sources from the ISA subdirectories. 1384762Snate@binkert.org# 1396143Snate@binkert.org 1406143Snate@binkert.orgisa = env['TARGET_ISA'] # someday this may be a list of ISAs 1416143Snate@binkert.org 1426143Snate@binkert.org# Let the target architecture define what additional sources it needs 1436727Ssteve.reinhardt@amd.comsources += SConscript(os.path.join(isa, 'SConscript'), 1446143Snate@binkert.org exports = 'env', duplicate = False) 1456143Snate@binkert.org 1466143Snate@binkert.orgReturn('sources') 1475604Snate@binkert.org