aboutsummaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-02 02:34:19 -0500
committerMustafa Quraish <[email protected]>2022-02-02 02:34:19 -0500
commitae3638402a41f1c75f59aa1da923d6f7ffd058ac (patch)
treed1f985eb73ce3def8aa3caa6220687af71a4d125 /src/ast.c
parentModify how types are stored. (diff)
downloadcup-ae3638402a41f1c75f59aa1da923d6f7ffd058ac.tar.xz
cup-ae3638402a41f1c75f59aa1da923d6f7ffd058ac.zip
Add `size_for_type()` helper instead of hard-coding variable sizes
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/ast.c b/src/ast.c
index edaf5c3..2a388bb 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -55,6 +55,16 @@ char *data_type_to_str(DataType type)
}
}
+i64 size_for_type(Type *type)
+{
+ switch (type->type)
+ {
+ case TYPE_INT: return 8;
+ case TYPE_PTR: return 8;
+ default: assert(false && "Unreachable type");
+ }
+}
+
Type *type_new(DataType type)
{
Type *t = calloc(sizeof(Type), 1);