[gimplefe] Fixing the bug for gimple_assign statement with ternary operands

Sandeep Soni soni.sandeepb@gmail.com
Fri Jul 6 04:38:00 GMT 2012


The following patch fixes the issues that were faced by the
introduction of the previous patch

Diego, the crux was using gimple_build_assign_with_ops3 for ternary
operands. Thanks for your help in finding it.
I am halfway through the patch for building gimple_cond statements. I
will be able to complete the patch over the weekend. I am also working
towards a patch that generalizes the assignment statements considering
all possible types of assignments.

Tested on x86.

ChangeLog as follows:

2012-06-06   Sandeep Soni  <soni.sandeepb@gmail.com>

	* parser.c (gp_parse_expect_rhs_op): Tidy. Returns the tree operand in rhs.	
	(gp_parse_assign_stmt): Tidy. Creates the gimple assignment statement .

Index: gcc/gimple/parser.c
===================================================================
--- gcc/gimple/parser.c	(revision 188546)
+++ gcc/gimple/parser.c	(working copy)
@@ -105,6 +105,31 @@
 		     gimple_symtab_eq_hash, NULL);
 }

+
+/* Return the string representation of token TOKEN.  */
+
+static const char *
+gl_token_as_text (const gimple_token *token)
+{
+  switch (token->type)
+    {
+    case CPP_NAME:
+      return IDENTIFIER_POINTER (token->value);
+
+    case CPP_STRING:
+    case CPP_STRING16:
+    case CPP_STRING32:
+    case CPP_WSTRING:
+    case CPP_UTF8STRING:
+      return TREE_STRING_POINTER (token->value);
+      break;
+
+    default:
+      return cpp_type2name (token->type, token->flags);
+    }
+}
+
+
 /* Registers DECL with the gimple symbol table as having identifier ID.  */

 static void
@@ -123,29 +148,41 @@
     *slot = new_entry;
 }

-/* Return the string representation of token TOKEN.  */

-static const char *
-gl_token_as_text (const gimple_token *token)
+/* Gets the tree node for the corresponding identifier ID  */
+
+static tree
+gimple_symtab_get (tree id)
 {
-  switch (token->type)
+  struct gimple_symtab_entry_def temp;
+  gimple_symtab_entry_t entry;
+  void **slot;
+
+  gimple_symtab_maybe_init_hash_table();
+  temp.id = id;
+  slot = htab_find_slot (gimple_symtab, &temp, NO_INSERT);
+  if (slot)
     {
-    case CPP_NAME:
-      return IDENTIFIER_POINTER (token->value);
+      entry = (gimple_symtab_entry_t) *slot;
+      return entry->decl;
+    }
+  else
+    return NULL;
+}

-    case CPP_STRING:
-    case CPP_STRING16:
-    case CPP_STRING32:
-    case CPP_WSTRING:
-    case CPP_UTF8STRING:
-      return TREE_STRING_POINTER (token->value);
-      break;

-    default:
-      return cpp_type2name (token->type, token->flags);
-    }
+/* Gets the tree node of token TOKEN from the global gimple symbol table.  */
+
+static tree
+gimple_symtab_get_token (const gimple_token *token)
+{
+  const char *name = gl_token_as_text (token);
+  tree id = get_identifier (name);
+  tree decl = gimple_symtab_get (id);
+  return decl;
 }

+
 /* Helper function to register the variable declaration having token NAME_TOKEN
    in the global gimple symbol table.  */

@@ -360,10 +397,11 @@
 /* Helper for gp_parse_assign_stmt. The token read from reader PARSER should
    be the lhs of the tuple.  */

-static void
+static tree
 gp_parse_expect_lhs (gimple_parser *parser)
 {
   const gimple_token *next_token;
+  tree lhs;

   /* Just before the name of the identifier we might get the symbol
      of dereference too. If we do get it then consume that token, else
@@ -372,18 +410,22 @@
   if (next_token->type == CPP_MULT)
     next_token = gl_consume_token (parser->lexer);

-  gl_consume_expected_token (parser->lexer, CPP_NAME);
+  next_token = gl_consume_token (parser->lexer);
+  lhs = gimple_symtab_get_token (next_token);
   gl_consume_expected_token (parser->lexer, CPP_COMMA);
+  return lhs;
+
 }


 /* Helper for gp_parse_assign_stmt. The token read from reader PARSER should
    be the first operand in rhs of the tuple.  */

-static void
+static tree
 gp_parse_expect_rhs_op (gimple_parser *parser)
 {
   const gimple_token *next_token;
+  tree rhs = NULL_TREE;

   next_token = gl_peek_token (parser->lexer);

@@ -402,11 +444,14 @@
     case CPP_NUMBER:
     case CPP_STRING:
       next_token = gl_consume_token (parser->lexer);
+      rhs = gimple_symtab_get_token (next_token);
       break;

     default:
       break;
     }
+
+  return rhs;
 }


@@ -414,15 +459,16 @@
    For now we only recognize the tuple. Refer gimple.def for the
    format of this tuple.  */

-static void
+static gimple
 gp_parse_assign_stmt (gimple_parser *parser)
 {
   gimple_token *optoken;
   enum tree_code opcode;
   enum gimple_rhs_class rhs_class;
+  tree op1 = NULL_TREE, op2 = NULL_TREE, op3 = NULL_TREE;

   opcode = gp_parse_expect_subcode (parser, &optoken);
-  gp_parse_expect_lhs (parser);
+  tree lhs = gp_parse_expect_lhs (parser);

   rhs_class = get_gimple_rhs_class (opcode);
   switch (rhs_class)
@@ -436,16 +482,16 @@
       case GIMPLE_UNARY_RHS:
       case GIMPLE_BINARY_RHS:
       case GIMPLE_TERNARY_RHS:
-	gp_parse_expect_rhs_op (parser);
+	op1 = gp_parse_expect_rhs_op (parser);
 	if (rhs_class == GIMPLE_BINARY_RHS || rhs_class == GIMPLE_TERNARY_RHS)
 	  {
 	    gl_consume_expected_token (parser->lexer, CPP_COMMA);
-	    gp_parse_expect_rhs_op (parser);
+	    op2 = gp_parse_expect_rhs_op (parser);
 	  }
 	if (rhs_class == GIMPLE_TERNARY_RHS)
 	  {
 	    gl_consume_expected_token (parser->lexer, CPP_COMMA);
-	    gp_parse_expect_rhs_op (parser);
+	    op3 = gp_parse_expect_rhs_op (parser);
 	  }
 	break;

@@ -454,6 +500,9 @@
     }

   gl_consume_expected_token (parser->lexer, CPP_GREATER);
+
+  gimple stmt = gimple_build_assign_with_ops3 (opcode, lhs, op1, op2, op3);
+  return stmt;
 }

 /* Helper for gp_parse_cond_stmt. The token read from reader PARSER should



-- 
Cheers
Sandy



More information about the Gcc-patches mailing list