BPConfig.py (13774:a1be2a0c55f2) BPConfig.py (13958:1945df12e5b0)
1# Copyright (c) 2018 Metempsy Technology Consulting
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

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

81def bp_names():
82 """Return a list of valid Branch Predictor names."""
83 return list(_bp_classes.keys())
84
85# Add all BPs in the object hierarchy.
86for name, cls in inspect.getmembers(m5.objects, is_bp_class):
87 _bp_classes[name] = cls
88
1# Copyright (c) 2018 Metempsy Technology Consulting
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

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

81def bp_names():
82 """Return a list of valid Branch Predictor names."""
83 return list(_bp_classes.keys())
84
85# Add all BPs in the object hierarchy.
86for name, cls in inspect.getmembers(m5.objects, is_bp_class):
87 _bp_classes[name] = cls
88
89
90# The same for indirect branch predictors...
91# Dictionary of mapping names of real branch predictor models to classes.
92_indirect_bp_classes = {}
93
94
95def is_indirect_bp_class(cls):
96 """Determine if a class is an indirect branch predictor that can be
97 instantiated"""
98
99 # We can't use the normal inspect.isclass because the ParamFactory
100 # and ProxyFactory classes have a tendency to confuse it.
101 try:
102 return issubclass(cls, m5.objects.IndirectPredictor) and \
103 not cls.abstract
104 except (TypeError, AttributeError):
105 return False
106
107def get_indirect(name):
108 """Get an Indirect BP class from a user provided class name or alias."""
109
110 try:
111 indirect_bp_class = _indirect_bp_classes[name]
112 return indirect_bp_class
113 except KeyError:
114 print("%s is not a valid indirect BP model." % (name,))
115 sys.exit(1)
116
117def print_indirect_bp_list():
118 """Print a list of available indirect BP classes."""
119
120 print("Available Indirect BranchPredictor classes:")
121 doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t")
122 for name, cls in _indirect_bp_classes.items():
123 print("\t%s" % name)
124
125 # Try to extract the class documentation from the class help
126 # string.
127 doc = inspect.getdoc(cls)
128 if doc:
129 for line in doc_wrapper.wrap(doc):
130 print(line)
131
132def indirect_bp_names():
133 """Return a list of valid Indirect Branch Predictor names."""
134 return _indirect_bp_classes.keys()
135
136# Add all indirect BPs in the object hierarchy.
137for name, cls in inspect.getmembers(m5.objects, is_indirect_bp_class):
138 _indirect_bp_classes[name] = cls
139