From: Ian Lance Taylor Date: Tue, 7 Mar 1995 22:34:39 +0000 (+0000) Subject: Add support for #pragma align X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c9040e2c81683a96a8e1b0903096d612d0f84013;p=gcc.git Add support for #pragma align From-SVN: r9128 --- diff --git a/gcc/config/i960/i960.c b/gcc/config/i960/i960.c index a9dfd411622..7d72000b3c8 100644 --- a/gcc/config/i960/i960.c +++ b/gcc/config/i960/i960.c @@ -83,57 +83,86 @@ static int ret_label = 0; && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (FNDECL)))) != void_type_node)) \ || current_function_varargs) -#if 0 /* Handle pragmas for compatibility with Intel's compilers. */ /* ??? This is incomplete, since it does not handle all pragmas that the - intel compilers understand. Also, it needs to be rewritten to accept - a stream instead of a string for GCC 2. */ + intel compilers understand. */ void -process_pragma(str) - char *str; +process_pragma (finput) + FILE *finput; { - int align; + int c; int i; - if ((i = sscanf (str, " align %d", &align)) == 1) - switch (align) - { - case 0: /* Return to last alignment. */ - align = i960_last_maxbitalignment / 8; - - case 16: /* Byte alignments. */ - case 8: - case 4: - case 2: - case 1: - i960_last_maxbitalignment = i960_maxbitalignment; - i960_maxbitalignment = align * 8; - break; - - default: /* Unknown, silently ignore. */ - break; - } + c = getc (finput); + while (c == ' ' || c == '\t') + c = getc (finput); - /* NOTE: ic960 R3.0 pragma align definition: + if (c == 'a' + && getc (finput) == 'l' + && getc (finput) == 'i' + && getc (finput) == 'g' + && getc (finput) == 'n' + && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) + { + char buf[20]; + char *s = buf; + int align; + + while (c == ' ' || c == '\t') + c = getc (finput); + if (c == '(') + c = getc (finput); + while (c >= '0' && c <= '9') + { + if (s < buf + sizeof buf - 1) + *s++ = c; + c = getc (finput); + } + *s = '\0'; - #pragma align [(size)] | (identifier=size[,...]) - #pragma noalign [(identifier)[,...]] + align = atoi (buf); + switch (align) + { + case 0: + /* Return to last alignment. */ + align = i960_last_maxbitalignment / 8; + /* Fall through. */ + case 16: + case 8: + case 4: + case 2: + case 1: + i960_last_maxbitalignment = i960_maxbitalignment; + i960_maxbitalignment = align * 8; + break; - (all parens are optional) + default: + /* Silently ignore bad values. */ + break; + } + + /* NOTE: ic960 R3.0 pragma align definition: - - size is [1,2,4,8,16] - - noalign means size==1 - - applies only to component elements of a struct (and union?) - - identifier applies to structure tag (only) - - missing identifier means next struct + #pragma align [(size)] | (identifier=size[,...]) + #pragma noalign [(identifier)[,...]] - - alignment rules for bitfields need more investigation */ + (all parens are optional) + + - size is [1,2,4,8,16] + - noalign means size==1 + - applies only to component elements of a struct (and union?) + - identifier applies to structure tag (only) + - missing identifier means next struct + + - alignment rules for bitfields need more investigation */ + } /* Should be pragma 'far' or equivalent for callx/balx here. */ + + ungetc (c, finput); } -#endif /* Initialize variables before compiling any files. */ @@ -2133,45 +2162,29 @@ i960_object_bytes_bitalign (n) return n; } -/* Compute the size of an aggregate type TSIZE. */ - -tree -i960_round_size (tsize) - tree tsize; -{ - int size, byte_size, align; - - if (TREE_CODE (tsize) != INTEGER_CST) - return tsize; - - size = TREE_INT_CST_LOW (tsize); - byte_size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT; - align = i960_object_bytes_bitalign (byte_size); - - /* Handle #pragma align. */ - if (align > i960_maxbitalignment) - align = i960_maxbitalignment; - - if (size % align) - size = ((size / align) + 1) * align; - - return size_int (size); -} - -/* Compute the alignment for an aggregate type TSIZE. */ +/* Compute the alignment for an aggregate type TSIZE. + Alignment is MAX (greatest member alignment, + MIN (pragma align, structure size alignment)). */ int i960_round_align (align, tsize) int align; tree tsize; { - int byte_size; + int new_align; if (TREE_CODE (tsize) != INTEGER_CST) return align; - byte_size = (TREE_INT_CST_LOW (tsize) + BITS_PER_UNIT - 1) / BITS_PER_UNIT; - align = i960_object_bytes_bitalign (byte_size); + new_align = i960_object_bytes_bitalign (TREE_INT_CST_LOW (tsize) + / BITS_PER_UNIT); + /* Handle #pragma align. */ + if (new_align > i960_maxbitalignment) + new_align = i960_maxbitalignment; + + if (align < new_align) + align = new_align; + return align; } diff --git a/gcc/config/i960/i960.h b/gcc/config/i960/i960.h index 4f81a2fcc6d..67b39095e3c 100644 --- a/gcc/config/i960/i960.h +++ b/gcc/config/i960/i960.h @@ -117,6 +117,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #define PUT_SDB_TYPE(A) \ fprintf (asm_out_file, "\t.type\t0x%x;", (A & 0xf) + 2 * (A & ~0xf)) +/* Handle pragmas for compatibility with Intel's compilers. */ +#define HANDLE_PRAGMA(FILE) process_pragma (FILE) + /* Run-time compilation parameters selecting different hardware subsets. */ /* 960 architecture with floating-point. */ @@ -391,13 +394,8 @@ extern int target_flags; #define ROUND_TYPE_ALIGN(TYPE, COMPUTED, SPECIFIED) \ ((!TARGET_OLD_ALIGN && TREE_CODE (TYPE) == RECORD_TYPE) \ - ? i960_round_align ((SPECIFIED), TYPE_SIZE (TYPE)) \ + ? i960_round_align (MAX ((COMPUTED), (SPECIFIED)), TYPE_SIZE (TYPE)) \ : MAX ((COMPUTED), (SPECIFIED))) - -#define ROUND_TYPE_SIZE(TYPE, SIZE, ALIGN) \ - ((!TARGET_OLD_ALIGN && TREE_CODE (TYPE) == RECORD_TYPE) \ - ? (tree) i960_round_size (SIZE) \ - : round_up ((SIZE), (ALIGN))) /* Standard register usage. */