aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/compiler.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-04 19:53:05 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-04 20:25:23 +0200
commit399addc8754ed0b484d3c159ac35befe1d3f652c (patch)
tree38f937a6c625d253b50b0f51e988ed1c22630b57 /pkg/compiler/compiler.go
parent94e151ceb51191698a068d96191cdd86326050f9 (diff)
sys, pkg/compiler: move padding computation to compiler
This makes types constant during execution, everything is precomputed.
Diffstat (limited to 'pkg/compiler/compiler.go')
-rw-r--r--pkg/compiler/compiler.go59
1 files changed, 33 insertions, 26 deletions
diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go
index f08a32987..fe9f286ad 100644
--- a/pkg/compiler/compiler.go
+++ b/pkg/compiler/compiler.go
@@ -33,11 +33,9 @@ import (
// Prog is description compilation result.
type Prog struct {
- // Processed AST (temporal measure, remove later).
- Desc *ast.Description
- Resources []*sys.ResourceDesc
- Syscalls []*sys.Call
- StructFields []*sys.StructFields
+ Resources []*sys.ResourceDesc
+ Syscalls []*sys.Call
+ StructDescs []*sys.KeyedStruct
// Set of unsupported syscalls/flags.
Unsupported map[string]bool
}
@@ -48,15 +46,17 @@ func Compile(desc *ast.Description, consts map[string]uint64, ptrSize uint64, eh
eh = ast.LoggingHandler
}
comp := &compiler{
- desc: ast.Clone(desc),
- eh: eh,
- ptrSize: ptrSize,
- unsupported: make(map[string]bool),
- resources: make(map[string]*ast.Resource),
- structs: make(map[string]*ast.Struct),
- intFlags: make(map[string]*ast.IntFlags),
- strFlags: make(map[string]*ast.StrFlags),
- structUses: make(map[sys.StructKey]*ast.Struct),
+ desc: ast.Clone(desc),
+ eh: eh,
+ ptrSize: ptrSize,
+ unsupported: make(map[string]bool),
+ resources: make(map[string]*ast.Resource),
+ structs: make(map[string]*ast.Struct),
+ intFlags: make(map[string]*ast.IntFlags),
+ strFlags: make(map[string]*ast.StrFlags),
+ structDescs: make(map[sys.StructKey]*sys.StructDesc),
+ structNodes: make(map[*sys.StructDesc]*ast.Struct),
+ structVarlen: make(map[string]bool),
}
comp.assignSyscallNumbers(consts)
comp.patchConsts(consts)
@@ -67,12 +67,12 @@ func Compile(desc *ast.Description, consts map[string]uint64, ptrSize uint64, eh
for _, w := range comp.warnings {
eh(w.pos, w.msg)
}
+ syscalls := comp.genSyscalls()
return &Prog{
- Desc: comp.desc,
- Resources: comp.genResources(),
- Syscalls: comp.genSyscalls(),
- StructFields: comp.genStructFields(),
- Unsupported: comp.unsupported,
+ Resources: comp.genResources(),
+ Syscalls: syscalls,
+ StructDescs: comp.genStructDescs(syscalls),
+ Unsupported: comp.unsupported,
}
}
@@ -88,7 +88,10 @@ type compiler struct {
structs map[string]*ast.Struct
intFlags map[string]*ast.IntFlags
strFlags map[string]*ast.StrFlags
- structUses map[sys.StructKey]*ast.Struct
+
+ structDescs map[sys.StructKey]*sys.StructDesc
+ structNodes map[*sys.StructDesc]*ast.Struct
+ structVarlen map[string]bool
}
type warn struct {
@@ -162,12 +165,16 @@ func (comp *compiler) getArgsBase(t *ast.Type, field string, dir sys.Dir, isArg
*typeDesc, []*ast.Type, sys.IntTypeCommon) {
desc := comp.getTypeDesc(t)
args, opt := removeOpt(t)
- com := genCommon(t.Ident, field, dir, opt)
- base := genIntCommon(com, comp.ptrSize, 0, false)
- if !isArg && desc.NeedBase {
- baseType := args[len(args)-1]
- args = args[:len(args)-1]
- base = typeInt.Gen(comp, baseType, nil, base).(*sys.IntType).IntTypeCommon
+ size := sizeUnassigned
+ com := genCommon(t.Ident, field, size, dir, opt)
+ base := genIntCommon(com, 0, false)
+ if desc.NeedBase {
+ base.TypeSize = comp.ptrSize
+ if !isArg {
+ baseType := args[len(args)-1]
+ args = args[:len(args)-1]
+ base = typeInt.Gen(comp, baseType, nil, base).(*sys.IntType).IntTypeCommon
+ }
}
return desc, args, base
}