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 (gimple_symtab_get): New. (gl_symtab_get_token): New. Gets the tree for the token. (gp_parse_expect_lhs): Tidy. Returns the tree node for lhs. (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,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,6 +443,7 @@ case CPP_NUMBER: case CPP_STRING: next_token = gl_consume_token (parser->lexer); + rhs = gimple_symtab_get_token (next_token); break; default: @@ -414,15 +456,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 +479,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 +497,10 @@ } 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)); + return stmt; } /* Helper for gp_parse_cond_stmt. The token read from reader PARSER should -- Cheers Sandy