ref: fa1371e250b1b0129057bfe16c3f688685b0df4f
parent: d0234eb0cd492eac9501ba1e359757ce90ccb234
author: Ori Bernstein <[email protected]>
date: Fri Mar 9 13:20:18 EST 2012
The backend now compiles. It's still nowhere near working.
--- a/8/Makefile
+++ b/8/Makefile
@@ -1,5 +1,7 @@
BIN=8m
-OBJ=main.o
+OBJ=main.o \
+ simp.o \
+ gen.o \
CFLAGS+=-I../parse
LDFLAGS+=-L../parse -lparse
--- a/8/main.c
+++ b/8/main.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include "parse.h"
+#include "gen.h"
Node *file;
static char *outfile;
@@ -71,13 +72,9 @@
/* after all processing */
dump(file, stdout);
- gen();
+ gen(file, "a.s");
}
return 0;
}
-void gen(void)
-{
- printf("GEN!\n");
-}
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -535,7 +535,7 @@
;
label : TColon TIdent
- {$$ = mklabel($1->line, $1->str);}
+ {$$ = mklbl($1->line, $1->str);}
;
%%
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -95,12 +95,6 @@
}
-static Op exprop(Node *e)
-{
- assert(e->type == Nexpr);
- return e->expr.op;
-}
-
static Type *littype(Node *n)
{
switch (n->lit.littype) {
@@ -322,7 +316,10 @@
t = unify(n, mkty(-1, Tyvoid), ret);
settype(n, t);
break;
- case Ogoto: /* goto void* -> void */
+ case Ocjmp:
+ die("Should not see cjmp in fe");
+ break;
+ case Ojmp: /* goto void* -> void */
settype(n, mkty(-1, Tyvoid));
break;
case Ovar: /* a:@a -> @a */
--- a/parse/node.c
+++ b/parse/node.c
@@ -125,7 +125,7 @@
return n;
}
-Node *mklabel(int line, char *lbl)
+Node *mklbl(int line, char *lbl)
{
Node *n;
@@ -199,6 +199,17 @@
return n;
}
+Node *mkbool(int line, int val)
+{
+ Node *n;
+
+ n = mknode(line, Nlit);
+ n->lit.littype = Lbool;
+ n->lit.boolval = val;
+
+ return n;
+}
+
Type *decltype(Node *n)
{
assert(n->type == Ndecl);
@@ -216,25 +227,9 @@
n->name.parts[0] = strdup(name);
}
-Node *mkbool(int line, int val)
+Op exprop(Node *e)
{
- Node *n;
-
- n = mknode(line, Nlit);
- n->lit.littype = Lbool;
- n->lit.boolval = val;
-
- return n;
-}
-
-void lappend(void *l, size_t *len, void *n)
-{
- void ***pl;
-
- assert(n != NULL);
- pl = l;
- *pl = xrealloc(*pl, (*len + 1)*sizeof(Node*));
- (*pl)[*len] = n;
- (*len)++;
+ assert(e->type == Nexpr);
+ return e->expr.op;
}
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -44,7 +44,8 @@
O(Ocall)
O(Ocast)
O(Oret)
-O(Ogoto)
+O(Ojmp)
+O(Ocjmp)
O(Ovar)
O(Olit)
O(Olbl)
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -86,6 +86,7 @@
struct Sym {
int line;
+ int isconst;
Node *name;
Type *type;
};
@@ -314,12 +315,13 @@
Node *mkarray(int line, Node **vals);
Node *mkname(int line, char *name);
Node *mkdecl(int line, Sym *sym);
-Node *mklabel(int line, char *lbl);
+Node *mklbl(int line, char *lbl);
/* node util functions */
Type *decltype(Node *n);
void addstmt(Node *file, Node *stmt);
void setns(Node *n, char *name);
+Op exprop(Node *n);
/* usefiles */
void readuse(Node *use, Stab *into);
@@ -342,6 +344,3 @@
/* convenience func */
void lappend(void *nl, size_t *len, void *n); /* ugly hack; nl is void* because void*** != @a*** */
-
-/* backend functions */
-void gen(void);