mirror of git://gcc.gnu.org/git/gcc.git
runtime/goc2c: Drop gc support, change int to intgo.
From-SVN: r193046
This commit is contained in:
parent
2455de3809
commit
e212c7f56c
|
|
@ -536,35 +536,35 @@ goc2c: goc2c.$(OBJEXT)
|
||||||
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ $<
|
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ $<
|
||||||
|
|
||||||
malloc.c: $(srcdir)/runtime/malloc.goc goc2c
|
malloc.c: $(srcdir)/runtime/malloc.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
mprof.c: $(srcdir)/runtime/mprof.goc goc2c
|
mprof.c: $(srcdir)/runtime/mprof.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
reflect.c: $(srcdir)/runtime/reflect.goc goc2c
|
reflect.c: $(srcdir)/runtime/reflect.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c
|
runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
sema.c: $(srcdir)/runtime/sema.goc goc2c
|
sema.c: $(srcdir)/runtime/sema.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
sigqueue.c: $(srcdir)/runtime/sigqueue.goc goc2c
|
sigqueue.c: $(srcdir)/runtime/sigqueue.goc goc2c
|
||||||
./goc2c --gcc --go-pkgpath os_signal $< > $@.tmp
|
./goc2c --go-pkgpath os_signal $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
time.c: $(srcdir)/runtime/time.goc goc2c
|
time.c: $(srcdir)/runtime/time.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
%.c: $(srcdir)/runtime/%.goc goc2c
|
%.c: $(srcdir)/runtime/%.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
go_bufio_files = \
|
go_bufio_files = \
|
||||||
|
|
|
||||||
|
|
@ -4310,35 +4310,35 @@ goc2c: goc2c.$(OBJEXT)
|
||||||
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ $<
|
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ $<
|
||||||
|
|
||||||
malloc.c: $(srcdir)/runtime/malloc.goc goc2c
|
malloc.c: $(srcdir)/runtime/malloc.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
mprof.c: $(srcdir)/runtime/mprof.goc goc2c
|
mprof.c: $(srcdir)/runtime/mprof.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
reflect.c: $(srcdir)/runtime/reflect.goc goc2c
|
reflect.c: $(srcdir)/runtime/reflect.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c
|
runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
sema.c: $(srcdir)/runtime/sema.goc goc2c
|
sema.c: $(srcdir)/runtime/sema.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
sigqueue.c: $(srcdir)/runtime/sigqueue.goc goc2c
|
sigqueue.c: $(srcdir)/runtime/sigqueue.goc goc2c
|
||||||
./goc2c --gcc --go-pkgpath os_signal $< > $@.tmp
|
./goc2c --go-pkgpath os_signal $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
time.c: $(srcdir)/runtime/time.goc goc2c
|
time.c: $(srcdir)/runtime/time.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
%.c: $(srcdir)/runtime/%.goc goc2c
|
%.c: $(srcdir)/runtime/%.goc goc2c
|
||||||
./goc2c --gcc $< > $@.tmp
|
./goc2c $< > $@.tmp
|
||||||
mv -f $@.tmp $@
|
mv -f $@.tmp $@
|
||||||
|
|
||||||
version.go: s-version; @true
|
version.go: s-version; @true
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/* Whether we're emitting for gcc */
|
/* Package path to use. */
|
||||||
static int gcc;
|
|
||||||
|
|
||||||
/* Package path to use; only meaningful for gcc */
|
|
||||||
static const char *pkgpath;
|
static const char *pkgpath;
|
||||||
|
|
||||||
/* Package prefix to use; only meaningful for gcc */
|
/* Package prefix to use. */
|
||||||
static const char *prefix;
|
static const char *prefix;
|
||||||
|
|
||||||
/* File and line number */
|
/* File and line number */
|
||||||
|
|
@ -50,53 +47,6 @@ struct params {
|
||||||
char *type;
|
char *type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* index into type_table */
|
|
||||||
enum {
|
|
||||||
Bool,
|
|
||||||
Float,
|
|
||||||
Int,
|
|
||||||
Uint,
|
|
||||||
Uintptr,
|
|
||||||
String,
|
|
||||||
Slice,
|
|
||||||
Eface,
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct {
|
|
||||||
char *name;
|
|
||||||
int size;
|
|
||||||
} type_table[] = {
|
|
||||||
/* variable sized first, for easy replacement */
|
|
||||||
/* order matches enum above */
|
|
||||||
/* default is 32-bit architecture sizes */
|
|
||||||
"bool", 1,
|
|
||||||
"float", 4,
|
|
||||||
"int", 4,
|
|
||||||
"uint", 4,
|
|
||||||
"uintptr", 4,
|
|
||||||
"String", 8,
|
|
||||||
"Slice", 12,
|
|
||||||
"Eface", 8,
|
|
||||||
|
|
||||||
/* fixed size */
|
|
||||||
"float32", 4,
|
|
||||||
"float64", 8,
|
|
||||||
"byte", 1,
|
|
||||||
"int8", 1,
|
|
||||||
"uint8", 1,
|
|
||||||
"int16", 2,
|
|
||||||
"uint16", 2,
|
|
||||||
"int32", 4,
|
|
||||||
"uint32", 4,
|
|
||||||
"int64", 8,
|
|
||||||
"uint64", 8,
|
|
||||||
|
|
||||||
NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Fixed structure alignment (non-gcc only) */
|
|
||||||
int structround = 4;
|
|
||||||
|
|
||||||
char *argv0;
|
char *argv0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -147,6 +97,15 @@ xrealloc(void *buf, unsigned int size)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Copy a string into memory without fail. */
|
||||||
|
static char *
|
||||||
|
xstrdup(const char *p)
|
||||||
|
{
|
||||||
|
char *ret = xmalloc(strlen(p) + 1);
|
||||||
|
strcpy(ret, p);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* Free a list of parameters. */
|
/* Free a list of parameters. */
|
||||||
static void
|
static void
|
||||||
free_params(struct params *p)
|
free_params(struct params *p)
|
||||||
|
|
@ -351,14 +310,29 @@ read_type(void)
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
|
||||||
p = read_token_no_eof();
|
p = read_token_no_eof();
|
||||||
if (*p != '*')
|
if (*p != '*') {
|
||||||
|
/* Convert the Go type "int" to the C type "intgo",
|
||||||
|
and similarly for "uint". */
|
||||||
|
if (strcmp(p, "int") == 0)
|
||||||
|
return xstrdup("intgo");
|
||||||
|
else if (strcmp(p, "uint") == 0)
|
||||||
|
return xstrdup("uintgo");
|
||||||
return p;
|
return p;
|
||||||
|
}
|
||||||
op = p;
|
op = p;
|
||||||
pointer_count = 0;
|
pointer_count = 0;
|
||||||
while (*p == '*') {
|
while (*p == '*') {
|
||||||
++pointer_count;
|
++pointer_count;
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert the Go type "int" to the C type "intgo", and
|
||||||
|
similarly for "uint". */
|
||||||
|
if (strcmp(p, "int") == 0)
|
||||||
|
p = (char *) "intgo";
|
||||||
|
else if (strcmp(p, "uint") == 0)
|
||||||
|
p = (char *) "uintgo";
|
||||||
|
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
q = xmalloc(len + pointer_count + 1);
|
q = xmalloc(len + pointer_count + 1);
|
||||||
memcpy(q, p, len);
|
memcpy(q, p, len);
|
||||||
|
|
@ -372,39 +346,19 @@ read_type(void)
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the size of the given type. */
|
|
||||||
static int
|
|
||||||
type_size(char *p)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if(p[strlen(p)-1] == '*')
|
|
||||||
return type_table[Uintptr].size;
|
|
||||||
|
|
||||||
for(i=0; type_table[i].name; i++)
|
|
||||||
if(strcmp(type_table[i].name, p) == 0)
|
|
||||||
return type_table[i].size;
|
|
||||||
if(!gcc) {
|
|
||||||
sysfatal("%s:%ud: unknown type %s\n", file, lineno, p);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read a list of parameters. Each parameter is a name and a type.
|
* Read a list of parameters. Each parameter is a name and a type.
|
||||||
* The list ends with a ')'. We have already read the '('.
|
* The list ends with a ')'. We have already read the '('.
|
||||||
*/
|
*/
|
||||||
static struct params *
|
static struct params *
|
||||||
read_params(int *poffset)
|
read_params()
|
||||||
{
|
{
|
||||||
char *token;
|
char *token;
|
||||||
struct params *ret, **pp, *p;
|
struct params *ret, **pp, *p;
|
||||||
int offset, size, rnd;
|
|
||||||
|
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
pp = &ret;
|
pp = &ret;
|
||||||
token = read_token_no_eof();
|
token = read_token_no_eof();
|
||||||
offset = 0;
|
|
||||||
if (strcmp(token, ")") != 0) {
|
if (strcmp(token, ")") != 0) {
|
||||||
while (1) {
|
while (1) {
|
||||||
p = xmalloc(sizeof(struct params));
|
p = xmalloc(sizeof(struct params));
|
||||||
|
|
@ -414,14 +368,6 @@ read_params(int *poffset)
|
||||||
*pp = p;
|
*pp = p;
|
||||||
pp = &p->next;
|
pp = &p->next;
|
||||||
|
|
||||||
size = type_size(p->type);
|
|
||||||
rnd = size;
|
|
||||||
if(rnd > structround)
|
|
||||||
rnd = structround;
|
|
||||||
if(offset%rnd)
|
|
||||||
offset += rnd - offset%rnd;
|
|
||||||
offset += size;
|
|
||||||
|
|
||||||
token = read_token_no_eof();
|
token = read_token_no_eof();
|
||||||
if (strcmp(token, ",") != 0)
|
if (strcmp(token, ",") != 0)
|
||||||
break;
|
break;
|
||||||
|
|
@ -432,8 +378,6 @@ read_params(int *poffset)
|
||||||
sysfatal("%s:%ud: expected '('\n",
|
sysfatal("%s:%ud: expected '('\n",
|
||||||
file, lineno);
|
file, lineno);
|
||||||
}
|
}
|
||||||
if (poffset != NULL)
|
|
||||||
*poffset = offset;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -442,7 +386,7 @@ read_params(int *poffset)
|
||||||
* '{' character. Returns 1 if it read a header, 0 at EOF.
|
* '{' character. Returns 1 if it read a header, 0 at EOF.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
read_func_header(char **name, struct params **params, int *paramwid, struct params **rets)
|
read_func_header(char **name, struct params **params, struct params **rets)
|
||||||
{
|
{
|
||||||
int lastline;
|
int lastline;
|
||||||
char *token;
|
char *token;
|
||||||
|
|
@ -474,13 +418,13 @@ read_func_header(char **name, struct params **params, int *paramwid, struct para
|
||||||
sysfatal("%s:%ud: expected \"(\"\n",
|
sysfatal("%s:%ud: expected \"(\"\n",
|
||||||
file, lineno);
|
file, lineno);
|
||||||
}
|
}
|
||||||
*params = read_params(paramwid);
|
*params = read_params();
|
||||||
|
|
||||||
token = read_token();
|
token = read_token();
|
||||||
if (token == NULL || strcmp(token, "(") != 0)
|
if (token == NULL || strcmp(token, "(") != 0)
|
||||||
*rets = NULL;
|
*rets = NULL;
|
||||||
else {
|
else {
|
||||||
*rets = read_params(NULL);
|
*rets = read_params();
|
||||||
token = read_token();
|
token = read_token();
|
||||||
}
|
}
|
||||||
if (token == NULL || strcmp(token, "{") != 0) {
|
if (token == NULL || strcmp(token, "{") != 0) {
|
||||||
|
|
@ -505,43 +449,6 @@ write_params(struct params *params, int *first)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a 6g function header. */
|
|
||||||
static void
|
|
||||||
write_6g_func_header(char *package, char *name, struct params *params,
|
|
||||||
int paramwid, struct params *rets)
|
|
||||||
{
|
|
||||||
int first, n;
|
|
||||||
|
|
||||||
printf("void\n%s·%s(", package, name);
|
|
||||||
first = 1;
|
|
||||||
write_params(params, &first);
|
|
||||||
|
|
||||||
/* insert padding to align output struct */
|
|
||||||
if(rets != NULL && paramwid%structround != 0) {
|
|
||||||
n = structround - paramwid%structround;
|
|
||||||
if(n & 1)
|
|
||||||
printf(", uint8");
|
|
||||||
if(n & 2)
|
|
||||||
printf(", uint16");
|
|
||||||
if(n & 4)
|
|
||||||
printf(", uint32");
|
|
||||||
}
|
|
||||||
|
|
||||||
write_params(rets, &first);
|
|
||||||
printf(")\n{\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write a 6g function trailer. */
|
|
||||||
static void
|
|
||||||
write_6g_func_trailer(struct params *rets)
|
|
||||||
{
|
|
||||||
struct params *p;
|
|
||||||
|
|
||||||
for (p = rets; p != NULL; p = p->next)
|
|
||||||
printf("\tFLUSH(&%s);\n", p->name);
|
|
||||||
printf("}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Define the gcc function return type if necessary. */
|
/* Define the gcc function return type if necessary. */
|
||||||
static void
|
static void
|
||||||
define_gcc_return_type(char *package, char *name, struct params *rets)
|
define_gcc_return_type(char *package, char *name, struct params *rets)
|
||||||
|
|
@ -619,14 +526,10 @@ write_gcc_func_trailer(char *package, char *name, struct params *rets)
|
||||||
|
|
||||||
/* Write out a function header. */
|
/* Write out a function header. */
|
||||||
static void
|
static void
|
||||||
write_func_header(char *package, char *name,
|
write_func_header(char *package, char *name, struct params *params,
|
||||||
struct params *params, int paramwid,
|
|
||||||
struct params *rets)
|
struct params *rets)
|
||||||
{
|
{
|
||||||
if (gcc)
|
write_gcc_func_header(package, name, params, rets);
|
||||||
write_gcc_func_header(package, name, params, rets);
|
|
||||||
else
|
|
||||||
write_6g_func_header(package, name, params, paramwid, rets);
|
|
||||||
printf("#line %d \"%s\"\n", lineno, file);
|
printf("#line %d \"%s\"\n", lineno, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -635,10 +538,7 @@ static void
|
||||||
write_func_trailer(char *package, char *name,
|
write_func_trailer(char *package, char *name,
|
||||||
struct params *rets)
|
struct params *rets)
|
||||||
{
|
{
|
||||||
if (gcc)
|
write_gcc_func_trailer(package, name, rets);
|
||||||
write_gcc_func_trailer(package, name, rets);
|
|
||||||
else
|
|
||||||
write_6g_func_trailer(rets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -713,12 +613,11 @@ process_file(void)
|
||||||
{
|
{
|
||||||
char *package, *name;
|
char *package, *name;
|
||||||
struct params *params, *rets;
|
struct params *params, *rets;
|
||||||
int paramwid;
|
|
||||||
|
|
||||||
package = read_package();
|
package = read_package();
|
||||||
read_preprocessor_lines();
|
read_preprocessor_lines();
|
||||||
while (read_func_header(&name, ¶ms, ¶mwid, &rets)) {
|
while (read_func_header(&name, ¶ms, &rets)) {
|
||||||
write_func_header(package, name, params, paramwid, rets);
|
write_func_header(package, name, params, rets);
|
||||||
copy_body();
|
copy_body();
|
||||||
write_func_trailer(package, name, rets);
|
write_func_trailer(package, name, rets);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
@ -731,7 +630,7 @@ process_file(void)
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
sysfatal("Usage: goc2c [--6g | --gc] [--go-pkgpath PKGPATH] [--go-prefix PREFIX] [file]\n");
|
sysfatal("Usage: goc2c [--go-pkgpath PKGPATH] [--go-prefix PREFIX] [file]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -743,11 +642,7 @@ main(int argc, char **argv)
|
||||||
while(argc > 1 && argv[1][0] == '-') {
|
while(argc > 1 && argv[1][0] == '-') {
|
||||||
if(strcmp(argv[1], "-") == 0)
|
if(strcmp(argv[1], "-") == 0)
|
||||||
break;
|
break;
|
||||||
if(strcmp(argv[1], "--6g") == 0)
|
if (strcmp(argv[1], "--go-pkgpath") == 0 && argc > 2) {
|
||||||
gcc = 0;
|
|
||||||
else if(strcmp(argv[1], "--gcc") == 0)
|
|
||||||
gcc = 1;
|
|
||||||
else if (strcmp(argv[1], "--go-pkgpath") == 0 && argc > 2) {
|
|
||||||
pkgpath = argv[2];
|
pkgpath = argv[2];
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
|
@ -775,18 +670,6 @@ main(int argc, char **argv)
|
||||||
sysfatal("open %s: %r\n", file);
|
sysfatal("open %s: %r\n", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!gcc) {
|
|
||||||
// 6g etc; update size table
|
|
||||||
goarch = getenv("GOARCH");
|
|
||||||
if(goarch != NULL && strcmp(goarch, "amd64") == 0) {
|
|
||||||
type_table[Uintptr].size = 8;
|
|
||||||
type_table[String].size = 16;
|
|
||||||
type_table[Slice].size = 8+4+4;
|
|
||||||
type_table[Eface].size = 8+8;
|
|
||||||
structround = 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("// AUTO-GENERATED by autogen.sh; DO NOT EDIT\n\n");
|
printf("// AUTO-GENERATED by autogen.sh; DO NOT EDIT\n\n");
|
||||||
process_file();
|
process_file();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue