generate: Support LSI tags

This commit is contained in:
Sasha Koshka 2025-08-11 20:59:20 -04:00
parent 0e03f84b8a
commit dc72cc2010

View File

@ -308,7 +308,7 @@ func (this *Generator) generateEncodeValue(typ Type, valueSource, tagSource stri
switch typ := typ.(type) {
case TypeInt:
// SI: (none)
// LI: <value: IntN>
// LI/LSI: <value: IntN>
if typ.Bits <= 5 {
// SI stores the value in the tag, so we write nothing here
break
@ -479,7 +479,7 @@ func (this *Generator) generateDecodeValue(typ Type, typeName, valueSource, tagS
switch typ := typ.(type) {
case TypeInt:
// SI: (none)
// LI: <value: IntN>
// LI/LSI: <value: IntN>
if typ.Bits <= 5 {
// SI stores the value in the tag
nn, err := this.iprintf("*%s = uint8(%s.CN())\n", valueSource, tagSource)
@ -837,6 +837,9 @@ func (this *Generator) generateTag(typ Type, source string) (n int, err error) {
if typ.Bits <= 5 {
nn, err := this.printf("tape.SI.WithCN(int(%s))", source)
n += nn; if err != nil { return n, err }
} else if typ.Signed {
nn, err := this.printf("tape.LSI.WithCN(%d)", bitsToCN(typ.Bits))
n += nn; if err != nil { return n, err }
} else {
nn, err := this.printf("tape.LI.WithCN(%d)", bitsToCN(typ.Bits))
n += nn; if err != nil { return n, err }
@ -881,6 +884,9 @@ func (this *Generator) generateTN(typ Type) (n int, err error) {
if typ.Bits <= 5 {
nn, err := this.printf("tape.SI")
n += nn; if err != nil { return n, err }
} else if typ.Signed {
nn, err := this.printf("tape.LSI")
n += nn; if err != nil { return n, err }
} else {
nn, err := this.printf("tape.LI")
n += nn; if err != nil { return n, err }