Skip to content

Commit

Permalink
Merge pull request #200 from reventlov/debug_stop_after_step
Browse files Browse the repository at this point in the history
Add `--debug-stop-before-step` flag.
  • Loading branch information
robrussell authored Oct 9, 2024
2 parents cefa726 + 9af089c commit 8b25b90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 13 additions & 3 deletions compiler/front_end/emboss_front_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def _parse_command_line(argv):
help="Show the module-level IR of the main input file "
"before symbol resolution.",
)
parser.add_argument(
"--debug-stop-before-step",
type=str,
help="Stop processing before the specified step.",
)
parser.add_argument(
"--debug-show-full-ir",
action="store_true",
Expand Down Expand Up @@ -146,7 +151,7 @@ def _find_and_read(file_name):
return _find_and_read


def parse_and_log_errors(input_file, import_dirs, color_output):
def parse_and_log_errors(input_file, import_dirs, color_output, stop_before_step=None):
"""Fully parses an .emb and logs any errors.
Arguments:
Expand All @@ -158,7 +163,9 @@ def parse_and_log_errors(input_file, import_dirs, color_output):
(ir, debug_info, errors)
"""
ir, debug_info, errors = glue.parse_emboss_file(
input_file, _find_in_dirs_and_read(import_dirs)
input_file,
_find_in_dirs_and_read(import_dirs),
stop_before_step=stop_before_step,
)
if errors:
_show_errors(errors, ir, color_output)
Expand All @@ -168,7 +175,10 @@ def parse_and_log_errors(input_file, import_dirs, color_output):

def main(flags):
ir, debug_info, errors = parse_and_log_errors(
flags.input_file[0], flags.import_dirs, flags.color_output
flags.input_file[0],
flags.import_dirs,
flags.color_output,
stop_before_step=flags.debug_stop_before_step,
)
if errors:
return 1
Expand Down
9 changes: 6 additions & 3 deletions compiler/front_end/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""

import collections
import sys

from compiler.front_end import attribute_checker
from compiler.front_end import constraints
Expand Down Expand Up @@ -323,9 +324,11 @@ def process_ir(ir, stop_before_step):
constraints.check_constraints,
write_inference.set_write_methods,
)
assert stop_before_step in [None] + [
f.__name__ for f in passes
], "Bad value for stop_before_step."
valid_step_names = [f.__name__ for f in passes]
assert stop_before_step in [None] + valid_step_names, (
f"Bad value '{stop_before_step}' for stop_before_step. Valid values: "
+ " ".join(valid_step_names)
)
# Some parts of the IR are synthesized from "natural" parts of the IR, before
# the natural parts have been fully error checked. Because of this, the
# synthesized parts can have errors; in a couple of cases, they can have
Expand Down

0 comments on commit 8b25b90

Please sign in to comment.