aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/consts.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-03-02 14:26:58 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-03-05 12:10:27 +0100
commita339951e5f3c045290340330bcea3ff4155b8334 (patch)
treee7ec9a7d5379d2ef2bef4c682ed7873f7e725dbb /pkg/compiler/consts.go
parent5110ff445ddb5a09a13e17b187c06d2dc3a7d52a (diff)
pkg/compiler: add size attribute for structs
The size attribute allows to pad a struct up to the specified size.
Diffstat (limited to 'pkg/compiler/consts.go')
-rw-r--r--pkg/compiler/consts.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/pkg/compiler/consts.go b/pkg/compiler/consts.go
index b4f674124..789674578 100644
--- a/pkg/compiler/consts.go
+++ b/pkg/compiler/consts.go
@@ -83,6 +83,18 @@ func (comp *compiler) extractConsts() map[string]*ConstInfo {
}
}
+ for _, decl := range comp.desc.Nodes {
+ switch n := decl.(type) {
+ case *ast.Struct:
+ for _, attr := range n.Attrs {
+ if !n.IsUnion && attr.Ident == "size" {
+ info := getConstInfo(infos, attr.Pos)
+ info.consts[attr.Args[0].Ident] = true
+ }
+ }
+ }
+ }
+
comp.desc.Walk(ast.Recursive(func(n0 ast.Node) {
if n, ok := n0.(*ast.Int); ok {
info := getConstInfo(infos, n.Pos)
@@ -185,6 +197,15 @@ func (comp *compiler) patchConsts(consts map[string]uint64) {
&v.Ident, consts, &missing)
}
}
+ if n, ok := decl.(*ast.Struct); ok {
+ for _, attr := range n.Attrs {
+ if !n.IsUnion && attr.Ident == "size" {
+ sz := attr.Args[0]
+ comp.patchIntConst(sz.Pos, &sz.Value,
+ &sz.Ident, consts, &missing)
+ }
+ }
+ }
if missing == "" {
continue
}