util: Port util to python3

This commit is the result of running 2to3 converter on the util
subdirectory

JIRA: https://gem5.atlassian.net/browse/GEM5-832

Change-Id: I4e7e2d2b1b99f7bcc5fe0f6dc5d25880323616eb
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/37797
Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Giacomo Travaglini
2020-11-19 18:51:13 +00:00
parent da7ce72144
commit 2a2bc262f3
58 changed files with 578 additions and 583 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
# Copyright (c) 2013-2014 ARM Limited
# All rights reserved
@@ -60,39 +60,39 @@ import sys
try:
import packet_pb2
except:
print "Did not find packet proto definitions, attempting to generate"
print("Did not find packet proto definitions, attempting to generate")
from subprocess import call
error = call(['protoc', '--python_out=util', '--proto_path=src/proto',
'src/proto/packet.proto'])
if not error:
print "Generated packet proto definitions"
print("Generated packet proto definitions")
try:
import google.protobuf
except:
print "Please install the Python protobuf module"
print("Please install the Python protobuf module")
exit(-1)
import packet_pb2
else:
print "Failed to import packet proto definitions"
print("Failed to import packet proto definitions")
exit(-1)
def main():
if len(sys.argv) != 3:
print "Usage: ", sys.argv[0], " <ASCII input> <protobuf output>"
print("Usage: ", sys.argv[0], " <ASCII input> <protobuf output>")
exit(-1)
try:
ascii_in = open(sys.argv[1], 'r')
except IOError:
print "Failed to open ", sys.argv[1], " for reading"
print("Failed to open ", sys.argv[1], " for reading")
exit(-1)
try:
proto_out = open(sys.argv[2], 'wb')
except IOError:
print "Failed to open ", sys.argv[2], " for writing"
print("Failed to open ", sys.argv[2], " for writing")
exit(-1)
# Write the magic number in 4-byte Little Endian, similar to what
@@ -111,10 +111,10 @@ def main():
for line in ascii_in:
cmd, addr, size, tick = line.split(',')
packet = packet_pb2.Packet()
packet.tick = long(tick)
packet.tick = int(tick)
# ReadReq is 1 and WriteReq is 4 in src/mem/packet.hh Command enum
packet.cmd = 1 if cmd == 'r' else 4
packet.addr = long(addr)
packet.addr = int(addr)
packet.size = int(size)
protolib.encodeMessage(proto_out, packet)