All files / utils RegisterAccessMode.ts

100% Statements 2/2
100% Branches 2/2
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                                                              54x                     107x              
/**
 * RegisterAccessMode — what a register member's access modifier means.
 *
 * ADR-004 gives a register member one of `rw`, `ro`, `wo`, `w1c`, `w1s`. Three
 * of those — `wo`, `w1s`, `w1c` — share a property that decides how a write is
 * emitted and whether a zero-bit write means anything: the hardware cannot be
 * read back to build a read-modify-write, so the value must be composed from
 * nothing.
 *
 * That membership was written out THREE times, in two passes that cannot import
 * each other:
 *
 *   1-Analyze/RegisterAccessAnalyzer   `new Set(["wo", "w1s", "w1c"])`
 *   3-Render/.../RegisterUtils          `=== "wo" || === "w1s" || === "w1c"`
 *   3-Render/.../BitmapHandlers         the same expression again
 *
 * 2.1 Analyze used it to decide a DIAGNOSTIC — a zero written to a write-1 bit
 * is meaningless — and 2.3 Render used it to decide WHICH C to emit. All three
 * agreed, which is the whole problem: nothing fails when they agree, and the
 * first edit that adds a fourth modifier has to find all three. `output/` may
 * not import `1-Analyze` (depcruise makes that an error), so the only home both
 * can reach is here, the same reason `CompositeType` lives in `utils/`
 * (#1450, #1668).
 */
class RegisterAccessMode {
  /**
   * Modifiers whose bits are written rather than read-modify-written.
   *
   * `wo` cannot be read at all; `w1s` and `w1c` act on a 1 and ignore a 0, so
   * a read-modify-write would be both wrong and pointless.
   */
  private static readonly WRITE_ONE: ReadonlySet<string> = new Set([
    "wo",
    "w1s",
    "w1c",
  ]);
 
  /**
   * True when writing this member composes the value instead of reading it
   * back first.
   */
  static isWriteOne(accessMod: string | undefined): boolean {
    return (
      accessMod !== undefined && RegisterAccessMode.WRITE_ONE.has(accessMod)
    );
  }
}
 
export default RegisterAccessMode;