3 # Copyright (c) 2016 ARM Limited
6 # The license below extends only to copyright in the software and shall
7 # not be construed as granting a license to any other intellectual
8 # property including but not limited to intellectual property relating
9 # to a hardware implementation of the functionality of the software
10 # licensed hereunder. You may use the software subject to the license
11 # terms below provided that you ensure that this notice is replicated
12 # unmodified and in its entirety in all distributions of the software,
13 # modified or unmodified, in source code or in binary form.
15 # Copyright (c) 2006 The Regents of The University of Michigan
16 # All rights reserved.
18 # Redistribution and use in source and binary forms, with or without
19 # modification, are permitted provided that the following conditions are
20 # met: redistributions of source code must retain the above copyright
21 # notice, this list of conditions and the following disclaimer;
22 # redistributions in binary form must reproduce the above copyright
23 # notice, this list of conditions and the following disclaimer in the
24 # documentation and/or other materials provided with the distribution;
25 # neither the name of the copyright holders nor the names of its
26 # contributors may be used to endorse or promote products derived from
27 # this software without specific prior written permission.
29 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 # Authors: Steve Reinhardt
49 #################################################################
51 # ISA "switch header" generation.
53 # Auto-generate arch headers that include the right ISA-specific
54 # header based on the setting of THE_ISA preprocessor variable.
56 #################################################################
79 env.subst('${TARGET_ISA}'))
88 env.subst('${TARGET_GPU_ISA}'))
90 #################################################################
92 # Include architecture-specific files.
94 #################################################################
97 # Build a SCons scanner for ISA files
101 isa_scanner = SCons.Scanner.Classic("ISAScan",
104 r'^\s*##include\s+"([\w/.-]*)"')
106 env.Append(SCANNERS = isa_scanner)
109 # Now create a Builder object that uses isa_parser.py to generate C++
110 # output from the ISA description (*.isa) files.
113 isa_parser = File('isa_parser.py')
115 # The emitter patches up the sources & targets to include the
116 # autogenerated files as targets and isa parser itself as a source.
117 def isa_desc_emitter(target, source, env):
118 # List the isa parser as a source.
121 Value("ExecContext"),
124 # Specify different targets depending on if we're running the ISA
125 # parser for its dependency information, or for the generated files.
126 # (As an optimization, the ISA parser detects the useless second run
127 # and skips doing any work, if the first run was performed, since it
128 # always generates all its files). The way we track this in SCons is the
129 # <arch>_isa_outputs value in the environment (env). If it's unset, we
130 # don't know what the dependencies are so we ask for generated/inc.d to
131 # be generated so they can be acquired. If we know what they are, then
132 # it's because we've already processed inc.d and then claim that our
133 # outputs (targets) will be thus.
134 isa = env['TARGET_ISA']
135 key = '%s_isa_outputs' % isa
137 targets = [ os.path.join('generated', f) for f in env[key] ]
139 targets = [ os.path.join('generated','inc.d') ]
142 return os.path.join(target[0].dir.up().abspath, s)
144 return [ prefix(t) for t in targets ], source
148 # import ply here because SCons screws with sys.path when performing actions.
151 def isa_desc_action_func(target, source, env):
152 # Add the current directory to the system path so we can import files
153 sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ]
156 # Skip over the ISA description itself and the parser to the CPU models.
157 models = [ s.get_contents() for s in source[2:] ]
158 parser = isa_parser.ISAParser(target[0].dir.abspath)
159 parser.parse_isa_desc(source[0].abspath)
160 isa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1))
162 # Also include the CheckerCPU as one of the models if it is being
163 # enabled via command line.
164 isa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter)
166 env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
168 # The ISA is generated twice: the first time to find out what it generates,
169 # and the second time to make scons happy by telling the ISADesc builder
170 # what it will make before it builds it.
171 def scan_isa_deps(target, source, env):
172 # Process dependency file generated by the ISA parser --
173 # add the listed files to the dependency tree of the build.
175 archbase = source.dir.up().path
178 depfile = open(source.abspath, 'r')
180 print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \
181 (source.path,os.getcwd())
184 # Scan through the lines
187 # Read the dependency line with the format
188 # <target file>: [ <dependent file>* ]
189 m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line)
191 targ, extn = m.group(1,2)
192 deps = m.group(3).split()
194 files = [ targ ] + deps
197 # Eliminate unnecessary re-generation if we already generated it
198 env.Precious(os.path.join(archbase, 'generated', f))
200 files = [ os.path.join(archbase, 'generated', f) for f in files ]
203 Source(os.path.join(archbase,'generated', targ))
205 env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys()
207 isa = env.ISADesc(os.path.join(archbase,'isa','main.isa'))
209 env.Depends('#all-isas', isa)
211 env.Append(BUILDERS = {'ScanISA' :
212 Builder(action=MakeAction(scan_isa_deps,
213 Transform("NEW DEPS", 1)))})
216 DebugFlag('FloatRegs')
219 DebugFlag('MiscRegs')
220 CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])