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