Skip to content

Commit

Permalink
trace_limit을 환경변수로 설정하도록 하고 기본값 끔
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Apr 4, 2024
1 parent 1601c9b commit c2b3488
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
3 changes: 2 additions & 1 deletion aheui/_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def parse_args(self, args):
""")
parser.add_argument('--cmd', '-c', default='', description='Program passed in as string')
parser.add_argument('--no-c', '--no-c', narg='0', default='no', description='Do not generate `.aheuic` file automatically.', full_description='\tWhat is .aheuic? https://github.com/aheui/snippets/commit/cbb5a12e7cd2db771538ab28dfbc9ad1ada86f35\n')
parser.add_argument('--warning-limit', '--warning-limit', default='3', description='Set repetitive warning limit. 0 means no warning. -1 means no limit.')
parser.add_argument('--warning-limit', '--warning-limit', default='', description='Set repetitive warning limit. '' fallbacks to environment variable `RPAHEUI_WARNING_LIMIT`. 0 means no warning. -1 means no limit. Default is 3.')
parser.add_argument('--trace-limit', '--trace-limit', default='', description='Set JIT trace limit. '' fallbacks to environment variable `RPAHEUI_TRACE_LIMIT`.')
parser.add_argument('--version', '-v', narg='-1', default='no', description='Show program version', message=VERSION)
parser.add_argument('--help', '-h', narg='-1', default='no', description='Show this help text')
40 changes: 35 additions & 5 deletions aheui/aheui.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ def get_label(self, pc):


def mainloop(program, debug):
jit.set_param(driver, 'trace_limit', 30000)
program = jit.promote(program)
jit.assert_green(program)
pc = 0
Expand Down Expand Up @@ -441,7 +440,34 @@ def mainloop(program, debug):
return 0


def process_opt(argv):
def kwarg_or_environ(kwargs, environ, arg_key, env_key):
if arg_key in kwargs and kwargs[arg_key] != '':
return (1, kwargs[arg_key])
try:
return (2, environ[env_key])
except KeyError:
return (0, '')


def kwarg_or_environ_int(kwargs, environ, arg_key, env_key, default):
source, arg = kwarg_or_environ(kwargs, environ, arg_key, env_key)
if source == 0:
return default
try:
value = int(arg)
except ValueError:
if source == 1:
msg = b'The value of --%s="%s" is not a valid integer\n' % (arg_key, arg)
elif source == 2:
msg = b'The value %s="%s" is not a valid integer\n' % (env_key, arg)
else:
assert False
os.write(2, msg)
raise
return value


def process_opt(argv, environ):
def open_r(filename):
return os.open(filename, os.O_RDONLY, 0o777)

Expand Down Expand Up @@ -520,9 +546,10 @@ def open_r(filename):
os.write(2, b'aheui: error: --target,-t must be one of "bytecode", "asm", "asm+comment", "run"\n') # noqa: E501
raise SystemExit()

warning_limit = int(kwargs['warning-limit'])
warning_limit = kwarg_or_environ_int(kwargs, environ, 'warning-limit', 'RPAHEUI_WARNING_LIMIT', 3)
trace_limit = kwarg_or_environ_int(kwargs, environ, 'trace-limit', 'RPAHEUI_TRACE_LIMIT', -1)

return cmd, source, contents, opt_level, target, aheuic_output, comment_aheuis, output, warning_limit
return cmd, source, contents, opt_level, target, aheuic_output, comment_aheuis, output, warning_limit, trace_limit


def open_w(filename):
Expand Down Expand Up @@ -563,10 +590,13 @@ def prepare_compiler(contents, opt_level=2, source='code', aheuic_output=None, a

def entry_point(argv):
try:
cmd, source, contents, str_opt_level, target, aheuic_output, comment_aheuis, output, warning_limit = process_opt(argv)
cmd, source, contents, str_opt_level, target, aheuic_output, comment_aheuis, output, warning_limit, trace_limit = process_opt(argv, os.environ)
except SystemExit:
return 1

warnings.limit = warning_limit
if trace_limit >= 0:
jit.set_param(driver, 'trace_limit', trace_limit)

add_debug_info = DEBUG or target != 'run' # debug flag for user program
compiler = prepare_compiler(contents, int(str_opt_level), source, aheuic_output, add_debug_info)
Expand Down

0 comments on commit c2b3488

Please sign in to comment.