From 54e0cede4384b7c1655f9183577bfccc11d9a7d5 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Tue, 10 Jan 2017 16:45:52 +0100 Subject: 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. --- prog/encodingexec.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'prog/encodingexec.go') diff --git a/prog/encodingexec.go b/prog/encodingexec.go index 17cb2b553..57ff32eab 100644 --- a/prog/encodingexec.go +++ b/prog/encodingexec.go @@ -46,7 +46,9 @@ func (p *Prog) SerializeForExec(pid int) []byte { w.args[base] = &argInfo{} } w.args[arg] = &argInfo{Offset: w.args[base].CurSize} - w.args[base].CurSize += arg.Size() + if arg.Type.BitfieldLength() == 0 || arg.Type.BitfieldLast() { + w.args[base].CurSize += arg.Size() + } }) // Generate copyin instructions that fill in data into pointer arguments. foreachArg(c, func(arg, _ *Arg, _ *[]*Arg) { @@ -149,6 +151,8 @@ func (w *execContext) writeArg(arg *Arg, pid int) { w.write(ExecArgConst) w.write(arg.Size()) w.write(arg.Value(pid)) + w.write(arg.Type.BitfieldOffset()) + w.write(arg.Type.BitfieldLength()) case ArgResult: w.write(ExecArgResult) w.write(arg.Size()) @@ -159,10 +163,14 @@ func (w *execContext) writeArg(arg *Arg, pid int) { w.write(ExecArgConst) w.write(arg.Size()) w.write(physicalAddr(arg)) + w.write(0) // bit field offset + w.write(0) // bit field length case ArgPageSize: w.write(ExecArgConst) w.write(arg.Size()) w.write(arg.AddrPage * pageSize) + w.write(0) // bit field offset + w.write(0) // bit field length case ArgData: w.write(ExecArgData) w.write(uintptr(len(arg.Data))) -- cgit mrf-deployment