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