changeset 35:3f5886e153cb

modify cbc_replace_args
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Dec 2009 20:49:36 +0900
parents 5f3bba7b355c
children 27e6f95b2c21
files CbC-examples/quicksort/Makefile CbC-examples/quicksort/quicksort_test.cbc gcc/c-parser.c gcc/calls.c
diffstat 4 files changed, 48 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/CbC-examples/quicksort/Makefile	Tue Dec 22 20:46:05 2009 +0900
+++ b/CbC-examples/quicksort/Makefile	Tue Dec 22 20:49:36 2009 +0900
@@ -1,13 +1,14 @@
 
-CbCC=../../../build_gcc/INSTALL_DIR/bin/gcc
+CbCC=../../../build_cbc44/INSTALL_DIR/bin/gcc
 
 #CC=gcc
-CC=../../../build_gcc/INSTALL_DIR/bin/gcc
+CC=../../../build_cbc44/INSTALL_DIR/bin/gcc
 
 HEADERMAKER=../../CbC-scripts/make_headers.py2
 
 # fastcall版では-O0,-O2は動作確認、-O3以上はだめ
-CFLAGS=-g -O2 -fomit-frame-pointer
+#CFLAGS=-g -O2 -fomit-frame-pointer
+CFLAGS=-g -O2
 #CFLAGS=-g -O0
 
 .SUFFIXES: .cbc .o
--- a/CbC-examples/quicksort/quicksort_test.cbc	Tue Dec 22 20:46:05 2009 +0900
+++ b/CbC-examples/quicksort/quicksort_test.cbc	Tue Dec 22 20:49:36 2009 +0900
@@ -97,10 +97,10 @@
 	b = check_sort(arg, size);
 	if (b) {
 		printf("sorting successful!\n");
-		exit(-1);
+		exit(EXIT_SUCCESS);
 	} else {
 		printf("sorting failure! \n");
-		exit(0);
+		exit(EXIT_FAILURE);
 	}
 }
 
--- a/gcc/c-parser.c	Tue Dec 22 20:46:05 2009 +0900
+++ b/gcc/c-parser.c	Tue Dec 22 20:49:36 2009 +0900
@@ -1552,9 +1552,9 @@
 	  attrs = build_tree_list(attrs, NULL_TREE);
 	  declspecs_add_attrs(specs, attrs);
 	  */
-	  attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE);
-	  //attrs = build_tree_list (get_identifier("noreturn"), attrs);
-	  declspecs_add_attrs(specs, attrs);
+	  //attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE);
+	  /*attrs = build_tree_list (get_identifier("noreturn"), attrs);*/
+	  //declspecs_add_attrs(specs, attrs);
 
 	  c_parser_consume_token (parser);
 	  break;
@@ -3737,22 +3737,34 @@
 cbc_replace_arguments (location_t loc, tree call)
 {
   tree args;
+  tree fn;
   tree tmp_decl;
   int i=0;
 
+  fn = CALL_EXPR_FN (call);
+  if ( TREE_CODE (fn)==PARM_DECL || !TREE_CONSTANT (fn) )
+    {
+      tmp_decl = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE(fn));
+      pushdecl (tmp_decl);
+
+      add_stmt (build_modify_expr (loc, tmp_decl, NOP_EXPR, fn));
+      CALL_EXPR_FN (call) = tmp_decl;
+    }
+
   args = CALL_EXPR_ARGS (call);
   for ( ;args; args = TREE_CHAIN (args), i++)
     {
       tree arg = TREE_VALUE (args);
 
-      if (CONSTANT_CLASS_P (arg) || VAR_OR_FUNCTION_DECL_P (arg) )
-	continue;
-
-      tmp_decl = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE(arg));
-      pushdecl (tmp_decl);
-
-      add_stmt (build_modify_expr (loc, tmp_decl, NOP_EXPR, arg));
-      CALL_EXPR_ARG (call, i) = tmp_decl;
+      //if ( !CONSTANT_CLASS_P (arg) && !VAR_OR_FUNCTION_DECL_P (arg) )
+      if ( TREE_CODE (arg)==PARM_DECL || !TREE_CONSTANT (arg) )
+	{
+	  tmp_decl = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE(arg));
+	  pushdecl (tmp_decl);
+
+	  add_stmt (build_modify_expr (loc, tmp_decl, NOP_EXPR, arg));
+	  CALL_EXPR_ARG (call, i) = tmp_decl;
+	}
     }
 
   return call;
