aboutsummaryrefslogtreecommitdiff
path: root/cc.h
diff options
context:
space:
mode:
authorNihal Jere <nihal@nihaljere.xyz>2024-04-27 14:47:15 -0700
committerMichael Forney <mforney@mforney.org>2024-04-27 15:34:03 -0700
commit4f206ac1ea1b20400fa242f2f3be86237c4ba3bf (patch)
tree2dc2742c051e6601874fc699265da40fd51bd5e5 /cc.h
parent487079af3d6f39b379f52f7e0ea6edec63587e5b (diff)
Implement variable length arrays
Variably modified types are required for C23. Since QBE doesn't currently support saving and restoring the stack pointer, a current limitation is that we can't reclaim stack space from VLAs that go out of scope. This is potentially problematic for VLAs appearing in a loop, but this case is uncommon enough that it is silently ignored for now. Implements: https://todo.sr.ht/~mcf/cproc/1 References: https://todo.sr.ht/~mcf/cproc/88 Co-authored-by: Michael Forney <mforney@mforney.org>
Diffstat (limited to 'cc.h')
-rw-r--r--cc.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/cc.h b/cc.h
index ea237c5..ce0d6ca 100644
--- a/cc.h
+++ b/cc.h
@@ -178,7 +178,8 @@ enum typeprop {
PROPREAL = 1<<2,
PROPARITH = 1<<3,
PROPSCALAR = 1<<4,
- PROPFLOAT = 1<<5
+ PROPFLOAT = 1<<5,
+ PROPVM = 1<<6 /* variably-modified type */
};
struct bitfield {
@@ -213,6 +214,7 @@ struct type {
struct {
struct expr *length;
enum typequal ptrqual;
+ struct value *size;
} array;
struct {
bool isvararg;
@@ -321,6 +323,7 @@ enum exprkind {
EXPRBUILTIN,
EXPRTEMP,
+ EXPRSIZEOF,
};
struct stringlit {
@@ -341,6 +344,7 @@ struct expr {
enum tokenkind op;
struct expr *base;
struct expr *next;
+ struct expr *toeval;
union {
struct {
struct decl *decl;
@@ -377,6 +381,9 @@ struct expr {
struct {
enum builtinkind kind;
} builtin;
+ struct {
+ struct type *type;
+ } szof;
struct value *temp;
} u;
};
@@ -482,7 +489,7 @@ bool gnuattr(struct attr *, enum attrkind);
struct decl *mkdecl(char *name, enum declkind, struct type *, enum typequal, enum linkage);
bool decl(struct scope *, struct func *);
-struct type *typename(struct scope *, enum typequal *);
+struct type *typename(struct scope *, enum typequal *, struct expr **);
struct decl *stringdecl(struct expr *);