commit | 592cd5df41ec282a5923f53b492a60894c81dc4a | [log] [tgz] |
---|---|---|
author | Rupert Swarbrick <rswarbrick@lowrisc.org> | Wed Jun 10 16:45:03 2020 +0100 |
committer | sriyerg <46467186+sriyerg@users.noreply.github.com> | Thu Oct 29 23:53:54 2020 -0700 |
tree | bb587eacbf7ada9ae45edd58ed71f60ac737eeb4 | |
parent | 3afeacb3d213fb15e9e785a65bf7c10a33276e70 [diff] |
[dvsim] Document and slightly improve subst_wildcards in utils.py When messing around with config files, I managed to trigger an infinite loop in the subst_wildcards function. This patch fixes that, and also adds a big documentation comment and tests. Changes: - Document exactly what subst_wildcards does (it's quite complicated!) - Spot circular recursion rather than blowing the call stack. - Fix some odd behaviour in {eval_cmd} support. The previous code would transform "foo {eval_cmd} echo bar" to "bar", ignoring the "foo" prefix entirely. Similarly, it would transform "{eval_cmd}xecho foo" to "foo" (skipping over the 'x', which it assumed to be a space). - Be more explicit about how values get stringified - Make the interaction between {eval_cmd} and ignore_error=True a more uniform. The previous code performed partial evaluation when ignore_error was true except when doing {eval_cmd}, when it would discard the partially evaluated command string. - Add some simple tests. These correspond to documentation examples. You can run them with pytest. Note that this doesn't add a dependency on pytest unless you actually want to run the tests (since Python will merrily "parse" code where the named modules aren't in scope!) Differences in behaviour from the original code: - Clearer eval_cmd behavior (see above) - Circular references are now spotted. Before, a call to subst_wildcards('{a}', {'a': '{b}', 'b': '{a}'}) would cause an infinite loop. This is the sort of thing that you can trigger by a mistake in your config files, and what caused me to look at the function in the first place. Now it reports an error (regardless of the value of ignore_error). - List items are now stringified recursively in _stringify_wildcard_value. This makes rules like {'a': ['b', 10]} work. The functionality isn't used in dvsim at the moment (because all lists are lists of strings), but it's probably a bit cleaner. - Computed wildcard names are now possible. Probably not a particularly useful feature, but it comes for free with the "iterate over matches from the left" implementation, so it can't hurt to support explicitly. Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
OpenTitan is an open source silicon Root of Trust (RoT) project. OpenTitan will make the silicon RoT design and implementation more transparent, trustworthy, and secure for enterprises, platform providers, and chip manufacturers. OpenTitan is administered by lowRISC CIC as a collaborative project to produce high quality, open IP for instantiation as a full-featured product. See the OpenTitan site and OpenTitan docs for more information about the project.
This repository contains hardware, software and utilities written as part of the OpenTitan project. It is structured as monolithic repository, or “monorepo”, where all components live in one repository. It exists to enable collaboration across partners participating in the OpenTitan project.
The project contains comprehensive documentation of all IPs and tools. You can access it online at docs.opentitan.org.
Have a look at CONTRIBUTING for guidelines on how to contribute code to this repository.
Unless otherwise noted, everything in this repository is covered by the Apache License, Version 2.0 (see LICENSE for full text).