Fix SCons version check.
[gem5.git] / src / base / traceflags.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2004-2005 The Regents of The University of Michigan
4 # All rights reserved.
5 #
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.
16 #
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.
28
29 #
30 # This file generates the header and source files for the flags
31 # that control the tracing facility.
32 #
33
34 import sys
35
36 if len(sys.argv) != 2:
37 print "%s: Need argument (basename of cc/hh files)" % sys.argv[0]
38 sys.exit(1)
39
40 hhfilename = sys.argv[1] + '.hh'
41 ccfilename = sys.argv[1] + '.cc'
42
43 #
44 # The list of trace flags that can be used to condition DPRINTFs etc.
45 # To define a new flag, simply add it to this list.
46 #
47 baseFlags = [
48 'AlphaConsole',
49 'BADADDR',
50 'BPredRAS',
51 'Bus',
52 'BusAddrRanges',
53 'BusBridge',
54 'Cache',
55 'Chains',
56 'Clock',
57 'Commit',
58 'CommitRate',
59 'Config',
60 'Console',
61 'ConsolePoll',
62 'ConsoleVerbose',
63 'Context',
64 'Cycle',
65 'DMA',
66 'DMAReadVerbose',
67 'DMAWriteVerbose',
68 'DebugPrintf',
69 'Decode',
70 'DiskImage',
71 'DiskImageRead',
72 'DiskImageWrite',
73 'DynInst',
74 'Ethernet',
75 'EthernetCksum',
76 'EthernetDMA',
77 'EthernetData',
78 'EthernetDesc',
79 'EthernetIntr',
80 'EthernetPIO',
81 'EthernetSM',
82 'Event',
83 'Fault',
84 'Fetch',
85 'Flow',
86 'FreeList',
87 'FullCPU',
88 'GDBAcc',
89 'GDBExtra',
90 'GDBMisc',
91 'GDBRead',
92 'GDBRecv',
93 'GDBSend',
94 'GDBWrite',
95 'HWPrefetch',
96 'IEW',
97 'IIC',
98 'IICMore',
99 'IPI',
100 'IQ',
101 'ISP',
102 'IdeCtrl',
103 'IdeDisk',
104 'InstExec',
105 'Interrupt',
106 'LDSTQ',
107 'Loader',
108 'MC146818',
109 'MMU',
110 'MSHR',
111 'Mbox',
112 'MemDepUnit',
113 'OoOCPU',
114 'PCEvent',
115 'PCIA',
116 'PCIDEV',
117 'PciConfigAll',
118 'Pipeline',
119 'Printf',
120 'ROB',
121 'Regs',
122 'Rename',
123 'RenameMap',
124 'SQL',
125 'Sampler',
126 'ScsiCtrl',
127 'ScsiDisk',
128 'ScsiNone',
129 'Serialize',
130 'SimpleCPU',
131 'SimpleDisk',
132 'SimpleDiskData',
133 'Sparc',
134 'Split',
135 'Stack',
136 'StatEvents',
137 'Stats',
138 'StoreSet',
139 'Syscall',
140 'SyscallVerbose',
141 'TCPIP',
142 'TLB',
143 'Thread',
144 'Timer',
145 'Tsunami',
146 'Uart',
147 'VtoPhys',
148 'WriteBarrier',
149 ]
150
151 #
152 # "Compound" flags correspond to a set of base flags. These exist
153 # solely for convenience in setting them via the command line: if a
154 # compound flag is specified, all of the corresponding base flags are
155 # set. Compound flags cannot be used directly in DPRINTFs etc.
156 # To define a new compound flag, add a new entry to this hash
157 # following the existing examples.
158 #
159 compoundFlagMap = {
160 'GDBAll' : [ 'GDBMisc', 'GDBAcc', 'GDBRead', 'GDBWrite', 'GDBSend', 'GDBRecv', 'GDBExtra' ],
161 'ScsiAll' : [ 'ScsiDisk', 'ScsiCtrl', 'ScsiNone' ],
162 'DiskImageAll' : [ 'DiskImage', 'DiskImageRead', 'DiskImageWrite' ],
163 'EthernetAll' : [ 'Ethernet', 'EthernetPIO', 'EthernetDMA', 'EthernetData' , 'EthernetDesc', 'EthernetIntr', 'EthernetSM', 'EthernetCksum' ],
164 'EthernetNoData' : [ 'Ethernet', 'EthernetPIO', 'EthernetDesc', 'EthernetIntr', 'EthernetSM', 'EthernetCksum' ],
165 'IdeAll' : [ 'IdeCtrl', 'IdeDisk' ],
166 'FullCPUAll' : [ 'Fetch', 'Decode', 'Rename', 'IEW', 'Commit', 'IQ', 'ROB', 'FreeList', 'RenameMap', 'LDSTQ', 'StoreSet', 'MemDepUnit', 'DynInst', 'FullCPU']
167 }
168
169 #############################################################
170 #
171 # Everything below this point generates the appropriate C++
172 # declarations and definitions for the trace flags. If you are simply
173 # adding or modifying flag definitions, you should not have to change
174 # anything below.
175 #
176
177 import sys
178
179 # extract just the compound flag names into a list
180 compoundFlags = []
181 compoundFlags.extend(compoundFlagMap.keys())
182 compoundFlags.sort()
183
184 #
185 # First generate the header file. This defines the Flag enum
186 # and some extern declarations for the .cc file.
187 #
188 try:
189 hhfile = file(hhfilename, 'w')
190 except IOError, e:
191 sys.exit("can't open %s: %s" % (hhfilename, e))
192
193 # file header boilerplate
194 print >>hhfile, '''
195 /*
196 * DO NOT EDIT THIS FILE!
197 *
198 * Automatically generated from traceflags.py
199 */
200
201 #ifndef __BASE_TRACE_FLAGS_HH__
202 #define __BASE_TRACE_FLAGS_HH__
203
204 namespace Trace {
205
206 enum Flags {
207 ''',
208
209 # Generate the enum. Base flags come first, then compound flags.
210 idx = 0
211 for flag in baseFlags:
212 print >>hhfile, ' %s = %d,' % (flag, idx)
213 idx += 1
214
215 numBaseFlags = idx
216 print >>hhfile, ' NumFlags = %d,' % idx
217
218 # put a comment in here to separate base from compound flags
219 print >>hhfile, '''
220 // The remaining enum values are *not* valid indices for Trace::flags.
221 // They are "compound" flags, which correspond to sets of base
222 // flags, and are used only by TraceParamContext::setFlags().
223 ''',
224
225 for flag in compoundFlags:
226 print >>hhfile, ' %s = %d,' % (flag, idx)
227 idx += 1
228
229 numCompoundFlags = idx - numBaseFlags
230 print >>hhfile, ' NumCompoundFlags = %d' % numCompoundFlags
231
232 # trailer boilerplate
233 print >>hhfile, '''\
234 }; // enum Flags
235
236 // Array of strings for SimpleEnumParam
237 extern const char *flagStrings[];
238 extern const int numFlagStrings;
239
240 // Array of arraay pointers: for each compound flag, gives the list of
241 // base flags to set. Inidividual flag arrays are terminated by -1.
242 extern const Flags *compoundFlags[];
243
244 /* namespace Trace */ }
245
246 #endif // __BASE_TRACE_FLAGS_HH__
247 ''',
248
249 hhfile.close()
250
251 #
252 #
253 # Print out .cc file with array definitions.
254 #
255 #
256 try:
257 ccfile = file(ccfilename, 'w')
258 except OSError, e:
259 sys.exit("can't open %s: %s" % (ccfilename, e))
260
261 # file header
262 print >>ccfile, '''
263 /*
264 * DO NOT EDIT THIS FILE!
265 *
266 * Automatically generated from traceflags.pl.
267 */
268
269 #include "base/traceflags.hh"
270
271 using namespace Trace;
272
273 const char *Trace::flagStrings[] =
274 {
275 ''',
276
277 # The string array is used by SimpleEnumParam to map the strings
278 # provided by the user to enum values.
279 for flag in baseFlags:
280 print >>ccfile, ' "%s",' % flag
281
282 for flag in compoundFlags:
283 print >>ccfile, ' "%s",' % flag
284
285 print >>ccfile, '};\n'
286
287 numFlagStrings = len(baseFlags) + len(compoundFlags);
288
289 print >>ccfile, 'const int Trace::numFlagStrings = %d;' % numFlagStrings
290 print >>ccfile
291
292 #
293 # Now define the individual compound flag arrays. There is an array
294 # for each compound flag listing the component base flags.
295 #
296
297 for flag in compoundFlags:
298 flags = compoundFlagMap[flag]
299 flags.append('(Flags)-1')
300 print >>ccfile, 'static const Flags %sMap[] =' % flag
301 print >>ccfile, '{ %s };' % (', '.join(flags))
302 print >>ccfile
303
304 #
305 # Finally the compoundFlags[] array maps the compound flags
306 # to their individual arrays/
307 #
308 print >>ccfile, 'const Flags *Trace::compoundFlags[] ='
309 print >>ccfile, '{'
310
311 for flag in compoundFlags:
312 print >>ccfile, ' %sMap,' % flag
313
314 # file trailer
315 print >>ccfile, '};'
316
317 ccfile.close()
318