Commit c9040e2c by Ian Lance Taylor

Add support for #pragma align

From-SVN: r9128
parent ae8b85c2
...@@ -83,57 +83,86 @@ static int ret_label = 0; ...@@ -83,57 +83,86 @@ static int ret_label = 0;
&& (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (FNDECL)))) != void_type_node)) \ && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (FNDECL)))) != void_type_node)) \
|| current_function_varargs) || current_function_varargs)
#if 0
/* Handle pragmas for compatibility with Intel's compilers. */ /* Handle pragmas for compatibility with Intel's compilers. */
/* ??? This is incomplete, since it does not handle all pragmas that the /* ??? This is incomplete, since it does not handle all pragmas that the
intel compilers understand. Also, it needs to be rewritten to accept intel compilers understand. */
a stream instead of a string for GCC 2. */
void void
process_pragma(str) process_pragma (finput)
char *str; FILE *finput;
{ {
int align; int c;
int i; int i;
if ((i = sscanf (str, " align %d", &align)) == 1) c = getc (finput);
switch (align) while (c == ' ' || c == '\t')
{ c = getc (finput);
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;
}
/* 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[,...]) align = atoi (buf);
#pragma noalign [(identifier)[,...]] 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] #pragma align [(size)] | (identifier=size[,...])
- noalign means size==1 #pragma noalign [(identifier)[,...]]
- 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 */ (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. */ /* Should be pragma 'far' or equivalent for callx/balx here. */
ungetc (c, finput);
} }
#endif
/* Initialize variables before compiling any files. */ /* Initialize variables before compiling any files. */
...@@ -2133,45 +2162,29 @@ i960_object_bytes_bitalign (n) ...@@ -2133,45 +2162,29 @@ i960_object_bytes_bitalign (n)
return n; return n;
} }
/* Compute the size of an aggregate type TSIZE. */ /* Compute the alignment for an aggregate type TSIZE.
Alignment is MAX (greatest member alignment,
tree MIN (pragma align, structure size alignment)). */
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. */
int int
i960_round_align (align, tsize) i960_round_align (align, tsize)
int align; int align;
tree tsize; tree tsize;
{ {
int byte_size; int new_align;
if (TREE_CODE (tsize) != INTEGER_CST) if (TREE_CODE (tsize) != INTEGER_CST)
return align; return align;
byte_size = (TREE_INT_CST_LOW (tsize) + BITS_PER_UNIT - 1) / BITS_PER_UNIT; new_align = i960_object_bytes_bitalign (TREE_INT_CST_LOW (tsize)
align = i960_object_bytes_bitalign (byte_size); / BITS_PER_UNIT);
/* Handle #pragma align. */
if (new_align > i960_maxbitalignment)
new_align = i960_maxbitalignment;
if (align < new_align)
align = new_align;
return align; return align;
} }
......
...@@ -117,6 +117,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -117,6 +117,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#define PUT_SDB_TYPE(A) \ #define PUT_SDB_TYPE(A) \
fprintf (asm_out_file, "\t.type\t0x%x;", (A & 0xf) + 2 * (A & ~0xf)) 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. */ /* Run-time compilation parameters selecting different hardware subsets. */
/* 960 architecture with floating-point. */ /* 960 architecture with floating-point. */
...@@ -391,13 +394,8 @@ extern int target_flags; ...@@ -391,13 +394,8 @@ extern int target_flags;
#define ROUND_TYPE_ALIGN(TYPE, COMPUTED, SPECIFIED) \ #define ROUND_TYPE_ALIGN(TYPE, COMPUTED, SPECIFIED) \
((!TARGET_OLD_ALIGN && TREE_CODE (TYPE) == RECORD_TYPE) \ ((!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))) : 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. */ /* Standard register usage. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment