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