OLD | NEW |
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 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "debug/elf" | 9 "debug/elf" |
10 "debug/macho" | 10 "debug/macho" |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 _, argSize = p.structType(n) | 406 _, argSize = p.structType(n) |
407 | 407 |
408 // C wrapper calls into gcc, passing a pointer to the argument frame. | 408 // C wrapper calls into gcc, passing a pointer to the argument frame. |
409 fmt.Fprintf(fc, "#pragma cgo_import_static _cgo%s%s\n", cPrefix, n.Mangl
e) | 409 fmt.Fprintf(fc, "#pragma cgo_import_static _cgo%s%s\n", cPrefix, n.Mangl
e) |
410 fmt.Fprintf(fc, "void _cgo%s%s(void*);\n", cPrefix, n.Mangle) | 410 fmt.Fprintf(fc, "void _cgo%s%s(void*);\n", cPrefix, n.Mangle) |
411 fmt.Fprintf(fc, "\n") | 411 fmt.Fprintf(fc, "\n") |
412 fmt.Fprintf(fc, "void\n") | 412 fmt.Fprintf(fc, "void\n") |
413 if argSize == 0 { | 413 if argSize == 0 { |
414 argSize++ | 414 argSize++ |
415 } | 415 } |
416 » fmt.Fprintf(fc, "·%s(struct{uint8 x[%d];}p)\n", n.Mangle, argSize) | 416 » fmt.Fprintf(fc, "·%s(struct{", n.Mangle) |
| 417 » // TODO: properly generate the structure so that GC will recognize the |
| 418 » // pointers on stack. |
| 419 » if argSize/p.PtrSize != 0 { |
| 420 » » fmt.Fprintf(fc, "uint8 *x[%d];", argSize/p.PtrSize) |
| 421 » } |
| 422 » if argSize%p.PtrSize != 0 { |
| 423 » » fmt.Fprintf(fc, "uint8 y[%d];", argSize%p.PtrSize) |
| 424 » } |
| 425 » fmt.Fprintf(fc, "}p)\n") |
417 fmt.Fprintf(fc, "{\n") | 426 fmt.Fprintf(fc, "{\n") |
418 fmt.Fprintf(fc, "\truntime·cgocall(_cgo%s%s, &p);\n", cPrefix, n.Mangle) | 427 fmt.Fprintf(fc, "\truntime·cgocall(_cgo%s%s, &p);\n", cPrefix, n.Mangle) |
419 if n.AddError { | 428 if n.AddError { |
420 // gcc leaves errno in first word of interface at end of p. | 429 // gcc leaves errno in first word of interface at end of p. |
421 // check whether it is zero; if so, turn interface into nil. | 430 // check whether it is zero; if so, turn interface into nil. |
422 // if not, turn interface into errno. | 431 // if not, turn interface into errno. |
423 // Go init function initializes ·_Cerrno with an os.Errno | 432 // Go init function initializes ·_Cerrno with an os.Errno |
424 // for us to copy. | 433 // for us to copy. |
425 fmt.Fprintln(fc, ` { | 434 fmt.Fprintln(fc, ` { |
426 int32 e; | 435 int32 e; |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 typedef double GoFloat64; | 1262 typedef double GoFloat64; |
1254 typedef __complex float GoComplex64; | 1263 typedef __complex float GoComplex64; |
1255 typedef __complex double GoComplex128; | 1264 typedef __complex double GoComplex128; |
1256 | 1265 |
1257 typedef struct { char *p; GoInt n; } GoString; | 1266 typedef struct { char *p; GoInt n; } GoString; |
1258 typedef void *GoMap; | 1267 typedef void *GoMap; |
1259 typedef void *GoChan; | 1268 typedef void *GoChan; |
1260 typedef struct { void *t; void *v; } GoInterface; | 1269 typedef struct { void *t; void *v; } GoInterface; |
1261 typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; | 1270 typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; |
1262 ` | 1271 ` |
OLD | NEW |