Skip to content

Commit

Permalink
Merge pull request #1743 from ibuclaw/target2
Browse files Browse the repository at this point in the history
Add new Target hook to retrieve align sizes of basic types.
  • Loading branch information
WalterBright committed Mar 14, 2013
2 parents 33d4b70 + 52bab06 commit 0742dcc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
37 changes: 2 additions & 35 deletions src/mtype.c
Expand Up @@ -2759,41 +2759,8 @@ d_uns64 TypeBasic::size(Loc loc)
}

unsigned TypeBasic::alignsize()
{ unsigned sz;

switch (ty)
{
case Tfloat80:
case Timaginary80:
case Tcomplex80:
sz = Target::realalignsize;
break;

#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
case Tint64:
case Tuns64:
sz = global.params.is64bit ? 8 : 4;
break;

case Tfloat64:
case Timaginary64:
sz = global.params.is64bit ? 8 : 4;
break;

case Tcomplex32:
sz = 4;
break;

case Tcomplex64:
sz = global.params.is64bit ? 8 : 4;
break;
#endif

default:
sz = size(0);
break;
}
return sz;
{
return Target::alignsize(this);
}


Expand Down
34 changes: 34 additions & 0 deletions src/target.c
Expand Up @@ -11,6 +11,7 @@

#include "target.h"
#include "mars.h"
#include "mtype.h"

int Target::ptrsize;
int Target::realsize;
Expand Down Expand Up @@ -58,3 +59,36 @@ void Target::init()
}
}

unsigned Target::alignsize (Type* type)
{
assert (type->isTypeBasic());

switch (type->ty)
{
case Tfloat80:
case Timaginary80:
case Tcomplex80:
return Target::realalignsize;

case Tcomplex32:
if (global.params.isLinux || global.params.isOSX || global.params.isFreeBSD
|| global.params.isOpenBSD || global.params.isSolaris)
return 4;
break;

case Tint64:
case Tuns64:
case Tfloat64:
case Timaginary64:
case Tcomplex64:
if (global.params.isLinux || global.params.isOSX || global.params.isFreeBSD
|| global.params.isOpenBSD || global.params.isSolaris)
return global.params.is64bit ? 8 : 4;
break;

default:
break;
}
return type->size(0);
}

3 changes: 3 additions & 0 deletions src/target.h
Expand Up @@ -14,6 +14,8 @@
// At present it is incomplete, but in future it should grow to contain
// most or all target machine and target O/S specific information.

struct Type;

struct Target
{
static int ptrsize;
Expand All @@ -22,6 +24,7 @@ struct Target
static int realalignsize; // alignment for reals

static void init();
static unsigned alignsize(Type* type);
};

#endif

0 comments on commit 0742dcc

Please sign in to comment.