Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(862)

Side by Side Diff: src/cmd/cgo/gcc.go

Issue 180059: code review 180059: Use BitSize instead of the field's type native ByteSize... (Closed)
Patch Set: code review 180059: Use BitSize instead of the field's type native ByteSize... Created 15 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Annotate Crefs in Prog with C types by parsing gcc debug output. 5 // Annotate Crefs in Prog with C types by parsing gcc debug output.
6 // Conversion of debug output to Go types. 6 // Conversion of debug output to Go types.
7 7
8 package main 8 package main
9 9
10 import ( 10 import (
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 // Also avoid existing fields 685 // Also avoid existing fields
686 for _, exist := used[goid]; exist; _, exist = used[goid] { 686 for _, exist := used[goid]; exist; _, exist = used[goid] {
687 goid = "_" + goid 687 goid = "_" + goid
688 } 688 }
689 689
690 used[goid] = true 690 used[goid] = true
691 ident[cid] = goid 691 ident[cid] = goid
692 } 692 }
693 } 693 }
694 694
695 bitsRemaining := int64(0)
696
695 for _, f := range dt.Field { 697 for _, f := range dt.Field {
698 if bitsRemaining > 0 {
rsc 2009/12/16 17:25:21 I don't think it makes sense to show the first bit
699 bitsRemaining -= f.BitSize
700 continue
701 }
696 if f.ByteOffset > off { 702 if f.ByteOffset > off {
697 fld = c.pad(fld, f.ByteOffset-off) 703 fld = c.pad(fld, f.ByteOffset-off)
698 off = f.ByteOffset 704 off = f.ByteOffset
699 } 705 }
700 t := c.Type(f.Type) 706 t := c.Type(f.Type)
701 n := len(fld) 707 n := len(fld)
702 fld = fld[0 : n+1] 708 fld = fld[0 : n+1]
703 709
704 fld[n] = &ast.Field{Names: []*ast.Ident{c.Ident(ident[f.Name])}, Type: t.Go} 710 fld[n] = &ast.Field{Names: []*ast.Ident{c.Ident(ident[f.Name])}, Type: t.Go}
705 off += t.Size 711 off += t.Size
706 csyntax += t.C + " " + f.Name + "; " 712 csyntax += t.C + " " + f.Name + "; "
707 if t.Align > align { 713 if t.Align > align {
708 align = t.Align 714 align = t.Align
709 } 715 }
716 // If this is the first member of a bitfield, skip the rest
717 if f.BitSize > 0 {
718 // 8 bits per byte - number of bits for this field
719 bitsRemaining = f.ByteSize*8 - f.BitSize
720 }
710 } 721 }
711 if off < dt.ByteSize { 722 if off < dt.ByteSize {
712 fld = c.pad(fld, dt.ByteSize-off) 723 fld = c.pad(fld, dt.ByteSize-off)
713 off = dt.ByteSize 724 off = dt.ByteSize
714 } 725 }
715 if off != dt.ByteSize { 726 if off != dt.ByteSize {
716 fatal("struct size calculation error") 727 fatal("struct size calculation error")
717 } 728 }
718 csyntax += "}" 729 csyntax += "}"
719 expr = &ast.StructType{Fields: fld} 730 expr = &ast.StructType{Fields: fld}
720 return 731 return
721 } 732 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b