Add escape characters to an identifier name, if necessary.
Usually
Note: we assume that
Function:
(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:
(defthm stringp-of-vl-maybe-escape-identifier (b* ((x-escaped (vl-maybe-escape-identifier x))) (stringp x-escaped)) :rule-classes :type-prescription)
Theorem:
(defthm vl-maybe-escape-identifier-of-str-fix-x (equal (vl-maybe-escape-identifier (str-fix x)) (vl-maybe-escape-identifier x)))
Theorem:
(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)