changeset 7:7ff9aed93de8

partially written goto with env...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 20 Aug 2009 19:09:17 +0900
parents 983001f85155
children 5066dc73ff8f
files gcc/c-parser.c gcc/cbc-goto.h
diffstat 2 files changed, 69 insertions(+), 239 deletions(-) [+]
line wrap: on
line diff
--- a/gcc/c-parser.c	Thu Aug 20 13:38:58 2009 +0900
+++ b/gcc/c-parser.c	Thu Aug 20 19:09:17 2009 +0900
@@ -3676,6 +3676,42 @@
   c_parser_statement_after_labels (parser);
 }
 
+#if 0
+static tree
+c_parser_cbc_make_env(c_parser *parser)
+{
+  struct c_expr env;
+  tree field, fields=NULL_TREE;
+  tree env_struct, env_struct_type;
+  tree ebp, argsp;
+  tree tmp;
+
+  c_parser_consume_token (parser);
+  env = c_parser_expr_no_commas (parser, NULL);
+  env = default_function_array_conversion (env);
+
+    /* build type_node of environment structure  */
+    env_struct_type = start_struct (RECORD_TYPE, NULL_TREE);
+    field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node);
+    fields = chainon (field, fields);
+    field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node);
+    fields = chainon (field, fields);
+    //field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node);
+    //fields = chainon (field, fields);
+    fields = nreverse(fields);
+    finish_struct (env_struct_type, fields, NULL_TREE);
+
+    env_struct = build_c_cast (build_pointer_type(env_struct_type), env.value);
+    //build_component_ref (cbc_env, get_identifier("argsp"));
+    ebp = build_component_ref (build_indirect_ref (loc,env_struct, "CbCenv->sp"), get_identifier("sp"));
+    argsp = build_component_ref (build_indirect_ref (loc, env_struct, "CbCenv->sp"), get_identifier("argsp"));
+    //ebp = chainon (ebp, argsp);
+    tmp = build_tree_list (ebp, argsp);
+
+    return tmp;
+}
+#endif
+
 /* Parse a statement, other than a labeled statement.  */
 
 static void
@@ -3740,53 +3776,9 @@
 	      if (TREE_CODE(expr.value) == CALL_EXPR )
 		{
 		  TREE_TYPE(expr.value) = void_type_node;
-		  if (c_parser_next_token_is (parser, CPP_COMMA)) 
-		    {
-		      struct c_expr env;
-		      tree field, fields=NULL_TREE;
-		      tree env_struct, env_struct_type;
-		      tree ebp, argsp;
-		      tree tmp;
-
-		      c_parser_consume_token (parser);
-		      env = c_parser_expr_no_commas (parser, NULL);
-		      env = default_function_array_conversion (env);
-
-			/* build type_node of environment structure  */
-			env_struct_type = start_struct (RECORD_TYPE, NULL_TREE);
-			field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node);
-			fields = chainon (field, fields);
-			field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node);
-			fields = chainon (field, fields);
-			//field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node);
-			//fields = chainon (field, fields);
-			fields = nreverse(fields);
-			finish_struct (env_struct_type, fields, NULL_TREE);
-
-			env_struct = build_c_cast (build_pointer_type(env_struct_type), env.value);
-			//build_component_ref (cbc_env, get_identifier("argsp"));
-			ebp = build_component_ref (build_indirect_ref (loc,env_struct, "CbCenv->sp"), get_identifier("sp"));
-			argsp = build_component_ref (build_indirect_ref (loc, env_struct, "CbCenv->sp"), get_identifier("argsp"));
-			//ebp = chainon (ebp, argsp);
-			tmp = build_tree_list (ebp, argsp);
-
-		      // TREE_OPERAND (expr.value, 2) = tmp;
-
-
-		      /*
-		      c_parser_consume_token (parser);
-		      expr = default_function_array_conversion (expr);
-			ident = c_parser_peek_token (parser)->value;
-		      c_parser_consume_token (parser);
-		      expr.value = build_component_ref (build_indirect_ref (expr.value,
-			    "->"), ident);
-		      expr.original_code = ERROR_MARK;
-		      */
-
-
-		    }
-		  // else
-		  //  TREE_OPERAND (expr.value, 2) = NULL_TREE;
+		  tree env = NULL_TREE;
+//		  if (c_parser_next_token_is (parser, CPP_COMMA)) 
+//		    env = c_parser_cbc_make_env(parser);
 		  CbC_IS_CbC_GOTO (expr.value) = 1;
 		  CALL_EXPR_TAILCALL (expr.value) = 1;
 		  add_stmt(expr.value);
