[gimplefe] Patch for recognizing function declarations

2012-07-31 Thread Sandeep Soni
Hi Diego,

The following patch recognizes function declarations. I am now trying
to create a gimple sequence of all the statements within the function
body.
The chagelog is as follows:

2012-07-31   Sandeep Soni soni.sande...@gmail.com

* parser.c (gl_token_starts_decl): Modify. Matches function decls.
(gp_parse_parm_decl): New.
(gp_parse_return_type): New.
(gp_parse_function_decl): New.
(gp_parse_decl): Modify. Adds case for function decls.

Index: gcc/gimple/parser.c
===
--- gcc/gimple/parser.c (revision 188546)
+++ gcc/gimple/parser.c (working copy)
@@ -234,7 +271,7 @@
 gl_token_starts_decl (gimple_token *token)
 {
   enum tree_code code = gl_tree_code_for_token (token);
-  return code == VAR_DECL;
+  return code == VAR_DECL || code == FUNCTION_DECL;
 }


@@ -746,6 +817,24 @@
 }


+/* Helper for gp_parse_function_decl. The parm_decl's
+   are read from gimple_parser PARSER.  */
+
+static void
+gp_parse_parm_decl (gimple_parser *parser)
+{
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gl_consume_expected_token (parser-lexer, CPP_COMMA);
+  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_NUMBER);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+
+}
+
+
 /* Helper for gp_parse_expect_record_type and
gp_parse_expect_union_type. The field_decl's
are read from gimple_parser PARSER.  */
@@ -939,6 +1028,27 @@
 }


