aboutsummaryrefslogtreecommitdiffstats
path: root/sys/decl.go
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-01-10 16:45:52 +0100
committerAndrey Konovalov <andreyknvl@google.com>2017-01-17 13:25:33 +0100
commit54e0cede4384b7c1655f9183577bfccc11d9a7d5 (patch)
tree68e1f734a5e82ac7ecbe2968942d9983650ed8f8 /sys/decl.go
parentf6c7b90523285663e51fc6804ae2c0c171bb390c (diff)
prog: add bitfields to templates
Now it's possible to use `int32:18` to denote a bitfield of size 18 as a struct field. This fixes #72.
Diffstat (limited to 'sys/decl.go')
-rw-r--r--sys/decl.go200
1 files changed, 97 insertions, 103 deletions
diff --git a/sys/decl.go b/sys/decl.go
index aa59e8e0a..9c7887f99 100644
--- a/sys/decl.go
+++ b/sys/decl.go
@@ -34,6 +34,9 @@ type Type interface {
Default() uintptr
Size() uintptr
Align() uintptr
+ BitfieldOffset() uintptr
+ BitfieldLength() uintptr
+ BitfieldLast() bool
}
func IsPad(t Type) bool {
@@ -61,6 +64,18 @@ func (t *TypeCommon) Default() uintptr {
return 0
}
+func (t *TypeCommon) BitfieldOffset() uintptr {
+ return 0
+}
+
+func (t *TypeCommon) BitfieldLength() uintptr {
+ return 0
+}
+
+func (t *TypeCommon) BitfieldLast() bool {
+ return false
+}
+
func (t TypeCommon) Dir() Dir {
return t.ArgDir
}
@@ -97,6 +112,88 @@ func (t *ResourceType) Align() uintptr {
return t.Desc.Type.Align()
}
+type IntTypeCommon struct {
+ TypeCommon
+ TypeSize uintptr
+ BigEndian bool
+ BitfieldOff uintptr
+ BitfieldLen uintptr
+ BitfieldLst bool
+}
+
+func (t *IntTypeCommon) Size() uintptr {
+ return t.TypeSize
+}
+
+func (t *IntTypeCommon) Align() uintptr {
+ return t.Size()
+}
+
+func (t *IntTypeCommon) BitfieldOffset() uintptr {
+ return t.BitfieldOff
+}
+
+func (t *IntTypeCommon) BitfieldLength() uintptr {
+ return t.BitfieldLen
+}
+
+func (t *IntTypeCommon) BitfieldLast() bool {
+ return t.BitfieldLst
+}
+
+type ConstType struct {
+ IntTypeCommon
+ Val uintptr
+ IsPad bool
+}
+
+type IntKind int
+
+const (
+ IntPlain IntKind = iota
+ IntSignalno
+ IntFileoff // offset within a file
+ IntRange
+)
+
+type IntType struct {
+ IntTypeCommon
+ Kind IntKind
+ RangeBegin int64
+ RangeEnd int64
+}
+
+type FlagsType struct {
+ IntTypeCommon
+ Vals []uintptr
+}
+
+type LenType struct {
+ IntTypeCommon
+ ByteSize uintptr // want size in multiple of bytes instead of array size
+ Buf string
+}
+
+type ProcType struct {
+ IntTypeCommon
+ ValuesStart int64
+ ValuesPerProc uint64
+}
+
+type VmaType struct {
+ TypeCommon
+ RangeBegin int64 // in pages
+ RangeEnd int64
+}
+
+func (t *VmaType) Size() uintptr {
+ return ptrSize
+}
+
+func (t *VmaType) Align() uintptr {
+ return t.Size()
+}
+
type BufferKind int
const (
@@ -153,109 +250,6 @@ func (t *BufferType) Align() uintptr {
return 1
}
-type VmaType struct {
- TypeCommon
- RangeBegin int64 // in pages
- RangeEnd int64
-}
-
-func (t *VmaType) Size() uintptr {
- return ptrSize
-}
-
-func (t *VmaType) Align() uintptr {
- return t.Size()
-}
-
-type LenType struct {
- TypeCommon
- TypeSize uintptr
- BigEndian bool
- ByteSize uintptr // want size in multiple of bytes instead of array size
- Buf string
-}
-
-func (t *LenType) Size() uintptr {
- return t.TypeSize
-}
-
-func (t *LenType) Align() uintptr {
- return t.Size()
-}
-
-type FlagsType struct {
- TypeCommon
- TypeSize uintptr
- BigEndian bool
- Vals []uintptr
-}
-
-func (t *FlagsType) Size() uintptr {
- return t.TypeSize
-}
-
-func (t *FlagsType) Align() uintptr {
- return t.Size()
-}
-
-type ConstType struct {
- TypeCommon
- TypeSize uintptr
- BigEndian bool
- Val uintptr
- IsPad bool
-}
-
-func (t *ConstType) Size() uintptr {
- return t.TypeSize
-}
-
-func (t *ConstType) Align() uintptr {
- return t.Size()
-}
-
-type IntKind int
-
-const (
- IntPlain IntKind = iota
- IntSignalno
- IntFileoff // offset within a file
- IntRange
-)
-
-type IntType struct {
- TypeCommon
- TypeSize uintptr
- BigEndian bool
- Kind IntKind
- RangeBegin int64
- RangeEnd int64
-}
-
-func (t *IntType) Size() uintptr {
- return t.TypeSize
-}
-
-func (t *IntType) Align() uintptr {
- return t.Size()
-}
-
-type ProcType struct {
- TypeCommon
- TypeSize uintptr
- BigEndian bool
- ValuesStart int64
- ValuesPerProc uint64
-}
-
-func (t *ProcType) Size() uintptr {
- return t.TypeSize
-}
-
-func (t *ProcType) Align() uintptr {
- return t.Size()
-}
-
type ArrayKind int
const (