scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 7681aff4af1f56f6a0ed6a9451cc632f14bffbdd
parent afa081af77e19c67b8ded5203f8bed341af1cba6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  8 Aug 2014 11:44:41 +0200

Add addresability of constants

Diffstat:
Mcc2/cc2.h | 1+
Mcc2/cgen.c | 11++++++++++-
Mcc2/parser.c | 3++-
3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -39,6 +39,7 @@ enum nerrors { #define AUTO 'A' #define REGISTER 'R' #define STATIC 'S' +#define CONST '#' extern void error(unsigned nerror, ...); extern void genaddable(Node *np); diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -5,6 +5,13 @@ #include "cc2.h" +/* + * calculate addresability as follows + * AUTO => 11 + * REGISTER => 13 + * STATIC => 12 + * CONST => 20 + */ void genaddable(Node *np) { @@ -23,6 +30,8 @@ genaddable(Node *np) case STATIC: np->addable = 12; break; + case CONST: + np->addable = 20; + break; } - return; } diff --git a/cc2/parser.c b/cc2/parser.c @@ -132,7 +132,8 @@ immediate(char op) { Node *np = newnode(); - np->op = '#'; + np->op = CONST; + /* TODO: deal with constant non integer */ np->type = L_INT; scanf("%d", &np->u.imm); np->left = np->right = NULL;