scripts: Reworked tagrepr -> Tag.repr to rely more on self-parsing

This should make tag editing less tedious/error-prone. We already used
self-parsing to generate -l/--list in dbgtag.py, but this extends the
idea to tagrepr (now Tag.repr), which is used in quite a few more
scripts.

To make this work the little tag encoding spec had to become a bit more
rigorous, fortunately the only real change was the addition of '+'
characters to mark reserved-but-expected-zero bits.

Example:

  TAG_CKSUM = 0x3000  ## v-11 ---- ++++ +pqq
                         ^--^----^----^--^-^-- valid bit, unmatched
                            '----|----|--|-|-- matches 1
                                 '----|--|-|-- matches 0
                                      '--|-|-- reserved 0, unmatched
                                         '-|-- perturb bit, unmatched
                                           '-- phase bits, unmatched

  dbgtag.py 0x3000  =>  cksumq0
  dbgtag.py 0x3007  =>  cksumq3p
  dbgtag.py 0x3017  =>  cksumq3p 0x10
  dbgtag.py 0x3417  =>  0x3417

Though Tag.repr still does a bit of manual formatting for the
differences between shrub/normal/null/alt tags.

Still, this should reduce the number of things that need to be changed
from 2 -> 1 when adding/editing most new tags.
This commit is contained in:
Christopher Haster
2025-10-22 14:27:18 -05:00
parent 3f15b61c72
commit ffc40da878
9 changed files with 1657 additions and 1426 deletions
+22 -20
View File
@@ -52,25 +52,27 @@ class Err:
def line(self):
return ('LFS3_%s' % self.name, '%d' % self.code, self.help)
@ft.cache
def errs():
# parse our script's source to figure out errs
import inspect
import re
errs = []
err_pattern = re.compile(
'^(?P<name>ERR_[^ ]*) *= *(?P<code>[^#]*?) *'
'#+ *(?P<help>.*)$')
for line in (inspect.getsource(inspect.getmodule(inspect.currentframe()))
.replace('\\\n', '')
.splitlines()):
m = err_pattern.match(line)
if m:
errs.append(Err(
m.group('name'),
globals()[m.group('name')],
m.group('help')))
return errs
@staticmethod
@ft.cache
def errs():
# parse our script's source to figure out errs
import inspect
import re
errs = []
err_pattern = re.compile(
'^(?P<name>ERR_[^ ]*) *= *(?P<code>[^#]*?) *'
'#+ *(?P<help>.*)$')
for line in (inspect.getsource(
inspect.getmodule(inspect.currentframe()))
.replace('\\\n', '')
.splitlines()):
m = err_pattern.match(line)
if m:
errs.append(Err(
m.group('name'),
globals()[m.group('name')],
m.group('help')))
return errs
def main(errs, *,
@@ -79,7 +81,7 @@ def main(errs, *,
list_, list = list, builtins.list
# find errs
errs__ = globals()['errs']()
errs__ = Err.errs()
lines = []
# list all known error codes