+/* Recognizes the return type of the function. The tuple is read from
+   PARSER.  */
+
+static void
+gp_parse_return_type (gimple_parser *parser)
+{
+  gimple_token *next_token = gl_consume_token (parser-lexer);
+  enum tree_code code = gl_tree_code_for_token (next_token);
+
+  switch (code)
+  {
+  case INTEGER_TYPE:
+  case REAL_TYPE:
+gl_consume_expected_token (parser-lexer, CPP_LESS);
+gl_consume_expected_token (parser-lexer, CPP_NUMBER);
+gl_consume_expected_token (parser-lexer, CPP_GREATER);
+break;
+  }
+}
+
+
 /* The Declaration section within a .gimple file can consist of
a) Declaration of variables.
b) Declaration of functions.
@@ -1070,6 +1180,103 @@
 }


+/* The syntax of a function declaration is as follows:
+
+   FUNCTION_DECLName, Type, Parms
+   
+  function body
+   
+
+   Here, each of the PARMS in itself is a parameter declaration similar to a
+   variable declaration, TYPE is the type of the variable that this
+   function returns and FUNCTION BODY is the series of statements that define
+   the beahavior of the function.
+
+   Following are some of the examples for which the syntax of the function
+   declarations are described.
+
+   1. C-like function as
+  void foo (int first, float second)
+{
+  first = second;
+}
+
+   The corresponding gimple syntax is:
+ FUNCTION_DECL foo, VOID_TYPE,
+PARM_DECLfirst, INTEGER_TYPE4,
+PARM_DECLsecond, REAL_TYPE4
+ 
+   GIMPLE_ASSIGN PARM_DECL,first, second, NULL
+ 
+
+   2. C-like function as
+  int foo (int first, float second)
+   {
+  int local_first;
+  float local_second;
+   
+  local_first = first;
+  local_second = second;
+
+  return local_first;
+   }
+
+   The corresponding gimple syntax is:
+ FUNCTION_DECL foo, INTEGER_TYPE4,
+PARM_DECLfirst, INTEGER_TYPE4,
+PARM_DECLsecond, REAL_TYPE4
+ 
+VAR_DECL local_first, INTEGER_TYPE4
+   VAR_DECL local_second, REAL_TYPE4
+   VAR_DECL return_var, INTEGER_TYPE4
+
+   gimple_assign parm_decl, local_first, first, NULL
+   gimple_assign parm_decl, local_second, second, NULL
+   gimple_assign parm_decl, return_var, first, NULL
+   gimple_return return_var
+ 
+
+   Note: 1) The syntax closely mimics the -fdump-tree-gimple-raw option.
+2) The function declaration tuple needs to be checked against the
+   call of the function for order and the number of arguments.
+3) A symbol table entry for the function should be made. The
+   variables defined within the function should be made to have
+   function scope.  */
+
+/* Recognizer function for function declarations. The declaration tuple is read
+   from gimple_parser PARSER.  */
+
+static void
+gp_parse_function_decl (gimple_parser *parser)
+{
+  const gimple_token *next_token;
+
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gl_consume_expected_token (parser-lexer, CPP_COMMA);
+  gp_parse_return_type (parser);
+
+  next_token = gl_consume_token (parser-lexer);
+  while (!gl_at_eof(parser-lexer))
+{
+  if (next_token-type == CPP_COMMA

Re: [gimplefe] Construction of individual gimple statements for gimple_cond and gimple_label

2012-07-18 Thread Sandeep Soni
On Tue, Jul 17, 2012 at 6:16 PM, Diego Novillo dnovi...@google.com wrote:


 Not so much, anymore
 (http://gcc.gnu.org/codingconventions.html#Variable).  When gimplefe
 is merged into trunk, we will be using the C++ conventions which now
 allow this.

 No need to change anything, Sandy.

Ah..Saved by the skin of my teeth. Thanks!

-- 
Cheers
Sandy


Re: [gimplefe] Construction of individual gimple statements for gimple_cond and gimple_label

2012-07-17 Thread Sandeep Soni
On Tue, Jul 17, 2012 at 1:22 PM, Bernhard Reutner-Fischer
rep.dot@gmail.com wrote:

 I'm curious if the coding conventions were relaxed to allow for variable
 declarations that are not at the beginning of a function or scope?

 You seem to do this pretty often in the gimplefe..

 cheers,

Not really. I guess, I am the one at fault for this. I will ensure the
existing code is fixed so that the conventions are followed. Thanks
for pointing it out.

-- 
Cheers
Sandy


[gimplefe] Construction of individual gimple statements for gimple_cond and gimple_label

2012-07-10 Thread Sandeep Soni
The patch adds support for creating individual gimple statements for
the gimple_cond and gimple_label statements.

Diego, I need your help in generalizing to include all possible cases
of these statements.

Here is the ChangeLog

2012-07-10   Sandeep Soni soni.sande...@gmail.com

* parser.c (gp_parse_expect_op1): Tidy. Returns tree operand.
Update all callers.
(gp_parse_expect_op2): Likewise.
(gp_parse_expect_true_label): Tidy. Returns a label.
Update all callers.
(gp_parse_expect_false_label): Likewise.
(gp_parse_cond_stmt): Tidy. Creates and returns a gimple cond
statement.
(gp_parse_label_stmt): Creates and returns the gimple label statement.


And the patch
Index: gcc/gimple/parser.c
===
--- gcc/gimple/parser.c (revision 188546)
+++ gcc/gimple/parser.c (working copy)

-static void
+static tree
 gp_parse_expect_op1 (gimple_parser *parser)
 {
   const gimple_token *next_token;
   next_token = gl_consume_token (parser-lexer);
+  tree op1 = NULL_TREE;

   switch (next_token-type)
 {
 case CPP_NAME:
+  op1 = gimple_symtab_get_token (next_token);
+  break;
+
 case CPP_NUMBER:
   break;

@@ -476,20 +529,24 @@
 }

   gl_consume_expected_token (parser-lexer, CPP_COMMA);
+  return op1;
 }

 /* Helper for gp_parse_cond_stmt. The token read from reader PARSER should
be the second operand in the tuple.  */

-static void
+static tree
 gp_parse_expect_op2 (gimple_parser *parser)
 {
   const gimple_token *next_token;
   next_token = gl_consume_token (parser-lexer);
-
+  tree op2 = NULL_TREE;
   switch (next_token-type)
 {
 case CPP_NAME:
+  op2 = gimple_symtab_get_token (next_token);
+  break;
+
 case CPP_NUMBER:
 case CPP_STRING:
   break;
@@ -503,50 +560,55 @@
   break;
 }

-  gl_consume_expected_token (parser-lexer, CPP_COMMA);
+  gl_consume_expected_token (parser-lexer, CPP_COMMA);
+  return op2;
 }

 /* Helper for gp_parse_cond_stmt. The token read from reader PARSER should
be the true label in the tuple that means the label where the control
jumps if the condition evaluates to true.  */

-static void
+static tree
 gp_parse_expect_true_label (gimple_parser *parser)
 {
   gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
   gl_consume_expected_token (parser-lexer, CPP_GREATER);
   gl_consume_expected_token (parser-lexer, CPP_COMMA);
+  return create_artificial_label (UNKNOWN_LOCATION);
 }

 /* Helper for gp_parse_cond_stmt. The token read from reader PARSER should
be the false label in the tuple that means the label where the control
jumps if the condition evaluates to false.  */

-static void
+static tree
 gp_parse_expect_false_label (gimple_parser *parser)
 {
   gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
   gl_consume_expected_token (parser-lexer, CPP_GREATER);
   gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  return create_artificial_label (UNKNOWN_LOCATION);
 }

 /* Parse a gimple_cond tuple that is read from the reader PARSER. For
now we only recognize the tuple. Refer gimple.def for the format of
this tuple.  */

-static void
+static gimple
 gp_parse_cond_stmt (gimple_parser *parser)
 {
   gimple_token *optoken;
   enum tree_code opcode = gp_parse_expect_subcode (parser, optoken);
   if (get_gimple_rhs_class (opcode) != GIMPLE_BINARY_RHS)
 error_at (optoken-location, Unsupported gimple_cond expression);
-  gp_parse_expect_op1 (parser);
-  gp_parse_expect_op2 (parser);
-  gp_parse_expect_true_label (parser);
-  gp_parse_expect_false_label (parser);
+  tree op1 = gp_parse_expect_op1 (parser);
+  tree op2 = gp_parse_expect_op2 (parser);
+  tree true_label = gp_parse_expect_true_label (parser);
+  tree false_label = gp_parse_expect_false_label (parser);
+  gimple cond_stmt = gimple_build_cond (opcode, op1, op2, true_label,
false_label);
+  return cond_stmt;
 }

 /* Parse a gimple_goto tuple that is read from the reader PARSER. For
@@ -567,14 +629,18 @@
now we only recognize the tuple. Refer gimple.def for the format of
this tuple.  */

-static void
+static gimple
 gp_parse_label_stmt (gimple_parser *parser)
 {
   gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_LESS);
-  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gimple_token *token = gl_consume_token (parser-lexer);
   gl_consume_expected_token (parser-lexer, CPP_GREATER);
-  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+
+  tree label = create_artificial_label (token-location);
+  gimple stmt = gimple_build_label (label);
+  return stmt;
 }

 /* Parse a gimple_switch tuple that is read from the reader PARSER.


-- 
Cheers
Sandy


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

2012-07-10 Thread Sandeep Soni
On Fri, Jul 6, 2012 at 7:26 PM, Diego Novillo dnovi...@google.com wrote:
 On 12-07-06 00:38 , Sandeep Soni wrote:

 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.


 Great!  Thanks.



 Tested on x86.

 ChangeLog as follows:

 2012-06-06   Sandeep Soni  soni.sande...@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 .


 OK with a couple of minor nits.


 -/* 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  */


 Period at the end of the comment.


 +
 +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();


 Space before '('.


 Diego.

Done with both the changes.

-- 
Cheers
Sandy


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

2012-07-05 Thread Sandeep Soni
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.sande...@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

Re: [gimplefe] creating individual gimple_assign statements

2012-06-23 Thread Sandeep Soni
On Thu, Jun 21, 2012 at 11:33 AM, Diego Novillo dnovi...@google.com wrote:
 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.sande...@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?

Yes we do. I will be adding some more now to the testsuite that
specifically check gimple assignments.

Here is a new patch with all the suggested changes.

ChangeLog

2012-06-25   Sandeep Soni  soni.sande...@gmail.com

* parser.c

[gimplefe] creating individual gimple_assign statements

2012-06-20 Thread Sandeep Soni
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.sande...@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.

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





-- 
Cheers
Sandy


[gimplefe] Tests for type declarations and variable declarations

2012-06-12 Thread Sandeep Soni
The patch adds some preliminary tests for type declarations and
varaible declarations for the gimple front end.

Following is the ChangeLog Entry.

2012-06-12 Sandeep Soni soni.sande...@gmail.com

gimple.dg/20120611-1.gimple : New.
gimple.dg/20120611-2.gimple : New.
gimple.dg/20120611-3.gimple : New.
gimple.dg/20120611-4.gimple : New.
gimple.dg/type-1.gimple : New.
gimple.dg/type-2.gimple : New.
gimple.dg/type-3.gimple : New.


I have thus far added some very basic tests to the front end. I want
to add more tests periodically and now I want to get back to the
original building gimple statements problem.

-- 
Cheers
Sandy


test003.diff
Description: Binary data


[gimplefe] patch that fixes the bug for the failure test case

2012-06-08 Thread Sandeep Soni
Hi,

This patch fixes the failure test case that I had submitted the last time.

The changeLog is testsuite/gChangeLog.gimplefe is as follows.

2012-06-09   Sandeep Soni soni.sande...@gmail.com
  * gimple.dg/20120605-2.gimple : New.

While the changelog in gimple/ChangeLog is as follows
2012-06-09   Sandeep Soni soni.sande...@gmail.com
  * parser.c (gp_parse_expect_return_var) : Modify to have
correct token consumption.

Index: gcc/testsuite/gimple.dg/20120604-2.gimple
===
--- gcc/testsuite/gimple.dg/20120604-2.gimple   (revision 0)
+++ gcc/testsuite/gimple.dg/20120604-2.gimple   (revision 0)
@@ -0,0 +1 @@
+gimple_condmodify_expr,a,3,tlabel,flabel /* { dg-error
Unsupported gimple_cond expression } */
Index: gcc/gimple/parser.c
===
--- gcc/gimple/parser.c (revision 188324)
+++ gcc/gimple/parser.c (working copy)
@@ -634,16 +634,11 @@
 static void
 gp_parse_expect_return_var (gimple_parser *parser)
 {
-  const gimple_token *next_token;
-
-  next_token = gl_consume_token (parser-lexer);
-
-  if (next_token-type == CPP_NAME)
-next_token = gl_consume_token (parser-lexer);
-
   /* There may be no variable in which the return value is collected.
  In that case this field in the tuple will contain NULL. We need
  to handle it too.  */
+  gl_consume_expected_token (parser-lexer, CPP_NAME);
+
 }


@@ -664,7 +659,6 @@
   break;

 case CPP_MULT:
-  next_token = gl_consume_token (parser-lexer);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
   break;

@@ -692,7 +686,6 @@
break;
   else if (next_token-type == CPP_COMMA)
 {
-  next_token = gl_consume_token (parser-lexer);
   gp_parse_expect_argument (parser);
 }
 }


-- 
Cheers
Sandy


[gimplefe] Adding more preliminary tests

2012-06-04 Thread Sandeep Soni
Hi,

I have added some more preliminary tests for the gimple front end..
These are really simple individual statement tests which have helped
me get a hang of the testing mechanism in gcc. I will be adding a few
more tests tonight.

At this point, make check-gimple passes 7 cases and fails one. I will
fix up the bug in a later patch tonight.

Here is the output of make check-gimple

=== gimple tests ===

Schedule of variations:
unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file
for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/sandeep/gimple-front-end/gcc/testsuite/config/default.exp
as tool-and-target-specific interface file.
Running /home/sandeep/gimple-front-end/gcc/testsuite/gimple.dg/dg.exp ...
FAIL: gimple.dg/20120605-2.gimple  -O  (test for excess errors)

=== gimple Summary ===

# of expected passes7
# of unexpected failures1
/home/sandeep/gimple_build/gcc/testsuite/gimple/../../xgcc  version
4.8.0-gimplefe 20120524 (experimental) (GCC)

make[1]: [check-parallel-gimple] Error 1 (ignored)
make[1]: Leaving directory `/home/sandeep/gimple_build/gcc'


Here is the changeLog.in testsuite/ChangeLog.gimplefe

2012-06-05  Sandeep Soni  soni.sande...@gmail.com
  *gimple.dg/20120604-1.gimple : New.
  *gimple.dg/20120604-2.gimple : New.
  *gimple.dg/20120605-1.gimple: New.
  *gimple.dg/20120605-2.gimple: New.

Index: gcc/testsuite/gimple.dg/20120604-1.gimple
===
--- gcc/testsuite/gimple.dg/20120604-1.gimple   (revision 0)
+++ gcc/testsuite/gimple.dg/20120604-1.gimple   (revision 0)
@@ -0,0 +1 @@
+gimple_condeq_expr,a,b,tlabel,flabel
Index: gcc/testsuite/gimple.dg/20120604-2.gimple
===
--- gcc/testsuite/gimple.dg/20120604-2.gimple   (revision 0)
+++ gcc/testsuite/gimple.dg/20120604-2.gimple   (revision 0)
@@ -0,0 +1 @@
+gimple_condmodify_expr,a,3,tlabel,flabel /* { dg-error
Unsupported gimple_cond expression } */
Index: gcc/testsuite/gimple.dg/20120605-1.gimple
===
--- gcc/testsuite/gimple.dg/20120605-1.gimple   (revision 0)
+++ gcc/testsuite/gimple.dg/20120605-1.gimple   (revision 0)
@@ -0,0 +1 @@
+gimple_switch a, default: default_label, case 1: first_label,
case 2: second_label, case 3: third_label
Index: gcc/testsuite/gimple.dg/20120605-2.gimple
===
--- gcc/testsuite/gimple.dg/20120605-2.gimple   (revision 0)
+++ gcc/testsuite/gimple.dg/20120605-2.gimple   (revision 0)
@@ -0,0 +1 @@
+gimple_callfoo,return_var,1,2

-- 
Cheers
Sandy


Re: [gimplefe] [patch] splits cpp_lshift and cpp_rshift tokens into discrete cpp_less and cpp_greater tokens respectively

2012-03-14 Thread Sandeep Soni
On Tue, Mar 13, 2012 at 9:42 PM, Diego Novillo dnovi...@google.com wrote:
 On 08/03/12 20:47 , Sandeep Soni wrote:

 +/* Splits the token TOKEN into two tokens FIRST_TOKEN and SECOND_TOKEN.
 +   Note that the split should work only if the type of the TOKEN is
 +   either CPP_RSHIFT or CPP_LSHIFT which gets splitted into two tokens


 s/splitted/split/

   while (gl_lex_token (lexer, token))
 -    VEC_safe_push (gimple_token, gc, lexer-tokens, token);
 +    {
 +      if (gl_token_is_of_type (token,CPP_LSHIFT) ||
 +         gl_token_is_of_type (token,CPP_RSHIFT))


 '||' goes at the start of the second line, aligned with the first character
 after the '('.


 OK with those changes.


 Diego.

Done.

-- 
Cheers
Sandy


[gimplefe] [patch] splits cpp_lshift and cpp_rshift tokens into discrete cpp_less and cpp_greater tokens respectively

2012-03-08 Thread Sandeep Soni
Hi,
The current patch splits cpp_lshift and cpp_rshift tokens into
cpp_less and cpp_greater tokens respectively.The necessary changes due
to this are made throughout the parser. The changelog is as follows.
Up for review.

2012-03-08  Sandeep Soni  soni.sande...@gmail.com

* parser.c (gl_lex_token): For every CPP_LSHIFT and CPP_RSHIFT tokens,
split the token into two discrete CPP_LESS and CPP_GREATER tokens
respectively.
(gl_split_token): New. The split function for the case above.
(gl_token_is_of_type): New. Checks if the tokens type is the expected
type.
(gp_parse_var_decl): Changing consumption of CPP_LSHIFT and CPP_RSHIFT
tokens into CPP_LESS and CPP_GREATER tokens.
(gp_parse_record_type): Ditto.
(gp_parse_union_type): Ditto.
(gp_parse_cond_stmt): Ditto.
(gp_parse_goto_stmt): Ditto.
(gp_parse_label_stmt): Ditto.
(gp_parse_switch_stmt): Ditto.


-- 
Cheers
Sandy
Index: gcc/gimple/parser.c
===
--- gcc/gimple/parser.c	(revision 184993)
+++ gcc/gimple/parser.c	(working copy)
@@ -494,7 +494,8 @@
 {
   gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
-  gl_consume_expected_token (parser-lexer, CPP_RSHIFT);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
 }
 
 /* Parse a gimple_cond tuple that is read from the reader PARSER. For now we only 
@@ -516,9 +517,11 @@
 static void
 gp_parse_goto_stmt (gimple_parser *parser)
 {
-  gl_consume_expected_token (parser-lexer, CPP_LSHIFT);
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
-  gl_consume_expected_token (parser-lexer, CPP_RSHIFT);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
 }
 
 /* Parse a gimple_label tuple that is read from the reader PARSER. For now we only 
@@ -527,9 +530,11 @@
 static void
 gp_parse_label_stmt (gimple_parser *parser)
 {
-  gl_consume_expected_token (parser-lexer, CPP_LSHIFT);
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
-  gl_consume_expected_token (parser-lexer, CPP_RSHIFT);  
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);  
 }
 
 /* Parse a gimple_switch tuple that is read from the reader PARSER. For now we only 
@@ -547,25 +552,23 @@
   gl_consume_expected_token (parser-lexer, CPP_COLON);
   gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
 
   while (!gl_at_eof (parser-lexer))
 {
   next_token = gl_consume_token (parser-lexer);
   
-  if (next_token-type == CPP_GREATER)
+  if (next_token-type == CPP_COMMA)
 {
-  gl_consume_expected_token (parser-lexer, CPP_COMMA);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
   gl_consume_expected_token (parser-lexer, CPP_NUMBER);
   gl_consume_expected_token (parser-lexer, CPP_COLON);
   gl_consume_expected_token (parser-lexer, CPP_LESS);
-  gl_consume_expected_token (parser-lexer, CPP_NAME);  
+  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
 }
-  else if (next_token-type == CPP_RSHIFT)
-{
-  next_token = gl_consume_token (parser-lexer);
-  break;
-}
+  else if (next_token-type == CPP_GREATER)
+break;
   else
 error_at (next_token-location, 
 	  Incorrect use of the gimple_switch statement);
@@ -715,14 +718,14 @@
 static void
 gp_parse_expect_field_decl (gimple_parser *parser)
 {
-  gl_consume_expected_token (parser-lexer, CPP_NAME);
   gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
   gl_consume_expected_token (parser-lexer, CPP_COMMA);
   gl_consume_expected_token (parser-lexer, CPP_NAME);
   gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NUMBER);
-  gl_consume_expected_token (parser-lexer, CPP_RSHIFT);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
 
 }
 
@@ -788,7 +791,9 @@
};
 
The tuple representation is done as :
-   UNION_TYPE some_union,4,FIELD_DECLfirst_var,INTEGER_TYPE4,FIELD_DECLsecond_var,REAL_TYPE4
+   UNION_TYPE some_union,4,
+  FIELD_DECL first_var,INTEGER_TYPE4,
+  FIELD_DECLsecond_var,REAL_TYPE4
 */
 
 /* Recognizer function for Union declarations. The union tuple

Re: [gimplefe][patch] The symbol table for declarations

2012-03-01 Thread Sandeep Soni
On Wed, Feb 29, 2012 at 8:14 PM, Diego Novillo dnovi...@google.com wrote:
 On 24/02/12 01:03 , Sandeep Soni wrote:

 +  name_token = gl_consume_expected_token (parser-lexer, CPP_NAME);
 +  name = gl_token_as_text (name_token);
 +
 +  e = ggc_alloc_cleared_gimple_symtab_entry_def ();
 +  e-id = get_identifier(name);
 +  slot = htab_find_slot (gimple_symtab, e, NO_INSERT);
 +  if (!slot)


 Why not just use INSERT here?  If the slot is empty, you can then test 'if
 (*slot == NULL)' (since the INSERT operation guarantees that 'slot' will be
 non-NULL.

 Also, please factor this code to a helper function to abstract the hash
 table operations.   We will later want to add a pure lookup routine and we
 may want to add symbols to the symbol table from other contexts.

Done with the above changes. The hash table operations are abstracted
out to two helper functions. Also added is a function to lazily
initialize the hash table similar to the one we have in the LTO front
end.

The patch is attached. Up for review. The changelog is as follows:
2012-03-01  Sandeep Soni  soni.sande...@gmail.com

* parser.c : Include hashtab.h.
(gimple_symtab): New. The symbol table.
(gimple_symtab_entry_hash): New.
(gimple_symtab_eq_hash): New.
(gimple_symtab_entry_marked_p):New.
(gimple_symtab_maybe_init_hash_table):New.
(gimple_symtab_register_decl):New.
(gimple_register_var_decl_in_symtab):New.
(gp_parse_var_decl): Put declaration in the symbol table.
(gimple_main): Creates the symbol table
* parser.h : (struct gimple_symtab_entry_def): New.

2011-10-11  Sandeep Soni  soni.sande...@gmail.com

* parser.c (gp_parse_var_decl): Fixed a bug for the
missing symbol 'CPP_LESS' in the 'INTEGER_TYPE' declaration.


-- 
Cheers
Sandy
Index: gcc/gimple/parser.h
===
--- gcc/gimple/parser.h	(revision 174754)
+++ gcc/gimple/parser.h	(working copy)
@@ -27,6 +27,19 @@
 #include vec.h
 
 
+/* The GIMPLE symbol table entry.  */
+
+struct GTY(()) gimple_symtab_entry_def 
+{
+  /* symbol table entry key, an identifier.  */
+  tree id;
+
+  /* symbol table entry, a DECL.  */
+  tree decl;
+};
+
+typedef struct gimple_symtab_entry_def *gimple_symtab_entry_t;
+
 /* A GIMPLE token.  */
 
 typedef struct GTY(()) gimple_token {
@@ -81,7 +94,7 @@
   struct GTY((skip)) ht *ident_hash;
 } gimple_parser;
 
-
+ 
 /* In parser.c  */
 extern void gimple_main (void);
 
Index: gcc/gimple/parser.c
===
--- gcc/gimple/parser.c	(revision 174754)
+++ gcc/gimple/parser.c	(working copy)
@@ -28,6 +28,7 @@
 #include tree.h
 #include gimple.h
 #include parser.h
+#include hashtab.h
 #include ggc.h
 
 /* The GIMPLE parser.  Note: do not use this variable directly.  It is
@@ -44,6 +45,84 @@
 /* EOF token.  */
 static gimple_token gl_eof_token = { CPP_EOF, 0, 0, 0 };
 
+/* Gimple symbol table.  */
+
+static GTY ((if_marked (gimple_symtab_entry_marked_p),
+	 param_is (struct gimple_symtab_entry_def)))
+  htab_t gimple_symtab;
+
+/* Return the hash value of the declaration name of a gimple_symtab_entry_def
+   object pointed by ENTRY.  */
+
+static hashval_t
+gimple_symtab_entry_hash (const void *entry)
+{
+  const struct gimple_symtab_entry_def *base =
+(const struct gimple_symtab_entry_def *)entry;
+  return IDENTIFIER_HASH_VALUE (base-id);
+}
+
+/* Returns non-zero if ENTRY1 and ENTRY2 point to gimple_symtab_entry_def
+   objects corresponding to the same declaration.  */
+
+static int
+gimple_symtab_eq_hash (const void *entry1, const void *entry2)
+{
+  const struct gimple_symtab_entry_def *base1 =
+(const struct gimple_symtab_entry_def *)entry1;
+  const struct gimple_symtab_entry_def *base2 =
+(const struct gimple_symtab_entry_def *)entry2;
+
+  return (base1-id == base2-id);
+}
+
+/* Returns non-zero if P points to an gimple_symtab_entry_def struct that needs
+   to be marked for GC.  */
+
+static int
+gimple_symtab_entry_marked_p (const void *p)
+{
+  const struct gimple_symtab_entry_def *base =
+ (const struct gimple_symtab_entry_def *) p;
+
+  /* Keep this only if the common IDENTIFIER_NODE of the symtab chain
+ is marked which it will be if at least one of the DECLs in the
+ chain is marked.  */
+  return ggc_marked_p (base-id);
+}
+
+
+/* Lazily initialize hash tables.  */
+
+static void
+gimple_symtab_maybe_init_hash_table (void)
+{
+  if (gimple_symtab)
+return;
+
+  gimple_symtab =
+htab_create_ggc (1021, gimple_symtab_entry_hash,
+		 gimple_symtab_eq_hash, NULL);
+}
+
+/* Registers DECL with the gimple symbol table as having identifier ID.  */
+
+static void
+gimple_symtab_register_decl (tree decl, tree id)
+{
+  gimple_symtab_entry_t new_entry;
+  void **slot;
+
+  new_entry = ggc_alloc_cleared_gimple_symtab_entry_def ();
+  new_entry-id = id;
+  new_entry-decl = decl

Re: [gimplefe][patch] The symbol table for declarations

2012-02-23 Thread Sandeep Soni
On Wed, Nov 30, 2011 at 9:48 AM, Sandeep Soni soni.sande...@gmail.com wrote:
 Sorry. Wrong patch. New patch attached.

 I am getting the following error in the new patch though.

 ../../gimple-front-end/gcc/gimple/parser.c: In function ‘gp_parse_var_decl’:
 ../../gimple-front-end/gcc/gimple/parser.c:927:3: error: implicit
 declaration of function ‘ggc_alloc_cleared_gimple_symtab_entry_def’
 [-Werror=implicit-function-declaration]
 ../../gimple-front-end/gcc/gimple/parser.c:927:5: error: assignment
 makes pointer from integer without a cast [-Werror]
 cc1: all warnings being treated as errors

 make[3]: *** [gimple/parser.o] Error 1
 make[3]: *** Waiting for unfinished jobs
 rm gfdl.pod cpp.pod gcov.pod gfortran.pod fsf-funding.pod gcc.pod
 make[3]: Leaving directory `/home/Sandy/gimple_build/gcc'
 make[2]: *** [all-stage2-gcc] Error 2
 make[2]: Leaving directory `/home/Sandy/gimple_build'
 make[1]: *** [stage2-bubble] Error 2
 make[1]: Leaving directory `/home/Sandy/gimple_build'
 make: *** [all] Error 2

 Is there anything that needs to be initialized to use the
 ggc_alloc_cleared_* function?

I was finally able to circumvent the error. I guess what I missed was
I did not mark the symbol table (the global variable) for garbage
collection. Once I did that the error was removed.

Builds correctly on x86. Up for review.


-- 
Cheers
Sandy

PS: We finally have the symbol table :)
Index: gcc/gimple/parser.h
===
--- gcc/gimple/parser.h	(revision 174754)
+++ gcc/gimple/parser.h	(working copy)
@@ -27,6 +27,19 @@
 #include vec.h
 
 
+/* The GIMPLE symbol table entry.  */
+
+struct GTY(()) gimple_symtab_entry_def 
+{
+  /* symbol table entry key, an identifier.  */
+  tree id;
+
+  /* symbol table entry, a DECL.  */
+  tree decl;
+};
+
+typedef struct gimple_symtab_entry_def *gimple_symtab_entry_t;
+
 /* A GIMPLE token.  */
 
 typedef struct GTY(()) gimple_token {
@@ -81,7 +94,7 @@
   struct GTY((skip)) ht *ident_hash;
 } gimple_parser;
 
-
+ 
 /* In parser.c  */
 extern void gimple_main (void);
 
Index: gcc/gimple/parser.c
===
--- gcc/gimple/parser.c	(revision 174754)
+++ gcc/gimple/parser.c	(working copy)
@@ -28,6 +28,7 @@
 #include tree.h
 #include gimple.h
 #include parser.h
+#include hashtab.h
 #include ggc.h
 
 /* The GIMPLE parser.  Note: do not use this variable directly.  It is
@@ -44,6 +45,52 @@
 /* EOF token.  */
 static gimple_token gl_eof_token = { CPP_EOF, 0, 0, 0 };
 
+/* Gimple symbol table.  */
+
+static GTY ((if_marked (gimple_symtab_entry_marked_p),
+	 param_is (struct gimple_symtab_entry_def)))
+  htab_t gimple_symtab;
+
+/* Return the hash value of the declaration name of a gimple_symtab_entry_def
+   object pointed by ENTRY.  */
+
+static hashval_t
+gimple_symtab_entry_hash (const void *entry)
+{
+  const struct gimple_symtab_entry_def *base =
+(const struct gimple_symtab_entry_def *)entry;
+  return IDENTIFIER_HASH_VALUE (base-id);
+}
+
+/* Returns non-zero if ENTRY1 and ENTRY2 point to gimple_symtab_entry_def
+   objects corresponding to the same declaration.  */
+
+static int
+gimple_symtab_eq_hash (const void *entry1, const void *entry2)
+{
+  const struct gimple_symtab_entry_def *base1 =
+(const struct gimple_symtab_entry_def *)entry1;
+  const struct gimple_symtab_entry_def *base2 =
+(const struct gimple_symtab_entry_def *)entry2;
+
+  return (base1-id == base2-id);
+}
+
+/* Returns non-zero if P points to an gimple_symtab_entry_def struct that needs
+   to be marked for GC.  */
+
+static int
+gimple_symtab_entry_marked_p (const void *p)
+{
+  const struct gimple_symtab_entry_def *base =
+ (const struct gimple_symtab_entry_def *) p;
+
+  /* Keep this only if the common IDENTIFIER_NODE of the symtab chain
+ is marked which it will be if at least one of the DECLs in the
+ chain is marked.  */
+  return ggc_marked_p (base-id);
+}
+
 /* Return the string representation of token TOKEN.  */
 
 static const char *
@@ -807,6 +854,7 @@
 }
 }
 
