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