From 1ba2ae76235806c8f3b4381582cba4266fd6d409 Mon Sep 17 00:00:00 2001 From: Nikos Nikoleris Date: Fri, 7 Jun 2019 13:28:07 +0100 Subject: [PATCH] configs: Add python3 workarounds in read_config Change-Id: Ib065f41b87e5ada9535b9c2645067162aa69234b Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/19150 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- configs/example/read_config.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/configs/example/read_config.py b/configs/example/read_config.py index 6ab5a8199..b1e820c62 100644 --- a/configs/example/read_config.py +++ b/configs/example/read_config.py @@ -1,4 +1,4 @@ -# Copyright (c) 2014 ARM Limited +# Copyright (c) 2014,2019 ARM Limited # All rights reserved. # # The license below extends only to copyright in the software and shall @@ -53,13 +53,17 @@ import ConfigParser import inspect import json import re +import six import sys import m5 import m5.ticks as ticks +if six.PY3: + long = int + sim_object_classes_by_name = { - cls.__name__: cls for cls in m5.objects.__dict__.itervalues() + cls.__name__: cls for cls in m5.objects.__dict__.values() if inspect.isclass(cls) and issubclass(cls, m5.objects.SimObject) } # Add some parsing functions to Param classes to handle reading in .ini @@ -120,7 +124,7 @@ param_parsers = { 'EthernetAddr': simple_parser() } -for name, parser in param_parsers.iteritems(): +for name, parser in param_parsers.items(): setattr(m5.params.__dict__[name], 'parse_ini', classmethod(parser)) class PortConnection(object): @@ -184,7 +188,7 @@ class ConfigManager(object): parsed_params = {} - for param_name, param in object_class._params.iteritems(): + for param_name, param in object_class._params.items(): if issubclass(param.ptype, m5.params.ParamValue): if isinstance(param, m5.params.VectorParamDesc): param_values = self.config.get_param_vector(object_name, @@ -212,7 +216,7 @@ class ConfigManager(object): if object_name == 'Null': return NULL - for param_name, param in obj.__class__._params.iteritems(): + for param_name, param in obj.__class__._params.items(): if issubclass(param.ptype, m5.objects.SimObject): if isinstance(param, m5.params.VectorParamDesc): param_values = self.config.get_param_vector(object_name, @@ -277,7 +281,7 @@ class ConfigManager(object): return NULL parsed_ports = [] - for port_name, port in obj.__class__._ports.iteritems(): + for port_name, port in obj.__class__._ports.items(): # Assume that unnamed ports are unconnected peers = self.config.get_port_peers(object_name, port_name) @@ -359,12 +363,12 @@ class ConfigManager(object): # Now fill in SimObject-valued parameters in the knowledge that # this won't be interpreted as becoming the parent of objects # which are already in the root hierarchy - for name, obj in self.objects_by_name.iteritems(): + for name, obj in self.objects_by_name.items(): self.fill_in_simobj_parameters(name, obj) # Gather a list of all port-to-port connections connections = [] - for name, obj in self.objects_by_name.iteritems(): + for name, obj in self.objects_by_name.items(): connections += self.gather_port_connections(name, obj) # Find an acceptable order to bind those port connections and @@ -457,7 +461,7 @@ class ConfigJsonFile(ConfigFile): for elem in node: self.find_all_objects(elem) elif isinstance(node, dict): - for elem in node.itervalues(): + for elem in node.values(): self.find_all_objects(elem) def load(self, config_file): @@ -496,7 +500,7 @@ class ConfigJsonFile(ConfigFile): obj = self.object_dicts[object_name] children = [] - for name, node in obj.iteritems(): + for name, node in obj.items(): if self.is_sim_object(node): children.append((name, node['path'])) elif isinstance(node, list) and node != [] and all([ -- 2.30.2