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