summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--minic/minic.y71
-rw-r--r--minic/test/queen.c4
2 files changed, 60 insertions, 15 deletions
diff --git a/minic/minic.y b/minic/minic.y
index 3843b54..1564a1f 100644
--- a/minic/minic.y
+++ b/minic/minic.y
@@ -296,11 +296,10 @@ call(Node *n, Symb *sr)
 			a = a->r;
 			if (a)
 				fprintf(of, ", ");
-			else {
-				fprintf(of, ")\n");
+			else
 				break;
-			}
 		}
+	fprintf(of, ")\n");
 }
 
 Symb
@@ -359,7 +358,7 @@ expr(Node *n)
 		load(sr, s0);
 		break;
 
-	case '&':
+	case 'A':
 		sr = lval(n->l);
 		sr.ctyp = IDIR(sr.ctyp);
 		break;
@@ -555,6 +554,17 @@ mkstmt(int t, void *p1, void *p2, void *p3)
 	return s;
 }
 
+Node *
+param(char *v, unsigned ctyp, Node *pl)
+{
+	Node *n;
+
+	n = mknode(0, 0, pl);
+	varadd(v, 0, ctyp);
+	strcpy(n->u.v, v);
+	return n;
+}
+
 %}
 
 %union {
@@ -580,7 +590,7 @@ mkstmt(int t, void *p1, void *p2, void *p3)
 
 %type <u> type
 %type <s> stmt stmts
-%type <n> expr pref post arg0 arg1
+%type <n> expr pref post arg0 arg1 par0 par1
 
 %%
 
@@ -600,23 +610,58 @@ idcl: type IDENT ';'
 	varadd($2->u.v, nglo++, $1);
 };
 
-func: prot '{' dcls stmts '}'
+init:
+{
+	varclr();
+	tmp = 0;
+};
+
+func: init prot '{' dcls stmts '}'
 {
-	if (!stmt($4, -1))
+	if (!stmt($5, -1))
 		fprintf(of, "\tret 0\n");
 	fprintf(of, "}\n\n");
 };
 
-prot: IDENT '(' ')'
+prot: IDENT '(' par0 ')'
 {
-	varclr();
-	lbl = 0;
-	tmp = 0;
+	Symb *s;
+	Node *n;
+	int t, m;
+
 	varadd($1->u.v, 1, FUNC(INT));
-	fprintf(of, "function w $%s() {\n", $1->u.v);
+	fprintf(of, "function w $%s(", $1->u.v);
+	n = $3;
+	if (n)
+		for (;;) {
+			s = varget(n->u.v);
+			fprintf(of, "%c ", irtyp(s->ctyp));
+			fprintf(of, "%%tmp%d", tmp++);
+			n = n->r;
+			if (n)
+				fprintf(of, ", ");
+			else
+				break;
+		}
+	fprintf(of, ") {\n");
 	fprintf(of, "@l%d\n", lbl++);
+	for (t=0, n=$3; n; t++, n=n->r) {
+		s = varget(n->u.v);
+		m = SIZE(s->ctyp);
+		fprintf(of, "\t%%%s =l alloc%d %d\n", n->u.v, m, m);
+		fprintf(of, "\tstore%c %%tmp%d", irtyp(s->ctyp), t);
+		fprintf(of, ", %%%s\n", n->u.v);
+	}
 };
 
+par0: par1
+    |                     { $$ = 0; }
+    ;
+par1: type IDENT ',' par1 { $$ = param($2->u.v, $1, $4); }
+    | type IDENT          { $$ = param($2->u.v, $1, 0); }
+    ;
+
+
 dcls: | dcls type IDENT ';'
 {
 	int s;
@@ -666,7 +711,7 @@ expr: pref
 pref: post
     | '-' pref          { $$ = mkneg($2); }
     | '*' pref          { $$ = mknode('@', $2, 0); }
-    | '&' pref          { $$ = mknode('&', $2, 0); }
+    | '&' pref          { $$ = mknode('A', $2, 0); }
     ;
 
 post: NUM
diff --git a/minic/test/queen.c b/minic/test/queen.c
index d9d93fc..c998e2a 100644
--- a/minic/test/queen.c
+++ b/minic/test/queen.c
@@ -1,5 +1,5 @@
-#include <stdio.h>
-#include <stdlib.h>
+int printf();
+int *calloc();
 
 int N;
 int *t;