aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2016-09-09 18:27:42 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-09-09 18:27:42 +0000
commit34144b6ec0548510df171956040f91a8742def29 (patch)
tree8e69d15b9145f6056b170cf44fb802a3b9139ed2
parente81e83d04796b834c9f3e63d74b7202bca28e5c9 (diff)
downloadgcc-34144b6ec0548510df171956040f91a8742def29.zip
gcc-34144b6ec0548510df171956040f91a8742def29.tar.gz
gcc-34144b6ec0548510df171956040f91a8742def29.tar.bz2
compiler: add abstraction layer for sha1 checksums.
Add new interface for the front end code to use when computing SHA1 checksums; the intent is to allow the different implementation in different back ends. No change in functionality for gccgo; this is an enabling change to permit the front end to be used with other back ends (e.g. LLVM). Reviewed-on: https://go-review.googlesource.com/28833 * go-sha1.cc: New file. * Make-lang.in (GO_OBJS): Add go/go-sha1.o. (CFLAGS-go/go-sha1.o): New variable. From-SVN: r240053
-rw-r--r--gcc/go/ChangeLog6
-rw-r--r--gcc/go/Make-lang.in2
-rw-r--r--gcc/go/go-sha1.cc71
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/export.cc22
-rw-r--r--gcc/go/gofrontend/export.h6
-rw-r--r--gcc/go/gofrontend/go-sha1.h33
7 files changed, 124 insertions, 18 deletions
diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog
index 7fa2729..8214ece 100644
--- a/gcc/go/ChangeLog
+++ b/gcc/go/ChangeLog
@@ -1,3 +1,9 @@
+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-09-01 Martin Sebor <msebor@redhat.com>
* gofrontend/expressions.cc: Increase buffer size to guarantee
diff --git a/gcc/go/Make-lang.in b/gcc/go/Make-lang.in
index d5b2a77..e7011f9 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-sha1.cc b/gcc/go/go-sha1.cc
new file mode 100644
index 0000000..874b963
--- /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 26ce264..af731f1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-4de301275dfed034a1dd9dff3d1af8643ee5cb4b
+2022ddc85f812b6990b72c7e95b8207e07ac8984
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 e9040ef..bec4c7f 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 ee61d27..fec73fb 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/go-sha1.h b/gcc/go/gofrontend/go-sha1.h
new file mode 100644
index 0000000..22db5a2
--- /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)