aboutsummaryrefslogtreecommitdiffstats
path: root/prog/size.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-14 19:25:01 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-15 16:02:37 +0200
commit52a33fd516102a98d3753bf69417235b655a68dc (patch)
tree351ab73db934d3b4e4babbe27e8801c659f2631b /prog/size.go
parent25f4fe0662f7f3b390d16b2e786f2ba0aa0293f1 (diff)
prog: remove default target and all global state
Now each prog function accepts the desired target explicitly. No global, implicit state involved. This is much cleaner and allows cross-OS/arch testing, etc.
Diffstat (limited to 'prog/size.go')
-rw-r--r--prog/size.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/prog/size.go b/prog/size.go
index b9920c19b..538b60c5d 100644
--- a/prog/size.go
+++ b/prog/size.go
@@ -7,7 +7,7 @@ import (
"fmt"
)
-func generateSize(arg Arg, lenType *LenType) Arg {
+func (target *Target) generateSize(arg Arg, lenType *LenType) Arg {
if arg == nil {
// Arg is an optional pointer, set size to 0.
return MakeConstArg(lenType, 0)
@@ -16,7 +16,7 @@ func generateSize(arg Arg, lenType *LenType) Arg {
switch arg.Type().(type) {
case *VmaType:
a := arg.(*PointerArg)
- return MakeConstArg(lenType, a.PagesNum*pageSize)
+ return MakeConstArg(lenType, a.PagesNum*target.PageSize)
case *ArrayType:
a := arg.(*GroupArg)
if lenType.ByteSize != 0 {
@@ -33,7 +33,7 @@ func generateSize(arg Arg, lenType *LenType) Arg {
}
}
-func assignSizes(args []Arg, parentsMap map[Arg]Arg) {
+func (target *Target) assignSizes(args []Arg, parentsMap map[Arg]Arg) {
// Create a map from field names to args.
argsMap := make(map[string]Arg)
for _, arg := range args {
@@ -53,7 +53,7 @@ func assignSizes(args []Arg, parentsMap map[Arg]Arg) {
buf, ok := argsMap[typ.Buf]
if ok {
- *a = *generateSize(InnerArg(buf), typ).(*ConstArg)
+ *a = *target.generateSize(InnerArg(buf), typ).(*ConstArg)
continue
}
@@ -86,7 +86,7 @@ func assignSizes(args []Arg, parentsMap map[Arg]Arg) {
}
}
-func assignSizesArray(args []Arg) {
+func (target *Target) assignSizesArray(args []Arg) {
parentsMap := make(map[Arg]Arg)
foreachArgArray(&args, nil, func(arg, base Arg, _ *[]Arg) {
if _, ok := arg.Type().(*StructType); ok {
@@ -95,14 +95,14 @@ func assignSizesArray(args []Arg) {
}
}
})
- assignSizes(args, parentsMap)
+ target.assignSizes(args, parentsMap)
foreachArgArray(&args, nil, func(arg, base Arg, _ *[]Arg) {
if _, ok := arg.Type().(*StructType); ok {
- assignSizes(arg.(*GroupArg).Inner, parentsMap)
+ target.assignSizes(arg.(*GroupArg).Inner, parentsMap)
}
})
}
-func assignSizesCall(c *Call) {
- assignSizesArray(c.Args)
+func (target *Target) assignSizesCall(c *Call) {
+ target.assignSizesArray(c.Args)
}