aboutsummaryrefslogtreecommitdiff
path: root/src/prc1
diff options
context:
space:
mode:
Diffstat (limited to 'src/prc1')
-rw-r--r--src/prc1/CMakeLists.txt1
-rw-r--r--src/prc1/cgen/CMakeLists.txt1
-rw-r--r--src/prc1/cgen/prv.h1
-rw-r--r--src/prc1/cgen/qbe/CMakeLists.txt1
-rw-r--r--src/prc1/cgen/qbe/fn.c4
-rw-r--r--src/prc1/cgen/qbe/qbe.c1
-rw-r--r--src/prc1/cgen/qbe/qbe.h1
-rw-r--r--src/prc1/cgen/qbe/st.c20
-rw-r--r--src/prc1/cgen/st.c8
-rw-r--r--src/prc1/div.c2
-rw-r--r--src/prc1/fn.c1
-rw-r--r--src/prc1/parse.h2
-rw-r--r--src/prc1/st.c12
-rw-r--r--src/prc1/st.h11
14 files changed, 65 insertions, 1 deletions
diff --git a/src/prc1/CMakeLists.txt b/src/prc1/CMakeLists.txt
index e738343..de3870d 100644
--- a/src/prc1/CMakeLists.txt
+++ b/src/prc1/CMakeLists.txt
@@ -26,6 +26,7 @@ add_executable(prc1
print.c
push.c
sdup.c
+ st.c
stmt.c
storage.c
td.c
diff --git a/src/prc1/cgen/CMakeLists.txt b/src/prc1/cgen/CMakeLists.txt
index d788d2f..94b4f2d 100644
--- a/src/prc1/cgen/CMakeLists.txt
+++ b/src/prc1/cgen/CMakeLists.txt
@@ -9,5 +9,6 @@ target_sources(prc1 PRIVATE
param.c
print.c
set.c
+ st.c
ws.c
)
diff --git a/src/prc1/cgen/prv.h b/src/prc1/cgen/prv.h
index 32601f0..a9b33fa 100644
--- a/src/prc1/cgen/prv.h
+++ b/src/prc1/cgen/prv.h
@@ -13,6 +13,7 @@ struct cgen_drv
int (*print)(const struct print *, struct cgen *, const char *);
int (*gl)(const struct storage *, struct cgen *);
int (*ws)(const struct storage *, struct cgen *);
+ int (*st)(const struct storage *, struct cgen *);
int (*call)(const struct call *, struct cgen *);
int (*from)(const struct from *, struct cgen *);
int (*set)(const struct set *, struct cgen *);
diff --git a/src/prc1/cgen/qbe/CMakeLists.txt b/src/prc1/cgen/qbe/CMakeLists.txt
index a9e7155..0a71cb7 100644
--- a/src/prc1/cgen/qbe/CMakeLists.txt
+++ b/src/prc1/cgen/qbe/CMakeLists.txt
@@ -6,6 +6,7 @@ target_sources(prc1 PRIVATE
gl.c
print.c
set.c
+ st.c
qbe.c
ws.c
)
diff --git a/src/prc1/cgen/qbe/fn.c b/src/prc1/cgen/qbe/fn.c
index 61b0bf0..d13695c 100644
--- a/src/prc1/cgen/qbe/fn.c
+++ b/src/prc1/cgen/qbe/fn.c
@@ -3,6 +3,7 @@
#include "gl.h"
#include "stmt.h"
#include "qbe.h"
+#include "st.h"
#include "ws.h"
#include <stdio.h>
@@ -67,6 +68,9 @@ int qbe_fn(const struct fn *fn, struct cgen *c)
if (fn->ws && ws_cgen(fn->ws, c))
return -1;
+ if (fn->st && st_cgen(fn->st, c))
+ return -1;
+
for (const struct tmp *tmp = fn->tmps; tmp; tmp = tmp->next)
{
const struct stentry *e = &tmp->e;
diff --git a/src/prc1/cgen/qbe/qbe.c b/src/prc1/cgen/qbe/qbe.c
index d727bc0..95e6f1f 100644
--- a/src/prc1/cgen/qbe/qbe.c
+++ b/src/prc1/cgen/qbe/qbe.c
@@ -158,6 +158,7 @@ int cgen_qbe(const struct ast *ast, struct cgen *c)
.set = qbe_set,
.gl = qbe_gl,
.ws = qbe_ws,
+ .st = qbe_st,
.fn = qbe_fn
};
diff --git a/src/prc1/cgen/qbe/qbe.h b/src/prc1/cgen/qbe/qbe.h
index 206cf32..f50b242 100644
--- a/src/prc1/cgen/qbe/qbe.h
+++ b/src/prc1/cgen/qbe/qbe.h
@@ -21,6 +21,7 @@ int qbe_call(const struct call *m, struct cgen *c);
int qbe_set(const struct set *m, struct cgen *c);
int qbe_gl(const struct storage *gl, struct cgen *c);
int qbe_ws(const struct storage *s, struct cgen *c);
+int qbe_st(const struct storage *s, struct cgen *c);
int qbe_from(const struct from *fn, struct cgen *c);
int qbe_fn(const struct fn *fn, struct cgen *c);
void qbe_free(struct cgen_prv *p);
diff --git a/src/prc1/cgen/qbe/st.c b/src/prc1/cgen/qbe/st.c
new file mode 100644
index 0000000..d736497
--- /dev/null
+++ b/src/prc1/cgen/qbe/st.c
@@ -0,0 +1,20 @@
+#include "cgen.h"
+#include "storage.h"
+#include "qbe.h"
+#include <stddef.h>
+#include <stdio.h>
+
+static int stpush(const struct stentry *e, struct cgen *c)
+{
+ fprintf(stderr, "%s: TODO\n", __func__);
+ return -1;
+}
+
+int qbe_st(const struct storage *s, struct cgen *c)
+{
+ for (size_t i = 0; i < s->nentries; i++)
+ if (stpush(&s->entries[i], c))
+ return -1;
+
+ return 0;
+}
diff --git a/src/prc1/cgen/st.c b/src/prc1/cgen/st.c
new file mode 100644
index 0000000..d86da3a
--- /dev/null
+++ b/src/prc1/cgen/st.c
@@ -0,0 +1,8 @@
+#include "cgen.h"
+#include "cgen/prv.h"
+#include "st.h"
+
+int st_cgen(const struct storage *s, struct cgen *c)
+{
+ return c->drv->st(s, c);
+}
diff --git a/src/prc1/div.c b/src/prc1/div.c
index 5c6422f..99077e4 100644
--- a/src/prc1/div.c
+++ b/src/prc1/div.c
@@ -4,6 +4,7 @@
#include "im.h"
#include "lk.h"
#include "pr.h"
+#include "st.h"
#include "td.h"
#include "ws.h"
@@ -21,6 +22,7 @@ static const struct seq fnseq[] =
procedure,
{(struct step[]){{ID, "locals"}, {0}}, .fn = ws},
{(struct step[]){{ID, "globals"}, {0}}, .fn = gl},
+ {(struct step[]){{ID, "statics"}, {0}}, .fn = st},
{0}
};
diff --git a/src/prc1/fn.c b/src/prc1/fn.c
index 7b3343c..3a9809e 100644
--- a/src/prc1/fn.c
+++ b/src/prc1/fn.c
@@ -152,6 +152,7 @@ void fn_free(struct fn *fn)
storage_free(fn->lk);
storage_free(fn->ws);
storage_free(fn->gl);
+ storage_free(fn->st);
pr_free(fn->pr);
td_free(fn->td);
free(fn->imps);
diff --git a/src/prc1/parse.h b/src/prc1/parse.h
index 74380ed..8b61d78 100644
--- a/src/prc1/parse.h
+++ b/src/prc1/parse.h
@@ -131,7 +131,7 @@ struct fn
const struct tk *tk, *im;
const struct fn *parent;
enum linkage {EXTERNAL, STATIC} linkage;
- struct storage *lk, *ws, *gl;
+ struct storage *lk, *ws, *gl, *st;
struct stmt *stmts;
struct sym *syms;
struct tmp *tmps;
diff --git a/src/prc1/st.c b/src/prc1/st.c
new file mode 100644
index 0000000..9de73ee
--- /dev/null
+++ b/src/prc1/st.c
@@ -0,0 +1,12 @@
+#include "st.h"
+#include "fn.h"
+#include "prv.h"
+#include "parse.h"
+#include "storage.h"
+
+int st(const struct lex *l, struct prv *p)
+{
+ struct fn *fn = fn_cur(p);
+
+ return storage(l, p, "statics section", 1, &fn->st);
+}
diff --git a/src/prc1/st.h b/src/prc1/st.h
new file mode 100644
index 0000000..60f06b4
--- /dev/null
+++ b/src/prc1/st.h
@@ -0,0 +1,11 @@
+#ifndef ST_H
+#define ST_H
+
+#include "lex.h"
+#include "cgen.h"
+#include "prv.h"
+
+int st(const struct lex *l, struct prv *p);
+int st_cgen(const struct storage *s, struct cgen *c);
+
+#endif