Hi Richard, The attached patch tries to handle ABS_EXPR in gimple-fe. I am not sure if __ABS_EXPR should be parsed as id (like __MEM) or parse it as keyword (like __GIMPLE). Currently in the patch, I parse it as id. Patch passes gimplefe tests, is it OK to commit after bootstrap+test ?
Thanks, Prathamesh
2017-02-07 Prathamesh Kulkarni <prathamesh.kulka...@linaro.org> * gimple-pretty-print.c (dump_unary_rhs): Change dump format for ABS_EXPR for gimple dump. c/ * gimple-parser.c (c_parser_gimple_unary_expression): Handle ABS_EXPR. (c_parser_gimple_statement): Likewise. testsuite/ * gcc.dg/gimplefe-25.c: New test-case. diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index e167e42..51bbfdc 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -61,7 +61,7 @@ static bool c_parser_gimple_compound_statement (c_parser *, gimple_seq *); static void c_parser_gimple_label (c_parser *, gimple_seq *); static void c_parser_gimple_statement (c_parser *, gimple_seq *); static struct c_expr c_parser_gimple_binary_expression (c_parser *); -static struct c_expr c_parser_gimple_unary_expression (c_parser *); +static struct c_expr c_parser_gimple_unary_expression (c_parser *, enum tree_code oper_code = ERROR_MARK); static struct c_expr c_parser_gimple_postfix_expression (c_parser *); static struct c_expr c_parser_gimple_postfix_expression_after_primary (c_parser *, location_t, @@ -323,8 +323,19 @@ c_parser_gimple_statement (c_parser *parser, gimple_seq *seq) } /* Unary expression. */ + enum tree_code oper_code = ERROR_MARK; switch (c_parser_peek_token (parser)->type) { + case CPP_NAME: + { + tree id = c_parser_peek_token (parser)->value; + if (strcmp (IDENTIFIER_POINTER (id), "__ABS_EXPR") == 0) + { + oper_code = ABS_EXPR; + goto build_unary_expr; + } + break; + } case CPP_KEYWORD: if (c_parser_peek_token (parser)->keyword != RID_REALPART && c_parser_peek_token (parser)->keyword != RID_IMAGPART) @@ -336,7 +347,8 @@ c_parser_gimple_statement (c_parser *parser, gimple_seq *seq) case CPP_COMPL: case CPP_NOT: case CPP_MULT: /* pointer deref */ - rhs = c_parser_gimple_unary_expression (parser); + build_unary_expr: + rhs = c_parser_gimple_unary_expression (parser, oper_code); if (rhs.value != error_mark_node) { assign = gimple_build_assign (lhs.value, rhs.value); @@ -537,11 +549,11 @@ c_parser_gimple_binary_expression (c_parser *parser) unary-operator gimple-postfix-expression unary-operator: one of - & * + - ~ + & * + - ~ abs_expr */ static c_expr -c_parser_gimple_unary_expression (c_parser *parser) +c_parser_gimple_unary_expression (c_parser *parser, enum tree_code oper_code) { struct c_expr ret, op; location_t op_loc = c_parser_peek_token (parser)->location; @@ -599,6 +611,25 @@ c_parser_gimple_unary_expression (c_parser *parser) default: return c_parser_gimple_postfix_expression (parser); } + case CPP_NAME: + { + if (oper_code != ERROR_MARK) + { + c_parser_consume_token (parser); + op = c_parser_gimple_postfix_expression (parser); + return parser_build_unary_op (op_loc, oper_code, op); + } + + tree id = c_parser_peek_token (parser)->value; + if (strcmp (IDENTIFIER_POINTER (id), "__ABS_EXPR") == 0) + { + c_parser_consume_token (parser); + op = c_parser_gimple_postfix_expression (parser); + return parser_build_unary_op (op_loc, ABS_EXPR, op); + } + else + return c_parser_gimple_postfix_expression (parser); + } default: return c_parser_gimple_postfix_expression (parser); } diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index 91c839d..6e9102e 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -323,9 +323,17 @@ dump_unary_rhs (pretty_printer *buffer, gassign *gs, int spc, int flags) break; case ABS_EXPR: - pp_string (buffer, "ABS_EXPR <"); - dump_generic_node (buffer, rhs, spc, flags, false); - pp_greater (buffer); + if (flags & TDF_GIMPLE) + { + pp_string (buffer, "__ABS_EXPR "); + dump_generic_node (buffer, rhs, spc, flags, false); + } + else + { + pp_string (buffer, "ABS_EXPR <"); + dump_generic_node (buffer, rhs, spc, flags, false); + pp_greater (buffer); + } break; default: