python: Enable -c in gem5 to mimic python
Adds a -c parameter to gem5 that works like python's -c to execute commands from a string. This is to set up getting multiprocessing and spawn to work in a later changeset. Change-Id: I11a1dedb481fbe88898abc1e525d781ec3f66494 Signed-off-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63131 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Bobby Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Jason Lowe-Power
parent
f43e722238
commit
170c998b8f
@@ -281,6 +281,14 @@ def parse_options():
|
||||
help="List all built-in SimObjects, their params and default values",
|
||||
)
|
||||
|
||||
option(
|
||||
"-c",
|
||||
type=str,
|
||||
help="program passed in as string (terminates option list)",
|
||||
default="",
|
||||
metavar="cmd",
|
||||
)
|
||||
|
||||
arguments = options.parse_args()
|
||||
return options, arguments
|
||||
|
||||
@@ -471,7 +479,7 @@ def main():
|
||||
print()
|
||||
|
||||
# check to make sure we can find the listed script
|
||||
if not arguments or not os.path.isfile(arguments[0]):
|
||||
if not options.c and (not arguments or not os.path.isfile(arguments[0])):
|
||||
if arguments and not os.path.isfile(arguments[0]):
|
||||
print("Script %s not found" % arguments[0])
|
||||
|
||||
@@ -546,12 +554,17 @@ def main():
|
||||
trace.ignore(ignore)
|
||||
|
||||
sys.argv = arguments
|
||||
sys.path = [os.path.dirname(sys.argv[0])] + sys.path
|
||||
|
||||
filename = sys.argv[0]
|
||||
filedata = open(filename, "r").read()
|
||||
filecode = compile(filedata, filename, "exec")
|
||||
scope = {"__file__": filename, "__name__": "__m5_main__"}
|
||||
if options.c:
|
||||
filedata = options.c
|
||||
filecode = compile(filedata, "<string>", "exec")
|
||||
scope = {"__name__": "__m5_main__"}
|
||||
else:
|
||||
sys.path = [os.path.dirname(sys.argv[0])] + sys.path
|
||||
filename = sys.argv[0]
|
||||
filedata = open(filename, "r").read()
|
||||
filecode = compile(filedata, filename, "exec")
|
||||
scope = {"__file__": filename, "__name__": "__m5_main__"}
|
||||
|
||||
# if pdb was requested, execfile the thing under pdb, otherwise,
|
||||
# just do the execfile normally
|
||||
|
||||
Reference in New Issue
Block a user