+
 /* The Declaration section within a .gimple file can consist of 
a) Declaration of variables.
b) Declaration of functions.
@@ -870,18 +918,35 @@
 static void
 gp_parse_var_decl (gimple_parser *parser)
 {
-  const gimple_token *next_token;
+  const gimple_token *next_token, *name_token;
+  const char *name;
   enum tree_code code ;
+  gimple_symtab_entry_t e;
+  void **slot;
+  void **new_entry;
 
   gl_consume_expected_token (parser-lexer, CPP_LESS);
-  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  name_token = gl_consume_expected_token (parser-lexer, CPP_NAME);
+  name = gl_token_as_text (name_token);
+
+  e = ggc_alloc_cleared_gimple_symtab_entry_def ();
+  e-id = get_identifier(name);
+  slot = htab_find_slot (gimple_symtab, e, NO_INSERT); 
+  if (!slot)
+{
+  e-decl = build_decl (name_token-location, VAR_DECL, get_identifier(name), void_type_node

Re: [gimplefe][patch] The symbol table for declarations

2011-11-29 Thread Sandeep Soni
Sorry. Wrong patch. New patch attached.

I am getting the following error in the new patch though.

../../gimple-front-end/gcc/gimple/parser.c: In function ‘gp_parse_var_decl’:
../../gimple-front-end/gcc/gimple/parser.c:927:3: error: implicit
declaration of function ‘ggc_alloc_cleared_gimple_symtab_entry_def’
[-Werror=implicit-function-declaration]
../../gimple-front-end/gcc/gimple/parser.c:927:5: error: assignment
makes pointer from integer without a cast [-Werror]
cc1: all warnings being treated as errors

make[3]: *** [gimple/parser.o] Error 1
make[3]: *** Waiting for unfinished jobs
rm gfdl.pod cpp.pod gcov.pod gfortran.pod fsf-funding.pod gcc.pod
make[3]: Leaving directory `/home/Sandy/gimple_build/gcc'
make[2]: *** [all-stage2-gcc] Error 2
make[2]: Leaving directory `/home/Sandy/gimple_build'
make[1]: *** [stage2-bubble] Error 2
make[1]: Leaving directory `/home/Sandy/gimple_build'
make: *** [all] Error 2

Is there anything that needs to be initialized to use the
ggc_alloc_cleared_* function?
-- 
Cheers
Sandy


mod.diff
Description: Binary data


[gimplefe][patch] The symbol table for declarations

2011-11-17 Thread Sandeep Soni
On Wed, Oct 12, 2011 at 7:01 PM, Diego Novillo dnovi...@google.com wrote:

 On 11-10-10 17:47 , Sandeep Soni wrote:

 Hi,
 The following patch is a basic attempt to build a symbol table that
 stores the names of all the declarations made in the input file.

 Index: gcc/gimple/parser.c
 ===
 --- gcc/gimple/parser.c (revision 174754)
 +++ gcc/gimple/parser.c (working copy)
 @@ -28,6 +28,7 @@
  #include tree.h
  #include gimple.h
  #include parser.h
 +#include hashtab.h
  #include ggc.h

  /* The GIMPLE parser.  Note: do not use this variable directly.  It is
 @@ -44,6 +45,43 @@
  /* EOF token.  */
  static gimple_token gl_eof_token = { CPP_EOF, 0, 0, 0 };

 +/* The GIMPLE symbol table entry.  */
 +
 +struct GTY (()) gimple_symtab_entry_def
 +{
 +  /* Variable that is declared.  */
 +  tree decl;
 +
 +};

 No blank line before '};'

 Add 'typedef struct gimple_symtab_entry_def gimple_symtab_entry;' to shorten 
 declarations.

 +
 +/* Gimple symbol table.  */
 +static htab_t gimple_symtab;
 +
 +/* Return the hash value of the declaration name of a 
 gimple_symtab_entry_def
 +   object pointed by ENTRY.  */
 +
 +static hashval_t
 +gimple_symtab_entry_hash (const void *entry)
 +{
 +  const struct gimple_symtab_entry_def *base =
 +    (const struct gimple_symtab_entry_def *)entry;
 +  return IDENTIFIER_HASH_VALUE (DECL_NAME(base-decl));

 Space after DECL_NAME.

 +}
 +
 +/* Returns non-zero if ENTRY1 and ENTRY2 points to gimple_symtab_entry_def

 s/points/point/

 +   objects corresponding to the same declaration.  */
 +
 +static int
 +gimple_symtab_eq_hash (const void *entry1, const void *entry2)
 +{
 +  const struct gimple_symtab_entry_def *p1 =
 +    (const struct gimple_symtab_entry_def *)entry1;
 +  const struct gimple_symtab_entry_def *p2 =
 +    (const struct gimple_symtab_entry_def *)entry2;
 +
 +  return DECL_NAME(p1-decl) == DECL_NAME(p2-decl);

 Space after DECL_NAME.

 +}
 +
  /* Return the string representation of token TOKEN.  */

  static const char *
 @@ -807,6 +845,7 @@
      }
  }

 +
  /* The Declaration section within a .gimple file can consist of
     a) Declaration of variables.
     b) Declaration of functions.
 @@ -870,11 +909,17 @@
  static void
  gp_parse_var_decl (gimple_parser *parser)
  {
 -  const gimple_token *next_token;
 +  const gimple_token *next_token, *name_token;
 +  const char* name;

 s/char* /char */

    enum tree_code code ;
 +  struct gimple_symtab_entry_def e;

    gl_consume_expected_token (parser-lexer, CPP_LESS);
 -  gl_consume_expected_token (parser-lexer, CPP_NAME);
 +  name_token = gl_consume_expected_token (parser-lexer, CPP_NAME);
 +  name = gl_token_as_text (name_token);
 +  e.decl =
 +  build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier(name),
 void_type_node);

 No need to use UNKNOWN_LOCATION.  Get the location for E.DECL from 
 name_token.location.

 Additionally, before building the decl, you should make sure that the symbol 
 table does not already have it.  So, instead of looking up with a DECL, you 
 should look it up using IDENTIFIER_NODEs.  There are two approaches you can 
 use:

 1- Add an identifier field to gimple_symtab_entry_def.  Use that field for 
 hash table lookups (in this code you'd then fill E.ID with NAME_TOKEN).

 2- Use a pointer_map_t and a VEC().  With this approach, you use a pointer 
 map to map identifier nodes to unsigned integers.  These integers are the 
 index into the VEC() array where the corresponding decl is stored.

 In this case, I think #1 is the simplest approach.

 +  htab_find_slot (gimple_symtab,e, INSERT);

 This looks wrong.  Where are you actually filling in the slot?  You need to 
 check the returned slot, if it's empty, you fill it in with E.DECL. See other 
 uses of htab_*.

I have made all the changes to the earlier patch. I have attached the
new patch. In the new patch, hashing is done by IDENTIFIERs. I just
made a small change of putting the gimple_symtab_entry instance in the
symbol table rather than only the declaration. Is that okay?
ChangeLog is as follows:
2011-11-18  Sandeep Soni  soni.sande...@gmail.com

       * parser.c : Include hashtab.h.
       (struct gimple_symtab_entry_def): New.
       (gimple_symtab): New. The symbol table.
       (gimple_symtab_entry_hash): New.
       (gimple_symtab_eq_hash): New.
       (gp_parse_var_decl): Build the declaration and put it in the symbol
       table.
       (gimple_main): Creates the symbol table

    gl_consume_expected_token (parser-lexer, CPP_COMMA);

    next_token = gl_consume_token (parser-lexer);
 @@ -981,6 +1027,7 @@
    gimple_parser *parser = ggc_alloc_cleared_gimple_parser ();
    line_table = parser-line_table = ggc_alloc_cleared_line_maps ();
    parser-ident_hash = ident_hash;
 +
    linemap_init (parser-line_table);
    parser-lexer = gl_init (parser, fname);

 @@ -1403,6 +1450,9 @@
    if (parser-lexer-filename == NULL)
      return;

 +  gimple_symtab

[gimplefe][patch] A bugfix for a missed symbol

2011-10-10 Thread Sandeep Soni
Ketaki had pointed a minor bug a long time back. This patch fixes it.

Index: parser.c
===
--- parser.c(revision 174754)
+++ parser.c(working copy)
@@ -882,6 +882,7 @@
   switch (code)
 {
 case INTEGER_TYPE:
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
   gl_consume_expected_token (parser-lexer, CPP_NUMBER);
   gl_consume_expected_token (parser-lexer, CPP_RSHIFT);
   break;

The changelog is:

2011-10-11  Sandeep Soni  soni.sande...@gmail.com

* parser.c (gp_parse_var_decl): Fixed a bug for the
missing symbol 'CPP_LESS' in the 'INTEGER_TYPE' declaration.

-- 
Cheers
Sandy


[gimplefe][patch] The symbol table for declarations

2011-10-10 Thread Sandeep Soni
Hi,
The following patch is a basic attempt to build a symbol table that
stores the names of all the declarations made in the input file.

Index: gcc/gimple/parser.c
===
--- gcc/gimple/parser.c (revision 174754)
+++ gcc/gimple/parser.c (working copy)
@@ -28,6 +28,7 @@
 #include tree.h
 #include gimple.h
 #include parser.h
+#include hashtab.h
 #include ggc.h

 /* The GIMPLE parser.  Note: do not use this variable directly.  It is
@@ -44,6 +45,43 @@
 /* EOF token.  */
 static gimple_token gl_eof_token = { CPP_EOF, 0, 0, 0 };

+/* The GIMPLE symbol table entry.  */
+
+struct GTY (()) gimple_symtab_entry_def
+{
+  /* Variable that is declared.  */
+  tree decl;
+
+};
+
+/* Gimple symbol table.  */
+static htab_t gimple_symtab;
+
+/* Return the hash value of the declaration name of a gimple_symtab_entry_def
+   object pointed by ENTRY.  */
+
+static hashval_t
+gimple_symtab_entry_hash (const void *entry)
+{
+  const struct gimple_symtab_entry_def *base =
+(const struct gimple_symtab_entry_def *)entry;
+  return IDENTIFIER_HASH_VALUE (DECL_NAME(base-decl));
+}
+
+/* Returns non-zero if ENTRY1 and ENTRY2 points to gimple_symtab_entry_def
+   objects corresponding to the same declaration.  */
+
+static int
+gimple_symtab_eq_hash (const void *entry1, const void *entry2)
+{
+  const struct gimple_symtab_entry_def *p1 =
+(const struct gimple_symtab_entry_def *)entry1;
+  const struct gimple_symtab_entry_def *p2 =
+(const struct gimple_symtab_entry_def *)entry2;
+
+  return DECL_NAME(p1-decl) == DECL_NAME(p2-decl);
+}
+
 /* Return the string representation of token TOKEN.  */

 static const char *
@@ -807,6 +845,7 @@
 }
 }

