diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-10-31 15:15:13 -0600 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-11-11 14:33:37 -0800 |
| commit | 588a542b2a23ba477031bf20b4c46b0f40a04b7d (patch) | |
| tree | 9e517866f45cdb903505e72c0fcbf821c0b00dcd /sys/decl.go | |
| parent | 5ed6283b64f91c8aa036122b18974aabed4c5249 (diff) | |
sys: add string flags
Allow to define string flags in txt descriptions. E.g.:
filesystem = "ext2", "ext3", "ext4"
and then use it in string type:
ptr[in, string[filesystem]]
Diffstat (limited to 'sys/decl.go')
| -rw-r--r-- | sys/decl.go | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/sys/decl.go b/sys/decl.go index d5ec9a547..2f86ea87c 100644 --- a/sys/decl.go +++ b/sys/decl.go @@ -105,7 +105,6 @@ const ( BufferString BufferFilename BufferSockaddr - BufferFilesystem BufferAlgType BufferAlgName ) @@ -115,6 +114,8 @@ type BufferType struct { Kind BufferKind RangeBegin uintptr // for BufferBlobRange kind RangeEnd uintptr // for BufferBlobRange kind + SubKind string + Values []string // possible values for BufferString kind } func (t *BufferType) Size() uintptr { @@ -123,14 +124,16 @@ func (t *BufferType) Size() uintptr { return 14 case BufferAlgName: return 64 + case BufferString: + if len(t.Values) == 1 { + return uintptr(len(t.Values[0])) + } case BufferBlobRange: if t.RangeBegin == t.RangeEnd { return t.RangeBegin } - fallthrough - default: - panic(fmt.Sprintf("buffer size is not statically known: %v", t.Name())) } + panic(fmt.Sprintf("buffer size is not statically known: %v", t.Name())) } func (t *BufferType) Align() uintptr { @@ -196,20 +199,6 @@ func (t *ConstType) Align() uintptr { return t.Size() } -type StrConstType struct { - TypeCommon - TypeSize uintptr - Val string -} - -func (t *StrConstType) Size() uintptr { - return uintptr(len(t.Val)) -} - -func (t *StrConstType) Align() uintptr { - return 1 -} - type IntKind int const ( @@ -486,9 +475,8 @@ func ForeachType(meta *Call, f func(Type)) { for _, opt := range a.Options { rec(opt) } - case *ResourceType, *BufferType, - *VmaType, *LenType, *FlagsType, *ConstType, - *StrConstType, *IntType: + case *ResourceType, *BufferType, *VmaType, *LenType, + *FlagsType, *ConstType, *IntType: default: panic("unknown type") } |
