shithub: scc

Download patch

ref: 414ccc5a4e31eb805c5031d43f01d73c373019f7
parent: 091ac73575727b8f19c47d1af325874f0b538993
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Apr 16 07:21:55 EDT 2014

First version of emitdcl()

This first version is not full functional, but it enough
in order  to can begin with a code evaluator.

--- a/cc.h
+++ b/cc.h
@@ -233,6 +233,7 @@
 };
 
 extern void
+	emitdcl(Symbol *),
 	emitsym(Node *), emitunary(Node *),
 	emitbin(Node *), emitexp(Node *), emitconst(Node *np);
 
--- a/code.c
+++ b/code.c
@@ -60,10 +60,9 @@
 	return np;
 }
 
-void
-emitsym(Node *np)
+static void
+emitsym2(Symbol *sym)
 {
-	Symbol *sym = np->u.sym;
 	char c;
 
 	if (sym->s.isglobal)
@@ -74,7 +73,29 @@
 		c = 'Q';
 	else
 		c = 'A';
-	printf("\t%c%d", c, sym->id);
+	printf("%c%d", c, sym->id);
+}
+
+void
+emitsym(Node *np)
+{
+	putchar('\t');
+	emitsym2(np->u.sym);
+}
+
+static void
+emittype(Type *tp)
+{
+	putchar(tp->letter);
+}
+
+void
+emitdcl(Symbol *sym)
+{
+	emitsym2(sym);
+	putchar('\t');
+	emittype(sym->type);
+	putchar('\n');
 }
 
 void
--- a/decl.c
+++ b/decl.c
@@ -440,11 +440,11 @@
 			case STATIC: sym->s.isstatic = 1; break;
 			case EXTERN: /* TODO: */; break;
 			case TYPEDEF: /* TODO: */;break;
-			case AUTO: /* TODO: */; break;
-			default: sym->s.isauto = 1;
+			case AUTO: default: sym->s.isauto = 1;
 			}
 			if (accept('='))
-				initializer(sym->type);
+				initializer(sym->type); /* TODO: emit initializer */
+			emitdcl(sym);
 		} while (accept(','));
 	}
 }