@@ -5581,135 +5573,43 @@
 #ifndef noCbC
 	case RID_CbC_ENV:
           {
-#if 0
-	    tree valuep_tree;
-	    tree value_tree;
-	    tree env_tree;
-
-	    tree exprstmt;
-	    tree stmt = c_begin_stmt_expr ();
-	    /*
-	     * __value = {
-	     *   void *ebp;
-	     *   char args[sizeof(arguments)];
-	     * };
-	     *
-	     *  __env = ({
-	     *    ebp = __builtin_frame_address(0);
-	     *    *__value=ebp;
-	     *    __value;
-	     *  })
-	     */
-
+	    c_parser_consume_token (parser);
 	    /* get value of %ebp.  */
-	    env_tree = build_external_ref (
+	    tree env_tree = build_external_ref (
 		        get_identifier ("__builtin_frame_address"), 0,
 			c_parser_peek_token (parser)->location);
-	    env_tree = build_function_call(env_tree, 
+	    expr.value = build_function_call(env_tree, 
 			   build_tree_list (NULL_TREE, build_int_cst (NULL_TREE,0)));
-
-	    /* ebp = __builtin_frame_address(0)  */
-	    valuep_tree = build_decl (VAR_DECL, get_identifier("__value"), intTI_type_node);
-	    TREE_STATIC (valuep_tree) = 1;
-	    lang_hooks.decls.pushdecl(valuep_tree);
-	    /* cast __value to pointer to pointer to void.  */
-	    valuep_tree = build_c_cast (build_pointer_type(ptr_type_node), valuep_tree);
-	    value_tree = build_indirect_ref (valuep_tree, "cbc: *__value");
-
-	    /* *__value = ebp;  */
-	    exprstmt = build_modify_expr (value_tree, NOP_EXPR, env_tree);
-	    add_stmt(exprstmt);
-
-	    /* __value;  */
-	    add_stmt(valuep_tree);
-#else
-
-	    //tree env;        // environment structure
-	    tree env_struct; // type of environment structure
-	    tree field;
-	    tree fields=NULL_TREE;
-	    tree comp, comp0;       // component of environment
-	    tree ebp;
-
-	    tree stmt = c_begin_stmt_expr ();
-
-	    /*
-	     * struct {
-	     *     void *sp;     <= %ebp
-	     *     void *argp;   <= &__environment.retval
-	     *     int retval;  // int? or return type of this function
-	     * } __CbCenv;
-	     *
-	     * __environment = &__CbCenv;
-	     *
-	     */
-
-	    if (!cbc_env)
-	      {
-		/* build type_node of environment structure  */
-		env_struct = start_struct (RECORD_TYPE, NULL_TREE);
-		field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node);
-		fields = chainon (field, fields);
-		field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node);
-		fields = chainon (field, fields);
-		field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node);
-		fields = chainon (field, fields);
-		fields = nreverse(fields);
-		//env_struct = make_node(RECORD_TYPE);
-		//TYPE_FIELDS (env_struct) = fields;
-		finish_struct (env_struct, fields, NULL_TREE);
-
-		/* declare __environment structure.  */
-		cbc_env = build_decl (VAR_DECL, get_identifier("__CbCenv"), env_struct);
-		TREE_STATIC (cbc_env) = 1;
-		lang_hooks.decls.pushdecl(cbc_env);
-	      }
-
-	    /* get value of %ebp.  */
-	    ebp = build_external_ref (
-		        get_identifier ("__builtin_frame_address"), 0,
-			(loc = c_parser_peek_token (parser)->location));
-	    ebp = build_function_call(ebp, 
-			   build_tree_list (NULL_TREE, build_int_cst (NULL_TREE,0)));
-
-	    /* assignment  void *sp = %ebp  */
-	    comp = build_component_ref (cbc_env, get_identifier("sp"));
-	    add_stmt (build_modify_expr (loc, comp, NOP_EXPR, ebp));
-
-	    /* void *argsp = &__environment.retval  */
-	    comp = build_component_ref (cbc_env, get_identifier("argsp"));
-	    comp0 = build_component_ref (cbc_env, get_identifier("retval"));
-	    comp0 = build_unary_op (loc, ADDR_EXPR, comp0, 0);
-	    add_stmt (build_modify_expr (loc, comp, NOP_EXPR, comp0));
-
-
-	    /* &__environment for value of stmt_expr. */
-	    add_stmt (build_unary_op (loc, ADDR_EXPR, cbc_env, 0));
-#endif
-	    //expr.value = valuep_tree;
-	    TREE_SIDE_EFFECTS (stmt) = 1;
-	    expr.value = c_finish_stmt_expr (stmt);
-	    //expr.value = build_unary_op (ADDR_EXPR, env, 0);
-	    c_parser_consume_token (parser);
+	    expr.original_code = ERROR_MARK;
+
           }
 	  break;
 	case RID_CbC_RET:
 	case RID_RETURN:
