From 038d3bde71accea06a4e86bc9d3d9abf68b8d692 Mon Sep 17 00:00:00 2001 From: dosisod <39638017+dosisod@users.noreply.github.com> Date: Fri, 14 Aug 2020 16:01:06 -0700 Subject: [PATCH] added floats to skullc --- skullc/llvm/aliases.h | 5 +++++ skullc/llvm/var.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/skullc/llvm/aliases.h b/skullc/llvm/aliases.h index 9afa4251..c3e4a480 100644 --- a/skullc/llvm/aliases.h +++ b/skullc/llvm/aliases.h @@ -19,3 +19,8 @@ true \ ) +#define LLVM_FLOAT(ctx, str) \ + LLVMConstRealOfString( \ + LLVMFP128TypeInContext(ctx), \ + str \ + ) diff --git a/skullc/llvm/var.c b/skullc/llvm/var.c index 5936875c..aa348f34 100644 --- a/skullc/llvm/var.c +++ b/skullc/llvm/var.c @@ -32,6 +32,24 @@ void var_to_llvm_ir(variable_t *var, LLVMBuilderRef builder, LLVMContextRef ctx) ir_var ); } + if (var->type == &TYPE_FLOAT) { + LLVMValueRef ir_var = LLVMBuildAlloca( + builder, + LLVMFP128TypeInContext(ctx), + var_name + ); + + // suboptimal way of converting 64bit floats to llvm + char32_t *tmp = var->type->to_string(var); + char *var_as_str = c32stombs(tmp); + free(tmp); + + LLVMBuildStore( + builder, + LLVM_FLOAT(ctx, var_as_str), + ir_var + ); + } else if (var->type == &TYPE_BOOL) { LLVMValueRef ir_var = LLVMBuildAlloca( builder,