def levels(self, with_mem=True):
p = self.first_level<EOL>while p is not None:<EOL><INDENT>yield p<EOL>if p.victims_to is not None and p.victims_to != p.load_from:<EOL><INDENT>yield p.victims_to<EOL><DEDENT>if p.store_to is not None and p.store_to != p.load_from and p.store_to != p.victims_to:<EOL><INDENT>yield p.store_to<EOL><DEDENT>p = p.load_from<EOL><DEDENT>if with_mem:<EOL><INDENT>yield self.main_memory<EOL><DEDENT>
Return cache levels, optionally including main memory.