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