diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2005-02-17 01:11:10 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2005-02-17 01:11:10 +0000 |
commit | 1312e76330285d50143e2b48c2ed73693ebef1f6 (patch) | |
tree | e76c251f2426f8ef5963551aaf8353477ab40ddf /gcc | |
parent | 857726c5ad97a47e6c109001b96c195612800f7e (diff) |
Radar 3970655
OKed by Ziem.
Radar 3970646
OKed by Mike.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/apple-ppc-branch@95139 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog.apple-ppc | 22 | ||||
-rw-r--r-- | gcc/c-common.c | 35 | ||||
-rw-r--r-- | gcc/c-common.h | 2 | ||||
-rw-r--r-- | gcc/c-lex.c | 1 | ||||
-rw-r--r-- | gcc/c-parse.in | 4 | ||||
-rw-r--r-- | gcc/cp/ChangeLog.apple-ppc | 8 | ||||
-rw-r--r-- | gcc/cp/parser.c | 70 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog.apple-ppc | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asm-function-12.C | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asm-function-13.C | 26 | ||||
-rw-r--r-- | gcc/testsuite/gcc.apple/asm-function-12.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/gcc.apple/asm-function-13.c | 26 |
12 files changed, 229 insertions, 8 deletions
diff --git a/gcc/ChangeLog.apple-ppc b/gcc/ChangeLog.apple-ppc index fd5152101fe..207f469cf4f 100644 --- a/gcc/ChangeLog.apple-ppc +++ b/gcc/ChangeLog.apple-ppc @@ -1,3 +1,25 @@ +2005-02-16 Fariborz Jahanian <fjahanian@apple.com> + + Radar 3970655 + + * c-common.c (prepend_char_identifier): Modified old + get_atsign_identifier to handle any character. + * c-common.h (prepend_char_identifier): New function declaration. + Removed get_atsign_identifier declaration. + * c-lex.c (c_lex_with_flags): Add '.' to those tokens which + can start a CW asm statement. + * c-parse.in (cw_identifier): New CW identifier syntax. + +2005-02-15 Fariborz Jahanian <fjahanian@apple.com> + + Radar 3970646 + * c-common.c (cw_asm_identifier): New routine. + (cw_asm_stmt): call cw_asm_identifier on asm operator. + * cp/parser.c (cp_parser_cw_asm_relative_branch): New routine. + (cp_parser_cw_asm_postfix_expression): Call + cp_parser_cw_asm_relative_branch to parse relative branch + operand. + 2005-02-14 Devang Patel <dpatel@apple.com> Radar 4002184 diff --git a/gcc/c-common.c b/gcc/c-common.c index 1511729246a..bbfa13154af 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -612,6 +612,7 @@ static GTY(()) varray_type cw_asm_labels_uniq; static int cw_asm_expr_val (tree arg); static void print_cw_asm_operand (char *, tree, unsigned, bool, bool); static int cw_asm_get_register_var (tree, unsigned, bool); +static tree cw_asm_identifier (tree expr); /* APPLE LOCAL end CW asm blocks */ static tree handle_packed_attribute (tree *, tree, tree, int, bool *); @@ -6084,6 +6085,30 @@ cw_process_arg (const char *opcodename, tree var, unsigned argnum, *inputsp = chainon (*inputsp, one); } +/* CW identifier may include '.', '+' or '-'. Except that an operator + can only end in a '.'. This routine creates a new valid operator + parsed as a CW identifier. */ + +static tree +cw_asm_identifier (tree expr) +{ + const char *opcodename = IDENTIFIER_POINTER (expr); + int len = IDENTIFIER_LENGTH (expr); + int i; + for (i = 0; i < len; i++) + if (opcodename[i] == '.') + break; + if (i+1 < len) /* operator. is ok */ + { + char *buf = (char *) alloca (IDENTIFIER_LENGTH (expr) + 1); + strncpy (buf, opcodename, i); + buf[i] = ' '; + strcpy (buf+i+1, opcodename + i); + return get_identifier (buf); + } + return expr; +} + /* Build an asm statement from CW-syntax bits. */ tree cw_asm_stmt (tree expr, tree args) @@ -6107,6 +6132,8 @@ cw_asm_stmt (tree expr, tree args) if (TREE_CODE (expr) == ADDR_EXPR) expr = TREE_OPERAND (expr, 0); + expr = cw_asm_identifier (expr); + opcodename = IDENTIFIER_POINTER (expr); /* Handle special directives specially. */ @@ -6413,7 +6440,7 @@ cw_asm_label (tree labid, int atsign) STRIP_NOPS (labid); if (atsign) - labid = get_atsign_identifier (labid); + labid = prepend_char_identifier (labid, '@'); if (cw_asm_buffer == NULL) cw_asm_buffer = xmalloc (4000); @@ -6431,13 +6458,13 @@ cw_asm_label (tree labid, int atsign) return stmt; } -/* Create a new identifier with an '@' stuck on the front. */ +/* Create a new identifier with an 'ch' stuck on the front. */ tree -get_atsign_identifier (tree ident) +prepend_char_identifier (tree ident, char ch) { char *buf = (char *) alloca (IDENTIFIER_LENGTH (ident) + 20); - buf[0] = '@'; + buf[0] = ch; strcpy (buf + 1, IDENTIFIER_POINTER (ident)); return get_identifier (buf); } diff --git a/gcc/c-common.h b/gcc/c-common.h index e882d0fbe73..3021f422842 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -1044,7 +1044,7 @@ extern void pp_dir_change (cpp_reader *, const char *); extern tree cw_asm_stmt (tree, tree); extern tree cw_asm_build_register_offset (tree, tree); extern tree cw_asm_label (tree, int); -extern tree get_atsign_identifier (tree); +extern tree prepend_char_identifier (tree, char); extern void clear_cw_asm_labels (void); extern tree cw_asm_reg_name (tree); extern tree get_cw_asm_label (tree); diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 61e24f2b746..346db21a35b 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -420,6 +420,7 @@ c_lex_with_flags (tree *value, unsigned char *cpp_flags) { if ((tok->flags & BOL) && (tok->type == CPP_ATSIGN + || tok->type == CPP_DOT || (tok->type == CPP_NAME && (*value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node))) && !cw_asm_typename_or_reserved (*value)))) diff --git a/gcc/c-parse.in b/gcc/c-parse.in index ab82d28bb34..299ff6809eb 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -2091,6 +2091,8 @@ cw_identifier: { $$ = cw_get_identifier ($1, "+"); } | cw_identifier '-' { $$ = cw_get_identifier ($1, "-"); } + | '.' identifier + { $$ = prepend_char_identifier ($2, '.'); } ; /* A single statement consists of one or more labels (identified by a @@ -2666,7 +2668,7 @@ cw_asm_primary: } | '@' IDENTIFIER { - tree atsignid = get_atsign_identifier ($2); + tree atsignid = prepend_char_identifier ($2, '@'); if (yychar == YYEMPTY) yychar = YYLEX; $$.value = build_external_ref (atsignid, yychar == '('); diff --git a/gcc/cp/ChangeLog.apple-ppc b/gcc/cp/ChangeLog.apple-ppc index 50ee57d83f3..c133e5238ef 100644 --- a/gcc/cp/ChangeLog.apple-ppc +++ b/gcc/cp/ChangeLog.apple-ppc @@ -1,3 +1,11 @@ +2005-02-16 Fariborz Jahanian <fjahanian@apple.com> + + Radar 3970655 + + * cp/parser.c (cw_build_identifier_string): New function. + (cp_parser_cw_identifier): Build the tree for a '.'identifier. + (cp_parser_cw_asm_postfix_expression): Some disambiguation case. + 2005-02-10 Ziemowit Laski <zlaski@apple.com> Radar 3993052 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2bb57a65d7a..81e59f06a9f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -1895,6 +1895,12 @@ static tree cp_parser_cw_asm_operand (cp_parser *); static tree cp_parser_cw_asm_postfix_expression (cp_parser *, bool); +static tree cp_parser_cw_identifier_or_number + (cp_parser* parser); +static tree cw_build_identifier_string + (cp_parser* parser, const char* str); +static tree cp_parser_cw_asm_relative_branch + (cp_parser *parser); /* APPLE LOCAL end CW asm blocks */ /* Returns nonzero if we are parsing tentatively. */ @@ -3019,7 +3025,7 @@ cp_parser_primary_expression (cp_parser *parser, /* APPLE LOCAL begin CW asm blocks */ /* Replace the id with an id prefixed with @. */ if (atsignhack) - id_expression = get_atsign_identifier (id_expression); + id_expression = prepend_char_identifier (id_expression, '@'); /* APPLE LOCAL end CW asm blocks */ if (id_expression == error_mark_node) return error_mark_node; @@ -16344,6 +16350,25 @@ cp_parser_cw_asm_statement_seq_opt (cp_parser* parser) } } +/* Build an identifier comprising the string passed and the + next token. */ + +static tree +cw_build_identifier_string (cp_parser* parser, const char* str) +{ + char *buf; + int len; + tree id; + + id = cp_parser_cw_identifier_or_number (parser); + len = strlen (str); + buf = (char *) alloca (IDENTIFIER_LENGTH (id) + len + 1); + memcpy (buf, str, len); + memcpy (buf+len, IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id)); + buf[IDENTIFIER_LENGTH (id) + len] = 0; + return get_identifier (buf); +} + /* Parse a CW asm identifier. Returns an IDENTIFIER_NODE representing the identifier. The CW asm identifieriers include [.+-] as part of the identifier. */ @@ -16383,7 +16408,14 @@ cp_parser_cw_identifier (cp_parser* parser) t = get_identifier (s); } else - t = cp_parser_identifier (parser); + if (token->type == CPP_DOT) + { + /* .align */ + cp_lexer_consume_token (parser->lexer); + t = cw_build_identifier_string (parser, "."); + } + else + t = cp_parser_identifier (parser); if (t == error_mark_node) return t; @@ -16541,6 +16573,25 @@ cp_parser_cw_asm_operand (cp_parser *parser) return operand; } +/* Need to handle case of relative branch using: .[+|-]number + syntax */ +static tree +cp_parser_cw_asm_relative_branch (cp_parser *parser) +{ + cp_token *token; + token = cp_lexer_peek_nth_token (parser->lexer, 2); + if (token->type == CPP_PLUS || token->type == CPP_MINUS) + { + const char *str = (token->type == CPP_PLUS) ? ".+" : ".-"; + /* consume '.' */ + cp_lexer_consume_token (parser->lexer); + /* consume '-' or '+' */ + cp_lexer_consume_token (parser->lexer); + return cw_build_identifier_string (parser, str); + } + return error_mark_node; +} + /* Parse a CW asm-style postfix-expression. postfix-expression: @@ -16622,6 +16673,13 @@ cp_parser_cw_asm_postfix_expression (cp_parser *parser, bool address_p) if (cp_parser_parse_definitely (parser)) break; + if (token->type == CPP_DOT) + { + postfix_expression = cp_parser_cw_asm_relative_branch (parser); + if (postfix_expression != error_mark_node) + break; + } + /* If the functional-cast didn't work out, try a compound-literal. */ if (cp_parser_allow_gnu_extensions_p (parser) @@ -16767,6 +16825,14 @@ cp_parser_cw_asm_postfix_expression (cp_parser *parser, bool address_p) break; case CPP_DOT: + /* Disambiguation of asm's last operand followed by a '.'. + This happens when an asm instruction is followed by a + directive, such as .align. Bail out early. */ + if (TREE_CODE (postfix_expression) == INTEGER_CST + || TREE_CODE (postfix_expression) == IDENTIFIER_NODE + || TREE_CODE (postfix_expression) == COMPOUND_EXPR) + return postfix_expression; + case CPP_DEREF: /* postfix-expression . template [opt] id-expression postfix-expression . pseudo-destructor-name diff --git a/gcc/testsuite/ChangeLog.apple-ppc b/gcc/testsuite/ChangeLog.apple-ppc index 0f2a8153add..ce901d2337d 100644 --- a/gcc/testsuite/ChangeLog.apple-ppc +++ b/gcc/testsuite/ChangeLog.apple-ppc @@ -1,3 +1,10 @@ +2005-02-16 Fariborz Jahanian <fjahanian@apple.com> + + Radar 3970655 + + * g++.dg/asm-function-13.C: New. + * gcc.apple/asm-function-13.c: New. + 2005-02-11 Ziemowit Laski <zlaski@apple.com> Radar 3962013 (Part 2) diff --git a/gcc/testsuite/g++.dg/asm-function-12.C b/gcc/testsuite/g++.dg/asm-function-12.C new file mode 100644 index 00000000000..c44df055dc8 --- /dev/null +++ b/gcc/testsuite/g++.dg/asm-function-12.C @@ -0,0 +1,18 @@ +/* APPLE LOCAL file CW asm blocks */ +/* { dg-do assemble } */ +/* { dg-options "-fasm-blocks" } */ + +asm void foo() +{ + b .+8 + bl .+24 + b .-8 + bl .-32 + andi. r1, r0, 3 +} + +int main (int argc, char * const argv[]) +{ + foo(); +} + diff --git a/gcc/testsuite/g++.dg/asm-function-13.C b/gcc/testsuite/g++.dg/asm-function-13.C new file mode 100644 index 00000000000..ace3cba12ef --- /dev/null +++ b/gcc/testsuite/g++.dg/asm-function-13.C @@ -0,0 +1,26 @@ +/* APPLE LOCAL file CW asm blocks */ +/* { dg-do assemble { target powerpc*-*-* } } */ +/* { dg-options "-fasm-blocks" } */ + +asm void foo() +{ + .align 15 + andi. r1,r2, 3 + .align 10 + b .+8 + .align 4 + b .-16 + .align 3 + lha r1, 4(r3) + .align 4 + add r1,r2,r3 + .align 3 + .align 4 +} + +int main (int argc, char * const argv[]) +{ + foo(); +} + + diff --git a/gcc/testsuite/gcc.apple/asm-function-12.c b/gcc/testsuite/gcc.apple/asm-function-12.c new file mode 100644 index 00000000000..0cb1e9adec7 --- /dev/null +++ b/gcc/testsuite/gcc.apple/asm-function-12.c @@ -0,0 +1,18 @@ +/* APPLE LOCAL file CW asm blocks */ +/* { dg-do assemble } */ +/* { dg-options "-fasm-blocks" } */ + +asm void foo() +{ + b .+8 + bl .+24 + b .-8 + bl .-32 + andi. r1,r0,2 +} + +int main (int argc, char * const argv[]) +{ + foo(); +} + diff --git a/gcc/testsuite/gcc.apple/asm-function-13.c b/gcc/testsuite/gcc.apple/asm-function-13.c new file mode 100644 index 00000000000..ace3cba12ef --- /dev/null +++ b/gcc/testsuite/gcc.apple/asm-function-13.c @@ -0,0 +1,26 @@ +/* APPLE LOCAL file CW asm blocks */ +/* { dg-do assemble { target powerpc*-*-* } } */ +/* { dg-options "-fasm-blocks" } */ + +asm void foo() +{ + .align 15 + andi. r1,r2, 3 + .align 10 + b .+8 + .align 4 + b .-16 + .align 3 + lha r1, 4(r3) + .align 4 + add r1,r2,r3 + .align 3 + .align 4 +} + +int main (int argc, char * const argv[]) +{ + foo(); +} + + |