ref: 7681aff4af1f56f6a0ed6a9451cc632f14bffbdd
parent: afa081af77e19c67b8ded5203f8bed341af1cba6
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 8 07:44:41 EDT 2014
Add addresability of constants
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -39,6 +39,7 @@
#define AUTO 'A'
#define REGISTER 'R'
#define STATIC 'S'
+#define CONST '#'
extern void error(unsigned nerror, ...);
extern void genaddable(Node *np);
--- 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 @@
case STATIC:
np->addable = 12;
break;
+ case CONST:
+ np->addable = 20;
+ break;
}
- return;
}
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -132,7 +132,8 @@
{
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;