aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encodingexec.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/encodingexec.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/encodingexec.go')
-rw-r--r--prog/encodingexec.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/prog/encodingexec.go b/prog/encodingexec.go
index a4f41a694..b2b173bbe 100644
--- a/prog/encodingexec.go
+++ b/prog/encodingexec.go
@@ -66,9 +66,10 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
}
instrSeq := 0
w := &execContext{
- buf: buffer,
- eof: false,
- args: make(map[Arg]argInfo),
+ target: p.Target,
+ buf: buffer,
+ eof: false,
+ args: make(map[Arg]argInfo),
}
for _, c := range p.Calls {
// Calculate checksums.
@@ -94,7 +95,7 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
foreachSubargOffset(a.Res, func(arg1 Arg, offset uint64) {
used, ok := arg1.(ArgUsed)
if (ok && len(*used.Used()) != 0) || csumUses[arg1] {
- w.args[arg1] = argInfo{Addr: physicalAddr(arg) + offset}
+ w.args[arg1] = argInfo{Addr: p.Target.physicalAddr(arg) + offset}
}
if _, ok := arg1.(*GroupArg); ok {
return
@@ -107,7 +108,7 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
}
if !IsPad(arg1.Type()) && arg1.Type().Dir() != DirOut {
w.write(ExecInstrCopyin)
- w.write(physicalAddr(arg) + offset)
+ w.write(p.Target.physicalAddr(arg) + offset)
w.writeArg(arg1, pid, csumMap)
instrSeq++
}
@@ -197,24 +198,25 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
return nil
}
-func physicalAddr(arg Arg) uint64 {
+func (target *Target) physicalAddr(arg Arg) uint64 {
a, ok := arg.(*PointerArg)
if !ok {
panic("physicalAddr: bad arg kind")
}
- addr := a.PageIndex*pageSize + dataOffset
+ addr := a.PageIndex*target.PageSize + target.DataOffset
if a.PageOffset >= 0 {
addr += uint64(a.PageOffset)
} else {
- addr += pageSize - uint64(-a.PageOffset)
+ addr += target.PageSize - uint64(-a.PageOffset)
}
return addr
}
type execContext struct {
- buf []byte
- eof bool
- args map[Arg]argInfo
+ target *Target
+ buf []byte
+ eof bool
+ args map[Arg]argInfo
}
type argInfo struct {
@@ -263,7 +265,7 @@ func (w *execContext) writeArg(arg Arg, pid int, csumMap map[Arg]CsumInfo) {
case *PointerArg:
w.write(ExecArgConst)
w.write(a.Size())
- w.write(physicalAddr(arg))
+ w.write(w.target.physicalAddr(arg))
w.write(0) // bit field offset
w.write(0) // bit field length
case *DataArg: