compute sizes by the new tsize() function.

This commit is contained in:
christos 2009-10-02 21:04:03 +00:00
parent 19f30f4ea2
commit 876a5b04b7
3 changed files with 25 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: decl.c,v 1.49 2009/10/02 20:45:06 christos Exp $ */
/* $NetBSD: decl.c,v 1.50 2009/10/02 21:04:03 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: decl.c,v 1.49 2009/10/02 20:45:06 christos Exp $");
__RCSID("$NetBSD: decl.c,v 1.50 2009/10/02 21:04:03 christos Exp $");
#endif
#include <sys/param.h>
@ -497,14 +497,16 @@ setpackedsize(type_t *tp)
case STRUCT:
sp = tp->t_str;
sp->size = 0;
for (mem = sp->memb; mem != NULL; mem = mem->s_nxt)
sp->size += size(mem->s_type->t_tspec);
for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) {
size_t x = (size_t)tsize(mem->s_type);
sp->size += x;
}
break;
case UNION:
sp = tp->t_str;
sp->size = 0;
for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) {
size_t x = size(mem->s_type->t_tspec);
size_t x = (size_t)tsize(mem->s_type);
if (x > sp->size)
sp->size = x;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs1.h,v 1.28 2009/10/02 15:03:45 christos Exp $ */
/* $NetBSD: externs1.h,v 1.29 2009/10/02 21:04:03 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -210,6 +210,7 @@ extern void expr(tnode_t *, int, int, int);
extern void chkmisc(tnode_t *, int, int, int, int, int, int);
extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *);
extern strg_t *catstrg(strg_t *, strg_t *);
extern int64_t tsize(type_t *);
/*
* func.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.61 2009/10/02 19:02:16 christos Exp $ */
/* $NetBSD: tree.c,v 1.62 2009/10/02 21:04:03 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.61 2009/10/02 19:02:16 christos Exp $");
__RCSID("$NetBSD: tree.c,v 1.62 2009/10/02 21:04:03 christos Exp $");
#endif
#include <stdlib.h>
@ -3030,14 +3030,26 @@ foldflt(tnode_t *tn)
return (getcnode(tn->tn_type, v));
}
/*
* Create a constant node for sizeof.
*/
tnode_t *
bldszof(type_t *tp)
{
int elem, elsz;
tspec_t st;
#if SIZEOF_IS_ULONG
st = ULONG;
#else
st = UINT;
#endif
return getinode(st, tsize(tp) / CHAR_BIT);
}
int64_t
tsize(type_t *tp)
{
int elem, elsz;
elem = 1;
while (tp->t_tspec == ARRAY) {
@ -3088,12 +3100,7 @@ bldszof(type_t *tp)
break;
}
#if SIZEOF_IS_ULONG
st = ULONG;
#else
st = UINT;
#endif
return (getinode(st, (int64_t)(elem * elsz / CHAR_BIT)));
return (int64_t)(elem * elsz);
}
/*