Skip to content

Commit

Permalink
added floats to skullc
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod committed Aug 14, 2020
1 parent 31b8bcf commit 038d3bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions skullc/llvm/aliases.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@
true \
)

#define LLVM_FLOAT(ctx, str) \
LLVMConstRealOfString( \
LLVMFP128TypeInContext(ctx), \
str \
)
18 changes: 18 additions & 0 deletions skullc/llvm/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 038d3bd

Please sign in to comment.