This patch by Than McIntosh moves the calls that create the GCC-specific Backend and Linemap objects out of the Go frontend into the gccgo interface code. This allows for more flexibility creating those objects. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline.
Ian 2016-10-10 Than McIntosh <th...@google.com> * go-gcc.h: New file. * go-c.h (struct go_create_gogo_args): Add backend and linemap fields. * go-lang.c: Include "go-gcc.h". (go_langhook_init): Set linemap and backend fields of args. * go-gcc.cc: Include "go-gcc.h". * go-linemap.cc: Include "go-gcc.h".
Index: gcc/go/go-c.h =================================================================== --- gcc/go/go-c.h (revision 240942) +++ gcc/go/go-c.h (working copy) @@ -22,6 +22,8 @@ along with GCC; see the file COPYING3. #define GO_EXTERN_C +class Linemap; +class Backend; /* Functions defined in the Go frontend proper called by the GCC interface. */ @@ -36,9 +38,11 @@ struct go_create_gogo_args int int_type_size; int pointer_size; const char* pkgpath; - const char *prefix; - const char *relative_import_path; - const char *c_header; + const char* prefix; + const char* relative_import_path; + const char* c_header; + Backend* backend; + Linemap* linemap; bool check_divide_by_zero; bool check_divide_overflow; bool compiling_runtime; Index: gcc/go/go-gcc.cc =================================================================== --- gcc/go/go-gcc.cc (revision 240942) +++ gcc/go/go-gcc.cc (working copy) @@ -43,6 +43,7 @@ #include "builtins.h" #include "go-c.h" +#include "go-gcc.h" #include "gogo.h" #include "backend.h" Index: gcc/go/go-gcc.h =================================================================== --- gcc/go/go-gcc.h (revision 0) +++ gcc/go/go-gcc.h (working copy) @@ -0,0 +1,33 @@ +/* go-gcc.h -- Header file for go backend-specific interfaces. + 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/>. */ + +#ifndef GO_GO_GCC_BACKEND_H +#define GO_GO_GCC_BACKEND_H + +class Backend; + +// Create and return a Backend object for use with the GCC backend. + +extern Backend *go_get_backend(); + +// Create and return a Linemap object for use with the GCC backend. + +extern Linemap *go_get_linemap(); + +#endif // !defined(GO_GCC_BACKEND_H) Index: gcc/go/go-lang.c =================================================================== --- gcc/go/go-lang.c (revision 240942) +++ gcc/go/go-lang.c (working copy) @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. #include <mpfr.h> #include "go-c.h" +#include "go-gcc.h" /* Language-dependent contents of a type. */ @@ -111,6 +112,8 @@ go_langhook_init (void) args.check_divide_overflow = go_check_divide_overflow; args.compiling_runtime = go_compiling_runtime; args.debug_escape_level = go_debug_escape_level; + args.linemap = go_get_linemap(); + args.backend = go_get_backend(); go_create_gogo (&args); build_common_builtin_nodes (); Index: gcc/go/go-linemap.cc =================================================================== --- gcc/go/go-linemap.cc (revision 240942) +++ gcc/go/go-linemap.cc (working copy) @@ -6,6 +6,8 @@ #include "go-linemap.h" +#include "go-gcc.h" + // This class implements the Linemap interface defined by the // frontend. Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 240956) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -ecf9b645cefc5c3b4e6339adeb452b2d8642cf3e +a700fa1908aa2a36f05b3ee09932f814fd94a10d The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/backend.h =================================================================== --- gcc/go/gofrontend/backend.h (revision 240942) +++ gcc/go/gofrontend/backend.h (working copy) @@ -740,8 +740,4 @@ class Backend const std::vector<Bvariable*>& variable_decls) = 0; }; -// The backend interface has to define this function. - -extern Backend* go_get_backend(); - #endif // !defined(GO_BACKEND_H) Index: gcc/go/gofrontend/go-linemap.h =================================================================== --- gcc/go/gofrontend/go-linemap.h (revision 240942) +++ gcc/go/gofrontend/go-linemap.h (working copy) @@ -149,8 +149,4 @@ class Linemap } }; -// The backend interface must define this function. It should return -// a fully implemented instance of Linemap. -extern Linemap* go_get_linemap(); - #endif // !defined(GO_LINEMAP_H) Index: gcc/go/gofrontend/go.cc =================================================================== --- gcc/go/gofrontend/go.cc (revision 240942) +++ gcc/go/gofrontend/go.cc (working copy) @@ -24,8 +24,7 @@ void go_create_gogo(const struct go_create_gogo_args* args) { go_assert(::gogo == NULL); - Linemap* linemap = go_get_linemap(); - ::gogo = new Gogo(go_get_backend(), linemap, args->int_type_size, + ::gogo = new Gogo(args->backend, args->linemap, args->int_type_size, args->pointer_size); if (args->pkgpath != NULL)