From df98b6bde521211c8f1246157e5e6a4a40e710f4 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Tue, 20 Dec 2016 18:12:07 +0100 Subject: prog: add bytesizeN types --- sysgen/sysgen.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'sysgen') diff --git a/sysgen/sysgen.go b/sysgen/sysgen.go index 5bda2ed2b..92258150d 100644 --- a/sysgen/sysgen.go +++ b/sysgen/sysgen.go @@ -465,7 +465,7 @@ func generateArg( failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a)) } fmt.Fprintf(out, "&VmaType{%v}", common()) - case "len", "bytesize": + case "len", "bytesize", "bytesize2", "bytesize4", "bytesize8": canBeArg = true size := uint64(ptrSize) bigEndian := false @@ -479,7 +479,11 @@ func generateArg( failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a)) } } - fmt.Fprintf(out, "&LenType{%v, Buf: \"%v\", TypeSize: %v, BigEndian: %v, ByteSize: %v}", common(), a[0], size, bigEndian, typ == "bytesize") + byteSize := uint8(0) + if typ != "len" { + byteSize = decodeByteSizeType(typ) + } + fmt.Fprintf(out, "&LenType{%v, Buf: \"%v\", TypeSize: %v, BigEndian: %v, ByteSize: %v}", common(), a[0], size, bigEndian, byteSize) case "flags": canBeArg = true size := uint64(ptrSize) @@ -683,6 +687,19 @@ func decodeIntType(typ string) (uint64, bool) { return uint64(sz / 8), bigEndian } +func decodeByteSizeType(typ string) uint8 { + switch typ { + case "bytesize", "bytesize2", "bytesize4", "bytesize8": + default: + failf("unknown type %v", typ) + } + sz := int64(1) + if typ != "bytesize" { + sz, _ = strconv.ParseInt(typ[8:], 10, 8) + } + return uint8(sz) +} + func isIdentifier(s string) bool { for i, c := range s { if c == '_' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || i > 0 && (c >= '0' && c <= '9') { -- cgit mrf-deployment