diff options
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/go/Make-lang.in | 2 | ||||
-rw-r--r-- | gcc/go/go-backend.c | 9 | ||||
-rw-r--r-- | gcc/go/go-c.h | 2 | ||||
-rw-r--r-- | gcc/go/go-gcc.cc | 22 | ||||
-rw-r--r-- | gcc/go/go-sha1.cc | 71 | ||||
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/export.cc | 22 | ||||
-rw-r--r-- | gcc/go/gofrontend/export.h | 6 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/go-sha1.h | 33 | ||||
-rw-r--r-- | gcc/go/gofrontend/import.cc | 3 | ||||
-rw-r--r-- | gcc/go/gofrontend/lex.cc | 76 | ||||
-rw-r--r-- | gcc/go/gofrontend/lex.h | 3 |
14 files changed, 222 insertions, 47 deletions
diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog index 2052a977029..9351ddafe16 100644 --- a/gcc/go/ChangeLog +++ b/gcc/go/ChangeLog @@ -1,3 +1,19 @@ +2016-09-11 Ian Lance Taylor <iant@golang.org> + + * go-gcc.cc (Gcc_backend::Gcc_backend): Add builtin versions of + ctz, ctzll, bswap32, bswap64. + +2016-09-10 Ian Lance Taylor <iant@golang.org> + + * go-backend.c (go_trampoline_info): Remove. + * go-c.h (go_trampoline_info): Don't declare. + +2016-09-09 Than McIntosh <thanm@google.com> + + * go-sha1.cc: New file. + * Make-lang.in (GO_OBJS): Add go/go-sha1.o. + (CFLAGS-go/go-sha1.o): New variable. + 2016-08-29 Ian Lance Taylor <iant@google.com> * lang.opt (fgo-c-header, fgo-compiling-runtime): New options. diff --git a/gcc/go/Make-lang.in b/gcc/go/Make-lang.in index d5b2a776776..e7011f9d242 100644 --- a/gcc/go/Make-lang.in +++ b/gcc/go/Make-lang.in @@ -59,6 +59,7 @@ GO_OBJS = \ go/go-lang.o \ go/go-linemap.o \ go/go-optimize.o \ + go/go-sha1.o \ go/go.o \ go/gogo.o \ go/import.o \ @@ -225,6 +226,7 @@ GOINCLUDES = -I $(srcdir)/go -I $(srcdir)/go/gofrontend CFLAGS-go/go-gcc.o += $(GOINCLUDES) CFLAGS-go/go-linemap.o += $(GOINCLUDES) +CFLAGS-go/go-sha1.o += $(GOINCLUDES) go/%.o: go/gofrontend/%.cc $(COMPILE) $(GOINCLUDES) $< diff --git a/gcc/go/go-backend.c b/gcc/go/go-backend.c index 1c62495c38d..99609f0fc16 100644 --- a/gcc/go/go-backend.c +++ b/gcc/go/go-backend.c @@ -80,15 +80,6 @@ go_field_alignment (tree t) return v / BITS_PER_UNIT; } -/* Return the size and alignment of a trampoline. */ - -void -go_trampoline_info (unsigned int *size, unsigned int *alignment) -{ - *size = TRAMPOLINE_SIZE; - *alignment = TRAMPOLINE_ALIGNMENT; -} - /* This is called by the Go frontend proper if the unsafe package was imported. When that happens we can not do type-based alias analysis. */ diff --git a/gcc/go/go-c.h b/gcc/go/go-c.h index a96812d3cb5..194c1a9ca64 100644 --- a/gcc/go/go-c.h +++ b/gcc/go/go-c.h @@ -63,8 +63,6 @@ extern const char *go_localize_identifier (const char*); extern unsigned int go_field_alignment (tree); -extern void go_trampoline_info (unsigned int *size, unsigned int *alignment); - extern void go_imported_unsafe (void); extern void go_write_export_data (const char *, unsigned int); diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index 13407ea5d37..a332831b310 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -692,6 +692,28 @@ Gcc_backend::Gcc_backend() NULL_TREE), false, false); + // Used by runtime/internal/sys. + this->define_builtin(BUILT_IN_CTZ, "__builtin_ctz", "ctz", + build_function_type_list(integer_type_node, + unsigned_type_node, + NULL_TREE), + true, false); + this->define_builtin(BUILT_IN_CTZLL, "__builtin_ctzll", "ctzll", + build_function_type_list(integer_type_node, + long_long_unsigned_type_node, + NULL_TREE), + true, false); + this->define_builtin(BUILT_IN_BSWAP32, "__builtin_bswap32", "bswap32", + build_function_type_list(uint32_type_node, + uint32_type_node, + NULL_TREE), + true, false); + this->define_builtin(BUILT_IN_BSWAP64, "__builtin_bswap64", "bswap64", + build_function_type_list(uint64_type_node, + uint64_type_node, + NULL_TREE), + true, false); + // We provide some functions for the math library. tree math_function_type = build_function_type_list(double_type_node, double_type_node, diff --git a/gcc/go/go-sha1.cc b/gcc/go/go-sha1.cc new file mode 100644 index 00000000000..874b9635a76 --- /dev/null +++ b/gcc/go/go-sha1.cc @@ -0,0 +1,71 @@ +/* go-sha1.cc -- Go frontend interface to gcc backend. + Copyright (C) 2016 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#include "go-sha1.h" +#include "sha1.h" + +class Gcc_sha1_helper : public Go_sha1_helper +{ + public: + + Gcc_sha1_helper() : ctx_(new sha1_ctx) { sha1_init_ctx(this->ctx_); } + + ~Gcc_sha1_helper(); + + // Incorporate 'len' bytes from 'buffer' into checksum. + void + process_bytes(const void* buffer, size_t len); + + // Finalize checksum and return in the form of a string. + std::string + finish(); + + private: + sha1_ctx *ctx_; +}; + +Gcc_sha1_helper::~Gcc_sha1_helper() +{ + delete ctx_; +} + +void +Gcc_sha1_helper::process_bytes(const void* buffer, size_t len) +{ + sha1_process_bytes(buffer, len, this->ctx_); +} + +std::string +Gcc_sha1_helper::finish() +{ + // Use a union to provide the required alignment. + union + { + char checksum[checksum_len]; + long align; + } u; + sha1_finish_ctx(this->ctx_, u.checksum); + return std::string(u.checksum, checksum_len); +} + +Go_sha1_helper* +go_create_sha1_helper() +{ + return new Gcc_sha1_helper(); +} diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 71a9f5bcd5e..987aef7a6ef 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -c8cf90f2daf62428ca6aa0b5674572cd99f25fe3 +b34c93bf00ec4f2ad043ec89ff96989e0d1b26aa The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/export.cc b/gcc/go/gofrontend/export.cc index e9040efeda9..bec4c7ff978 100644 --- a/gcc/go/gofrontend/export.cc +++ b/gcc/go/gofrontend/export.cc @@ -6,8 +6,7 @@ #include "go-system.h" -#include "sha1.h" - +#include "go-sha1.h" #include "go-c.h" #include "gogo.h" @@ -40,6 +39,7 @@ const int Export::checksum_len; Export::Export(Stream* stream) : stream_(stream), type_refs_(), type_index_(1), packages_() { + go_assert(Export::checksum_len == Go_sha1_helper::checksum_len); } // A functor to sort Named_object pointers by name. @@ -686,9 +686,8 @@ Export::register_builtin_type(Gogo* gogo, const char* name, Builtin_code code) Export::Stream::Stream() { - this->checksum_ = new sha1_ctx; - memset(this->checksum_, 0, sizeof(sha1_ctx)); - sha1_init_ctx(this->checksum_); + this->sha1_helper_ = go_create_sha1_helper(); + go_assert(this->sha1_helper_ != NULL); } Export::Stream::~Stream() @@ -701,7 +700,7 @@ Export::Stream::~Stream() void Export::Stream::write_and_sum_bytes(const char* bytes, size_t length) { - sha1_process_bytes(bytes, length, this->checksum_); + this->sha1_helper_->process_bytes(bytes, length); this->do_write(bytes, length); } @@ -710,14 +709,9 @@ Export::Stream::write_and_sum_bytes(const char* bytes, size_t length) std::string Export::Stream::checksum() { - // Use a union to provide the required alignment. - union - { - char checksum[Export::checksum_len]; - long align; - } u; - sha1_finish_ctx(this->checksum_, u.checksum); - return std::string(u.checksum, Export::checksum_len); + std::string rval = this->sha1_helper_->finish(); + delete this->sha1_helper_; + return rval; } // Write the checksum string to the export data. diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h index ee61d2752de..fec73fbd75e 100644 --- a/gcc/go/gofrontend/export.h +++ b/gcc/go/gofrontend/export.h @@ -9,7 +9,7 @@ #include "string-dump.h" -struct sha1_ctx; +class Go_sha1_helper; class Gogo; class Import_init; class Bindings; @@ -109,8 +109,8 @@ class Export : public String_dump void write_and_sum_bytes(const char*, size_t); - // The checksum. - sha1_ctx* checksum_; + // The checksum helper. + Go_sha1_helper* sha1_helper_; }; Export(Stream*); diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 803611d5442..aabb35391ac 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -9050,7 +9050,7 @@ Call_expression::do_flatten(Gogo* gogo, Named_object*, Location loc = this->location(); int i = 0; - char buf[10]; + char buf[20]; for (Typed_identifier_list::const_iterator p = results->begin(); p != results->end(); ++p, ++i) diff --git a/gcc/go/gofrontend/go-sha1.h b/gcc/go/gofrontend/go-sha1.h new file mode 100644 index 00000000000..22db5a2b4b9 --- /dev/null +++ b/gcc/go/gofrontend/go-sha1.h @@ -0,0 +1,33 @@ +// go-sha1.h -- GCC specific sha1 checksum utilities. -*- C++ -*- + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifndef GO_SHA1_H +#define GO_SHA1_H + +#include "go-system.h" + +// +// Interface class for computation of SHA1 checksums. Front end requests +// one of these objects from the back end to use for computing +// checksums (each back end tends to have a different SHA1 implementation). +// Back ends are expected to create a new class that derives from this +// one containing an implementation. +// + +class Go_sha1_helper +{ + public: + virtual ~Go_sha1_helper() { } + virtual void process_bytes(const void* buffer, size_t len) = 0; + virtual std::string finish() = 0; + static const int checksum_len = 20; +}; + +// Call to create and return a new sha1 helper (this routine defined +// by the backend). Caller is responsible for deletion. +extern Go_sha1_helper* go_create_sha1_helper(); + +#endif // !defined(GO_SHA1_H) diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc index 54fd4c95719..d150020a4a3 100644 --- a/gcc/go/gofrontend/import.cc +++ b/gcc/go/gofrontend/import.cc @@ -7,7 +7,6 @@ #include "go-system.h" #include "filenames.h" -#include "simple-object.h" #include "go-c.h" #include "gogo.h" @@ -233,7 +232,7 @@ Import::find_export_data(const std::string& filename, int fd, Location location) return NULL; } -// Look for export data in a simple_object. +// Look for export data in an object file. Import::Stream* Import::find_object_export_data(const std::string& filename, diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc index 692aa502fec..05705f581c9 100644 --- a/gcc/go/gofrontend/lex.cc +++ b/gcc/go/gofrontend/lex.cc @@ -985,6 +985,52 @@ Lex::is_hex_digit(char c) || (c >= 'a' && c <= 'f')); } +// not a hex value +#define NHV 100 + +// for use by Lex::hex_val +static const unsigned char hex_value_lookup_table[256] = +{ + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // NUL SOH STX ETX EOT ENQ ACK BEL + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // BS HT LF VT FF CR SO SI + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // DLE DC1 DC2 DC3 DC4 NAK SYN ETB + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // CAN EM SUB ESC FS GS RS US + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // SP ! " # $ % & ' + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // ( ) * + , - . / + 0, 1, 2, 3, 4, 5, 6, 7, // 0 1 2 3 4 5 6 7 + 8, 9, NHV, NHV, NHV, NHV, NHV, NHV, // 8 9 : ; < = > ? + NHV, 10, 11, 12, 13, 14, 15, NHV, // @ A B C D E F G + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // H I J K L M N O + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // P Q R S T U V W + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // X Y Z [ \ ] ^ _ + NHV, 10, 11, 12, 13, 14, 15, NHV, // ` a b c d e f g + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // h i j k l m n o + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // p q r s t u v w + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // x y z { | } ~ + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV, // + NHV, NHV, NHV, NHV, NHV, NHV, NHV, NHV // +}; + +unsigned +Lex::hex_val(char c) +{ + return hex_value_lookup_table[static_cast<unsigned char>(c)]; +} + // Return whether an exponent could start at P. bool @@ -1212,7 +1258,7 @@ Lex::advance_one_char(const char* p, bool is_single_quote, unsigned int* value, *is_character = false; if (Lex::is_hex_digit(p[1]) && Lex::is_hex_digit(p[2])) { - *value = (hex_value(p[1]) << 4) + hex_value(p[2]); + *value = (Lex::hex_val(p[1]) << 4) + Lex::hex_val(p[2]); return p + 3; } error_at(this->location(), "invalid hex character"); @@ -1259,10 +1305,10 @@ Lex::advance_one_char(const char* p, bool is_single_quote, unsigned int* value, if (Lex::is_hex_digit(p[1]) && Lex::is_hex_digit(p[2]) && Lex::is_hex_digit(p[3]) && Lex::is_hex_digit(p[4])) { - *value = ((hex_value(p[1]) << 12) - + (hex_value(p[2]) << 8) - + (hex_value(p[3]) << 4) - + hex_value(p[4])); + *value = ((Lex::hex_val(p[1]) << 12) + + (Lex::hex_val(p[2]) << 8) + + (Lex::hex_val(p[3]) << 4) + + Lex::hex_val(p[4])); if (*value >= 0xd800 && *value < 0xe000) { error_at(this->location(), @@ -1282,14 +1328,14 @@ Lex::advance_one_char(const char* p, bool is_single_quote, unsigned int* value, && Lex::is_hex_digit(p[5]) && Lex::is_hex_digit(p[6]) && Lex::is_hex_digit(p[7]) && Lex::is_hex_digit(p[8])) { - *value = ((hex_value(p[1]) << 28) - + (hex_value(p[2]) << 24) - + (hex_value(p[3]) << 20) - + (hex_value(p[4]) << 16) - + (hex_value(p[5]) << 12) - + (hex_value(p[6]) << 8) - + (hex_value(p[7]) << 4) - + hex_value(p[8])); + *value = ((Lex::hex_val(p[1]) << 28) + + (Lex::hex_val(p[2]) << 24) + + (Lex::hex_val(p[3]) << 20) + + (Lex::hex_val(p[4]) << 16) + + (Lex::hex_val(p[5]) << 12) + + (Lex::hex_val(p[6]) << 8) + + (Lex::hex_val(p[7]) << 4) + + Lex::hex_val(p[8])); if (*value > 0x10ffff || (*value >= 0xd800 && *value < 0xe000)) { @@ -2721,10 +2767,10 @@ Lex::is_exported_name(const std::string& name) for (size_t i = 2; i < len && p[i] != '$'; ++i) { c = p[i]; - if (!hex_p(c)) + if (!Lex::is_hex_digit(c)) return false; ci <<= 4; - ci |= hex_value(c); + ci |= Lex::hex_val(c); } return Lex::is_unicode_uppercase(ci); } diff --git a/gcc/go/gofrontend/lex.h b/gcc/go/gofrontend/lex.h index 5c4afb611b0..0a7a842ba88 100644 --- a/gcc/go/gofrontend/lex.h +++ b/gcc/go/gofrontend/lex.h @@ -454,6 +454,9 @@ class Lex octal_value(char c) { return c - '0'; } + static unsigned + hex_val(char c); + Token make_invalid_token() { return Token::make_invalid_token(this->location()); } |