Patchwork [gccgo] Remove general tm.h dependency

login
register
mail settings
Submitter Ian Taylor
Date Nov. 16, 2010, 8:51 p.m.
Message ID <mcrsjz16lgm.fsf@google.com>
Download mbox | patch
Permalink /patch/71452/
State New
Headers show

Comments

Ian Taylor - Nov. 16, 2010, 8:51 p.m.
This patch avoids including tm.h in every file in the Go frontend.
There are currently two files in the Go frontend which use tm.h:
expressions.cc uses ADJUST_FIELD_ALIGN and gogo-tree.cc uses
OBJECT_FORMAT_ELF.  Both dependencies will eventually move out of the
frontend proper.  This patch also cleans up go-c.h a bit.  Committed to
gccgo branch.

Ian

Patch

diff -r a15004e28ba8 go/expressions.cc
--- a/go/expressions.cc	Fri Nov 12 12:49:58 2010 -0800
+++ b/go/expressions.cc	Tue Nov 16 12:46:20 2010 -0800
@@ -21,6 +21,7 @@ 
 #include "convert.h"
 #include "real.h"
 #include "realmpfr.h"
+#include "tm.h"
 #include "tm_p.h"
 
 #ifndef ENABLE_BUILD_WITH_CXX
diff -r a15004e28ba8 go/go.cc
--- a/go/go.cc	Fri Nov 12 12:49:58 2010 -0800
+++ b/go/go.cc	Tue Nov 16 12:46:20 2010 -0800
@@ -28,10 +28,10 @@ 
 
 GO_EXTERN_C
 void
-go_create_gogo()
+go_create_gogo(int int_type_size, int float_type_size, int pointer_size)
 {
   gcc_assert(::gogo == NULL);
-  ::gogo = new Gogo();
+  ::gogo = new Gogo(int_type_size, float_type_size, pointer_size);
   if (!unique_prefix.empty())
     ::gogo->set_unique_prefix(unique_prefix);
 }
@@ -60,7 +60,8 @@ 
 
 GO_EXTERN_C
 void
