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