@@ -3825,7 +3837,7 @@
 		  cbc_replace_arguments (loc, expr.value);
 
 		  TREE_TYPE(expr.value) = void_type_node;
-		  //tree env = NULL_TREE;
+		  /*tree env = NULL_TREE;**/
 		  CbC_IS_CbC_GOTO (expr.value) = 1;
 		  CALL_EXPR_TAILCALL (expr.value) = 1;
 		  add_stmt(expr.value);
@@ -5266,7 +5278,7 @@
   {
     push_scope ();
     declare_parm_level ();
-    //tree retval_type = TREE_TYPE(retval_decl);
+    /*tree retval_type = TREE_TYPE(retval_decl);*/
 
     _retval_decl = build_decl (PARM_DECL, get_identifier ("_retval"), TREE_TYPE(retval_decl));
     DECL_SOURCE_LOCATION (_retval_decl) = loc;
@@ -5293,9 +5305,7 @@
   finish_declspecs (specs);
 
   /* make nested function.  */
-  //ident = build_decl (/*TODO:*/VAR_DECL, get_identifier ("_cbc_internal_return"), specs->type);
   declarator = build_id_declarator (get_identifier ("_cbc_internal_return"));
-  //declarator->id_loc = ;
   declarator = build_function_declarator (args, declarator);
 
   c_push_function_context ();
@@ -5892,7 +5902,6 @@
 	    /* define nested function.  */
 	    decl =
 	      cbc_finish_nested_function (location, label, decl_cond);
-	    //tree nested_func = cbc_make_nested_function (location);
 
 	    /* define if-ed goto label and return statement. */
 	    cbc_finish_labeled_goto (location, label, decl_cond);
@@ -5901,9 +5910,9 @@
 	    value = build_addr (decl , current_function_decl);
 	    SET_EXPR_LOCATION (value, location);
 	    add_stmt (value);
-	    //value = build_external_ref (get_identifier("_cbc_internal_return"), false, location);
-	    //value = build_unary_op (location, ADDR_EXPR, value, 0);
-	    //add_stmt (value);
+	    /*value = build_external_ref (get_identifier("_cbc_internal_return"), false, location);*/
+	    /*value = build_unary_op (location, ADDR_EXPR, value, 0);*/
+	    /*add_stmt (value);*/
 
 	    TREE_SIDE_EFFECTS (stmt) = 1;
 	    expr.value = c_finish_stmt_expr (stmt);
--- a/gcc/calls.c	Tue Dec 22 20:46:05 2009 +0900
+++ b/gcc/calls.c	Tue Dec 22 20:49:36 2009 +0900
@@ -2400,20 +2400,29 @@
   else if ( CbC_IS_CbC_GOTO (exp) )
     {
       // TODO: 関数からコードセグメントへの遷移
-      char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl));
-      warning(0, "no warning: code segment `%s' has been called from a function.", name_callee);
+      /*
+      if (fndecl)
+	{
+	  char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl));
+	  warning(0, "no warning: code segment `%s' has been called from a function.", name_callee);
+        }
+      else
+	{
+	  warning(0, "no warning: unnamed code segment has been called from a function.");
+	}
+	*/
       args_size.constant = CbC_PRETENDED_STACK_SIZE;
     }
   else if ( fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)) )
     {
       // 警告コードセグメントを関数呼び出し
-      char *name= IDENTIFIER_POINTER(DECL_NAME(fndecl));
-      warning (0, "code segment `%s' has been \"called\" instead \"goto\".", name);
+      //char *name= IDENTIFIER_POINTER(DECL_NAME(fndecl));
+      //warning (0, "code segment `%s' has been \"called\" instead \"goto\".", name);
     }
   else if (CbC_IS_CODE_SEGMENT(TREE_TYPE (current_function_decl)) )
     {
       // code segment内部からの関数呼び出し。なんも問題ない。
-      warning (0, "no warning: normal call from a code segment.");
+      //warning (0, "no warning: normal call from a code segment.");
     }
 #endif