Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
076ebed0
Commit
076ebed0
authored
Dec 14, 2011
by
Rémy Oudompheng
Committed by
Ian Lance Taylor
Dec 14, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgo: add basic gccgo support.
R=rsc, iant CC=golang-dev, remy
https://golang.org/cl/5485070
parent
d89b7173
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
3 deletions
+56
-3
src/cmd/cgo/main.go
src/cmd/cgo/main.go
+2
-0
src/cmd/cgo/out.go
src/cmd/cgo/out.go
+54
-3
No files found.
src/cmd/cgo/main.go
View file @
076ebed0
...
...
@@ -130,6 +130,8 @@ var dynobj = flag.String("dynimport", "", "if non-empty, print dynamic import da
var
godefs
=
flag
.
Bool
(
"godefs"
,
false
,
"for bootstrap: write Go definitions for C file to standard output"
)
var
cdefs
=
flag
.
Bool
(
"cdefs"
,
false
,
"for bootstrap: write C definitions for C file to standard output"
)
var
gccgo
=
flag
.
Bool
(
"gccgo"
,
false
,
"generate files for use with gccgo"
)
var
goarch
,
goos
string
func
main
()
{
...
...
src/cmd/cgo/out.go
View file @
076ebed0
...
...
@@ -46,7 +46,9 @@ func (p *Package) writeDefs() {
fmt
.
Fprintf
(
fgo2
,
"package %s
\n\n
"
,
p
.
PackageName
)
fmt
.
Fprintf
(
fgo2
,
"import
\"
unsafe
\"\n\n
"
)
fmt
.
Fprintf
(
fgo2
,
"import
\"
syscall
\"\n\n
"
)
fmt
.
Fprintf
(
fgo2
,
"import _
\"
runtime/cgo
\"\n\n
"
)
if
!*
gccgo
{
fmt
.
Fprintf
(
fgo2
,
"import _
\"
runtime/cgo
\"\n\n
"
)
}
fmt
.
Fprintf
(
fgo2
,
"type _ unsafe.Pointer
\n\n
"
)
fmt
.
Fprintf
(
fgo2
,
"func _Cerrno(dst *error, x int) { *dst = syscall.Errno(x) }
\n
"
)
...
...
@@ -57,7 +59,11 @@ func (p *Package) writeDefs() {
}
fmt
.
Fprintf
(
fgo2
,
"type _Ctype_void [0]byte
\n
"
)
fmt
.
Fprintf
(
fc
,
cProlog
)
if
*
gccgo
{
fmt
.
Fprintf
(
fc
,
cPrologGccgo
)
}
else
{
fmt
.
Fprintf
(
fc
,
cProlog
)
}
cVars
:=
make
(
map
[
string
]
bool
)
for
_
,
n
:=
range
p
.
Name
{
...
...
@@ -238,13 +244,22 @@ func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name) {
Type
:
gtype
,
}
printer
.
Fprint
(
fgo2
,
fset
,
d
)
fmt
.
Fprintf
(
fgo2
,
"
\n
"
)
if
*
gccgo
{
fmt
.
Fprintf
(
fgo2
,
" __asm__(
\"
%s
\"
)
\n
"
,
n
.
C
)
}
else
{
fmt
.
Fprintf
(
fgo2
,
"
\n
"
)
}
if
name
==
"CString"
||
name
==
"GoString"
||
name
==
"GoStringN"
||
name
==
"GoBytes"
{
// The builtins are already defined in the C prolog.
return
}
// gccgo does not require a wrapper unless an error must be returned.
if
*
gccgo
&&
!
n
.
AddError
{
return
}
var
argSize
int64
_
,
argSize
=
p
.
structType
(
n
)
...
...
@@ -730,6 +745,42 @@ void
}
`
const
cPrologGccgo
=
`
#include <stdint.h>
#include <string.h>
struct __go_string {
const unsigned char *__data;
int __length;
};
typedef struct __go_open_array {
void* __values;
int __count;
int __capacity;
} Slice;
struct __go_string __go_byte_array_to_string(const void* p, int len);
struct __go_open_array __go_string_to_byte_array (struct __go_string str);
const char *CString(struct __go_string s) {
return strndup(s.__data, s.__length);
}
struct __go_string GoString(char *p) {
return __go_byte_array_to_string(p, strlen(p));
}
struct __go_string GoStringN(char *p, int n) {
return __go_byte_array_to_string(p, n);
}
Slice GoBytes(char *p, int n) {
struct __go_string s = { p, n };
return __go_string_to_byte_array(s);
}
`
const
gccExportHeaderProlog
=
`
typedef unsigned int uint;
typedef signed char schar;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment