From 3c061ac0525eebec030eee46aab6671023177eea Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Tue, 11 Oct 2016 00:11:43 +0000 Subject: [PATCH] compiler: move Backend/Linemap creation out of front end. Push the calls to create Backend and Linemap object out of the front end into the back end, and instead pass pointers to these objects in the go_create_gogo_args struct. This allows for more flexibility in the interfaces used to create the objects. Reviewed-on: https://go-review.googlesource.com/30698 * 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". From-SVN: r240959 --- gcc/go/ChangeLog | 10 ++++++++++ gcc/go/go-c.h | 10 +++++++--- gcc/go/go-gcc.cc | 1 + gcc/go/go-gcc.h | 33 +++++++++++++++++++++++++++++++++ gcc/go/go-lang.c | 3 +++ gcc/go/go-linemap.cc | 2 ++ gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/backend.h | 4 ---- gcc/go/gofrontend/go-linemap.h | 4 ---- gcc/go/gofrontend/go.cc | 3 +-- 10 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 gcc/go/go-gcc.h diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog index 6ea6138c327..93bf4c12c2b 100644 --- a/gcc/go/ChangeLog +++ b/gcc/go/ChangeLog @@ -1,3 +1,13 @@ +2016-10-10 Than McIntosh + + * 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". + 2016-10-10 Than McIntosh * go-linemap.cc (Gcc_linemap::location_line): New method. diff --git a/gcc/go/go-c.h b/gcc/go/go-c.h index 194c1a9ca64..74e89463c43 100644 --- a/gcc/go/go-c.h +++ b/gcc/go/go-c.h @@ -22,6 +22,8 @@ along with GCC; see the file COPYING3. If not see #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; diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index b3701bf31e4..44daaa0aece 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -43,6 +43,7 @@ #include "builtins.h" #include "go-c.h" +#include "go-gcc.h" #include "gogo.h" #include "backend.h" diff --git a/gcc/go/go-gcc.h b/gcc/go/go-gcc.h new file mode 100644 index 00000000000..0dfd3927f10 --- /dev/null +++ b/gcc/go/go-gcc.h @@ -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 +. */ + +#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) diff --git a/gcc/go/go-lang.c b/gcc/go/go-lang.c index 88667e0c9b4..8d66ee0e176 100644 --- a/gcc/go/go-lang.c +++ b/gcc/go/go-lang.c @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see #include #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 (); diff --git a/gcc/go/go-linemap.cc b/gcc/go/go-linemap.cc index 22498d940ad..2accb95e5c4 100644 --- a/gcc/go/go-linemap.cc +++ b/gcc/go/go-linemap.cc @@ -6,6 +6,8 @@ #include "go-linemap.h" +#include "go-gcc.h" + // This class implements the Linemap interface defined by the // frontend. diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index c987dc90eb7..66b1b856c7e 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -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. diff --git a/gcc/go/gofrontend/backend.h b/gcc/go/gofrontend/backend.h index 3b9d3a6202a..8c45b6493b7 100644 --- a/gcc/go/gofrontend/backend.h +++ b/gcc/go/gofrontend/backend.h @@ -740,8 +740,4 @@ class Backend const std::vector& variable_decls) = 0; }; -// The backend interface has to define this function. - -extern Backend* go_get_backend(); - #endif // !defined(GO_BACKEND_H) diff --git a/gcc/go/gofrontend/go-linemap.h b/gcc/go/gofrontend/go-linemap.h index f0ca99d905c..704efdbfa53 100644 --- a/gcc/go/gofrontend/go-linemap.h +++ b/gcc/go/gofrontend/go-linemap.h @@ -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) diff --git a/gcc/go/gofrontend/go.cc b/gcc/go/gofrontend/go.cc index 927f29d8133..e0e84e3adc2 100644 --- a/gcc/go/gofrontend/go.cc +++ b/gcc/go/gofrontend/go.cc @@ -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) -- 2.30.2