-#if 1
-	  if (cbc_return_f==0) {
-	      tree retval;
+
+ if (cbc_return_f==0) {  tree retval; 
 
               /*
                    Generates something like...
 
-                   __return = ({
-                       static volatile int __return;
-                       if (__return) {
-                       return_label:
-                            return value;
-                       }
-                       &&return_label;
-                   })
+    int retval = 1;
+    void (*ret)(int retval_,void *fp) ;
+
+    ret = ({
+        __label__ exit0;
+        volatile static flag = 0;
+        void __return_func(int retval_,void *fp) {
+            retval = retval_;
+            goto exit0;
+        }
+        if (flag) {
+        exit0:
+            printf("f1: fp = 0x%x\n",__builtin_frame_address(0));
+            return retval;
+        }
+        __return_func;
+    });
+
                */
 
 	      tree stmt = c_begin_stmt_expr ();
@@ -5750,27 +5650,6 @@
 	      add_stmt(decl);
 
 	      //tree hoge = build_int_cst(NULL_TREE,55);
-		if (!cbc_env)
-		  {
-		      tree field,fields=NULL_TREE,env_struct;
-		    /* build type_node of environment structure  */
-		    env_struct = start_struct (RECORD_TYPE, NULL_TREE);
-		    field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node);
-		    fields = chainon (field, fields);
-		    field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node);
-		    fields = chainon (field, fields);
-		    field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node);
-		    fields = chainon (field, fields);
-		    fields = nreverse(fields);
-		    //env_struct = make_node(RECORD_TYPE);
-		    //TYPE_FIELDS (env_struct) = fields;
-		    finish_struct (env_struct, fields, NULL_TREE);
-
-		    /* declare __environment structure.  */
-		    cbc_env = build_decl (VAR_DECL, get_identifier("__CbCenv"), env_struct);
-		    TREE_STATIC (cbc_env) = 1;
-		    lang_hooks.decls.pushdecl(cbc_env);
-		  }
 		retval = build_component_ref (cbc_env, get_identifier("retval"));
 	      tree ret = c_finish_return (retval); 
 	      TREE_USED(ret) = 1;
@@ -5799,8 +5678,6 @@
 	      expr.value = c_finish_stmt_expr (stmt);
 	      expr.original_code = ERROR_MARK;
 
