3 # Copyright (c) 2016-2017 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.
45 from gem5_scons import Transform
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 #################################################################
76 env.subst('${TARGET_ISA}'))
85 env.subst('${TARGET_GPU_ISA}'))
87 #################################################################
89 # Include architecture-specific files.
91 #################################################################
94 # Build a SCons scanner for ISA files
99 scanner = SCons.Scanner.Classic("ISAScan",
102 r'^\s*##include\s+"([\w/.-]*)"')
104 env.Append(SCANNERS=scanner)
106 # Tell scons that when it sees a cc.inc file, it should scan it for includes.
107 SCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner)
110 # Now create a Builder object that uses isa_parser.py to generate C++
111 # output from the ISA description (*.isa) files.
114 parser_py = File('isa_parser.py')
115 micro_asm_py = File('micro_asm.py')
117 # import ply here because SCons screws with sys.path when performing actions.
120 def run_parser(target, source, env):
121 # Add the current directory to the system path so we can import files.
122 sys.path[0:0] = [ parser_py.dir.abspath ]
125 parser = isa_parser.ISAParser(target[0].dir.abspath)
126 parser.parse_isa_desc(source[0].abspath)
128 desc_action = MakeAction(run_parser, Transform("ISA DESC", 1))
130 IsaDescBuilder = Builder(action=desc_action)
133 # ISAs should use this function to set up an IsaDescBuilder and not try to
134 # set one up manually.
135 def ISADesc(desc, decoder_splits=1, exec_splits=1):
136 '''Set up a builder for an ISA description.
138 The decoder_splits and exec_splits parameters let us determine what
139 files the isa parser is actually going to generate. This needs to match
140 what files are actually generated, and there's no specific check for that
143 If the parser itself is responsible for generating a list of its products
144 and their dependencies, then using that output to set up the right
145 dependencies. This is what we used to do. The problem is that scons
146 fundamentally doesn't support using a build product to affect its graph
147 of possible products, dependencies, builders, etc. There are a couple ways
148 to work around that limitation.
150 One option is to compute dependencies while the build phase of scons is
151 running. That method can be quite complicated and cumbersome, because we
152 have to make sure our modifications are made before scons tries to
153 consume them. There's also no guarantee that this mechanism will work since
154 it subverts scons expectations and changes things behind its back. This
155 was implemented previously and constrained the builds parallelism
158 Another option would be to recursively call scons to have it update the
159 list of products/dependencies during the setup phase of this invocation of
160 scons. The problem with that is that it would be very difficult to make
161 the sub-invocation of scons observe the options passed to the primary one
162 in all possible cases, or to even determine conclusively what the name of
163 the scons executable is in the first place.
165 Possible future changes to the isa parser might make it easier to
166 determine what files it would generate, perhaps because there was a more
167 direct correspondence between input files and output files. Or, if the
168 parser could run quickly and determine what its output files would be
169 without having do actually generate those files, then it could be run
170 unconditionally without slowing down all builds or touching the output
173 generated_dir = File(desc).dir.up().Dir('generated')
175 return generated_dir.File(name)
179 gen.append(gen_file(name))
181 # Tell scons about the various files the ISA parser will generate.
182 add_gen('decoder-g.cc.inc')
183 add_gen('decoder-ns.cc.inc')
184 add_gen('decode-method.cc.inc')
186 add_gen('decoder.hh')
187 add_gen('decoder-g.hh.inc')
188 add_gen('decoder-ns.hh.inc')
190 add_gen('exec-g.cc.inc')
191 add_gen('exec-ns.cc.inc')
193 add_gen('max_inst_regs.hh')
196 # These generated files are also top level sources.
197 def source_gen(name):
199 Source(gen_file(name))
201 source_gen('decoder.cc')
203 if decoder_splits == 1:
204 source_gen('inst-constrs.cc')
206 for i in range(1, decoder_splits + 1):
207 source_gen('inst-constrs-%d.cc' % i)
210 source_gen('generic_cpu_exec.cc')
212 for i in range(1, exec_splits + 1):
213 source_gen('generic_cpu_exec_%d.cc' % i)
215 # Actually create the builder.
216 sources = [desc, parser_py, micro_asm_py]
217 IsaDescBuilder(target=gen, source=sources, env=env)
223 DebugFlag('FloatRegs')
225 DebugFlag('VecPredRegs')
227 DebugFlag('MiscRegs')
228 CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'VecRegs', 'VecPredRegs',
229 'CCRegs', 'MiscRegs' ])