LEFT | RIGHT |
(no file at all) | |
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 Ref in Prog with C types by parsing gcc debug output. | 5 // Annotate Ref 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 // gccCmd returns the gcc command line to use for compiling | 764 // gccCmd returns the gcc command line to use for compiling |
765 // the input. | 765 // the input. |
766 func (p *Package) gccCmd() []string { | 766 func (p *Package) gccCmd() []string { |
767 c := []string{ | 767 c := []string{ |
768 p.gccName(), | 768 p.gccName(), |
769 "-Wall", // many warnings | 769 "-Wall", // many warnings |
770 "-Werror", // warnings are errors | 770 "-Werror", // warnings are errors |
771 "-o" + gccTmp(), // write object to tmp | 771 "-o" + gccTmp(), // write object to tmp |
772 "-gdwarf-2", // generate DWARF v2 debugg
ing symbols | 772 "-gdwarf-2", // generate DWARF v2 debugg
ing symbols |
773 "-fno-eliminate-unused-debug-types", // gets rid of e.g. untyped
enum otherwise | 773 "-fno-eliminate-unused-debug-types", // gets rid of e.g. untyped
enum otherwise |
774 » » "-c", // do not link | 774 » » "-c", // do not link |
775 » » "-xc", // input language is C | 775 » » "-xc", // input language is C |
776 } | 776 } |
777 c = append(c, p.GccOptions...) | 777 c = append(c, p.GccOptions...) |
778 c = append(c, p.gccMachine()...) | 778 c = append(c, p.gccMachine()...) |
779 c = append(c, "-") //read input from standard input | 779 c = append(c, "-") //read input from standard input |
780 return c | 780 return c |
781 } | 781 } |
782 | 782 |
783 // gccDebug runs gcc -gdwarf-2 over the C program stdin and | 783 // gccDebug runs gcc -gdwarf-2 over the C program stdin and |
784 // returns the corresponding DWARF data and, if present, debug data block. | 784 // returns the corresponding DWARF data and, if present, debug data block. |
785 func (p *Package) gccDebug(stdin []byte) (*dwarf.Data, binary.ByteOrder, []byte)
{ | 785 func (p *Package) gccDebug(stdin []byte) (*dwarf.Data, binary.ByteOrder, []byte)
{ |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 Len: c.intExpr(dt.Count), | 1071 Len: c.intExpr(dt.Count), |
1072 } | 1072 } |
1073 t.Go = gt // publish before recursive call | 1073 t.Go = gt // publish before recursive call |
1074 sub := c.Type(dt.Type, pos) | 1074 sub := c.Type(dt.Type, pos) |
1075 t.Align = sub.Align | 1075 t.Align = sub.Align |
1076 gt.Elt = sub.Go | 1076 gt.Elt = sub.Go |
1077 t.C.Set("typeof(%s[%d])", sub.C, dt.Count) | 1077 t.C.Set("typeof(%s[%d])", sub.C, dt.Count) |
1078 | 1078 |
1079 case *dwarf.BoolType: | 1079 case *dwarf.BoolType: |
1080 t.Go = c.bool | 1080 t.Go = c.bool |
1081 » » t.Align = c.ptrSize | 1081 » » t.Align = 1 |
1082 | 1082 |
1083 case *dwarf.CharType: | 1083 case *dwarf.CharType: |
1084 if t.Size != 1 { | 1084 if t.Size != 1 { |
1085 fatalf("%s: unexpected: %d-byte char type - %s", lineno(
pos), t.Size, dtype) | 1085 fatalf("%s: unexpected: %d-byte char type - %s", lineno(
pos), t.Size, dtype) |
1086 } | 1086 } |
1087 t.Go = c.int8 | 1087 t.Go = c.int8 |
1088 t.Align = 1 | 1088 t.Align = 1 |
1089 | 1089 |
1090 case *dwarf.EnumType: | 1090 case *dwarf.EnumType: |
1091 if t.Align = t.Size; t.Align >= c.ptrSize { | 1091 if t.Align = t.Size; t.Align >= c.ptrSize { |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 } | 1598 } |
1599 if prefix == "" { | 1599 if prefix == "" { |
1600 prefix = n.Name[:i+1] | 1600 prefix = n.Name[:i+1] |
1601 } else if prefix != n.Name[:i+1] { | 1601 } else if prefix != n.Name[:i+1] { |
1602 return "" | 1602 return "" |
1603 } | 1603 } |
1604 } | 1604 } |
1605 } | 1605 } |
1606 return prefix | 1606 return prefix |
1607 } | 1607 } |
LEFT | RIGHT |