generate: Encode SI properly
This commit is contained in:
parent
b8047585fb
commit
6017ac1fa3
@ -412,7 +412,9 @@ func (this *Generator) generateDecodeValue(typ Type, valueSource, tagSource stri
|
||||
// SI: (none)
|
||||
// LI: <value: IntN>
|
||||
if typ.Bits <= 5 {
|
||||
// SI stores the value in the tag, so we write nothing here
|
||||
// SI stores the value in the tag
|
||||
nn, err := this.iprintf("*%s = uint8(%s.CN())\n", valueSource, tagSource)
|
||||
n += nn; if err != nil { return n, err }
|
||||
break
|
||||
}
|
||||
prefix := "ReadUint"
|
||||
@ -580,7 +582,7 @@ func (this *Generator) generateTag(typ Type, source string) (n int, err error) {
|
||||
switch typ := typ.(type) {
|
||||
case TypeInt:
|
||||
if typ.Bits <= 5 {
|
||||
nn, err := this.printf("tape.SI")
|
||||
nn, err := this.printf("tape.SI.WithCN(int(%s))", source)
|
||||
n += nn; if err != nil { return n, err }
|
||||
} else {
|
||||
nn, err := this.printf("tape.LI.WithCN(%d)", bitsToCN(typ.Bits))
|
||||
@ -664,6 +666,11 @@ func (this *Generator) generateType(typ Type) (n int, err error) {
|
||||
if err := this.validateIntBitSize(typ.Bits); err != nil {
|
||||
return n, err
|
||||
}
|
||||
if typ.Bits <= 5 {
|
||||
nn, err := this.printf("uint8")
|
||||
n += nn; if err != nil { return n, err }
|
||||
break
|
||||
}
|
||||
if typ.Signed {
|
||||
nn, err := this.printf("int%d", typ.Bits)
|
||||
n += nn; if err != nil { return n, err }
|
||||
@ -729,7 +736,7 @@ func (this *Generator) generateTypeTableDefined(typ TypeTableDefined) (n int, er
|
||||
|
||||
func (this *Generator) validateIntBitSize(size int) error {
|
||||
switch size {
|
||||
case 8, 16, 32, 64: return nil
|
||||
case 5, 8, 16, 32, 64: return nil
|
||||
default: return fmt.Errorf("integers of size %d are unsupported on this platform", size)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user