aboutsummaryrefslogtreecommitdiffstats
path: root/sysgen
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2016-12-20 18:12:07 +0100
committerAndrey Konovalov <andreyknvl@google.com>2016-12-20 18:12:07 +0100
commitdf98b6bde521211c8f1246157e5e6a4a40e710f4 (patch)
tree648a0abb9db00f2364c028154807666ec2b51d6b /sysgen
parent80b6c954f8daa8d9910698be9eca6d97284a75a0 (diff)
prog: add bytesizeN types
Diffstat (limited to 'sysgen')
-rw-r--r--sysgen/sysgen.go21
1 files changed, 19 insertions, 2 deletions
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') {