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