+
 /* The Declaration section within a .gimple file can consist of
a) Declaration of variables.
b) Declaration of functions.
@@ -870,11 +909,17 @@
 static void
 gp_parse_var_decl (gimple_parser *parser)
 {
-  const gimple_token *next_token;
+  const gimple_token *next_token, *name_token;
+  const char* name;
   enum tree_code code ;
+  struct gimple_symtab_entry_def e;

   gl_consume_expected_token (parser-lexer, CPP_LESS);
-  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  name_token = gl_consume_expected_token (parser-lexer, CPP_NAME);
+  name = gl_token_as_text (name_token);
+  e.decl =
+  build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier(name),
void_type_node);
+  htab_find_slot (gimple_symtab, e, INSERT);
   gl_consume_expected_token (parser-lexer, CPP_COMMA);

   next_token = gl_consume_token (parser-lexer);
@@ -981,6 +1027,7 @@
   gimple_parser *parser = ggc_alloc_cleared_gimple_parser ();
   line_table = parser-line_table = ggc_alloc_cleared_line_maps ();
   parser-ident_hash = ident_hash;
+
   linemap_init (parser-line_table);
   parser-lexer = gl_init (parser, fname);

@@ -1403,6 +1450,9 @@
   if (parser-lexer-filename == NULL)
 return;

+  gimple_symtab =
+htab_create_ggc (1021, gimple_symtab_entry_hash,
+gimple_symtab_eq_hash, NULL);
   gl_lex (parser-lexer);
   gp_parse (parser);
   gp_finish (parser);

The changelog is as follows:

2011-10-11  Sandeep Soni  soni.sande...@gmail.com

* parser.c : Include hashtab.h.
(struct gimple_symtab_entry_def): New.
(gimple_symtab): New. The symbol table.
(gimple_symtab_entry_hash): New.
(gimple_symtab_eq_hash): New.
(gp_parse_var_decl): Build the declaration and put it in the symbol
table.
(gimple_main): Creates the symbol table

-- 
Cheers
Sandy


Re: [patch][gimplefe] Preliminary variable declaration support

2011-05-12 Thread Sandeep Soni
On Wed, May 11, 2011 at 1:19 AM, Diego Novillo dnovi...@google.com wrote:

 Please add a ChangeLog entry.  OK with that change.

Committed after adding the ChangeLog entry.

-- 
Cheers
Sandy


[patch][gimplefe] Preliminary variable declaration support

2011-05-09 Thread Sandeep Soni
This patch is just a slight modification to an earlier patch that I
submitted which was non-working. This is working. It just recognizes
variable declarations and might be helpful for ketaki to start with
things. It is now more or less up to date with the information on the
wiki although not exactly analogous. I am going to fix it.

diff --git a/gcc/gimple/.parser.c.swp b/gcc/gimple/.parser.c.swp
deleted file mode 100644
index e639cd8..000
Binary files a/gcc/gimple/.parser.c.swp and /dev/null differ
diff --git a/gcc/gimple/.parser.h.swp b/gcc/gimple/.parser.h.swp
deleted file mode 100644
index 4ee1f23..000
Binary files a/gcc/gimple/.parser.h.swp and /dev/null differ
diff --git a/gcc/gimple/parser.c b/gcc/gimple/parser.c
index 41e25f5..b2929aa 100644
--- a/gcc/gimple/parser.c
+++ b/gcc/gimple/parser.c
@@ -124,6 +124,15 @@ gl_gimple_code_for_token (const gimple_token *token)
   return (enum gimple_code) code;
 }

+/* Return true if TOKEN is the start of a declaration.  */
+
+static bool
+gl_token_starts_decl (gimple_token *token)
+{
+  enum tree_code code = gl_tree_code_for_token (token);
+  return code == VAR_DECL;
+}
+

 /* Return true if TOKEN is the start of a type declaration.  */

