shithub: scc

Download patch

ref: 203eee14a2e6b32e23d94c0dfff68b32346609d3
parent: 97c2741373af5f85c0538a671c51d22bb3ef1d97
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 8 12:27:32 EDT 2014

Make list of variables and parameters of function

It is necessary to make this list because in the preambule of
the function we have to emit code for the list of local varibles
and parameters.

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -1,6 +1,7 @@
 
-typedef struct {
+typedef struct symbol {
 	char public;
+	struct symbol *next;
 	union {
 		struct {
 			char type;
@@ -11,6 +12,8 @@
 		} l;
 		struct {
 			char *name;
+			struct symbol *pars;
+			struct symbol *vars;
 		} f;
 	} u;
 } Symbol;
@@ -46,6 +49,7 @@
 #define AUTO      'A'
 #define REGISTER  'R'
 #define STATIC    'T'
+#define PARAMETER 'P'
 #define CONST     '#'
 #define LABEL     'L'
 #define OADD      '+'
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -197,6 +197,17 @@
 
 	sym = (class == 'G') ? global(token) : local(token);
 
+	switch (class) {
+	case 'A':
+		sym->next = curfun->u.f.vars;
+		curfun->u.f.vars = sym;
+	case 'P':
+		sym->next = curfun->u.f.pars;
+		curfun->u.f.pars = sym;
+		break;
+	case 'G': case 'R': case 'T':
+		break;
+	}
 	sym->u.v.storage = class;
 	sym->u.v.type = gettype(strtok(NULL, "\t"));
 }
@@ -254,7 +265,7 @@
 		case 'S':
 			/* struct */
 			break;
-		case 'T': case 'A': case 'R':
+		case 'T': case 'A': case 'R': case 'P':
 			if (!funbody)
 				goto syntax_error;
 			fun = declaration;