shithub: scc

Download patch

ref: 14ccdac412ca5138fc0492046ba62e9cada02b3c
parent: cfd9181ebc248b4eeb49e80fa82efbe95404e87b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Aug 10 07:17:07 EDT 2014

Add align field of types

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

--- 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;
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -12,16 +12,16 @@
 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 {
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -26,6 +26,7 @@
 
 Type l_int8 = {
 	.size = 1,
+	.align = 2,
 	.sign = 1,
 	.c_int = 1,
 };
@@ -32,6 +33,7 @@
 
 Type l_int16 = {
 	.size = 2,
+	.align = 2,
 	.sign = 1,
 	.c_int = 1,
 };
@@ -38,6 +40,7 @@
 
 Type l_int32 = {
 	.size = 4,
+	.align = 4,
 	.sign = 1,
 	.c_int = 1,
 };
@@ -44,6 +47,7 @@
 
 Type l_int64 = {
 	.size = 8,
+	.align = 8,
 	.sign = 1,
 	.c_int = 1,
 };
@@ -50,21 +54,25 @@
 
 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,
 };
 
--