⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.py

📁 linux下基于c++的处理器仿真平台。具有处理器流水线
💻 PY
📖 第 1 页 / 共 5 页
字号:
# Copyright (c) 2005# The Regents of The University of Michigan# All Rights Reserved## This code is part of the M5 simulator, developed by Nathan Binkert,# Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions# from Ron Dreslinski, Dave Greene, Lisa Hsu, Kevin Lim, Ali Saidi,# and Andrew Schultz.## Permission is granted to use, copy, create derivative works and# redistribute this software and such derivative works for any# purpose, so long as the copyright notice above, this grant of# permission, and the disclaimer below appear in all copies made; and# so long as the name of The University of Michigan is not used in any# advertising or publicity pertaining to the use or distribution of# this software without specific, written prior authorization.## THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE# UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND# WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER# EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR# PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE# LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT,# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM# ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN# IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH# DAMAGES.import sysstring_data = {}def AddModule(path, name, type, filename, data):    fullpath = path    if name != '__init__':        fullpath += [name]    fullpath = '.'.join(fullpath)    string_data[fullpath] = name,type,data,path,filenameclass StringImporter:    def find_module(self, fullname, path=None):        if string_data.has_key(fullname):            name,type,data,path,filename = string_data[fullname]            if type == 'py':                return self        return None    def load_module(self, fullname):        import imp        mod = imp.new_module(fullname)        sys.modules[fullname] = mod        name,type,data,path,filename = string_data[fullname]        mod.__file__ = "<embed: %s>" % filename        mod.__loader__ = self        if name == '__init__':            mod.__path__ = path        if type == 'py':            code = compile(data, mod.__file__, "exec")            exec code in mod.__dict__        else:            raise AttributeError, "File of the wrong type!"        return modsys.meta_path.append(StringImporter())AddModule([], 'jobfile', 'py', 'm5/util/pbs/jobfile.py', '''\import sysclass ternary(object):    def __new__(cls, *args):        if len(args) > 1:            raise TypeError, \\                  '%s() takes at most 1 argument (%d given)' % \\                  (cls.__name__, len(args))        if args:            if not isinstance(args[0], (bool, ternary)):                raise TypeError, \\                      '%s() argument must be True, False, or Any' % \\                      cls.__name__            return args[0]        return super(ternary, cls).__new__(cls)    def __bool__(self):        return True    def __neg__(self):        return self    def __eq__(self, other):        return True        def __ne__(self, other):        return False    def __str__(self):        return 'Any'    def __repr__(self):        return 'Any'Any = ternary()    class Flags(dict):    def __init__(self, *args, **kwargs):        super(Flags, self).__init__()        self.update(*args, **kwargs)    def __getattr__(self, attr):        return self[attr]    def __setattr__(self, attr, value):        self[attr] = value    def __setitem__(self, item, value):        return super(Flags, self).__setitem__(item, ternary(value))    def __getitem__(self, item):        if item not in self:            return False        return super(Flags, self).__getitem__(item)    def update(self, *args, **kwargs):        for arg in args:            if isinstance(arg, Flags):                super(Flags, self).update(arg)            elif isinstance(arg, dict):                for key,val in kwargs.iteritems():                    self[key] = val            else:                raise AttributeError, \\                      'flags not of type %s or %s, but %s' % \\                      (Flags, dict, type(arg))        for key,val in kwargs.iteritems():            self[key] = val    def match(self, *args, **kwargs):        match = Flags(*args, **kwargs)        for key,value in match.iteritems():            if self[key] != value:                return False        return Truedef crossproduct(items):    if not isinstance(items, (list, tuple)):        raise AttributeError, 'crossproduct works only on sequences'    if not items:        yield None        return    current = items[0]    remainder = items[1:]    if not hasattr(current, '__iter__'):        current = [ current ]        for item in current:        for rem in crossproduct(remainder):            data = [ item ]            if rem:                data += rem            yield datadef flatten(items):    if not isinstance(items, (list, tuple)):        yield items        return    for item in items:        for flat in flatten(item):            yield flatclass Data(object):    def __init__(self, name, desc, **kwargs):        self.name = name        self.desc = desc        self.system = None        self.flags = Flags()        self.env = {}        for k,v in kwargs.iteritems():            setattr(self, k, v)    def update(self, obj):        if not isinstance(obj, Data):            raise AttributeError, "can only update from Data object"        self.env.update(obj.env)        self.flags.update(obj.flags)        if obj.system:            if self.system and self.system != obj.system:                raise AttributeError, \\                      "conflicting values for system: '%s'/'%s'" % \\                      (self.system, obj.system)            self.system = obj.system    def printinfo(self):        if self.name:            print 'name: %s' % self.name        if self.desc:            print 'desc: %s' % self.desc        if self.system:            print 'system: %s' % self.system    def printverbose(self):        print 'flags:'        keys = self.flags.keys()        keys.sort()        for key in keys:            print '    %s = %s' % (key, self.flags[key])        print 'env:'        keys = self.env.keys()        keys.sort()        for key in keys:            print '    %s = %s' % (key, self.env[key])        print    def __str__(self):        return self.nameclass Job(Data):    def __init__(self, options):        super(Job, self).__init__('', '')        self.setoptions(options)        self.checkpoint = False        opts = []        for opt in options:            cpt = opt.group.checkpoint            if not cpt:                self.checkpoint = True                continue            if isinstance(cpt, Option):                opt = cpt.clone(suboptions=False)            else:                opt = opt.clone(suboptions=False)            opts.append(opt)        if not opts:            self.checkpoint = False        if self.checkpoint:            self.checkpoint = Job(opts)    def clone(self):        return Job(self.options)    def __getattribute__(self, attr):        if attr == 'name':            names = [ ]            for opt in self.options:                if opt.name:                    names.append(opt.name)            return ':'.join(names)        if attr == 'desc':            descs = [ ]            for opt in self.options:                if opt.desc:                    descs.append(opt.desc)            return ', '.join(descs)        return super(Job, self).__getattribute__(attr)                def setoptions(self, options):        config = options[0].config        for opt in options:            if opt.config != config:                raise AttributeError, \\                      "All options are not from the same Configuration"                    self.config = config        self.groups = [ opt.group for opt in options ]        self.options = options        self.update(self.config)        for group in self.groups:            self.update(group)                        for option in self.options:            self.update(option)            if option._suboption:                self.update(option._suboption)    def printinfo(self):        super(Job, self).printinfo()        if self.checkpoint:            print 'checkpoint: %s' % self.checkpoint.name        print 'config: %s' % self.config.name        print 'groups: %s' % [ g.name for g in self.groups ]        print 'options: %s' % [ o.name for o in self.options ]        super(Job, self).printverbose()class SubOption(Data):    def __init__(self, name, desc, **kwargs):        super(SubOption, self).__init__(name, desc, **kwargs)        self.number = Noneclass Option(Data):    def __init__(self, name, desc, **kwargs):        super(Option, self).__init__(name, desc, **kwargs)        self._suboptions = []        self._suboption = None        self.number = None    def __getattribute__(self, attr):        if attr == 'name':            name = self.__dict__[attr]            if self._suboption is not None:                name = '%s:%s' % (name, self._suboption.name)            return name        if attr == 'desc':            desc = self.__dict__[attr]            if self._suboption is not None:                desc = '%s, %s' % (desc, self._suboption.desc)            return desc        return super(Option, self).__getattribute__(attr)    def suboption(self, name, desc, **kwargs):        subo = SubOption(name, desc, **kwargs)        subo.config = self.config        subo.group = self.group        subo.option = self        subo.number = len(self._suboptions)        self._suboptions.append(subo)        return subo    def clone(self, suboptions=True):        option = Option(self.__dict__['name'], self.__dict__['desc'])        option.update(self)        option.group = self.group        option.config = self.config        option.number = self.number        if suboptions:            option._suboptions.extend(self._suboptions)            option._suboption = self._suboption        return option    def subopts(self):        if not self._suboptions:            return [ self ]        subopts = []        for subo in self._suboptions:            option = self.clone()            option._suboption = subo            subopts.append(option)        return subopts    def printinfo(self):        super(Option, self).printinfo()        print 'config: %s' % self.config.name        super(Option, self).printverbose()class Group(Data):     def __init__(self, name, desc, **kwargs):        super(Group, self).__init__(name, desc, **kwargs)        self._options = []        self.checkpoint = False        self.number = None    def option(self, name, desc, **kwargs):        opt = Option(name, desc, **kwargs)        opt.config = self.config        opt.group = self        opt.number = len(self._options)        self._options.append(opt)        return opt    def options(self):        return self._options    def subopts(self):        subopts = []        for opt in self._options:            for subo in opt.subopts():

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -