SConscript revision 2765
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.edu# Authors: Steve Reinhardt 302155SN/A 314202Sbinkertn@umich.eduimport os.path, sys 322155SN/A 337768SAli.Saidi@ARM.com# Import build environment variable from SConstruct. 347768SAli.Saidi@ARM.comImport('env') 357768SAli.Saidi@ARM.com 362178SN/A# Right now there are no source files immediately in this directory 372178SN/Asources = [] 382178SN/A 392178SN/A################################################################# 402178SN/A# 412178SN/A# ISA "switch header" generation. 422178SN/A# 432178SN/A# Auto-generate arch headers that include the right ISA-specific 442178SN/A# header based on the setting of THE_ISA preprocessor variable. 452178SN/A# 462178SN/A################################################################# 472155SN/A 485865Sksewell@umich.edu# List of headers to generate 496181Sksewell@umich.eduisa_switch_hdrs = Split(''' 506181Sksewell@umich.edu arguments.hh 515865Sksewell@umich.edu constants.hh 523918Ssaidi@eecs.umich.edu faults.hh 535865Sksewell@umich.edu isa_traits.hh 542623SN/A process.hh 553918Ssaidi@eecs.umich.edu regfile.hh 562155SN/A stacktrace.hh 572155SN/A tlb.hh 582292SN/A types.hh 596181Sksewell@umich.edu utility.hh 606181Sksewell@umich.edu vtophys.hh 613918Ssaidi@eecs.umich.edu ''') 622292SN/A 632292SN/A# Generate the header. target[0] is the full path of the output 642292SN/A# header to generate. 'source' is a dummy variable, since we get the 653918Ssaidi@eecs.umich.edu# list of ISAs from env['ALL_ISA_LIST']. 662292SN/Adef gen_switch_hdr(target, source, env): 672292SN/A fname = str(target[0]) 682766Sktlim@umich.edu basename = os.path.basename(fname) 692766Sktlim@umich.edu f = open(fname, 'w') 702766Sktlim@umich.edu f.write('#include "arch/isa_specific.hh"\n') 712921Sktlim@umich.edu cond = '#if' 722921Sktlim@umich.edu for isa in env['ALL_ISA_LIST']: 732766Sktlim@umich.edu f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 742766Sktlim@umich.edu % (cond, isa.upper(), isa, basename)) 755529Snate@binkert.org cond = '#elif' 762766Sktlim@umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 774762Snate@binkert.org f.close() 782155SN/A return 0 792155SN/A 802155SN/A# String to print when generating header 812155SN/Adef gen_switch_hdr_string(target, source, env): 822155SN/A return "Generating ISA switch header " + str(target[0]) 832155SN/A 842766Sktlim@umich.edu# Build SCons Action object. 'varlist' specifies env vars that this 852155SN/A# action depends on; when env['ALL_ISA_LIST'] changes these actions 865865Sksewell@umich.edu# should get re-executed. 872155SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 882155SN/A varlist=['ALL_ISA_LIST']) 892155SN/A 902155SN/A# Instantiate actions for each header 912178SN/Afor hdr in isa_switch_hdrs: 922178SN/A env.Command(hdr, [], switch_hdr_action) 937756SAli.Saidi@ARM.com 942766Sktlim@umich.edu################################################################# 952178SN/A# 962178SN/A# Include architecture-specific files. 976994Snate@binkert.org# 982178SN/A################################################################# 992766Sktlim@umich.edu 1002766Sktlim@umich.edu# 1012766Sktlim@umich.edu# Build a SCons scanner for ISA files 1022788Sktlim@umich.edu# 1032178SN/Aimport SCons.Scanner 1042733Sktlim@umich.edu 1052733Sktlim@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 1062817Sksewell@umich.edu [".isa", ".ISA"], 1072733Sktlim@umich.edu "SRCDIR", 1084486Sbinkertn@umich.edu r'^\s*##include\s+"([\w/.-]*)"') 1094486Sbinkertn@umich.edu 1104776Sgblack@eecs.umich.eduenv.Append(SCANNERS = isa_scanner) 1114776Sgblack@eecs.umich.edu 1128739Sgblack@eecs.umich.edu# 1136365Sgblack@eecs.umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 1144486Sbinkertn@umich.edu# output from the ISA description (*.isa) files. 1154202Sbinkertn@umich.edu# 1164202Sbinkertn@umich.edu 1174202Sbinkertn@umich.edu# Convert to File node to fix path 1188541Sgblack@eecs.umich.eduisa_parser = File('isa_parser.py') 1194202Sbinkertn@umich.educpu_models_file = File('../cpu/cpu_models.py') 1204202Sbinkertn@umich.edu 1214776Sgblack@eecs.umich.edu# This sucks in the defintions of the CpuModel objects. 1228739Sgblack@eecs.umich.eduexecfile(cpu_models_file.srcnode().abspath) 1236365Sgblack@eecs.umich.edu 1244202Sbinkertn@umich.edu# Several files are generated from the ISA description. 1254202Sbinkertn@umich.edu# We always get the basic decoder and header file. 1264202Sbinkertn@umich.eduisa_desc_gen_files = Split('decoder.cc decoder.hh') 1274202Sbinkertn@umich.edu# We also get an execute file for each selected CPU model. 1285217Ssaidi@eecs.umich.eduisa_desc_gen_files += [CpuModel.dict[cpu].filename 1294202Sbinkertn@umich.edu for cpu in env['CPU_MODELS']] 1302155SN/A 1314202Sbinkertn@umich.edu# The emitter patches up the sources & targets to include the 1324202Sbinkertn@umich.edu# autogenerated files as targets and isa parser itself as a source. 1332821Sktlim@umich.edudef isa_desc_emitter(target, source, env): 1344776Sgblack@eecs.umich.edu return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source) 1354776Sgblack@eecs.umich.edu 1364776Sgblack@eecs.umich.edu# Pieces are in place, so create the builder. 1374776Sgblack@eecs.umich.edupython = sys.executable # use same Python binary used to run scons 1382766Sktlim@umich.eduisa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS', 1394202Sbinkertn@umich.edu emitter = isa_desc_emitter) 1408335Snate@binkert.org 1412733Sktlim@umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1422733Sktlim@umich.edu 1432733Sktlim@umich.edu# 1442733Sktlim@umich.edu# Now include other ISA-specific sources from the ISA subdirectories. 1452733Sktlim@umich.edu# 1462874Sktlim@umich.edu 1472874Sktlim@umich.eduisa = env['TARGET_ISA'] # someday this may be a list of ISAs 1482874Sktlim@umich.edu 1494202Sbinkertn@umich.edu# Let the target architecture define what additional sources it needs 1502733Sktlim@umich.edusources += SConscript(os.path.join(isa, 'SConscript'), exports = 'env') 1515192Ssaidi@eecs.umich.edu 1528335Snate@binkert.orgReturn('sources') 1538335Snate@binkert.org