diff options
Diffstat (limited to 'gcc/go/gofrontend')
-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 |
8 files changed, 111 insertions, 36 deletions
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()); } |