diff gcc/c-decl.c @ 1:caeb520cebed

patch for CbC
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2009 17:43:54 +0900
parents a06113de4d67
children 27e6f95b2c21
line wrap: on
line diff
--- a/gcc/c-decl.c	Fri Jul 17 14:47:48 2009 +0900
+++ b/gcc/c-decl.c	Fri Jul 17 17:43:54 2009 +0900
@@ -63,6 +63,13 @@
 #include "langhooks-def.h"
 #include "pointer-set.h"
 #include "gimple.h"
+#ifndef noCbC
+#include "cbc-tree.h"
+tree cbc_env;
+tree cbc_return_f;
+location_t cbc_return;
+#endif
+
 
 /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
 enum decl_context
@@ -2339,8 +2346,13 @@
 /* Generate an implicit declaration for identifier FUNCTIONID as a
    function of type int ().  */
 
+#ifndef noCbC
+tree
+implicitly_declare (tree functionid, int fun)
+#else
 tree
 implicitly_declare (tree functionid)
+#endif
 {
   struct c_binding *b;
   tree decl = 0;
@@ -2415,7 +2427,12 @@
     }
 
   /* Not seen before.  */
+#ifndef noCbC
+  decl = build_decl (FUNCTION_DECL, functionid, 
+    fun==RID_CbC_CODE?build_function_type (void_type_node, NULL_TREE):default_function_type);
+#else
   decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
+#endif
   DECL_EXTERNAL (decl) = 1;
   TREE_PUBLIC (decl) = 1;
   C_DECL_IMPLICIT (decl) = 1;
@@ -4560,7 +4577,17 @@
 	      }
 	    type_quals = TYPE_UNQUALIFIED;
 
-	    type = build_function_type (type, arg_types);
+#ifndef noCbC
+          if ( declspecs->typespec_word == cts_CbC_code )
+            {
+              type = build_code_segment_type (type, arg_types);
+            }
+          else
+#endif
+            {
+              type = build_function_type (type, arg_types);
+            }
+
 	    declarator = declarator->declarator;
 
 	    /* Set the TYPE_CONTEXTs for each tagged type which is local to
@@ -6072,6 +6099,68 @@
   return tree_cons (decl, value, NULL_TREE);
 }
 
+#ifndef noCbC
+#define CbC_STACK_SIZE (1024 * 8)
+static void cbc_set_codesegment(tree fndecl){
+  tree args;
+  tree *nextp;
+//  tree itype;
+//  tree icst;
+//  tree padding_array;
+//  tree list;
+  int padding_size = CbC_STACK_SIZE;
+
+  //CbC_IS_CODE_SEGMENT(TREE_TYPE(fndecl)) = 1;
+  //CbC_IS_CODE_SEGMENT(fndecl) = 1;
+
+  nextp = & TYPE_ARG_TYPES (TREE_TYPE (fndecl));
+  for (args = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); args;
+      args = TREE_CHAIN (args))
+    {
+      tree type = args ? TREE_VALUE (args) : 0;
+      tree type_size;
+      unsigned int size;
+
+      if (type == void_type_node)
+	break;
+
+      type_size = TYPE_SIZE (type);
+      size = TREE_INT_CST_LOW (type_size);
+      padding_size -= size;
+
+      nextp = & TREE_CHAIN(args);
+    }
+
+  /* error check.  */
+  if (padding_size<0)
+    {
+      error ("CbC: too many arguments on code segment %qE", fndecl);
+      return ;
+    }
+  else if (padding_size==0)
+    return ;
+
+#if 0
+  /* itype is integer_type that means last index.  */
+  icst  = build_int_cst (NULL_TREE, padding_size-1);
+  itype = build_index_type (icst);
+
+  /* create array_type node.  */
+  padding_array = build_array_type (integer_type_node, itype);
+
+  /* add array_type to this function's argument list
+     before void_type_node.  */
+  if (!args)
+    args = build_tree_list(NULL_TREE, void_type_node);
+  list = build_tree_list(NULL_TREE, padding_array);
+  TREE_CHAIN(list) = args;
+  *nextp = list;
+#endif
+
+  return ;
+}
+#endif
+
 
 /* Create the FUNCTION_DECL for a function definition.
    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
@@ -6121,6 +6210,16 @@
   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
 			  &attributes, DEPRECATED_NORMAL);
 
+#ifndef noCbC
+  cbc_return_f = NULL_TREE;
+  cbc_env = NULL_TREE;
+  if ( declspecs->typespec_word == cts_CbC_code )
+    {
+	  cbc_set_codesegment(decl1);
+      //CbC_IS_CODE_SEGMENT(TREE_TYPE(decl1)) = 1;
+    }
+#endif
+
   /* If the declarator is not suitable for a function definition,
      cause a syntax error.  */
   if (decl1 == 0)
