From 4dbcfc991a4fb203ec2b50d950f59adb1ad61922 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 31 Oct 2026 13:51:06 +0100 Subject: Setup scaffolding for statics section --- src/prc1/cgen/CMakeLists.txt | 1 + src/prc1/cgen/prv.h | 1 + src/prc1/cgen/qbe/CMakeLists.txt | 1 + src/prc1/cgen/qbe/fn.c | 4 ++++ src/prc1/cgen/qbe/qbe.c | 1 + src/prc1/cgen/qbe/qbe.h | 1 + src/prc1/cgen/qbe/st.c | 20 ++++++++++++++++++++ src/prc1/cgen/st.c | 8 ++++++++ 8 files changed, 37 insertions(+) create mode 100644 src/prc1/cgen/qbe/st.c create mode 100644 src/prc1/cgen/st.c (limited to 'src/prc1/cgen') 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 @@ -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 +#include + +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); +} -- cgit v1.2.3