summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorAndrew Bardsley <Andrew.Bardsley@arm.com>2014-05-09 18:58:47 -0400
committerAndrew Bardsley <Andrew.Bardsley@arm.com>2014-05-09 18:58:47 -0400
commitbf78299f04f0a99a72a4a2977777ee67877784cb (patch)
tree3383e056aaf54fd4707cab9b005556f2beeb58b8 /src/python
parent8087d2622d4c7c55def5a0f2daec4be951f1929b (diff)
downloadgem5-bf78299f04f0a99a72a4a2977777ee67877784cb.tar.xz
cpu: Add flag name printing to StaticInst
This patch adds a the member function StaticInst::printFlags to allow all of an instruction's flags to be printed without using the individual is... member functions or resorting to exposing the 'flags' vector It also replaces the enum definition StaticInst::Flags with a Python-generated enumeration and adds to the enum generation mechanism in src/python/m5/params.py to allow Enums to be placed in namespaces other than Enums or, alternatively, in wrapper structs allowing them to be inherited by other classes (so populating that class's name-space with the enumeration element names).
Diffstat (limited to 'src/python')
-rw-r--r--src/python/m5/params.py71
1 files changed, 48 insertions, 23 deletions
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index 470b94754..ad06e5309 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -1040,12 +1040,16 @@ class MetaEnum(MetaParamValue):
# Note that we wrap the enum in a class/struct to act as a namespace,
# so that the enum strings can be brief w/o worrying about collisions.
def cxx_decl(cls, code):
- name = cls.__name__
+ wrapper_name = cls.wrapper_name
+ wrapper = 'struct' if cls.wrapper_is_struct else 'namespace'
+ name = cls.__name__ if cls.enum_name is None else cls.enum_name
+ idem_macro = '__ENUM__%s__%s__' % (wrapper_name, name)
+
code('''\
-#ifndef __ENUM__${name}__
-#define __ENUM__${name}__
+#ifndef $idem_macro
+#define $idem_macro
-namespace Enums {
+$wrapper $wrapper_name {
enum $name {
''')
code.indent(2)
@@ -1053,30 +1057,42 @@ namespace Enums {
code('$val = ${{cls.map[val]}},')
code('Num_$name = ${{len(cls.vals)}}')
code.dedent(2)
- code('''\
- };
-extern const char *${name}Strings[Num_${name}];
-}
+ code(' };')
-#endif // __ENUM__${name}__
-''')
+ if cls.wrapper_is_struct:
+ code(' static const char *${name}Strings[Num_${name}];')
+ code('};')
+ else:
+ code('extern const char *${name}Strings[Num_${name}];')
+ code('}')
+
+ code()
+ code('#endif // $idem_macro')
def cxx_def(cls, code):
- name = cls.__name__
- code('''\
-#include "enums/$name.hh"
-namespace Enums {
- const char *${name}Strings[Num_${name}] =
- {
-''')
- code.indent(2)
+ wrapper_name = cls.wrapper_name
+ file_name = cls.__name__
+ name = cls.__name__ if cls.enum_name is None else cls.enum_name
+
+ code('#include "enums/$file_name.hh"')
+ if cls.wrapper_is_struct:
+ code('const char *${wrapper_name}::${name}Strings'
+ '[Num_${name}] =')
+ else:
+ code('namespace Enums {')
+ code.indent(1)
+ code(' const char *${name}Strings[Num_${name}] =')
+
+ code('{')
+ code.indent(1)
for val in cls.vals:
code('"$val",')
- code.dedent(2)
- code('''
- };
-} // namespace Enums
-''')
+ code.dedent(1)
+ code('};')
+
+ if not cls.wrapper_is_struct:
+ code('} // namespace $wrapper_name')
+ code.dedent(1)
def swig_decl(cls, code):
name = cls.__name__
@@ -1096,6 +1112,15 @@ class Enum(ParamValue):
__metaclass__ = MetaEnum
vals = []
+ # The name of the wrapping namespace or struct
+ wrapper_name = 'Enums'
+
+ # If true, the enum is wrapped in a struct rather than a namespace
+ wrapper_is_struct = False
+
+ # If not None, use this as the enum name rather than this class name
+ enum_name = None
+
def __init__(self, value):
if value not in self.map:
raise TypeError, "Enum param got bad value '%s' (not in %s)" \