@@ -7249,6 +7348,11 @@
 	      else if (specs->typespec_word == cts_void)
 		error ("both %<long%> and %<void%> in "
 		       "declaration specifiers");
+#ifndef noCbC
+	      else if (specs->typespec_word == cts_CbC_code)
+		error ("both %<long%> and %<void%> in "
+		       "declaration specifiers");
+#endif
 	      else if (specs->typespec_word == cts_bool)
 		error ("both %<long%> and %<_Bool%> in "
 		       "declaration specifiers");
@@ -7278,6 +7382,11 @@
 	      else if (specs->typespec_word == cts_void)
 		error ("both %<short%> and %<void%> in "
 		       "declaration specifiers");
+#ifndef noCbC
+	      else if (specs->typespec_word == cts_CbC_code)
+		error ("both %<short%> and %<void%> in "
+		       "declaration specifiers");
+#endif
 	      else if (specs->typespec_word == cts_bool)
 		error ("both %<short%> and %<_Bool%> in "
 		       "declaration specifiers");
@@ -7310,6 +7419,11 @@
 	      else if (specs->typespec_word == cts_void)
 		error ("both %<signed%> and %<void%> in "
 		       "declaration specifiers");
+#ifndef noCbC
+	      else if (specs->typespec_word == cts_CbC_code)
+		error ("both %<signed%> and %<void%> in "
+		       "declaration specifiers");
+#endif
 	      else if (specs->typespec_word == cts_bool)
 		error ("both %<signed%> and %<_Bool%> in "
 		       "declaration specifiers");
@@ -7339,6 +7453,11 @@
 	      else if (specs->typespec_word == cts_void)
 		error ("both %<unsigned%> and %<void%> in "
 		       "declaration specifiers");
+#ifndef noCbC
+	      else if (specs->typespec_word == cts_CbC_code)
+		error ("both %<unsigned%> and %<void%> in "
+		       "declaration specifiers");
+#endif
 	      else if (specs->typespec_word == cts_bool)
 		error ("both %<unsigned%> and %<_Bool%> in "
 		       "declaration specifiers");
@@ -7367,6 +7486,11 @@
 	      if (specs->typespec_word == cts_void)
 		error ("both %<complex%> and %<void%> in "
 		       "declaration specifiers");
+#ifndef noCbC
+	      else if (specs->typespec_word == cts_CbC_code)
+		error ("both %<complex%> and %<void%> in "
+		       "declaration specifiers");
+#endif
 	      else if (specs->typespec_word == cts_bool)
 		error ("both %<complex%> and %<_Bool%> in "
 		       "declaration specifiers");
@@ -7469,6 +7593,27 @@
 	      else
 		specs->typespec_word = cts_void;
 	      return specs;
+#ifndef noCbC
+	    case RID_CbC_CODE:
+	      if (specs->long_p)
+		error ("both %<long%> and %<void%> in "
+		       "declaration specifiers");
+	      else if (specs->short_p)
+		error ("both %<short%> and %<void%> in "
+		       "declaration specifiers");
+	      else if (specs->signed_p)
+		error ("both %<signed%> and %<void%> in "
+		       "declaration specifiers");
+	      else if (specs->unsigned_p)
+		error ("both %<unsigned%> and %<void%> in "
+		       "declaration specifiers");
+	      else if (specs->complex_p)
+		error ("both %<complex%> and %<void%> in "
+		       "declaration specifiers");
+	      else
+		specs->typespec_word = cts_CbC_code;
+	      return specs;
+#endif
 	    case RID_BOOL:
 	      if (specs->long_p)
 		error ("both %<long%> and %<_Bool%> in "
@@ -7823,6 +7968,9 @@
   switch (specs->typespec_word)
     {
     case cts_void:
+#ifndef noCbC
+    case cts_CbC_code:
+#endif
       gcc_assert (!specs->long_p && !specs->short_p
 		  && !specs->signed_p && !specs->unsigned_p
 		  && !specs->complex_p);