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