diff options
| author | Andrey Konovalov <andreyknvl@google.com> | 2016-09-21 16:52:55 +0200 |
|---|---|---|
| committer | Andrey Konovalov <andreyknvl@google.com> | 2016-10-04 18:49:57 +0200 |
| commit | c99cbdbe58f7817a2ee6064e72db25fc1d067b41 (patch) | |
| tree | aa1bc1092c27601f9531d87b2b2a25e5d1063d7b /sys | |
| parent | e73ddfcb3ac418fc690b982f70da15b898096fa5 (diff) | |
Emit BufferBlob for array[int8]
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/align.go | 7 | ||||
| -rw-r--r-- | sys/decl.go | 12 |
2 files changed, 16 insertions, 3 deletions
diff --git a/sys/align.go b/sys/align.go index 6e8563da4..055a433f8 100644 --- a/sys/align.go +++ b/sys/align.go @@ -48,14 +48,19 @@ func addAlignment(t *StructType) { off += pad fields = append(fields, makePad(pad)) } - off += f.Size() fields = append(fields, f) if at, ok := f.(ArrayType); ok && (at.Kind == ArrayRandLen || (at.Kind == ArrayRangeLen && at.RangeBegin != at.RangeEnd)) { varLen = true } + if at, ok := f.(BufferType); ok && (at.Kind == BufferBlobRand || (at.Kind == BufferBlobRange && at.RangeBegin != at.RangeEnd)) { + varLen = true + } if varLen && i != len(t.Fields)-1 { panic("embed array in middle of a struct") } + if !varLen { + off += f.Size() + } } if align != 0 && off%align != 0 && !varLen { pad := align - off%align diff --git a/sys/decl.go b/sys/decl.go index f792f541c..275bbb380 100644 --- a/sys/decl.go +++ b/sys/decl.go @@ -100,7 +100,8 @@ func (t FileoffType) Align() uintptr { type BufferKind int const ( - BufferBlob BufferKind = iota + BufferBlobRand BufferKind = iota + BufferBlobRange BufferString BufferSockaddr BufferFilesystem @@ -110,7 +111,9 @@ const ( type BufferType struct { TypeCommon - Kind BufferKind + Kind BufferKind + RangeBegin uintptr // for BufferBlobRange kind + RangeEnd uintptr // for BufferBlobRange kind } func (t BufferType) Size() uintptr { @@ -119,6 +122,11 @@ func (t BufferType) Size() uintptr { return 14 case BufferAlgName: return 64 + case BufferBlobRange: + if t.RangeBegin == t.RangeEnd { + return t.RangeBegin + } + fallthrough default: panic(fmt.Sprintf("buffer size is not statically known: %v", t.Name())) } |
