From patchwork Wed Oct 31 20:50:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 195995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 02A722C0193 for ; Thu, 1 Nov 2012 07:50:24 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352321425; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=N5tjbAx +KLjlsDdMOOMO4XhKY2c=; b=pO0YMMo1uZV9d4U7mHhrHa1ufLOGaeY3jN9P4zY BQ6UahMNg49OYVENS17cU+h35kG0tkqCf5XstjPr8j6n6yElelfNyPNeUy+gVTA8 j+jMdPhcRNOFz7/5YlEu+na67/OPowAEwa4vHftXtTNvoRtGzHN7u9QcDVr5J2jd JSNY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Wg9Mmd3alkxc061mFUMzdIzM0USZAnMgnZFY8+AiSMzIhlN4ixEsbpSEGf3RuV I5LZPFTtNBDgIM9ScgggnRnNVT7/4+xpJUN//eyQxd396KKk1POY3NxcS5Q9wBZH lm1sVDwuzcJ1Kb79BNhLpTCkdvma4ev8WexlhBiyIbRF4=; Received: (qmail 23819 invoked by alias); 31 Oct 2012 20:50:14 -0000 Received: (qmail 23793 invoked by uid 22791); 31 Oct 2012 20:50:12 -0000 X-SWARE-Spam-Status: No, hits=-3.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, PERCENT_RANDOM, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SARE_RAND_2, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pa0-f47.google.com (HELO mail-pa0-f47.google.com) (209.85.220.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 31 Oct 2012 20:50:05 +0000 Received: by mail-pa0-f47.google.com with SMTP id fa11so1195592pad.20 for ; Wed, 31 Oct 2012 13:50:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=yO79iL6TjnFAEGv3cGogSCUX/EWDE4QSwthNsweifmE=; b=kXLSesDuf9zBJuoWyII1OfR5iAlVOskxyPcUpkOrqW6rFOUjmU/ZcMZfk9Mz9BOMld +mrUqGs77+idQnY/+oHDHAz/pKnUzrPiIOaw0bE/ATY4F2GJYYS3D0ErjSxeNxlZJXo4 8U8m8hRyr2ajDMMFZw5I9R4U8eEkPoU1ed44bEQh9rDg+GdfnwaLzWWdH3jlsKgDEJX3 8GeUdyGf3XuSKKvO8aLC9lLen6d9FbamSRSLuaLCgyosWQANEiFgs3jh/lUSQT6Tkdgj hP2sAS5Ur7QokVYbNx8rrp1U052QLEKLuS9qO2MK1fbHVesyKV5CUVvliWWQJq5RKXjD rC+A== Received: by 10.68.217.131 with SMTP id oy3mr9275811pbc.145.1351716605220; Wed, 31 Oct 2012 13:50:05 -0700 (PDT) Received: from coign.google.com ([172.29.166.34]) by mx.google.com with ESMTPS id nv2sm2800900pbc.44.2012.10.31.13.50.03 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 31 Oct 2012 13:50:04 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: libgo patch committed: Use intgo Date: Wed, 31 Oct 2012 13:50:02 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmk2MKVAnVzy/iK8WO1ZBP6VEkk8O5rUyFbC7TDuZvfNVDdAmw7r+SrV8ZFLhLxgiNIThVFrMUGvGvNzeindyG8V8hKlhBflIz/82FmWJjNgheVgN/Hccy6mSI9yZF4at4K551lwj+IVT4n9FDvGymbUlgYgIALk7rX9LxIjmz5UScvIMrkWaemJQp6zi9aZMJcfOBU X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch to libgo changes the goc2c program to change the Go type "int" to the C type "intgo". This is in preparation for changing the Go type "int" to be 64 bits on x86_64. The goc2c program used to be used by the gc compiler, but it no longer is, so while I was there I removed the gc support. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 47a142d6f93e libgo/Makefile.am --- a/libgo/Makefile.am Tue Oct 30 12:27:12 2012 -0700 +++ b/libgo/Makefile.am Wed Oct 31 13:46:56 2012 -0700 @@ -536,35 +536,35 @@ $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ $< malloc.c: $(srcdir)/runtime/malloc.goc goc2c - ./goc2c --gcc $< > $@.tmp + ./goc2c $< > $@.tmp mv -f $@.tmp $@ mprof.c: $(srcdir)/runtime/mprof.goc goc2c - ./goc2c --gcc $< > $@.tmp + ./goc2c $< > $@.tmp mv -f $@.tmp $@ reflect.c: $(srcdir)/runtime/reflect.goc goc2c - ./goc2c --gcc $< > $@.tmp + ./goc2c $< > $@.tmp mv -f $@.tmp $@ runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c - ./goc2c --gcc $< > $@.tmp + ./goc2c $< > $@.tmp mv -f $@.tmp $@ sema.c: $(srcdir)/runtime/sema.goc goc2c - ./goc2c --gcc $< > $@.tmp + ./goc2c $< > $@.tmp mv -f $@.tmp $@ sigqueue.c: $(srcdir)/runtime/sigqueue.goc goc2c - ./goc2c --gcc --go-pkgpath os_signal $< > $@.tmp + ./goc2c --go-pkgpath os_signal $< > $@.tmp mv -f $@.tmp $@ time.c: $(srcdir)/runtime/time.goc goc2c - ./goc2c --gcc $< > $@.tmp + ./goc2c $< > $@.tmp mv -f $@.tmp $@ %.c: $(srcdir)/runtime/%.goc goc2c - ./goc2c --gcc $< > $@.tmp + ./goc2c $< > $@.tmp mv -f $@.tmp $@ go_bufio_files = \ diff -r 47a142d6f93e libgo/runtime/goc2c.c --- a/libgo/runtime/goc2c.c Tue Oct 30 12:27:12 2012 -0700 +++ b/libgo/runtime/goc2c.c Wed Oct 31 13:46:56 2012 -0700 @@ -30,13 +30,10 @@ #include #include -/* Whether we're emitting for gcc */ -static int gcc; - -/* Package path to use; only meaningful for gcc */ +/* Package path to use. */ static const char *pkgpath; -/* Package prefix to use; only meaningful for gcc */ +/* Package prefix to use. */ static const char *prefix; /* File and line number */ @@ -50,53 +47,6 @@ 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; static void @@ -147,6 +97,15 @@ 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. */ static void free_params(struct params *p) @@ -351,14 +310,29 @@ unsigned int len; 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; + } op = p; pointer_count = 0; while (*p == '*') { ++pointer_count; ++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); q = xmalloc(len + pointer_count + 1); memcpy(q, p, len); @@ -372,39 +346,19 @@ 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. * The list ends with a ')'. We have already read the '('. */ static struct params * -read_params(int *poffset) +read_params() { char *token; struct params *ret, **pp, *p; - int offset, size, rnd; ret = NULL; pp = &ret; token = read_token_no_eof(); - offset = 0; if (strcmp(token, ")") != 0) { while (1) { p = xmalloc(sizeof(struct params)); @@ -414,14 +368,6 @@ *pp = p; 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(); if (strcmp(token, ",") != 0) break; @@ -432,8 +378,6 @@ sysfatal("%s:%ud: expected '('\n", file, lineno); } - if (poffset != NULL) - *poffset = offset; return ret; } @@ -442,7 +386,7 @@ * '{' character. Returns 1 if it read a header, 0 at EOF. */ 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; char *token; @@ -474,13 +418,13 @@ sysfatal("%s:%ud: expected \"(\"\n", file, lineno); } - *params = read_params(paramwid); + *params = read_params(); token = read_token(); if (token == NULL || strcmp(token, "(") != 0) *rets = NULL; else { - *rets = read_params(NULL); + *rets = read_params(); token = read_token(); } if (token == NULL || strcmp(token, "{") != 0) { @@ -505,43 +449,6 @@ } } -/* 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. */ static void define_gcc_return_type(char *package, char *name, struct params *rets) @@ -619,14 +526,10 @@ /* Write out a function header. */ static void -write_func_header(char *package, char *name, - struct params *params, int paramwid, +write_func_header(char *package, char *name, struct params *params, struct params *rets) { - if (gcc) - write_gcc_func_header(package, name, params, rets); - else - write_6g_func_header(package, name, params, paramwid, rets); + write_gcc_func_header(package, name, params, rets); printf("#line %d \"%s\"\n", lineno, file); } @@ -635,10 +538,7 @@ write_func_trailer(char *package, char *name, struct params *rets) { - if (gcc) - write_gcc_func_trailer(package, name, rets); - else - write_6g_func_trailer(rets); + write_gcc_func_trailer(package, name, rets); } /* @@ -713,12 +613,11 @@ { char *package, *name; struct params *params, *rets; - int paramwid; package = read_package(); read_preprocessor_lines(); - while (read_func_header(&name, ¶ms, ¶mwid, &rets)) { - write_func_header(package, name, params, paramwid, rets); + while (read_func_header(&name, ¶ms, &rets)) { + write_func_header(package, name, params, rets); copy_body(); write_func_trailer(package, name, rets); free(name); @@ -731,7 +630,7 @@ static 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 @@ -743,11 +642,7 @@ while(argc > 1 && argv[1][0] == '-') { if(strcmp(argv[1], "-") == 0) break; - if(strcmp(argv[1], "--6g") == 0) - gcc = 0; - else if(strcmp(argv[1], "--gcc") == 0) - gcc = 1; - else if (strcmp(argv[1], "--go-pkgpath") == 0 && argc > 2) { + if (strcmp(argv[1], "--go-pkgpath") == 0 && argc > 2) { pkgpath = argv[2]; argc--; argv++; @@ -775,18 +670,6 @@ 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"); process_file(); exit(0);