-go_parse_input_files(const char** filenames, unsigned int filename_count)
+go_parse_input_files(const char** filenames, unsigned int filename_count,
+		     bool only_check_syntax, bool require_return_statement)
 {
   gcc_assert(filename_count > 0);
   for (unsigned int i = 0; i < filename_count; ++i)
@@ -105,17 +106,17 @@ 
   // correct.
   ::gogo->verify_types();
 
-  if (flag_syntax_only)
-    return;
-
   // Work out types of unspecified constants and variables.
   ::gogo->determine_types();
 
   // Check types and issue errors as appropriate.
   ::gogo->check_types();
 
+  if (only_check_syntax)
+    return;
+
   // Check that functions have return statements.
-  if (go_require_return_statement)
+  if (require_return_statement)
     ::gogo->check_return_statements();
 
   // Export global identifiers as appropriate.
diff -r a15004e28ba8 go/gogo-tree.cc
--- a/go/gogo-tree.cc	Fri Nov 12 12:49:58 2010 -0800
+++ b/go/gogo-tree.cc	Tue Nov 16 12:46:20 2010 -0800
@@ -16,6 +16,7 @@ 
 {
 #endif
 
+#include "tm.h"
 #include "toplev.h"
 #include "tree.h"
 #include "gimple.h"
@@ -24,7 +25,6 @@ 
 #include "langhooks.h"
 #include "convert.h"
 #include "output.h"
-#include "tm_p.h"
 #include "diagnostic.h"
 #include "rtl.h"
 
diff -r a15004e28ba8 go/gogo.cc
--- a/go/gogo.cc	Fri Nov 12 12:49:58 2010 -0800
+++ b/go/gogo.cc	Tue Nov 16 12:46:20 2010 -0800
@@ -21,7 +21,7 @@ 
 
 // Class Gogo.
 
-Gogo::Gogo()
+Gogo::Gogo(int int_type_size, int float_type_size, int pointer_size)
   : package_(NULL),
     functions_(),
     globals_(new Bindings(NULL)),
@@ -68,7 +68,8 @@ 
   this->add_named_type(Type::make_complex_type("complex128", 128,
 					       RUNTIME_TYPE_KIND_COMPLEX128));
 
-  const int int_type_size = std::max(INT_TYPE_SIZE, 32);
+  if (int_type_size < 32)
+    int_type_size = 32;
   this->add_named_type(Type::make_integer_type("uint", true,
 					       int_type_size,
 					       RUNTIME_TYPE_KIND_UINT));
@@ -84,13 +85,13 @@ 
   byte_type->set_type_value(uint8_type);
 
   this->add_named_type(Type::make_integer_type("uintptr", true,
-					       POINTER_SIZE,
+					       pointer_size,
 					       RUNTIME_TYPE_KIND_UINTPTR));
 
-  this->add_named_type(Type::make_float_type("float", FLOAT_TYPE_SIZE,
+  this->add_named_type(Type::make_float_type("float", float_type_size,
 					     RUNTIME_TYPE_KIND_FLOAT));
 
-  this->add_named_type(Type::make_complex_type("complex", FLOAT_TYPE_SIZE * 2,
+  this->add_named_type(Type::make_complex_type("complex", float_type_size * 2,
 					       RUNTIME_TYPE_KIND_COMPLEX));
 
   this->add_named_type(Type::make_named_bool_type());
diff -r a15004e28ba8 go/gogo.h
--- a/go/gogo.h	Fri Nov 12 12:49:58 2010 -0800
+++ b/go/gogo.h	Tue Nov 16 12:46:20 2010 -0800
@@ -104,7 +104,9 @@ 
 class Gogo
 {
  public:
-  Gogo();
+  // Create the IR, passing in the sizes of the types "int", "float",
+  // and "uintptr" in bits.
+  Gogo(int int_type_size, int float_type_size, int pointer_size);
 
   // Get the package name.
   const std::string&
Index: Make-lang.in
===================================================================
--- Make-lang.in	(revision 166814)
+++ Make-lang.in	(working copy)
@@ -122,7 +122,7 @@  go.stageprofile: stageprofile-start
 go.stagefeedback: stagefeedback-start
 	-mv go/*$(objext) stagefeedback/go
 
-GO_SYSTEM_H = go/go-system.h $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
+GO_SYSTEM_H = go/go-system.h $(CONFIG_H) $(SYSTEM_H) coretypes.h \
 	$(DIAGNOSTIC_CORE_H) $(INPUT_H)
 
 GO_C_H = go/go-c.h $(MACHMODE_H)
@@ -151,16 +151,16 @@  go/export.o: go/gofrontend/export.cc $(G
 	$(GO_GOGO_H) $(GO_TYPES_H) $(GO_STATEMENTS_H) go/gofrontend/export.h
 go/expressions.o: go/gofrontend/expressions.cc $(GO_SYSTEM_H) $(TOPLEV_H) \
 	intl.h $(TREE_H) $(GIMPLE_H) tree-iterator.h convert.h $(REAL_H) \
-	realmpfr.h $(TM_P_H) $(GO_C_H) $(GO_GOGO_H) $(GO_TYPES_H) \
+	realmpfr.h $(TM_H) $(TM_P_H) $(GO_C_H) $(GO_GOGO_H) $(GO_TYPES_H) \
 	go/gofrontend/export.h $(GO_IMPORT_H) $(GO_STATEMENTS_H) $(GO_LEX_H) \
 	$(GO_EXPRESSIONS_H)
 go/go.o: go/gofrontend/go.cc $(GO_SYSTEM_H) $(GO_C_H) $(GO_LEX_H) \
 	$(GO_PARSE_H) $(GO_GOGO_H)
 go/go-dump.o: go/gofrontend/go-dump.cc $(GO_SYSTEM_H) $(GO_C_H) \
 	go/gofrontend/go-dump.h
-go/gogo-tree.o: go/gofrontend/gogo-tree.cc $(GO_SYSTEM_H) $(TOPLEV_H) \
+go/gogo-tree.o: go/gofrontend/gogo-tree.cc $(GO_SYSTEM_H) $(TM_H) $(TOPLEV_H) \
 	$(TREE_H) $(GIMPLE_H) tree-iterator.h $(CGRAPH_H) langhooks.h \
-	convert.h output.h $(TM_P_H) $(DIAGNOSTIC_H) $(RTL_H) $(GO_TYPES_H) \
+	convert.h output.h $(DIAGNOSTIC_H) $(RTL_H) $(GO_TYPES_H) \
 	$(GO_EXPRESSIONS_H) $(GO_STATEMENTS_H) $(GO_GOGO_H)
 go/gogo.o: go/gofrontend/gogo.cc $(GO_SYSTEM_H) go/gofrontend/go-dump.h \
 	$(GO_LEX_H) $(GO_TYPES_H) $(GO_STATEMENTS_H) $(GO_EXPRESSIONS_H) \
Index: go-lang.c
===================================================================
--- go-lang.c	(revision 166814)
+++ go-lang.c	(working copy)
@@ -103,7 +103,7 @@  go_langhook_init (void)
      to, e.g., unsigned_char_type_node) but before calling
      build_common_builtin_nodes (because it calls, indirectly,
      go_type_for_size).  */
-  go_create_gogo ();
+  go_create_gogo (INT_TYPE_SIZE, FLOAT_TYPE_SIZE, POINTER_SIZE);
 
   build_common_builtin_nodes ();
 
@@ -223,7 +223,8 @@  go_langhook_post_options (const char **p
 static void
 go_langhook_parse_file (int set_yy_debug ATTRIBUTE_UNUSED)
 {
-  go_parse_input_files (in_fnames, num_in_fnames);
+  go_parse_input_files (in_fnames, num_in_fnames, flag_syntax_only,
+			go_require_return_statement);
 }
 
 static tree
Index: go-c.h
===================================================================
--- go-c.h	(revision 166814)
+++ go-c.h	(working copy)
@@ -33,18 +33,29 @@  extern "C"
 
 #include "machmode.h"
 
-extern int go_enable_dump(const char*);
-extern void go_set_prefix(const char*);
+/* Functions defined in the Go frontend proper called by the GCC
+   interface.  */
 
-extern void go_preserve_from_gc(tree);
+extern int go_enable_dump (const char*);
+extern void go_set_prefix (const char*);
 
-extern void go_add_search_path(const char*);
-extern void go_create_gogo(void);
-extern void go_parse_input_files(const char**, unsigned int);
-extern void go_write_globals(void);
+extern void go_add_search_path (const char*);
 
-extern tree go_type_for_size(unsigned int bits, int unsignedp);
-extern tree go_type_for_mode(enum machine_mode, int unsignedp);
+extern void go_create_gogo (int int_type_size, int float_type_size,
+			    int pointer_size);
+
+extern void go_parse_input_files (const char**, unsigned int,
+				  bool only_check_syntax,
+				  bool require_return_statement);
+extern void go_write_globals (void);
+
+extern tree go_type_for_size (unsigned int bits, int unsignedp);
+extern tree go_type_for_mode (enum machine_mode, int unsignedp);
+
+/* Functions defined in the GCC interface called by the Go frontend
+   proper.  */
+
+extern void go_preserve_from_gc (tree);
 
 #if defined(__cplusplus) && !defined(ENABLE_BUILD_WITH_CXX)
 } /* End extern "C".  */
Index: go-system.h
===================================================================
--- go-system.h	(revision 166814)
+++ go-system.h	(working copy)
@@ -51,10 +51,9 @@  extern "C"
 #include "system.h"
 #include "ansidecl.h"
 #include "coretypes.h"
-#include "tm.h"
 
-#include "diagnostic-core.h"
-#include "input.h"
+#include "diagnostic-core.h"	/* For error_at and friends.  */
+#include "input.h"		/* For source_location.  */
 
 #ifndef ENABLE_BUILD_WITH_CXX
 } // End extern "C"