@@ -798,6 +807,148 @@ gp_parse_type (gimple_parser *parser, const
gimple_token *token)
 }
 }

+/* The Declaration section within a .gimple file can consist of
+   a) Declaration of variables.
+   b) Declaration of functions.
+
+   The syntax of a variable declaration is as follows:
+
+   VAR_DECLName, Type
+
+   Following are the broad cases for which the syntax of a variable
+   declaration is described:
+
+   Example:
+
+   1. C-like declaration as,
+ int var;
+
+   The Corresponding gimple syntax,
+ VAR_DECL var, INTEGER_TYPE 4
+
+   In General,any variable of an atomic data type,
+ VAR_DECL var_name, TYPE size
+
+   2. C-like declaration as,
+ int array[10];
+
+   The Corresponding gimple syntax,
+ VAR_DECL name, ARRAY_TYPE  0 , 9 , INTEGER_TYPE 4
+
+   In General,any variable of an array type,
+ VAR_DECL array_name, ARRAY_TYPE  min_index, max_index, TYPE size
+
+   3. C-like declaration as,
+ int *ptr;
+
+   The Corresponding gimple syntax,
+ VAR_DECL ptr,POINTER_TYPE  INTEGER_TYPE 4
+
+   In General,any variable of a pointer type,
+ VAR_DECL pointer_name, POINTER_TYPE TYPEsize
+
+   Note: The Nested Type in the Pointer Type tuple is the type of
+ the element to which the variable points.
+
+   4. C-like declaration as,
+struct A a;
+
+   The Corresponding gimple syntax,
+ VAR_DECL a, RECORD_TYPE A
+
+   In General, any variable of an aggregate type,
+ VAR_DECL var_name, AGGREGATE_TYPE aggregate_name
+
+   Note: 1) Records, Unions and Enumerals are considered as Aggregates.
+2) For the aggregates we store only the name of the aggregate.
+The other properties of the aggregate will already be stored
+from the type declarations parsing and can thus be deduced.   */
+
+/* Recognizer function for variable declarations. The declaration tuple is read
+   from gimple_parser PARSER.  */
+
+static void
+gp_parse_var_decl (gimple_parser *parser)
+{
+  const gimple_token *next_token;
+  enum tree_code code ;
+
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gl_consume_expected_token (parser-lexer, CPP_COMMA);
+
+  next_token = gl_consume_token (parser-lexer);
+  code = gl_tree_code_for_token (next_token);
+  switch (code)
+{
+case INTEGER_TYPE:
+  gl_consume_expected_token (parser-lexer, CPP_NUMBER);
+  gl_consume_expected_token (parser-lexer, CPP_RSHIFT);
+  break;
+
+case ARRAY_TYPE:
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_NUMBER);
+  gl_consume_expected_token (parser-lexer, CPP_COMMA);
+  gl_consume_expected_token (parser-lexer, CPP_NUMBER);
+  gl_consume_expected_token (parser-lexer, CPP_COMMA);
+
+  /*TODO The tree code that we recognize below can be processed further.
+No action is taken for now.  */
+
+  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_NUMBER);
+  gl_consume_expected_token (parser-lexer, CPP_RSHIFT);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  break;
+
+case POINTER_TYPE:
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+
+  /*TODO The tree code that we recognize below can be processed further.
+No action is taken for now.  */
+
+  gl_consume_expected_token (parser-lexer, CPP_NAME);
+  gl_consume_expected_token (parser-lexer, CPP_LESS);
+  gl_consume_expected_token (parser-lexer, CPP_NUMBER);
+  gl_consume_expected_token (parser-lexer, CPP_RSHIFT);
+  gl_consume_expected_token (parser-lexer, CPP_GREATER);
+  break;
+
+case