• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
        • Warnings
        • Primitives
        • Use-set
        • Syntax
        • Getting-started
        • Utilities
        • Loader
        • Transforms
        • Lint
        • Mlib
        • Server
        • Kit
        • Printer
          • Ps
          • Basic-printing
          • Verilog-printing
            • Vl-fmt
            • Vl-ppc-module
            • Vl-pp-expr
            • Vl-maybe-escape-identifier
              • Vl-simple-id-tail-string-p
            • Vl-print-ext-wirename
            • Vl-pp-module
            • Vl-print-wirename
            • Vl-print-loc
            • Vl-print-modname
            • Vl-pp-origexpr
            • Vl-pps-module
            • Vl-pps-expr
            • Vl-ppc-modulelist
            • Vl-ppcs-module
            • Vl-ps-update-show-atts
            • Vl-pps-origexpr
            • Vl-pps-modulelist
            • Vl-ppcs-modulelist
            • Vl-cw-obj
            • Vl-ps->show-atts-p
            • Vl-cw
          • Printing-locally
          • Formatted-printing
          • Accessing-printed-output
          • Vl-printedlist
          • Json-printing
        • Esim-vl
        • Well-formedness
      • Sv
      • Fgl
      • Vwsim
      • Vl
      • X86isa
      • Svl
      • Rtl
    • Software-verification
    • Math
    • Testing-utilities
  • Verilog-printing

Vl-maybe-escape-identifier

Add escape characters to an identifier name, if necessary.

Signature
(vl-maybe-escape-identifier x) → x-escaped
Arguments
x — Name of some identifier.
    Guard (stringp x).
Returns
x-escaped — Type (stringp x-escaped).

Usually x contains only ordinary characters and does not need to be escaped, and in such cases we return x unchanged. Otherwise, we add the leading \ character and trailing space.

Note: we assume that x has no embedded spaces and at least one character. These requirements aren't explicit about the names used in structures like vl-id-p, vl-modinst-p, and so forth. But they should hold for any valid Verilog that we parse or generate.

Definitions and Theorems

Function: vl-maybe-escape-identifier

(defun vl-maybe-escape-identifier (x)
  (declare (xargs :guard (stringp x)))
  (let ((__function__ 'vl-maybe-escape-identifier))
    (declare (ignorable __function__))
    (b* ((x (string-fix x))
         (len (length x))
         ((when (zp len))
          (raise "Empty identifier")
          "")
         ((when (and (vl-simple-id-head-p (char x 0))
                     (vl-simple-id-tail-string-p x 1 len)
                     (mbe :logic (not (member #\$ (explode x)))
                          :exec (not (position #\$ x)))))
          x)
         ((when (position #\Space x))
          (raise "Identifier name has spaces?  ~x0" x)
          ""))
      (implode (cons #\\
                     (str::append-chars x (list #\Space)))))))

Theorem: stringp-of-vl-maybe-escape-identifier

(defthm stringp-of-vl-maybe-escape-identifier
  (b* ((x-escaped (vl-maybe-escape-identifier x)))
    (stringp x-escaped))
  :rule-classes :type-prescription)

Theorem: vl-maybe-escape-identifier-of-str-fix-x

(defthm vl-maybe-escape-identifier-of-str-fix-x
  (equal (vl-maybe-escape-identifier (str-fix x))
         (vl-maybe-escape-identifier x)))

Theorem: vl-maybe-escape-identifier-streqv-congruence-on-x

(defthm vl-maybe-escape-identifier-streqv-congruence-on-x
  (implies (streqv x x-equiv)
           (equal (vl-maybe-escape-identifier x)
                  (vl-maybe-escape-identifier x-equiv)))
  :rule-classes :congruence)

Subtopics

Vl-simple-id-tail-string-p