Files
carbon-lang/testing/lit_test/lit.cfg.py
T
Prabhat SachdevaandRichard Smith 04d9a7b533 Improved trace output selection using program phase filtering (#2851)
By implementing these improvements, users will have the ability to choose specific parts of the trace output.

Currently, when executing a file using the explorer with the --trace_file=- or --trace_file=filename.txt flag, the resulting output is an extensive and verbose log containing all the information.

In this PR, I have introduced the `ProgramPhase` enum class, which have distinct phases encountered during the compilation of a program in the explorer. Each member of this enum class corresponds to a specific phase, signifying the relevant information to be included in the trace output.

The phases covered by the `ProgramPhase` enum class are as follows:

1. Printing the source program
2. Name resolution
3. Control flow resolution
4. Type checking
5. Unformed variable resolution
6. Printing declarations
7. Printing the timings
8. Printing whole output.

These phases can be selected by passing the following compiler flags along with `--trace_file=-`.
`-trace_source_program`, `-trace_name_resolution`, `-trace_control_flow_resolution`, `-trace_type_checking`, `-trace_unformed_variables_resolution`, `-trace_declarations`, `-trace_execution`, `-trace_timing` and `-trace_all`. If none of these flags is passed only execution trace will be added to the output.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-06-08 10:49:13 -07:00

79 lines
2.5 KiB
Python

__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import lit.formats
import os
from pathlib import Path
# This is a provided variable, ignore the undefined name warning.
config = config # noqa: F821
def fullpath(relative_path):
return Path(os.environ["TEST_SRCDIR"]).joinpath(relative_path)
def add_substitution(before, after):
"""Adds a substitution to the config. Wraps before as `%{before}`."""
config.substitutions.append((f"%{{{before}}}", after))
def add_substitutions():
"""Adds required substitutions to the config."""
tools = {
"carbon": fullpath("carbon/toolchain/driver/carbon"),
"explorer": fullpath("carbon/explorer/explorer"),
"explorer_prelude": fullpath("carbon/explorer/data/prelude.carbon"),
"filecheck": fullpath("llvm-project/llvm/FileCheck"),
"not": fullpath("llvm-project/llvm/not"),
"merge_output": fullpath("carbon/testing/lit_test/merge_output"),
}
run_carbon = f"{tools['merge_output']} {tools['carbon']}"
run_explorer = (
f"{tools['merge_output']} {tools['explorer']} %s "
f"--prelude={tools['explorer_prelude']}"
)
filecheck_allow_unmatched = (
f"{tools['filecheck']} %s --match-full-lines --strict-whitespace"
)
filecheck_strict = (
f"{filecheck_allow_unmatched} --implicit-check-not={{{{.}}}}"
)
add_substitution("carbon", f"{run_carbon}")
add_substitution(
"carbon-run-lowering",
f"{run_carbon} dump llvm-ir %s | {filecheck_strict}",
)
add_substitution(
"carbon-run-parser",
f"{run_carbon} dump parse-tree %s | {filecheck_strict}",
)
add_substitution(
"carbon-run-semantics",
f"{run_carbon} dump semantics-ir %s | {filecheck_strict}",
)
add_substitution(
"carbon-run-tokens", f"{run_carbon} dump tokens %s | {filecheck_strict}"
)
add_substitution("explorer-run", f"{run_explorer}")
add_substitution(
"explorer-run-trace",
f"{run_explorer} --parser_debug --trace_file=- | "
f"{filecheck_allow_unmatched}",
)
add_substitution("FileCheck-allow-unmatched", filecheck_allow_unmatched)
add_substitution("FileCheck-strict", filecheck_strict)
add_substitution("not", tools["not"])
config.name = "lit"
config.suffixes = [".carbon"]
config.test_format = lit.formats.ShTest()
add_substitutions()