SConscript revision 2152
12155SN/A# -*- mode:python -*- 22155SN/A 32155SN/A# Copyright (c) 2006 The Regents of The University of Michigan 42155SN/A# All rights reserved. 52155SN/A# 62155SN/A# Redistribution and use in source and binary forms, with or without 72155SN/A# modification, are permitted provided that the following conditions are 82155SN/A# met: redistributions of source code must retain the above copyright 92155SN/A# notice, this list of conditions and the following disclaimer; 102155SN/A# redistributions in binary form must reproduce the above copyright 112155SN/A# notice, this list of conditions and the following disclaimer in the 122155SN/A# documentation and/or other materials provided with the distribution; 132155SN/A# neither the name of the copyright holders nor the names of its 142155SN/A# contributors may be used to endorse or promote products derived from 152155SN/A# this software without specific prior written permission. 162155SN/A# 172155SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192155SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212155SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222155SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232155SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242155SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252155SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262155SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272155SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.eduimport os.path 302155SN/A 314202Sbinkertn@umich.edu# Import build environment variable from SConstruct. 322155SN/AImport('env') 332178SN/A 342178SN/A# Right now there are no source files immediately in this directory 352178SN/Asources = [] 362178SN/A 372178SN/A################################################################# 382178SN/A# 392178SN/A# ISA "switch header" generation. 402178SN/A# 412178SN/A# Auto-generate arch headers that include the right ISA-specific 422178SN/A# header based on the setting of THE_ISA preprocessor variable. 432178SN/A# 442155SN/A################################################################# 455865Sksewell@umich.edu 466181Sksewell@umich.edu# List of headers to generate 476181Sksewell@umich.eduisa_switch_hdrs = Split(''' 485865Sksewell@umich.edu isa_traits.hh 493918Ssaidi@eecs.umich.edu ''') 505865Sksewell@umich.edu 512623SN/A# Generate the header. target[0] is the full path of the output 523918Ssaidi@eecs.umich.edu# header to generate. 'source' is a dummy variable, since we get the 532155SN/A# list of ISAs from env['ALL_ISA_LIST']. 542155SN/Adef gen_switch_hdr(target, source, env): 552292SN/A fname = str(target[0]) 566181Sksewell@umich.edu basename = os.path.basename(fname) 576181Sksewell@umich.edu f = open(fname, 'w') 583918Ssaidi@eecs.umich.edu f.write('#include "arch/isa_specific.hh"\n') 592292SN/A cond = '#if' 602292SN/A for isa in env['ALL_ISA_LIST']: 612292SN/A f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 623918Ssaidi@eecs.umich.edu % (cond, isa.upper(), isa, basename)) 632292SN/A cond = '#elif' 642292SN/A f.write('#else\n#error "THE_ISA not set"\n#endif\n') 652766Sktlim@umich.edu f.close() 662766Sktlim@umich.edu return 0 672766Sktlim@umich.edu 682921Sktlim@umich.edu# String to print when generating header 692921Sktlim@umich.edudef gen_switch_hdr_string(target, source, env): 702766Sktlim@umich.edu return "Generating ISA switch header " + str(target[0]) 712766Sktlim@umich.edu 725529Snate@binkert.org# Build SCons Action object. 'varlist' specifies env vars that this 732766Sktlim@umich.edu# action depdnds on; when env['ALL_ISA_LIST'] changes these actions 744762Snate@binkert.org# should get re-executed. 752155SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 762155SN/A varlist=['ALL_ISA_LIST']) 772155SN/A 782155SN/A# Instantiate actions for each header 792155SN/Afor hdr in isa_switch_hdrs: 802155SN/A env.Command(hdr, [], switch_hdr_action) 812766Sktlim@umich.edu 822155SN/A################################################################# 835865Sksewell@umich.edu# 842155SN/A# Include architecture-specific files. 852155SN/A# 862155SN/A################################################################# 872155SN/A 882178SN/A# 892178SN/A# Build a SCons scanner for ISA files 902178SN/A# 912766Sktlim@umich.eduimport SCons.Scanner 922178SN/A 932178SN/Adef ISAScan(): 946994Snate@binkert.org return SCons.Scanner.Classic("ISAScan", 952178SN/A "$ISASUFFIXES", 962766Sktlim@umich.edu "SRCDIR", 972766Sktlim@umich.edu '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"') 982766Sktlim@umich.edu 992788Sktlim@umich.edudef ISAPath(env, dir, target=None, source=None, a=None): 1002178SN/A return (Dir(env['SRCDIR']), Dir('.')) 1012733Sktlim@umich.edu 1022733Sktlim@umich.eduiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"], 1032817Sksewell@umich.edu path_function = ISAPath) 1042733Sktlim@umich.eduenv.Append(SCANNERS = iscan) 1054486Sbinkertn@umich.edu 1064486Sbinkertn@umich.edu# 1074776Sgblack@eecs.umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 1084776Sgblack@eecs.umich.edu# output from the ISA description (*.isa) files. 1096365Sgblack@eecs.umich.edu# 1104486Sbinkertn@umich.edu 1114202Sbinkertn@umich.edu# several files are generated from the ISA description 1124202Sbinkertn@umich.eduisa_desc_gen_files = Split(''' 1134202Sbinkertn@umich.edu decoder.cc 1144202Sbinkertn@umich.edu alpha_o3_exec.cc 1154202Sbinkertn@umich.edu fast_cpu_exec.cc 1164776Sgblack@eecs.umich.edu simple_cpu_exec.cc 1176365Sgblack@eecs.umich.edu full_cpu_exec.cc 1184202Sbinkertn@umich.edu decoder.hh 1194202Sbinkertn@umich.edu ''') 1204202Sbinkertn@umich.edu 1214202Sbinkertn@umich.edu# Convert to File node to fix path 1225217Ssaidi@eecs.umich.eduisa_parser = File('isa_parser.py') 1234202Sbinkertn@umich.edu 1242155SN/A# The emitter patches up the sources & targets to include the 1254202Sbinkertn@umich.edu# autogenerated files as targets and isa parser itself as a source. 1264486Sbinkertn@umich.edudef isa_desc_emitter(target, source, env): 1274486Sbinkertn@umich.edu return (isa_desc_gen_files, [isa_parser] + source) 1284202Sbinkertn@umich.edu 1294202Sbinkertn@umich.edu# Pieces are in place, so create the builder. 1302821Sktlim@umich.eduisa_desc_builder = Builder(action='${SOURCES[0]} ${SOURCES[1]} $TARGET.dir', 1314776Sgblack@eecs.umich.edu source_scanner = iscan, 1324776Sgblack@eecs.umich.edu emitter = isa_desc_emitter) 1334776Sgblack@eecs.umich.edu 1344776Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1352766Sktlim@umich.edu 1364202Sbinkertn@umich.edu# 1375192Ssaidi@eecs.umich.edu# Now include other ISA-specific sources from the ISA subdirectories. 1382733Sktlim@umich.edu# 1392733Sktlim@umich.edu 1402733Sktlim@umich.eduisa = env['TARGET_ISA'] # someday this may be a list of ISAs 1412733Sktlim@umich.edu 1422733Sktlim@umich.edu# Let the target architecture define what additional sources it needs 1432874Sktlim@umich.edusources += SConscript(os.path.join(isa, 'SConscript'), 1442874Sktlim@umich.edu exports = 'env', duplicate = False) 1452874Sktlim@umich.edu 1464202Sbinkertn@umich.eduReturn('sources') 1472733Sktlim@umich.edu