aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <[email protected]>2015-10-12 21:30:14 -0400
committerQuentin Carbonneaux <[email protected]>2015-10-12 21:30:14 -0400
commitb402c8f7d575130d08b4588f8212ad6c9ae73108 (patch)
treed783c1cd84c275d9f68fa968b25f7c61a66a2f88
parent8733d14e6e719f1f3b0d677b1938d846baf13fd0 (diff)
make the queen test work
-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;