Skip to content

Commit

Permalink
Merge 1991c9c into 8ac688c
Browse files Browse the repository at this point in the history
  • Loading branch information
snim2 committed Jul 27, 2016
2 parents 8ac688c + 1991c9c commit 05e3a66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
13 changes: 9 additions & 4 deletions revelation/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"""


class DoNotInterpretError(Exception):
def __init__(self):
pass


def cli_parser(argv, simulator, debug_enabled):
filename_index = 0
debug_flags = []
Expand All @@ -52,7 +57,7 @@ def cli_parser(argv, simulator, debug_enabled):
if token == '--help' or token == '-h':
print (USAGE_TEXT % (simulator.arch_name, argv[0], argv[0],
argv[0], argv[0], argv[0]))
raise SystemExit
raise DoNotInterpretError
elif token == '--time' or token == '-t':
simulator.collect_times = True
elif token == '--debug' or token == '-d':
Expand All @@ -65,7 +70,7 @@ def cli_parser(argv, simulator, debug_enabled):
prev_token = token
elif token[:1] == '-':
print 'Unknown argument %s' % token
raise SystemExit
raise SyntaxError
else:
filename_index = index + 1
break
Expand All @@ -79,7 +84,7 @@ def cli_parser(argv, simulator, debug_enabled):
simulator.user_environment = True
else:
print ('--env can be OPERATING or USER.')
raise SystemExit
raise ValueError
elif prev_token == '--ext-base' or prev_token == '-b':
simulator.ext_base =int(token, 16)
elif prev_token == '--cols' or prev_token == '-c':
Expand All @@ -99,5 +104,5 @@ def cli_parser(argv, simulator, debug_enabled):
prev_token = ''
if filename_index == 0:
print 'You must supply a file name'
raise SystemExit
raise SyntaxError
return argv[filename_index], jit, debug_flags
11 changes: 8 additions & 3 deletions revelation/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pydgin.misc import FatalError
from pydgin.sim import Sim, init_sim

from revelation.argument_parser import cli_parser
from revelation.argument_parser import cli_parser, DoNotInterpretError
from revelation.elf_loader import load_program
from revelation.instruction import Instruction
from revelation.isa import decode, reg_map
Expand Down Expand Up @@ -83,15 +83,20 @@ def get_entry_point(self):
def entry_point(argv):
if self.jit_enabled:
set_param(self.jitdriver, 'trace_limit', self.default_trace_limit)
fname, jit, flags = cli_parser(argv, self, Debug.global_enabled)
try:
fname, jit, flags = cli_parser(argv, self, Debug.global_enabled)
except DoNotInterpretError: # CLI option such as --help or -h.
return 0
except (SyntaxError, ValueError):
return 1
if jit: # pragma: no cover
set_user_param(self.jitdriver, jit)
self.debug = Debug(flags, 0)
try:
elf_file = open(fname, 'rb')
except IOError:
print 'Could not open file %s' % fname
raise SystemExit
return 1
self.init_state(elf_file, fname, False)
for state in self.states: # FIXME: Interleaved log.
self.debug.set_state(state)
Expand Down
8 changes: 3 additions & 5 deletions revelation/test/test_argument_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from revelation.argument_parser import USAGE_TEXT
from revelation.argument_parser import USAGE_TEXT, DoNotInterpretError
from revelation.sim import Revelation

import os.path
Expand Down Expand Up @@ -89,8 +89,7 @@ def test_argv_flags_with_no_args(argv, capfd):
def test_argv_with_errors(argv, expected, capfd):
revelation = Revelation()
entry_point = revelation.get_entry_point()
with pytest.raises(SystemExit):
entry_point(argv)
entry_point(argv)
out, err = capfd.readouterr()
assert err == ''
assert out == expected
Expand All @@ -102,8 +101,7 @@ def test_argv_help(argv, capfd):
expected = (USAGE_TEXT % ('revelation', 'sim.py', 'sim.py', 'sim.py',
'sim.py', 'sim.py') + '\n')
entry_point = revelation.get_entry_point()
with pytest.raises(SystemExit):
entry_point(argv)
entry_point(argv)
out, err = capfd.readouterr()
assert err == ''
assert out == expected

0 comments on commit 05e3a66

Please sign in to comment.