3 # Copyright (c) 2006 The Regents of The University of Michigan
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met: redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer;
10 # redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution;
13 # neither the name of the copyright holders nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # Authors: Steve Reinhardt
37 #################################################################
39 # ISA "switch header" generation.
41 # Auto-generate arch headers that include the right ISA-specific
42 # header based on the setting of THE_ISA preprocessor variable.
44 #################################################################
46 # List of headers to generate
47 isa_switch_hdrs = Split('''
68 # Set up this directory to support switching headers
69 make_switching_dir('arch', isa_switch_hdrs, env)
71 #################################################################
73 # Include architecture-specific files.
75 #################################################################
78 # Build a SCons scanner for ISA files
82 isa_scanner = SCons.Scanner.Classic("ISAScan",
85 r'^\s*##include\s+"([\w/.-]*)"')
87 env.Append(SCANNERS = isa_scanner)
90 # Now create a Builder object that uses isa_parser.py to generate C++
91 # output from the ISA description (*.isa) files.
94 isa_parser = File('isa_parser.py')
96 # The emitter patches up the sources & targets to include the
97 # autogenerated files as targets and isa parser itself as a source.
98 def isa_desc_emitter(target, source, env):
99 # List the isa parser as a source.
102 Value("ExecContext"),
105 # Specify different targets depending on if we're running the ISA
106 # parser for its dependency information, or for the generated files.
107 # (As an optimization, the ISA parser detects the useless second run
108 # and skips doing any work, if the first run was performed, since it
109 # always generates all its files). The way we track this in SCons is the
110 # <arch>_isa_outputs value in the environment (env). If it's unset, we
111 # don't know what the dependencies are so we ask for generated/inc.d to
112 # be generated so they can be acquired. If we know what they are, then
113 # it's because we've already processed inc.d and then claim that our
114 # outputs (targets) will be thus.
115 isa = env['TARGET_ISA']
116 key = '%s_isa_outputs' % isa
118 targets = [ os.path.join('generated', f) for f in env[key] ]
120 targets = [ os.path.join('generated','inc.d') ]
123 return os.path.join(target[0].dir.up().abspath, s)
125 return [ prefix(t) for t in targets ], source
129 # import ply here because SCons screws with sys.path when performing actions.
132 def isa_desc_action_func(target, source, env):
133 # Add the current directory to the system path so we can import files
134 sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ]
137 # Skip over the ISA description itself and the parser to the CPU models.
138 models = [ s.get_contents() for s in source[2:] ]
139 parser = isa_parser.ISAParser(target[0].dir.abspath)
140 parser.parse_isa_desc(source[0].abspath)
141 isa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1))
143 # Also include the CheckerCPU as one of the models if it is being
144 # enabled via command line.
145 isa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter)
147 env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
149 # The ISA is generated twice: the first time to find out what it generates,
150 # and the second time to make scons happy by telling the ISADesc builder
151 # what it will make before it builds it.
152 def scan_isa_deps(target, source, env):
153 # Process dependency file generated by the ISA parser --
154 # add the listed files to the dependency tree of the build.
156 archbase = source.dir.up().path
159 depfile = open(source.abspath, 'r')
161 print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \
162 (source.path,os.getcwd())
165 # Scan through the lines
168 # Read the dependency line with the format
169 # <target file>: [ <dependent file>* ]
170 m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line)
172 targ, extn = m.group(1,2)
173 deps = m.group(3).split()
175 files = [ targ ] + deps
178 # Eliminate unnecessary re-generation if we already generated it
179 env.Precious(os.path.join(archbase, 'generated', f))
181 files = [ os.path.join(archbase, 'generated', f) for f in files ]
184 Source(os.path.join(archbase,'generated', targ))
186 env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys()
188 isa = env.ISADesc(os.path.join(archbase,'isa','main.isa'))
190 env.Depends('#all-isas', isa)
192 env.Append(BUILDERS = {'ScanISA' :
193 Builder(action=MakeAction(scan_isa_deps,
194 Transform("NEW DEPS", 1)))})
197 DebugFlag('FloatRegs')
199 DebugFlag('MiscRegs')
200 CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])