diff mbox

[gimplefe] creating individual gimple_assign statements

Message ID CANY-sXWjGhJkY-DdtKK_gDmGPHeJfQXNX_DCJgwJG0aePZvu9w@mail.gmail.com
State New
Headers show

Commit Message

Sandeep Soni June 21, 2012, 3:04 a.m. UTC
Hi,

This patch creates basic gimple_assign statements. It is a little raw
not considering all types of gimple_assign statements for which I have
already started working.

Here is the Changelog.

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

	* parser.c (gimple_symtab_get): New.
          (gimple_symtab_get_token): New.
          (gp_parse_expect_lhs): Returns tree node.
          (gp_parse_expect_rhs_op): Returns the op as tree node.
          (gp_parse_assign_stmt) : Builds gimple_assign statement.

Comments

Diego Novillo June 21, 2012, 6:33 p.m. UTC | #1
On 12-06-20 23:04 , Sandeep Soni wrote:
> Hi,
>
> This patch creates basic gimple_assign statements. It is a little raw
> not considering all types of gimple_assign statements for which I have
> already started working.
>
> Here is the Changelog.
>
> 2012-06-09   Sandeep Soni   <soni.sandeepb@gmail.com>
>
> 	* parser.c (gimple_symtab_get): New.
>            (gimple_symtab_get_token): New.
>            (gp_parse_expect_lhs): Returns tree node.
>            (gp_parse_expect_rhs_op): Returns the op as tree node.
>            (gp_parse_assign_stmt) : Builds gimple_assign statement.

Align the '(' with the '*'.

>
> Index: gcc/gimple/parser.c
> ===================================================================
> --- gcc/gimple/parser.c	(revision 188546)
> +++ gcc/gimple/parser.c	(working copy)
> @@ -105,6 +105,7 @@
>   		     gimple_symtab_eq_hash, NULL);
>   }
>
> +
>   /* Registers DECL with the gimple symbol table as having identifier ID.  */
>
>   static void
> @@ -123,6 +124,41 @@
>       *slot = new_entry;
>   }
>
> +
> +/* Gets the tree node for the corresponding identifier ID  */
> +
> +static tree
> +gimple_symtab_get (tree id)
> +{
> +  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)
> +    {
> +      entry = (gimple_symtab_entry_t) *slot;
> +      return entry->decl;
> +    }
> +  else
> +    return NULL;
> +}
> +
> +
> +/* 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);

Space before '('.

> +  tree decl = gimple_symtab_get (id);
> +  return decl;
> +}
> +
> +
>   /* Return the string representation of token TOKEN.  */
>
>   static const char *
> @@ -360,10 +396,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 +409,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 +443,13 @@
>       case CPP_NUMBER:
>       case CPP_STRING:
>         next_token = gl_consume_token (parser->lexer);
> +      rhs = gimple_symtab_get_token (next_token);
>         break;
>
>       default:
>         break;
>       }
> +
>   }

No empty line here.

The function returns nothing?

>
>
> @@ -420,9 +463,10 @@
>     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 +480,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 +498,9 @@
>       }
>
>     gl_consume_expected_token (parser->lexer, CPP_GREATER);
> +
> +  gimple stmt = gimple_build_assign_with_ops (code, lhs, op1, op2, op3);
> +  gcc_assert(verify_gimple_stmt(stmt));

Space before '('s.

Do we already have tests with assignments in the testsuite?



Diego.
diff mbox

Patch

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

+
 /* Registers DECL with the gimple symbol table as having identifier ID.  */

 static void
@@ -123,6 +124,41 @@ 
     *slot = new_entry;
 }

+
+/* Gets the tree node for the corresponding identifier ID  */
+
+static tree
+gimple_symtab_get (tree id)
+{
+  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)
+    {
+      entry = (gimple_symtab_entry_t) *slot;
+      return entry->decl;
+    }
+  else
+    return NULL;
+}
+
+
+/* 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;
+}
+
+
 /* Return the string representation of token TOKEN.  */

 static const char *
@@ -360,10 +396,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 +409,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 +443,13 @@ 
     case CPP_NUMBER:
     case CPP_STRING:
       next_token = gl_consume_token (parser->lexer);
+      rhs = gimple_symtab_get_token (next_token);
       break;

     default:
       break;
     }
+
 }


@@ -420,9 +463,10 @@ 
   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 +480,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 +498,9 @@ 
     }

   gl_consume_expected_token (parser->lexer, CPP_GREATER);
+
+  gimple stmt = gimple_build_assign_with_ops (code, lhs, op1, op2, op3);
+  gcc_assert(verify_gimple_stmt(stmt));
 }

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