diff options
Diffstat (limited to 'src/codegen.c')
-rw-r--r-- | src/codegen.c | 81 |
1 files changed, 61 insertions, 20 deletions
diff --git a/src/codegen.c b/src/codegen.c index f835f5c..48c43ce 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1,4 +1,6 @@ +#include <ctype.h> #include <stdint.h> +#include <stdlib.h> #include <string.h> #include <llvm-c/Analysis.h> @@ -23,12 +25,18 @@ struct cgctx { struct strview namespace; }; -static LLVMTypeRef type2llvm(struct cgctx, struct type); +// static LLVMTypeRef type2llvm(struct cgctx, struct type); +// static void str2val(mpq_t, struct strview); +// static struct val *cvmap_insert(cvmap **, struct strview, arena *) +// __attribute__((nonnull(1))); void codegen(const char *file, struct type *types, struct ast ast, struct lexemes toks) { + (void)types; + (void)ast; + (void)toks; char *triple = LLVMGetDefaultTargetTriple(); struct cgctx ctx; @@ -55,22 +63,55 @@ codegen(const char *file, struct type *types, struct ast ast, LLVMContextDispose(ctx.ctx); } -LLVMTypeRef -type2llvm(struct cgctx ctx, struct type t) -{ - switch (t.kind) { - case TYPE_FN: - err("codegen: %s: Not implemented for function types", __func__); - case TYPE_NUM: - /* TODO: Floats */ - if (t.isfloat) - err("codegen: %s: Not implemented for floats", __func__); - /* TODO: Arbitrary precision */ - if (t.size == 0) - return LLVMInt64TypeInContext(ctx.ctx); - assert((unsigned)t.size * 8 <= UINT8_MAX); - return LLVMIntTypeInContext(ctx.ctx, t.size * 8); - default: - __builtin_unreachable(); - } -} +// LLVMTypeRef +// type2llvm(struct cgctx ctx, struct type t) +// { +// switch (t.kind) { +// case TYPE_FN: +// err("codegen: %s: Not implemented for function types", __func__); +// case TYPE_NUM: +// /* TODO: Floats */ +// if (t.isfloat) +// err("codegen: %s: Not implemented for floats", __func__); +// /* TODO: Arbitrary precision */ +// if (t.size == 0) +// return LLVMInt64TypeInContext(ctx.ctx); +// assert((unsigned)t.size * 8 <= UINT8_MAX); +// return LLVMIntTypeInContext(ctx.ctx, t.size * 8); +// default: +// __builtin_unreachable(); +// } +// } +// +// void +// str2val(mpq_t rop, struct strview sv) +// { +// mpq_init(rop); +// char *clean = bufalloc(NULL, sv.len + 1, 1); +// size_t len = 0; +// +// for (size_t i = 0; i < sv.len; i++) { +// if (isdigit(sv.p[i])) +// clean[len++] = sv.p[i]; +// } +// clean[len] = 0; +// +// mpq_set_str(rop, clean, 10); +// +// free(clean); +// } +// +// struct val * +// cvmap_insert(cvmap **m, struct strview k, arena *a) +// { +// for (uint64_t h = strview_hash(k); *m; h <<= 2) { +// if (strview_eq(k, (*m)->key)) +// return &(*m)->val; +// m = &(*m)->child[h >> 62]; +// } +// if (a == NULL) +// return NULL; +// *m = arena_new(a, cvmap, 1); +// (*m)->key = k; +// return &(*m)->val; +// } |