ref: cfd9181ebc248b4eeb49e80fa82efbe95404e87b
parent: abf79a2fe6621ed253aa4559e06cc20d1189ff4b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Aug 10 06:55:35 EDT 2014
Add offset field in symbols When symbols are stored in the stack they have associated an offset in the same that will be used in the instructions.
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -12,7 +12,8 @@
union {
struct {
Type *type;
- char storage;
+ char sclass;
+ short off;
} v;
struct {
short addr;
@@ -68,4 +69,4 @@
extern void error(unsigned nerror, ...);
extern void genaddable(Node *list[]);
extern void cgen(Symbol *sym, Node *list[]);
-extern void genstack(Symbol *fun);
\ No newline at end of file
+extern void genstack(Symbol *fun);
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -12,11 +12,16 @@
genstack(Symbol *fun)
{
Symbol *p;
- short siz;
+ short size;
- for (siz = 0, p = fun->u.f.vars; p; p = p->next)
- siz += p->u.v.type->size;
- fun->u.f.stack = siz;
+ for (size = 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;
+ }
+ }
+
+ fun->u.f.stack = size;
}
enum {
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -273,7 +273,7 @@
break;
}
sym->type = VAR;
- sym->u.v.storage = class;
+ sym->u.v.sclass = class;
sym->u.v.type = gettype(strtok(NULL, "\t"));
}
--
⑨