diff options
| author | gingerBill <bill@gingerbill.org> | 2018-02-28 11:20:11 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-02-28 11:20:11 +0000 |
| commit | d3ea334e7ab2897bbc948acc57aa9ba073304215 (patch) | |
| tree | 8f6016ab7bd62c0320c893e0cb7fa6337054420f /src/ir.cpp | |
| parent | 223c473cf64845f0c0824375fa98ca51bad66fc1 (diff) | |
`cstring`
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index a1b3ca8ee..6ab3c9ef7 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -2890,6 +2890,14 @@ irValue *ir_string_len(irProcedure *proc, irValue *string) { return ir_emit_struct_ev(proc, string, 1); } +irValue *ir_cstring_len(irProcedure *proc, irValue *value) { + GB_ASSERT(is_type_cstring(ir_type(value))); + auto args = array_make<irValue *>(proc->module->allocator, 1); + args[0] = ir_emit_conv(proc, value, t_cstring); + return ir_emit_global_call(proc, "__cstring_len", args); +} + + void ir_fill_slice(irProcedure *proc, irValue *slice_ptr, irValue *data, irValue *len) { Type *t = ir_type(slice_ptr); @@ -3122,6 +3130,18 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { return ir_emit(proc, ir_instr_conv(proc, irConv_zext, b, t_llvm_bool, t)); } + if (src == t_cstring && is_type_u8_ptr(dst)) { + return ir_emit_bitcast(proc, value, dst); + } + + if (src == t_cstring && dst == t_string) { + irValue *c = ir_emit_conv(proc, value, t_cstring); + auto args = array_make<irValue *>(proc->module->allocator, 1); + args[0] = c; + irValue *s = ir_emit_global_call(proc, "__cstring_to_string", args); + return ir_emit_conv(proc, s, dst); + } + // integer -> boolean if (is_type_integer(src) && is_type_boolean(dst)) { @@ -4171,7 +4191,9 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv v = ir_emit_load(proc, v); t = type_deref(t); } - if (is_type_string(t)) { + if (is_type_cstring(t)) { + return ir_cstring_len(proc, v); + } else if (is_type_string(t)) { return ir_string_len(proc, v); } else if (is_type_array(t)) { GB_PANIC("Array lengths are constant"); @@ -7902,6 +7924,11 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info tag = ir_emit_conv(proc, variant_ptr, t_type_info_string_ptr); break; + case Basic_cstring: + tag = ir_emit_conv(proc, variant_ptr, t_type_info_string_ptr); + ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), v_true); // is_cstring + break; + case Basic_any: tag = ir_emit_conv(proc, variant_ptr, t_type_info_any_ptr); break; |