From 9f33ef8632ff6d32fa7b7c9c8cba824b27aebbe0 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 9 Oct 2007 07:39:34 +0000
Subject: [PATCH] Enhance cli.SubmitOpcode to use custom parameters

This patch allows the SubmitOpcode function to take a pre-created
Processor instance and a different feedback function. This is helpful
when submitting more than one opcode from a shell script.

Reviewed-by: imsnah
---
 lib/cli.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index 28d71a24e..d374a36b2 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -336,7 +336,7 @@ def AskUser(text, choices=None):
   return answer
 
 
-def SubmitOpCode(op):
+def SubmitOpCode(op, proc=None, feedback_fn=None):
   """Function to submit an opcode.
 
   This is just a simple wrapper over the construction of the processor
@@ -344,8 +344,11 @@ def SubmitOpCode(op):
   interaction functions.
 
   """
-  proc = mcpu.Processor()
-  return proc.ExecOpCode(op, logger.ToStdout)
+  if proc is None:
+    proc = mcpu.Processor()
+  if feedback_fn is None:
+    feedback_fn = logger.ToStdout
+  return proc.ExecOpCode(op, feedback_fn)
 
 
 def GenericMain(commands, override=None):
-- 
GitLab