]> Cypherpunks repositories - gostls13.git/commitdiff
cgo: add complex float, complex double
authorSebastien Binet <seb.binet@gmail.com>
Wed, 19 Jan 2011 19:30:57 +0000 (14:30 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 19 Jan 2011 19:30:57 +0000 (14:30 -0500)
R=rsc
CC=binet, golang-dev
https://golang.org/cl/3906041

src/cmd/cgo/gcc.go
src/pkg/debug/dwarf/testdata/typedef.c
src/pkg/debug/dwarf/testdata/typedef.elf
src/pkg/debug/dwarf/testdata/typedef.macho
src/pkg/debug/dwarf/type_test.go

index be3b8fe64a63eeacc374cb0eeb541dbe7868d130..57dc4dc83d32a6129596e06a5810c5a5731f9b4b 100644 (file)
@@ -27,13 +27,15 @@ var debugDefine = flag.Bool("debug-define", false, "print relevant #defines")
 var debugGcc = flag.Bool("debug-gcc", false, "print gcc invocations")
 
 var nameToC = map[string]string{
-       "schar":     "signed char",
-       "uchar":     "unsigned char",
-       "ushort":    "unsigned short",
-       "uint":      "unsigned int",
-       "ulong":     "unsigned long",
-       "longlong":  "long long",
-       "ulonglong": "unsigned long long",
+       "schar":         "signed char",
+       "uchar":         "unsigned char",
+       "ushort":        "unsigned short",
+       "uint":          "unsigned int",
+       "ulong":         "unsigned long",
+       "longlong":      "long long",
+       "ulonglong":     "unsigned long long",
+       "complexfloat":  "float complex",
+       "complexdouble": "double complex",
 }
 
 // cname returns the C name to use for C.s.
@@ -591,6 +593,7 @@ type typeConv struct {
        int8, int16, int32, int64              ast.Expr
        uint8, uint16, uint32, uint64, uintptr ast.Expr
        float32, float64                       ast.Expr
+       complex64, complex128                  ast.Expr
        void                                   ast.Expr
        unsafePointer                          ast.Expr
        string                                 ast.Expr
@@ -617,6 +620,8 @@ func (c *typeConv) Init(ptrSize int64) {
        c.uintptr = c.Ident("uintptr")
        c.float32 = c.Ident("float32")
        c.float64 = c.Ident("float64")
+       c.complex64 = c.Ident("complex64")
+       c.complex128 = c.Ident("complex128")
        c.unsafePointer = c.Ident("unsafe.Pointer")
        c.void = c.Ident("void")
        c.string = c.Ident("string")
@@ -648,6 +653,8 @@ var dwarfToName = map[string]string{
        "long long int":          "longlong",
        "long long unsigned int": "ulonglong",
        "signed char":            "schar",
+       "float complex":          "complexfloat",
+       "double complex":         "complexdouble",
 }
 
 // Type returns a *Type with the same memory layout as
@@ -749,6 +756,19 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
                        t.Align = c.ptrSize
                }
 
+       case *dwarf.ComplexType:
+               switch t.Size {
+               default:
+                       fatal("unexpected: %d-byte complex type - %s", t.Size, dtype)
+               case 8:
+                       t.Go = c.complex64
+               case 16:
+                       t.Go = c.complex128
+               }
+               if t.Align = t.Size; t.Align >= c.ptrSize {
+                       t.Align = c.ptrSize
+               }
+
        case *dwarf.FuncType:
                // No attempt at translation: would enable calls
                // directly between worlds, but we need to moderate those.
index 2ceb00ced8f07222fbd3a837ea9357d9504f6b7a..664d021ced5e6b884a2b5e7cbda08cfe7f5afcf0 100644 (file)
@@ -9,6 +9,7 @@ gcc -gdwarf-2 -m64 -c typedef.c && gcc -gdwarf-2 -m64 -o typedef.elf typedef.o
 OS X Mach-O:
 gcc -gdwarf-2 -m64 -c typedef.c -o typedef.macho
 */
+#include <complex.h>
 
 typedef volatile int* t_ptr_volatile_int;
 typedef const char *t_ptr_const_char;
@@ -16,6 +17,9 @@ typedef long t_long;
 typedef unsigned short t_ushort;
 typedef int t_func_int_of_float_double(float, double);
 typedef int (*t_ptr_func_int_of_float_double)(float, double);
+typedef int (*t_ptr_func_int_of_float_complex)(float complex);
+typedef int (*t_ptr_func_int_of_double_complex)(double complex);
+typedef int (*t_ptr_func_int_of_long_double_complex)(long double complex);
 typedef int *t_func_ptr_int_of_char_schar_uchar(char, signed char, unsigned char);
 typedef void t_func_void_of_char(char);
 typedef void t_func_void_of_void(void);
@@ -65,6 +69,9 @@ t_my_union *a12a;
 t_my_enum *a13;
 t_my_list *a14;
 t_my_tree *a15;
+t_ptr_func_int_of_float_complex *a16;
+t_ptr_func_int_of_double_complex *a17;
+t_ptr_func_int_of_long_double_complex *a18;
 
 int main()
 {
index ea9291fce7e484155980ce1441f0aab89e8cf0de..44df8da9bc7c4683d557a34bee8715ab754e2d34 100755 (executable)
Binary files a/src/pkg/debug/dwarf/testdata/typedef.elf and b/src/pkg/debug/dwarf/testdata/typedef.elf differ
index bf1dfd20ecb16c6c73fd329e895f2fdbc256696e..41019c1e1461536738788a750b49abb0a4fd626b 100644 (file)
Binary files a/src/pkg/debug/dwarf/testdata/typedef.macho and b/src/pkg/debug/dwarf/testdata/typedef.macho differ
index 6c2daaa56d6a7a598a4ab7e1b1e63b1ff5c8248d..e01f7353a4d6c83b1900d9dbcbd245dbec5b3684 100644 (file)
@@ -12,21 +12,24 @@ import (
 )
 
 var typedefTests = map[string]string{
-       "t_ptr_volatile_int":                 "*volatile int",
-       "t_ptr_const_char":                   "*const char",
-       "t_long":                             "long int",
-       "t_ushort":                           "short unsigned int",
-       "t_func_int_of_float_double":         "func(float, double) int",
-       "t_ptr_func_int_of_float_double":     "*func(float, double) int",
-       "t_func_ptr_int_of_char_schar_uchar": "func(char, signed char, unsigned char) *int",
-       "t_func_void_of_char":                "func(char) void",
-       "t_func_void_of_void":                "func() void",
-       "t_func_void_of_ptr_char_dots":       "func(*char, ...) void",
-       "t_my_struct":                        "struct my_struct {vi volatile int@0; x char@4 : 1@7; y int@4 : 4@27; array [40]long long int@8}",
-       "t_my_union":                         "union my_union {vi volatile int@0; x char@0 : 1@7; y int@0 : 4@28; array [40]long long int@0}",
-       "t_my_enum":                          "enum my_enum {e1=1; e2=2; e3=-5; e4=1000000000000000}",
-       "t_my_list":                          "struct list {val short int@0; next *t_my_list@8}",
-       "t_my_tree":                          "struct tree {left *struct tree@0; right *struct tree@8; val long long unsigned int@16}",
+       "t_ptr_volatile_int":                    "*volatile int",
+       "t_ptr_const_char":                      "*const char",
+       "t_long":                                "long int",
+       "t_ushort":                              "short unsigned int",
+       "t_func_int_of_float_double":            "func(float, double) int",
+       "t_ptr_func_int_of_float_double":        "*func(float, double) int",
+       "t_ptr_func_int_of_float_complex":       "*func(complex float) int",
+       "t_ptr_func_int_of_double_complex":      "*func(complex double) int",
+       "t_ptr_func_int_of_long_double_complex": "*func(complex long double) int",
+       "t_func_ptr_int_of_char_schar_uchar":    "func(char, signed char, unsigned char) *int",
+       "t_func_void_of_char":                   "func(char) void",
+       "t_func_void_of_void":                   "func() void",
+       "t_func_void_of_ptr_char_dots":          "func(*char, ...) void",
+       "t_my_struct":                           "struct my_struct {vi volatile int@0; x char@4 : 1@7; y int@4 : 4@27; array [40]long long int@8}",
+       "t_my_union":                            "union my_union {vi volatile int@0; x char@0 : 1@7; y int@0 : 4@28; array [40]long long int@0}",
+       "t_my_enum":                             "enum my_enum {e1=1; e2=2; e3=-5; e4=1000000000000000}",
+       "t_my_list":                             "struct list {val short int@0; next *t_my_list@8}",
+       "t_my_tree":                             "struct tree {left *struct tree@0; right *struct tree@8; val long long unsigned int@16}",
 }
 
 func elfData(t *testing.T, name string) *Data {