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