@classmethod<EOL><INDENT>def from_dict(cls, d):<DEDENT>
main_memory = MainMemory()<EOL>caches = {}<EOL>referred_caches = set()<EOL>for name, conf in d.items():<EOL><INDENT>caches[name] = Cache(name=name,<EOL>**{k: v for k, v in conf.items()<EOL>if k not in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']})<EOL>if '<STR_LIT>' in conf:<EOL><INDENT>referred_caches.add(conf['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT>' in conf:<EOL><INDENT>referred_caches.add(conf['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT>' in conf:<EOL><INDENT>referred_caches.add(conf['<STR_LIT>'])<EOL><DEDENT><DEDENT>for name, conf in d.items():<EOL><INDENT>if '<STR_LIT>' in conf and conf['<STR_LIT>'] is not None:<EOL><INDENT>caches[name].set_store_to(caches[conf['<STR_LIT>']])<EOL><DEDENT>if '<STR_LIT>' in conf and conf['<STR_LIT>'] is not None:<EOL><INDENT>caches[name].set_load_from(caches[conf['<STR_LIT>']])<EOL><DEDENT>if '<STR_LIT>' in conf and conf['<STR_LIT>'] is not None:<EOL><INDENT>caches[name].set_victims_to(caches[conf['<STR_LIT>']])<EOL><DEDENT><DEDENT>first_level = set(d.keys()) - referred_caches<EOL>assert len(first_level) == <NUM_LIT:1>, "<STR_LIT>"<EOL>first_level = caches[list(first_level)[<NUM_LIT:0>]]<EOL>last_level_load = c = first_level<EOL>while c is not None:<EOL><INDENT>last_level_load = c<EOL>c = c.load_from<EOL><DEDENT>assert last_level_load is not None, "<STR_LIT>"<EOL>last_level_store = c = first_level<EOL>while c is not None:<EOL><INDENT>last_level_store = c<EOL>c = c.store_to<EOL><DEDENT>assert last_level_store is not None, "<STR_LIT>"<EOL>main_memory.load_to(last_level_load)<EOL>main_memory.store_from(last_level_store)<EOL>return cls(first_level, main_memory), caches, main_memory<EOL>
Create cache hierarchy from dictionary.