params.py (10181:6270235e0585) params.py (10201:30a20d2072c1)
1# Copyright (c) 2012-2013 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 1026 unchanged lines hidden (view full) ---

1035 cls.cxx_type = 'Enums::%s' % name
1036
1037 super(MetaEnum, cls).__init__(name, bases, init_dict)
1038
1039 # Generate C++ class declaration for this enum type.
1040 # Note that we wrap the enum in a class/struct to act as a namespace,
1041 # so that the enum strings can be brief w/o worrying about collisions.
1042 def cxx_decl(cls, code):
1# Copyright (c) 2012-2013 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 1026 unchanged lines hidden (view full) ---

1035 cls.cxx_type = 'Enums::%s' % name
1036
1037 super(MetaEnum, cls).__init__(name, bases, init_dict)
1038
1039 # Generate C++ class declaration for this enum type.
1040 # Note that we wrap the enum in a class/struct to act as a namespace,
1041 # so that the enum strings can be brief w/o worrying about collisions.
1042 def cxx_decl(cls, code):
1043 name = cls.__name__
1043 wrapper_name = cls.wrapper_name
1044 wrapper = 'struct' if cls.wrapper_is_struct else 'namespace'
1045 name = cls.__name__ if cls.enum_name is None else cls.enum_name
1046 idem_macro = '__ENUM__%s__%s__' % (wrapper_name, name)
1047
1044 code('''\
1048 code('''\
1045#ifndef __ENUM__${name}__
1046#define __ENUM__${name}__
1049#ifndef $idem_macro
1050#define $idem_macro
1047
1051
1048namespace Enums {
1052$wrapper $wrapper_name {
1049 enum $name {
1050''')
1051 code.indent(2)
1052 for val in cls.vals:
1053 code('$val = ${{cls.map[val]}},')
1054 code('Num_$name = ${{len(cls.vals)}}')
1055 code.dedent(2)
1053 enum $name {
1054''')
1055 code.indent(2)
1056 for val in cls.vals:
1057 code('$val = ${{cls.map[val]}},')
1058 code('Num_$name = ${{len(cls.vals)}}')
1059 code.dedent(2)
1056 code('''\
1057 };
1058extern const char *${name}Strings[Num_${name}];
1059}
1060 code(' };')
1060
1061
1061#endif // __ENUM__${name}__
1062''')
1062 if cls.wrapper_is_struct:
1063 code(' static const char *${name}Strings[Num_${name}];')
1064 code('};')
1065 else:
1066 code('extern const char *${name}Strings[Num_${name}];')
1067 code('}')
1063
1068
1069 code()
1070 code('#endif // $idem_macro')
1071
1064 def cxx_def(cls, code):
1072 def cxx_def(cls, code):
1065 name = cls.__name__
1066 code('''\
1067#include "enums/$name.hh"
1068namespace Enums {
1069 const char *${name}Strings[Num_${name}] =
1070 {
1071''')
1072 code.indent(2)
1073 wrapper_name = cls.wrapper_name
1074 file_name = cls.__name__
1075 name = cls.__name__ if cls.enum_name is None else cls.enum_name
1076
1077 code('#include "enums/$file_name.hh"')
1078 if cls.wrapper_is_struct:
1079 code('const char *${wrapper_name}::${name}Strings'
1080 '[Num_${name}] =')
1081 else:
1082 code('namespace Enums {')
1083 code.indent(1)
1084 code(' const char *${name}Strings[Num_${name}] =')
1085
1086 code('{')
1087 code.indent(1)
1073 for val in cls.vals:
1074 code('"$val",')
1088 for val in cls.vals:
1089 code('"$val",')
1075 code.dedent(2)
1076 code('''
1077 };
1078} // namespace Enums
1079''')
1090 code.dedent(1)
1091 code('};')
1080
1092
1093 if not cls.wrapper_is_struct:
1094 code('} // namespace $wrapper_name')
1095 code.dedent(1)
1096
1081 def swig_decl(cls, code):
1082 name = cls.__name__
1083 code('''\
1084%module(package="m5.internal") enum_$name
1085
1086%{
1087#include "enums/$name.hh"
1088%}
1089
1090%include "enums/$name.hh"
1091''')
1092
1093
1094# Base class for enum types.
1095class Enum(ParamValue):
1096 __metaclass__ = MetaEnum
1097 vals = []
1098
1097 def swig_decl(cls, code):
1098 name = cls.__name__
1099 code('''\
1100%module(package="m5.internal") enum_$name
1101
1102%{
1103#include "enums/$name.hh"
1104%}
1105
1106%include "enums/$name.hh"
1107''')
1108
1109
1110# Base class for enum types.
1111class Enum(ParamValue):
1112 __metaclass__ = MetaEnum
1113 vals = []
1114
1115 # The name of the wrapping namespace or struct
1116 wrapper_name = 'Enums'
1117
1118 # If true, the enum is wrapped in a struct rather than a namespace
1119 wrapper_is_struct = False
1120
1121 # If not None, use this as the enum name rather than this class name
1122 enum_name = None
1123
1099 def __init__(self, value):
1100 if value not in self.map:
1101 raise TypeError, "Enum param got bad value '%s' (not in %s)" \
1102 % (value, self.vals)
1103 self.value = value
1104
1105 @classmethod
1106 def cxx_predecls(cls, code):

--- 540 unchanged lines hidden ---
1124 def __init__(self, value):
1125 if value not in self.map:
1126 raise TypeError, "Enum param got bad value '%s' (not in %s)" \
1127 % (value, self.vals)
1128 self.value = value
1129
1130 @classmethod
1131 def cxx_predecls(cls, code):

--- 540 unchanged lines hidden ---