From a548d9d0f7b889627c43b18811357fad88760b2d Mon Sep 17 00:00:00 2001 From: aarzilli Date: Fri, 2 May 2014 15:09:23 +0200 Subject: Fix Issue #21: automatic calculation of alignment padding after lists --- nexgb/xgbgen/go.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'nexgb/xgbgen/go.go') diff --git a/nexgb/xgbgen/go.go b/nexgb/xgbgen/go.go index 6c680e8..ace4e00 100644 --- a/nexgb/xgbgen/go.go +++ b/nexgb/xgbgen/go.go @@ -103,15 +103,27 @@ func (td *TypeDef) Define(c *Context) { // Pad fields func (f *PadField) Define(c *Context) { - c.Putln("// padding: %d bytes", f.Bytes) + if f.Align > 0 { + c.Putln("// alignment gap to multiple of %d", f.Align) + } else { + c.Putln("// padding: %d bytes", f.Bytes) + } } func (f *PadField) Read(c *Context, prefix string) { - c.Putln("b += %s // padding", f.Size()) + if f.Align > 0 { + c.Putln("b = (b + %d) & ^%d // alignment gap", f.Align-1, f.Align-1) + } else { + c.Putln("b += %s // padding", f.Size()) + } } func (f *PadField) Write(c *Context, prefix string) { - c.Putln("b += %s // padding", f.Size()) + if f.Align > 0 { + c.Putln("b = (b + %d) & ^%d // alignment gap", f.Align-1, f.Align-1) + } else { + c.Putln("b += %s // padding", f.Size()) + } } // Local fields -- cgit v1.2.3-70-g09d2