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)
|
// SI: (none)
|
||||||
// LI: <value: IntN>
|
// LI: <value: IntN>
|
||||||
if typ.Bits <= 5 {
|
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
|
break
|
||||||
}
|
}
|
||||||
prefix := "ReadUint"
|
prefix := "ReadUint"
|
||||||
@ -580,7 +582,7 @@ func (this *Generator) generateTag(typ Type, source string) (n int, err error) {
|
|||||||
switch typ := typ.(type) {
|
switch typ := typ.(type) {
|
||||||
case TypeInt:
|
case TypeInt:
|
||||||
if typ.Bits <= 5 {
|
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 }
|
n += nn; if err != nil { return n, err }
|
||||||
} else {
|
} else {
|
||||||
nn, err := this.printf("tape.LI.WithCN(%d)", bitsToCN(typ.Bits))
|
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 {
|
if err := this.validateIntBitSize(typ.Bits); err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
if typ.Bits <= 5 {
|
||||||
|
nn, err := this.printf("uint8")
|
||||||
|
n += nn; if err != nil { return n, err }
|
||||||
|
break
|
||||||
|
}
|
||||||
if typ.Signed {
|
if typ.Signed {
|
||||||
nn, err := this.printf("int%d", typ.Bits)
|
nn, err := this.printf("int%d", typ.Bits)
|
||||||
n += nn; if err != nil { return n, err }
|
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 {
|
func (this *Generator) validateIntBitSize(size int) error {
|
||||||
switch size {
|
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)
|
default: return fmt.Errorf("integers of size %d are unsupported on this platform", size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user