[llvm] [Dexter] Add ability to rewrite scripts to fill-in unknown values (PR #202799)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 08:18:31 PDT 2026


================
@@ -0,0 +1,201 @@
+# DExTer : Debugging Experience Tester
+# ~~~~~~   ~         ~~         ~   ~~
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+"""Utilities for using debugger output to generate expected values that match that output."""
+
+from collections import Counter, OrderedDict, defaultdict
+from copy import deepcopy
+from enum import Enum, IntEnum
+from typing import Any, Dict, List, Optional, Set, Tuple, Union
+
+from dex.dextIR import DextIR, StepIR, ValueIR
+from dex.evaluation.StateMatch import get_active_where_matches
+from dex.test_script.Nodes import Expect, Then, Value, Where
+from dex.test_script.Script import DexterScript, Scope
+from dex.tools.Main import Context
+
+
+class ExpectedValueWriter:
+    """Given a ValueIR for an Expect, generates a complete expected value that matches that value if one can be
+    provided."""
+
+    def __init__(self, expect: Expect, value: ValueIR):
+        self.expect = expect
+        self.root_value = value
+        self.expected_value = expect.get_variable_result(value)
+
+
+def unique_expected_values(elements: List[ExpectedValueWriter]):
+    """Given a list of ExpectedValueWriters, and returns either a list containing the unique set of non-None expected
+    values, or a single item if there is only one non-duplicated expected value in the list, or None if there are no
+    valid expected values."""
----------------
SLTozer wrote:

The reason for returning a single item here is that the caller doesn't inspect the return value - it will be serialized straight to YAML. So if we want to print a single expected value as a scalar rather than a list with one element, better to do so here than in the caller.

https://github.com/llvm/llvm-project/pull/202799


More information about the llvm-commits mailing list