aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-07-26 23:51:58 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-07-26 23:51:58 -0700
commit06c4b35eb12a54a4e260a80ed8ed21eb5bfae09a (patch)
tree33d8366daa35741ce302df23e2be1e217aa20187 /src/codegen.cpp
parentbc81ddfea67db0b3756027e98cc00bb8fa903a20 (diff)
downloadzig-06c4b35eb12a54a4e260a80ed8ed21eb5bfae09a.tar.gz
zig-06c4b35eb12a54a4e260a80ed8ed21eb5bfae09a.zip
std: improve rand implementation and API
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index d33c10116a..59ce94e02e 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -1007,6 +1007,31 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
return cast_expr->tmp_ptr;
}
+ case CastOpBytesToSlice:
+ {
+ assert(cast_expr->tmp_ptr);
+ assert(wanted_type->id == TypeTableEntryIdStruct);
+ assert(wanted_type->data.structure.is_slice);
+ assert(actual_type->id == TypeTableEntryIdArray);
+
+ TypeTableEntry *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry;
+ TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
+
+ set_debug_source_node(g, node);
+
+ int wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
+ LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_ptr_index, "");
+ LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, expr_val, wanted_pointer_type->type_ref, "");
+ LLVMBuildStore(g->builder, src_ptr_casted, dest_ptr_ptr);
+
+ int wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
+ LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_len_index, "");
+ LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
+ actual_type->data.array.len / type_size(g, wanted_child_type), false);
+ LLVMBuildStore(g->builder, len_val, len_ptr);
+
+ return cast_expr->tmp_ptr;
+ }
case CastOpIntToFloat:
assert(actual_type->id == TypeTableEntryIdInt);
if (actual_type->data.integral.is_signed) {