Merge zizzer:/bk/linux
[gem5.git] / base / traceflags.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2004 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 hhfilename="traceflags.hh"
34 ccfilename="traceflags.cc"
35
36 #
37 # The list of trace flags that can be used to condition DPRINTFs etc.
38 # To define a new flag, simply add it to this list.
39 #
40 baseFlags = [
41 'TCPIP',
42 'Bus',
43 'ScsiDisk',
44 'ScsiCtrl',
45 'ScsiNone',
46 'DMA',
47 'DMAReadVerbose',
48 'DMAWriteVerbose',
49 'TLB',
50 'SimpleDisk',
51 'SimpleDiskData',
52 'Clock',
53 'Regs',
54 'MC146818',
55 'IPI',
56 'Timer',
57 'Mbox',
58 'PCIA',
59 'PCIDEV',
60 'PciConfigAll',
61 'ISP',
62 'BADADDR',
63 'Console',
64 'ConsolePoll',
65 'ConsoleVerbose',
66 'TlaserUart',
67 'AlphaConsole',
68 'Flow',
69 'Interrupt',
70 'Cycle',
71 'Loader',
72 'MMU',
73 'Ethernet',
74 'EthernetPIO',
75 'EthernetDMA',
76 'EthernetData',
77 'GDBMisc',
78 'GDBAcc',
79 'GDBRead',
80 'GDBWrite',
81 'GDBSend',
82 'GDBRecv',
83 'GDBExtra',
84 'VtoPhys',
85 'Printf',
86 'DebugPrintf',
87 'Serialize',
88 'Event',
89 'PCEvent',
90 'SyscallWarnings',
91 'SyscallVerbose',
92 'DiskImage',
93 'DiskImageRead',
94 'DiskImageWrite',
95 'InstExec',
96 'BPredRAS',
97 'Cache',
98 'IIC',
99 'IICMore',
100 'MSHR',
101 'Chains',
102 'Dispatch',
103 'Stats',
104 'StatEvents',
105 'Context',
106 'Config',
107 'Sampler',
108 'WriteBarrier',
109 'IdeCtrl',
110 'IdeDisk',
111 'Tsunami',
112 'TsunamiUart'
113 ]
114
115 #
116 # "Compound" flags correspond to a set of base flags. These exist
117 # solely for convenience in setting them via the command line: if a
118 # compound flag is specified, all of the corresponding base flags are
119 # set. Compound flags cannot be used directly in DPRINTFs etc.
120 # To define a new compound flag, add a new entry to this hash
121 # following the existing examples.
122 #
123 compoundFlagMap = {
124 'GDBAll' : [ 'GDBMisc', 'GDBAcc', 'GDBRead', 'GDBWrite', 'GDBSend', 'GDBRecv', 'GDBExtra' ],
125 'ScsiAll' : [ 'ScsiDisk', 'ScsiCtrl', 'ScsiNone' ],
126 'DiskImageAll' : [ 'DiskImage', 'DiskImageRead', 'DiskImageWrite' ],
127 'EthernetAll' : [ 'Ethernet', 'EthernetPIO', 'EthernetDMA', 'EthernetData' ],
128 'IdeAll' : [ 'IdeCtrl', 'IdeDisk' ]
129 }
130
131 #############################################################
132 #
133 # Everything below this point generates the appropriate C++
134 # declarations and definitions for the trace flags. If you are simply
135 # adding or modifying flag definitions, you should not have to change
136 # anything below.
137 #
138
139 import sys
140
141 # extract just the compound flag names into a list
142 compoundFlags = []
143 compoundFlags.extend(compoundFlagMap.keys())
144 compoundFlags.sort()
145
146 #
147 # First generate the header file. This defines the Flag enum
148 # and some extern declarations for the .cc file.
149 #
150 try:
151 hhfile = file(hhfilename, 'w')
152 except IOError, e:
153 sys.exit("can't open %s: %s" % (hhfilename, e))
154
155 # file header boilerplate
156 print >>hhfile, '''/* $Id $ */
157
158 /*
159 * Copyright (c) 2004
160 * The Regents of The University of Michigan
161 * All Rights Reserved
162 *
163 * This code is part of the M5 simulator, developed by Nathan Binkert,
164 * Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions
165 * from Ron Dreslinski, Dave Greene, and Lisa Hsu.
166 *
167 * Permission is granted to use, copy, create derivative works and
168 * redistribute this software and such derivative works for any
169 * purpose, so long as the copyright notice above, this grant of
170 * permission, and the disclaimer below appear in all copies made; and
171 * so long as the name of The University of Michigan is not used in
172 * any advertising or publicity pertaining to the use or distribution
173 * of this software without specific, written prior authorization.
174 *
175 * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE
176 * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND
177 * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER
178 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
179 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
180 * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE
181 * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT,
182 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM
183 * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
184 * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH
185 * DAMAGES.
186 */
187
188 /*
189 * DO NOT EDIT THIS FILE!
190 *
191 * Automatically generated from traceflags.py
192 */
193
194 #ifndef __BASE_TRACE_FLAGS_HH__
195 #define __BASE_TRACE_FLAGS_HH__
196
197 namespace Trace {
198
199 enum Flags {
200 ''',
201
202 # Generate the enum. Base flags come first, then compound flags.
203 idx = 0
204 for flag in baseFlags:
205 print >>hhfile, ' %s = %d,' % (flag, idx)
206 idx += 1
207
208 numBaseFlags = idx
209 print >>hhfile, ' NumFlags = %d,' % idx
210
211 # put a comment in here to separate base from compound flags
212 print >>hhfile, '''
213 // The remaining enum values are *not* valid indices for Trace::flags.
214 // They are "compound" flags, which correspond to sets of base
215 // flags, and are used only by TraceParamContext::setFlags().
216 ''',
217
218 for flag in compoundFlags:
219 print >>hhfile, ' %s = %d,' % (flag, idx)
220 idx += 1
221
222 numCompoundFlags = idx - numBaseFlags
223 print >>hhfile, ' NumCompoundFlags = %d' % numCompoundFlags
224
225 # trailer boilerplate
226 print >>hhfile, '''\
227 }; // enum Flags
228
229 // Array of strings for SimpleEnumParam
230 extern const char *flagStrings[];
231 extern const int numFlagStrings;
232
233 // Array of arraay pointers: for each compound flag, gives the list of
234 // base flags to set. Inidividual flag arrays are terminated by -1.
235 extern const Flags *compoundFlags[];
236
237 /* namespace Trace */ }
238
239 #endif // __BASE_TRACE_FLAGS_HH__
240 ''',
241
242 hhfile.close()
243
244 #
245 #
246 # Print out .cc file with array definitions.
247 #
248 #
249 try:
250 ccfile = file(ccfilename, 'w')
251 except OSError, e:
252 sys.exit("can't open %s: %s" % (ccfilename, e))
253
254 # file header
255 print >>ccfile, '''\
256 /* $Id $ */
257
258 /*
259 * Copyright (c) 2004
260 * The Regents of The University of Michigan
261 * All Rights Reserved
262 *
263 * This code is part of the M5 simulator, developed by Nathan Binkert,
264 * Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions
265 * from Ron Dreslinski, Dave Greene, and Lisa Hsu.
266 *
267 * Permission is granted to use, copy, create derivative works and
268 * redistribute this software and such derivative works for any
269 * purpose, so long as the copyright notice above, this grant of
270 * permission, and the disclaimer below appear in all copies made; and
271 * so long as the name of The University of Michigan is not used in
272 * any advertising or publicity pertaining to the use or distribution
273 * of this software without specific, written prior authorization.
274 *
275 * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE
276 * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND
277 * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER
278 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
279 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
280 * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE
281 * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT,
282 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM
283 * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
284 * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH
285 * DAMAGES.
286 */
287
288 /*
289 * DO NOT EDIT THIS FILE!
290 *
291 * Automatically generated from traceflags.pl.
292 */
293
294 #include "base/traceflags.hh"
295
296 using namespace Trace;
297
298 const char *Trace::flagStrings[] =
299 {
300 ''',
301
302 # The string array is used by SimpleEnumParam to map the strings
303 # provided by the user to enum values.
304 for flag in baseFlags:
305 print >>ccfile, ' "%s",' % flag
306
307 for flag in compoundFlags:
308 print >>ccfile, ' "%s",' % flag
309
310 print >>ccfile, '};\n'
311
312 numFlagStrings = len(baseFlags) + len(compoundFlags);
313
314 print >>ccfile, 'const int Trace::numFlagStrings = %d;' % numFlagStrings
315 print >>ccfile
316
317 #
318 # Now define the individual compound flag arrays. There is an array
319 # for each compound flag listing the component base flags.
320 #
321
322 for flag in compoundFlags:
323 flags = compoundFlagMap[flag]
324 flags.append('(Flags)-1')
325 print >>ccfile, 'static const Flags %sMap[] =' % flag
326 print >>ccfile, '{ %s };' % (', '.join(flags))
327 print >>ccfile
328
329 #
330 # Finally the compoundFlags[] array maps the compound flags
331 # to their individual arrays/
332 #
333 print >>ccfile, 'const Flags *Trace::compoundFlags[] ='
334 print >>ccfile, '{'
335
336 for flag in compoundFlags:
337 print >>ccfile, ' %sMap,' % flag
338
339 # file trailer
340 print >>ccfile, '};'
341
342 ccfile.close()
343