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