scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 14ccdac412ca5138fc0492046ba62e9cada02b3c
parent cfd9181ebc248b4eeb49e80fa82efbe95404e87b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Aug 2014 11:17:07 +0200

Add align field of types

This field add the information about the memory align requirements
of the types.

Diffstat:
Mcc2/cc2.h | 1+
Mcc2/cgen.c | 10+++++-----
Mcc2/parser.c | 8++++++++
3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -1,6 +1,7 @@ typedef struct { short size; + uint8_t align; bool sign : 1; bool c_int : 1; } Type; diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -12,16 +12,16 @@ void genstack(Symbol *fun) { Symbol *p; - short size; + short off; - for (size = 0, p = fun->u.f.vars; p; p = p->next) { + for (off = 0, p = fun->u.f.vars; p; p = p->next) { if (p->u.v.sclass == AUTO) { - p->u.v.off = size; - size += p->u.v.type->size; + p->u.v.off = off; + off += p->u.v.type->align; } } - fun->u.f.stack = size; + fun->u.f.stack = off; } enum { diff --git a/cc2/parser.c b/cc2/parser.c @@ -26,45 +26,53 @@ static Symbol *globaltbl; Type l_int8 = { .size = 1, + .align = 2, .sign = 1, .c_int = 1, }; Type l_int16 = { .size = 2, + .align = 2, .sign = 1, .c_int = 1, }; Type l_int32 = { .size = 4, + .align = 4, .sign = 1, .c_int = 1, }; Type l_int64 = { .size = 8, + .align = 8, .sign = 1, .c_int = 1, }; Type l_uint8 = { .size = 1, + .align = 2, .c_int = 1, }; Type l_uint16 = { .size = 2, + .align = 2, .c_int = 1, }; Type l_uint32 = { .size = 4, + .align = 4, .c_int = 1, }; Type l_uint64 = { .size = 8, + .align = 8, .c_int = 1, };