-	      // cbc_return_f =0;
-
 	  } else {
 	      //tree label = lookup_label(c_parser_peek_token (parser)->value);
 	      //TREE_USED(label) = 1;
@@ -5810,7 +5687,6 @@
           }
 	  break;
 #endif
-#endif
 	default:
 	  c_parser_error (parser, "expected expression");
 	  expr.value = error_mark_node;
--- a/gcc/cbc-goto.h	Thu Aug 20 13:38:58 2009 +0900
+++ b/gcc/cbc-goto.h	Thu Aug 20 19:09:17 2009 +0900
@@ -77,13 +77,6 @@
   rtx insns;
   rtx before_call, next_arg_reg;
 
-  /* for environment.  */
-  rtx env_rtx;
-  tree env_tree;
-
-  // env_tree = TREE_OPERAND(exp, 2);
-  env_tree = NULL_TREE;
-
   /* State variables we need to save and restore between
      iterations.  */
   save_pending_stack_adjust = pending_stack_adjust;
@@ -135,45 +128,6 @@
 
   old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
 
-  /* The argument block when performing a sibling call is the
-     incoming argument block.  */
-  /*
-     if ( 0 && !CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl)) )
-     {
-     argblock = virtual_outgoing_args_rtx;
-     }
-     else
-   */
-
-  if ( env_tree!=NULL_TREE )
-    {
-	  /*
-	   * ebp <= TREE_VALUE ( env_tree );
-	   * argsp <= TREE_PURPOSE ( env_tree );
-	   *
-	   */
-      //rtx tmp;
-      /* compute environment.  */
-      push_temp_slots ();
-      /* expand_expr shouldn't be here... it's moved later.  */
-      //env_rtx = expand_expr ( env_tree, NULL_RTX,
-	      //VOIDmode, EXPAND_STACK_PARM);
-      //argblock = hard_frame_pointer_rtx;
-      //argblock = env_rtx;
-      //argblock = plus_constant (argblock, -current_function_arg_offset_rtx);
-      //tmp = gen_rtx_MINUS (Pmode, hard_frame_pointer_rtx, virtual_incoming_args_rtx);
-      //argblock = gen_rtx_MINUS (Pmode, env_rtx, tmp);
-      //argblock = plus_constant (argblock, frame_offset);
-      argblock = expand_expr ( TREE_VALUE (env_tree), NULL_RTX,
-	      VOIDmode, EXPAND_STACK_PARM);
-      env_rtx = expand_expr ( TREE_PURPOSE (env_tree), NULL_RTX,
-	      VOIDmode, EXPAND_STACK_PARM);
-      preserve_temp_slots (argblock);
-      pop_temp_slots ();
-    }
-  else
-    {
-      //argblock = virtual_incoming_args_rtx;
       argblock = crtl->args.internal_arg_pointer;
 
       argblock
@@ -182,7 +136,6 @@
 #else
 	  = plus_constant (argblock, -crtl->args.pretend_args_size);
 #endif
-    }
 
 
   stored_args_map = sbitmap_alloc (args_size->constant);
@@ -268,9 +221,9 @@
   precompute_register_parameters (num_actuals, args, &reg_parm_seen);
 
   /* operand[2] is environment.  */
-  //if (TREE_OPERAND (exp, 2))
-    //static_chain_value = expand_normal (TREE_OPERAND (exp, 2));
-  //else
+  if (TREE_OPERAND (exp, 2))
+    static_chain_value = expand_normal (TREE_OPERAND (exp, 2));
+  else
     static_chain_value = 0;
 
 
@@ -350,7 +303,7 @@
   /* Stack must be properly aligned now.  */
   gcc_assert (!pass
       || !(stack_pointer_delta % preferred_unit_stack_boundary));
-
+#if 0
   /* store environment.  */
   if ( env_tree!=NULL )
     {
@@ -363,6 +316,7 @@
 
       emit_indirect_jump (funexp);
     }
+#endif
 
   /* Generate the actual call instruction.  */
   emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,